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"
|
|
|
|
|
|
|
|
#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.
|
|
|
|
// Potentially it also adds a trip (if deletion of the dive resulted in deletion of the trip)
|
|
|
|
struct DiveToAdd {
|
|
|
|
OwningDivePtr dive; // Dive to add
|
|
|
|
dive_trip *trip; // Trip the dive belongs to, may be null
|
|
|
|
int idx; // Position in divelist
|
|
|
|
};
|
|
|
|
|
2018-11-26 21:06:17 +00:00
|
|
|
// Multiple trips and dives that have to be added for a command
|
|
|
|
struct DivesAndTripsToAdd {
|
|
|
|
std::vector<DiveToAdd> dives;
|
|
|
|
std::vector<OwningTripPtr> trips;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
std::vector<OwningTripPtr> 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
|
|
|
// All divelist commands derive from a common base class, which has a flag
|
|
|
|
// for when then selection changed. In such a case, in the redo() and undo()
|
|
|
|
// methods a signal will be sent. The base-class implements redo() and undo(),
|
|
|
|
// which resets the flag and sends a signal. Derived classes implement the
|
|
|
|
// virtual methods redoit() and undoit() [Yes, the names could be more expressive].
|
|
|
|
// Moreover, the class implements helper methods, which set the selectionChanged
|
|
|
|
// flag accordingly.
|
|
|
|
class DiveListBase : public Base {
|
|
|
|
protected:
|
|
|
|
// These are helper functions to add / remove dive from the C-core structures,
|
|
|
|
// which set the selectionChanged flag if the added / removed dive was selected.
|
2018-11-26 21:06:17 +00:00
|
|
|
DiveToAdd removeDive(struct dive *d, std::vector<OwningTripPtr> &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);
|
2018-11-26 21:06:17 +00:00
|
|
|
DivesAndTripsToAdd removeDives(std::vector<dive *> &divesToDelete);
|
|
|
|
std::vector<dive *> 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
|
|
|
|
|
|
|
// Set the selection to a given state. Set the selectionChanged flag if anything changed.
|
|
|
|
void restoreSelection(const std::vector<dive *> &selection, dive *currentDive);
|
|
|
|
|
|
|
|
// Commands set this flag if the selection changed on first execution.
|
|
|
|
// Only then, a new the divelist will be scanned again after the command.
|
|
|
|
// If this flag is set on first execution, a selectionChanged signal will
|
|
|
|
// be sent.
|
|
|
|
bool selectionChanged;
|
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 initWork(); // reset selectionChanged flag
|
|
|
|
void finishWork(); // emit signal if selection changed
|
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:
|
Undo: make adding of planned dive undo-able
Planned dives were still added by directly calling core code.
This could confuse the undo-machinery, leading to crashes.
Instead, use the proper undo-command. The problem is that as
opposed to the other AddDive-commands, planned dives may
belong to a trip. Thus, the interface to the AddDive command
was changed to respect the divetrip field. Make sure that
the other callers reset that field (actually, it should never
be set). Add a comment describing the perhaps surprising
interface (the passed-in dive, usually displayed dive, is
reset).
Moreover, a dive cloned in the planner is not assigned a
new number. Thus, add an argument to the AddDive-command,
which expresses whether a new number should be generated
for the to-be-added dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-08 17:58:11 +00:00
|
|
|
AddDive(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
|
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
|
|
|
std::vector<dive *> divesToRemove;
|
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.
|
2019-01-13 20:53:57 +00:00
|
|
|
ImportDives(struct dive_table *dives, struct trip_table *trips, 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;
|
|
|
|
std::vector<dive *> divesToRemove;
|
|
|
|
|
|
|
|
// For undo
|
|
|
|
std::vector<dive *> selection;
|
|
|
|
dive * currentDive;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
std::vector<struct dive*> divesToDelete;
|
|
|
|
|
|
|
|
std::vector<OwningTripPtr> 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:
|
|
|
|
ShiftTime(const QVector<dive *> &changedDives, int amount);
|
|
|
|
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
|
|
|
|
QVector<dive *> diveList;
|
|
|
|
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:
|
|
|
|
SplitDivesBase(dive *old, std::array<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.
|
|
|
|
std::vector<dive *> 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;
|
2018-08-10 12:02:02 +00:00
|
|
|
std::vector<dive *> 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);
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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;
|
2018-08-10 12:02:02 +00:00
|
|
|
std::vector<dive *> 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.
|
|
|
|
std::vector<dive *> 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;
|
2018-07-23 21:41:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
#endif // COMMAND_DIVELIST_H
|