Undo: implement rudimentary support for undo of dive-splitting

For this, the core functionality of the split_dive() and
split_dive_at_time() functions were split out into new
split_dive_dont_insert() and split_dive_at_time_dont_insert(),
which do not add the new dives to the log. Thus, the undo-command
can take ownership of these dives, without having to remove them
first.

The split-dive functionality is temporarily made desktop-only
until mobile also supports "UndoObjects".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-07-20 20:26:06 +02:00 committed by Dirk Hohndel
parent 12df9faaa2
commit 302f6adb79
6 changed files with 145 additions and 36 deletions

View file

@ -23,6 +23,7 @@
#include "desktop-widgets/diveplanner.h"
#include "desktop-widgets/simplewidgets.h"
#include "desktop-widgets/divepicturewidget.h"
#include "desktop-widgets/undocommands.h"
#include "desktop-widgets/mainwindow.h"
#include "core/qthelper.h"
#include "core/gettextfromc.h"
@ -1675,16 +1676,19 @@ void ProfileWidget2::addSetpointChange()
void ProfileWidget2::splitDive()
{
#ifndef SUBSURFACE_MOBILE
// Make sure that this is an actual dive and we're not in add mode
dive *d = get_dive_by_uniq_id(displayed_dive.id);
if (!d)
return;
QAction *action = qobject_cast<QAction *>(sender());
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
duration_t time;
time.seconds = lrint(timeAxis->valueAt((scenePos)));
split_dive_at_time(&displayed_dive, time);
time.seconds = lrint(timeAxis->valueAt(scenePos));
UndoSplitDives *undoCommand = new UndoSplitDives(d, time);
MainWindow::instance()->undoStack->push(undoCommand);
emit updateDiveInfo(false);
mark_divelist_changed(true);
replot();
MainWindow::instance()->refreshProfile();
MainWindow::instance()->refreshDisplay();
#endif
}
void ProfileWidget2::changeGas()