2018-07-23 21:41:23 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
// Note: this header file is used by the undo-machinery and should not be included elsewhere.
|
|
|
|
|
|
|
|
#ifndef COMMAND_DIVELIST_H
|
|
|
|
#define COMMAND_DIVELIST_H
|
|
|
|
|
|
|
|
#include "command_base.h"
|
2020-06-28 13:24:19 +00:00
|
|
|
#include "core/filterpreset.h"
|
2020-10-17 14:07:39 +00:00
|
|
|
#include "core/device.h"
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
|
|
|
|
namespace Command {
|
|
|
|
|
|
|
|
// This helper structure describes a dive that we want to add.
|
|
|
|
struct DiveToAdd {
|
2024-05-16 18:11:21 +00:00
|
|
|
std::unique_ptr<struct dive> dive; // Dive to add
|
|
|
|
dive_trip *trip; // Trip the dive belongs to, may be null
|
|
|
|
dive_site *site; // Site the dive is associated with, may be null
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
2019-03-03 14:12:22 +00:00
|
|
|
// Multiple trips, dives and dive sites that have to be added for a command
|
2018-11-26 21:06:17 +00:00
|
|
|
struct DivesAndTripsToAdd {
|
|
|
|
std::vector<DiveToAdd> dives;
|
2024-05-31 15:15:47 +00:00
|
|
|
std::vector<std::unique_ptr<dive_trip>> trips;
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sites;
|
2019-03-03 14:12:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Dives and sites that have to be removed for a command
|
|
|
|
struct DivesAndSitesToRemove {
|
|
|
|
std::vector<dive *> dives;
|
|
|
|
std::vector<dive_site *> sites;
|
2018-11-26 21:06:17 +00:00
|
|
|
};
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
// This helper structure describes a dive that should be moved to / removed from
|
|
|
|
// a trip. If the "trip" member is null, the dive is removed from its trip (if
|
|
|
|
// it is in a trip, that is)
|
|
|
|
struct DiveToTrip
|
|
|
|
{
|
|
|
|
struct dive *dive;
|
|
|
|
dive_trip *trip;
|
|
|
|
};
|
|
|
|
|
2018-11-26 21:06:17 +00:00
|
|
|
// This helper structure describes a number of dives to add to / remove from /
|
2018-07-23 21:41:23 +00:00
|
|
|
// move between trips.
|
|
|
|
// It has ownership of the trips (if any) that have to be added before hand.
|
|
|
|
struct DivesToTrip
|
|
|
|
{
|
|
|
|
std::vector<DiveToTrip> divesToMove; // If dive_trip is null, remove from trip
|
2024-05-31 15:15:47 +00:00
|
|
|
std::vector<std::unique_ptr<dive_trip>> tripsToAdd;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
2019-06-23 10:13:25 +00:00
|
|
|
// All divelist commands derive from a common base class. It keeps track
|
|
|
|
// of dive site counts that may have changed.
|
|
|
|
// Derived classes implement the virtual methods redoit() and undoit()
|
|
|
|
// [Yes, the names could be more expressive].
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
class DiveListBase : public Base {
|
|
|
|
protected:
|
2019-06-23 10:13:25 +00:00
|
|
|
// These are helper functions to add / remove dive from the C-core structures.
|
2024-05-31 15:15:47 +00:00
|
|
|
DiveToAdd removeDive(struct dive *d, std::vector<std::unique_ptr<dive_trip>> &tripsToAdd);
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
dive *addDive(DiveToAdd &d);
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndTripsToAdd removeDives(DivesAndSitesToRemove &divesAndSitesToDelete);
|
|
|
|
DivesAndSitesToRemove addDives(DivesAndTripsToAdd &toAdd);
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
|
2019-03-10 15:03:39 +00:00
|
|
|
// Register dive sites where counts changed so that we can signal the frontend later.
|
|
|
|
void diveSiteCountChanged(struct dive_site *ds);
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
private:
|
2019-03-10 15:03:39 +00:00
|
|
|
// Keep track of dive sites where the number of dives changed
|
|
|
|
std::vector<dive_site *> sitesCountChanged;
|
2019-06-23 10:13:25 +00:00
|
|
|
void initWork();
|
|
|
|
void finishWork(); // update dive site counts
|
2018-07-23 21:41:23 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
virtual void redoit() = 0;
|
|
|
|
virtual void undoit() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AddDive : public DiveListBase {
|
|
|
|
public:
|
2024-06-21 14:43:27 +00:00
|
|
|
AddDive(std::unique_ptr<struct dive> dive, bool autogroup, bool newNumber);
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
private:
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo
|
2018-11-26 21:06:17 +00:00
|
|
|
// Note: we a multi-dive structure even though we add only a single dive, so
|
Dive list: implement proper Qt-model semantics for DiveTripModel
Previously, each dive-list modifying function would lead to a
full model reset. Instead, implement proper Qt-model semantics
using beginInsertRows()/endInsertRows(), beginRemoveRows()/
endRemoveRows(), dataChange().
To do so, a DiveListNotifer singleton is generatated, which
broadcasts all changes to the dive-list. Signals are sent by
the commands and received by the DiveTripModel. Signals are
batched by dive-trip. This seems to be an adequate compromise
for the two kinds of list-views (tree and list). In the common
usecase mostly dives of a single trip are affected.
Thus, batching of dives is performed in two positions:
- At command-level to batch by trip
- In DiveTripModel to feed batches of contiguous elements
to Qt's begin*/end*-functions.
This is conceptually simple, but rather complex code. To avoid
repetition of complex loops, the batching is implemented in
templated-functions, which are passed lambda-functions, which
are called for each batch.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-30 07:20:25 +00:00
|
|
|
// that we can reuse the multi-dive functions of the other commands.
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd divesToAdd;
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
// For undo
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove divesAndSitesToRemove;
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
std::vector<dive *> selection;
|
|
|
|
dive * currentDive;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
2018-12-23 22:45:12 +00:00
|
|
|
class ImportDives : public DiveListBase {
|
|
|
|
public:
|
|
|
|
// Note: dives and trips are consumed - after the call they will be empty.
|
2022-11-12 07:40:04 +00:00
|
|
|
ImportDives(struct divelog *log, int flags, const QString &source);
|
2018-12-23 22:45:12 +00:00
|
|
|
private:
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo and undo
|
|
|
|
DivesAndTripsToAdd divesToAdd;
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove divesAndSitesToRemove;
|
2024-05-31 05:08:54 +00:00
|
|
|
device_table devicesToAddAndRemove;
|
2019-03-03 14:12:22 +00:00
|
|
|
|
|
|
|
// For redo
|
2024-05-04 11:39:04 +00:00
|
|
|
std::vector<std::unique_ptr<dive_site>> sitesToAdd;
|
2024-02-29 12:39:17 +00:00
|
|
|
std::vector<std::pair<std::string,FilterData>>
|
2020-06-28 13:24:19 +00:00
|
|
|
filterPresetsToAdd;
|
2018-12-23 22:45:12 +00:00
|
|
|
|
|
|
|
// For undo
|
2019-03-03 14:12:22 +00:00
|
|
|
std::vector<dive_site *> sitesToRemove;
|
2020-06-28 13:24:19 +00:00
|
|
|
std::vector<dive *> selection;
|
|
|
|
dive *currentDive;
|
|
|
|
std::vector<int> filterPresetsToRemove;
|
2018-12-23 22:45:12 +00:00
|
|
|
};
|
|
|
|
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
class DeleteDive : public DiveListBase {
|
2018-07-23 21:41:23 +00:00
|
|
|
public:
|
|
|
|
DeleteDive(const QVector<dive *> &divesToDelete);
|
|
|
|
private:
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove divesToDelete;
|
2018-07-23 21:41:23 +00:00
|
|
|
|
2024-05-31 15:15:47 +00:00
|
|
|
std::vector<std::unique_ptr<dive_trip>> tripsToAdd;
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd divesToAdd;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
class ShiftTime : public DiveListBase {
|
2018-07-23 21:41:23 +00:00
|
|
|
public:
|
2020-01-03 15:04:54 +00:00
|
|
|
ShiftTime(std::vector<dive *> changedDives, int amount);
|
2018-07-23 21:41:23 +00:00
|
|
|
private:
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo and undo
|
2020-01-03 15:04:54 +00:00
|
|
|
std::vector<dive *> diveList;
|
2018-07-23 21:41:23 +00:00
|
|
|
int timeChanged;
|
|
|
|
};
|
|
|
|
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
class RenumberDives : public DiveListBase {
|
2018-07-23 21:41:23 +00:00
|
|
|
public:
|
2018-07-30 13:55:29 +00:00
|
|
|
RenumberDives(const QVector<QPair<dive *, int>> &divesToRenumber);
|
2018-07-23 21:41:23 +00:00
|
|
|
private:
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo and undo: pairs of dive-id / new number
|
2018-07-30 13:55:29 +00:00
|
|
|
QVector<QPair<dive *, int>> divesToRenumber;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The classes RemoveDivesFromTrip, RemoveAutogenTrips, CreateTrip, AutogroupDives
|
|
|
|
// and MergeTrips all do the same thing, just the intialization differs.
|
|
|
|
// Therefore, define a base class with the proper data-structures, redo()
|
|
|
|
// and undo() functions and derive to specialize the initialization.
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
class TripBase : public DiveListBase {
|
2018-07-23 21:41:23 +00:00
|
|
|
protected:
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo and undo
|
|
|
|
DivesToTrip divesToMove;
|
|
|
|
};
|
|
|
|
struct RemoveDivesFromTrip : public TripBase {
|
|
|
|
RemoveDivesFromTrip(const QVector<dive *> &divesToRemove);
|
|
|
|
};
|
|
|
|
struct RemoveAutogenTrips : public TripBase {
|
|
|
|
RemoveAutogenTrips();
|
|
|
|
};
|
|
|
|
struct AddDivesToTrip : public TripBase {
|
|
|
|
AddDivesToTrip(const QVector<dive *> &divesToAdd, dive_trip *trip);
|
|
|
|
};
|
|
|
|
struct CreateTrip : public TripBase {
|
|
|
|
CreateTrip(const QVector<dive *> &divesToAdd);
|
|
|
|
};
|
|
|
|
struct AutogroupDives : public TripBase {
|
|
|
|
AutogroupDives();
|
|
|
|
};
|
|
|
|
struct MergeTrips : public TripBase {
|
|
|
|
MergeTrips(dive_trip *trip1, dive_trip *trip2);
|
|
|
|
};
|
|
|
|
|
2019-03-31 08:20:13 +00:00
|
|
|
class SplitDivesBase : public DiveListBase {
|
|
|
|
protected:
|
2024-06-03 19:50:08 +00:00
|
|
|
SplitDivesBase(dive *old, std::array<std::unique_ptr<dive>, 2> newDives);
|
2018-07-23 21:41:23 +00:00
|
|
|
private:
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
|
|
|
|
|
|
|
// For redo
|
|
|
|
// For each dive to split, we remove one from and put two dives into the backend
|
2018-08-10 12:02:02 +00:00
|
|
|
// Note: we use a vector even though we split only a single dive, so
|
|
|
|
// that we can reuse the multi-dive functions of the other commands.
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove diveToSplit;
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd splitDives;
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
// For undo
|
|
|
|
// For each dive to unsplit, we remove two dives from and add one into the backend
|
2018-11-26 21:06:17 +00:00
|
|
|
// Note: we use a multi-dive structure even though we unsplit only a single dive, so
|
2018-08-10 12:02:02 +00:00
|
|
|
// that we can reuse the multi-dive functions of the other commands.
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd unsplitDive;
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove divesToUnsplit;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
2019-03-31 08:20:13 +00:00
|
|
|
class SplitDives : public SplitDivesBase {
|
|
|
|
public:
|
|
|
|
// If time is < 0, split at first surface interval
|
|
|
|
SplitDives(dive *d, duration_t time);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SplitDiveComputer : public SplitDivesBase {
|
|
|
|
public:
|
|
|
|
// If time is < 0, split at first surface interval
|
|
|
|
SplitDiveComputer(dive *d, int dc_num);
|
|
|
|
};
|
|
|
|
|
2019-05-19 12:27:10 +00:00
|
|
|
// When manipulating dive computers (moving, deleting) we go the ineffective,
|
|
|
|
// but simple and robust way: We keep two full copies of the dive (before and after).
|
2019-05-17 20:22:55 +00:00
|
|
|
// Removing and readding assures that the dive stays at the correct
|
|
|
|
// position in the list (the dive computer list is used for sorting dives).
|
2019-05-19 12:27:10 +00:00
|
|
|
class DiveComputerBase : public DiveListBase {
|
|
|
|
protected:
|
|
|
|
// old_dive must be a dive known to the core.
|
|
|
|
// new_dive must be new dive whose ownership is taken.
|
2024-06-04 05:10:22 +00:00
|
|
|
DiveComputerBase(dive *old_dive, std::unique_ptr<dive> new_dive, int dc_nr_before, int dc_nr_after);
|
2019-05-17 20:22:55 +00:00
|
|
|
private:
|
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
|
|
|
bool workToBeDone() override;
|
|
|
|
|
2019-05-19 12:27:10 +00:00
|
|
|
protected:
|
2019-05-17 20:22:55 +00:00
|
|
|
// For redo and undo
|
|
|
|
DivesAndTripsToAdd diveToAdd;
|
|
|
|
DivesAndSitesToRemove diveToRemove;
|
2019-05-19 16:43:21 +00:00
|
|
|
int dc_nr_before, dc_nr_after;
|
2019-05-17 20:22:55 +00:00
|
|
|
};
|
|
|
|
|
2019-05-19 12:27:10 +00:00
|
|
|
class MoveDiveComputerToFront : public DiveComputerBase {
|
|
|
|
public:
|
|
|
|
MoveDiveComputerToFront(dive *d, int dc_num);
|
|
|
|
};
|
|
|
|
|
|
|
|
class DeleteDiveComputer : public DiveComputerBase {
|
|
|
|
public:
|
|
|
|
DeleteDiveComputer(dive *d, int dc_num);
|
|
|
|
};
|
|
|
|
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
class MergeDives : public DiveListBase {
|
2018-07-23 21:41:23 +00:00
|
|
|
public:
|
|
|
|
MergeDives(const QVector<dive *> &dives);
|
|
|
|
private:
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void undoit() override;
|
|
|
|
void redoit() override;
|
2018-07-23 21:41:23 +00:00
|
|
|
bool workToBeDone() override;
|
2024-09-01 12:12:05 +00:00
|
|
|
void swapDivesite(); // Common code for undo and redo.
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
// For redo
|
|
|
|
// Add one and remove a batch of dives
|
2018-11-26 21:06:17 +00:00
|
|
|
// Note: we use a multi-dives structure even though we add only a single dive, so
|
2018-08-10 12:02:02 +00:00
|
|
|
// that we can reuse the multi-dive functions of the other commands.
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd mergedDive;
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove divesToMerge;
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
// For undo
|
|
|
|
// Remove one and add a batch of dives
|
2018-08-10 12:02:02 +00:00
|
|
|
// Note: we use a vector even though we remove only a single dive, so
|
|
|
|
// that we can reuse the multi-dive functions of the other commands.
|
2019-03-03 14:12:22 +00:00
|
|
|
DivesAndSitesToRemove diveToUnmerge;
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd unmergedDives;
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
// For undo and redo
|
2018-07-30 13:55:29 +00:00
|
|
|
QVector<QPair<dive *, int>> divesToRenumber;
|
2024-09-01 12:12:05 +00:00
|
|
|
dive_site *site;
|
|
|
|
location_t location;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
#endif // COMMAND_DIVELIST_H
|