From 145f70aab59a5ebd1b4ca82432caf38b4821b055 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 31 Mar 2019 10:20:13 +0200 Subject: Undo: implement split-out of dive computer Allow splitting out a dive computer into a distinct dive. This is realized by generating a base class from SplitDive. This turned out to be more cumbersome than expected: we don't know a-priori which of the split dives will come first. Since the undo-command saves the indices where the dives will be insert, these have to be calculated. This is an premature optimization, which makes more pain than necessary. Let's remove it and simply determine the insertion index when executing the command. Original code by Linus Torvalds . Signed-off-by: Berthold Stoeger Signed-off-by: Dirk Hohndel --- profile-widget/profilewidget2.cpp | 9 ++++++++- profile-widget/profilewidget2.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'profile-widget') diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 5d282fd95..157ab9fcd 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1436,8 +1436,10 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) // create menu to show when right clicking on dive computer name if (dc_number > 0) m.addAction(tr("Make first dive computer"), this, SLOT(makeFirstDC())); - if (count_divecomputers() > 1) + if (count_divecomputers() > 1) { m.addAction(tr("Delete this dive computer"), this, SLOT(deleteCurrentDC())); + m.addAction(tr("Split this dive computer into own dive"), this, SLOT(splitCurrentDC())); + } m.exec(event->globalPos()); // don't show the regular profile context menu return; @@ -1581,6 +1583,11 @@ void ProfileWidget2::deleteCurrentDC() emit refreshDisplay(true); } +void ProfileWidget2::splitCurrentDC() +{ + Command::splitDiveComputer(current_dive, dc_number); +} + void ProfileWidget2::makeFirstDC() { make_first_dc(); diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 443b83c64..4cf69efa6 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -126,6 +126,7 @@ slots: // Necessary to call from QAction's signals. void editName(); void makeFirstDC(); void deleteCurrentDC(); + void splitCurrentDC(); void pointInserted(const QModelIndex &parent, int start, int end); void pointsRemoved(const QModelIndex &, int start, int end); void updateThumbnail(QString filename, QImage thumbnail, duration_t duration); -- cgit v1.2.3-70-g09d2