diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-30 10:33:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:22:27 -0700 |
commit | 63b65a7e20615d7e049ab09ae7dc6053d705c04b (patch) | |
tree | 870e1872e70cea37eabcedaea5564721cab79ed4 /desktop-widgets | |
parent | ec7d85835fb26ee9c0a9c780907441c312d7ac3f (diff) | |
download | subsurface-63b65a7e20615d7e049ab09ae7dc6053d705c04b.tar.gz |
Undo: implement autogrouping of trips in DiveAdd
If the autogroup flag is set, search for appropriate trips in
DiveAdd() and add the dive to this trip. If no trip exists, add
a new trip.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/command.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/command.h | 2 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 25 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.h | 2 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 2 |
5 files changed, 25 insertions, 10 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index a86b1fe76..fe16f1898 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -6,9 +6,9 @@ namespace Command { // Dive-list related commands -void addDive(dive *d) +void addDive(dive *d, bool autogroup) { - execute(new AddDive(d)); + execute(new AddDive(d, autogroup)); } void deleteDive(const QVector<struct dive*> &divesToDelete) diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index 213d8bcda..924365806 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -15,7 +15,7 @@ QAction *undoAction(QObject *parent); // Create an undo action. QAction *redoAction(QObject *parent); // Create an redo action. // Dive-list related commands -void addDive(dive *d); +void addDive(dive *d, bool autogroup); void deleteDive(const QVector<struct dive*> &divesToDelete); void shiftTime(const QVector<dive *> &changedDives, int amount); void renumberDives(const QVector<QPair<int, int>> &divesToRenumber); diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index bca6967e6..732932de3 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -289,16 +289,31 @@ static void moveDivesBetweenTrips(DivesToTrip &dives) std::reverse(dives.divesToMove.begin(), dives.divesToMove.end()); } -AddDive::AddDive(dive *d) +AddDive::AddDive(dive *d, bool autogroup) { setText(tr("add dive")); d->maxdepth.mm = 0; fixup_dive(d); - d->divetrip = nullptr; // TODO: consider autogroup == true - int idx = dive_get_insertion_index(d); - d->number = get_dive_nr_at_idx(idx); + d->divetrip = nullptr; + + // Get an owning pointer to a copy of the dive + // Note: this destroys the old dive! + OwningDivePtr divePtr(clone_dive(d)); + + // If we alloc a new-trip for autogrouping, get an owning pointer to it. + OwningTripPtr allocTrip; + dive_trip *trip = nullptr; + if (autogroup) { + bool alloc; + trip = get_trip_for_new_dive(divePtr.get(), &alloc); + if (alloc) + allocTrip.reset(trip); + } + + int idx = dive_get_insertion_index(divePtr.get()); + divePtr->number = get_dive_nr_at_idx(idx); - divesToAdd.push_back({ OwningDivePtr(clone_dive(d)), nullptr, d->divetrip, idx }); + divesToAdd.push_back({ std::move(divePtr), std::move(allocTrip), trip, idx }); } bool AddDive::workToBeDone() diff --git a/desktop-widgets/command_divelist.h b/desktop-widgets/command_divelist.h index e09d3bdc6..69824ce9f 100644 --- a/desktop-widgets/command_divelist.h +++ b/desktop-widgets/command_divelist.h @@ -40,7 +40,7 @@ struct DivesToTrip class AddDive : public Base { public: - AddDive(dive *dive); + AddDive(dive *dive, bool autogroup); private: void undo() override; void redo() override; diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 1f4fbc518..5f740b969 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -799,7 +799,7 @@ void MainTab::acceptChanges() updateDiveSite(ui.location->currDiveSiteUuid(), &displayed_dive); copyTagsToDisplayedDive(); - Command::addDive(&displayed_dive); + Command::addDive(&displayed_dive, autogroup); editMode = NONE; MainWindow::instance()->exitEditState(); |