mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
ec7d85835f
commit
63b65a7e20
7 changed files with 58 additions and 10 deletions
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
divesToAdd.push_back({ OwningDivePtr(clone_dive(d)), nullptr, d->divetrip, idx });
|
||||
// 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({ std::move(divePtr), std::move(allocTrip), trip, idx });
|
||||
}
|
||||
|
||||
bool AddDive::workToBeDone()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue