undo: more fine-grained undo of profile editing

Place undo commands for every change of the profile, not
only on "saving". Move the edit-mode from the mainwindow
and the maintab to the profile widget.

This is still very rough. For example, the only way to exit
the edit mode is changing the current dive.

The undo-commands are placed by the desktop-profile widget.
We might think about moving that down to the profile-view so
that this will be useable on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-02-19 11:58:36 +01:00
parent c5c8bfec65
commit fce48367cd
12 changed files with 162 additions and 100 deletions

View file

@ -28,21 +28,21 @@ CylindersModel *DivePlannerPointsModel::cylindersModel()
return &cylinders;
}
void DivePlannerPointsModel::removePoints(const QVector<int> &rows)
void DivePlannerPointsModel::removePoints(const std::vector<int> &rows)
{
if (!rows.count())
if (rows.empty())
return;
QVector<int> v2 = rows;
std::vector<int> v2 = rows;
std::sort(v2.begin(), v2.end());
for (int i = v2.count() - 1; i >= 0; i--) {
for (int i = (int)v2.size() - 1; i >= 0; i--) {
beginRemoveRows(QModelIndex(), v2[i], v2[i]);
divepoints.erase(divepoints.begin() + v2[i]);
endRemoveRows();
}
}
void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
void DivePlannerPointsModel::removeSelectedPoints(const std::vector<int> &rows)
{
removePoints(rows);
@ -230,7 +230,7 @@ bool DivePlannerPointsModel::updateMaxDepth()
void DivePlannerPointsModel::removeDeco()
{
QVector<int> computedPoints;
std::vector<int> computedPoints;
for (int i = 0; i < rowCount(); i++) {
if (!at(i).entered)
computedPoints.push_back(i);

View file

@ -4,6 +4,7 @@
#include <QAbstractTableModel>
#include <QDateTime>
#include <vector>
#include "core/deco.h"
#include "core/planner.h"
@ -36,7 +37,7 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const override;
void gasChange(const QModelIndex &index, int newcylinderid);
void cylinderRenumber(int mapping[]);
void removeSelectedPoints(const QVector<int> &rows);
void removeSelectedPoints(const std::vector<int> &rows);
void setPlanMode(Mode mode);
bool isPlanner() const;
void createSimpleDive(struct dive *d);
@ -116,7 +117,7 @@ private:
explicit DivePlannerPointsModel(QObject *parent = 0);
void clear();
int addStop(int millimeters, int seconds, int cylinderid_in, int ccpoint, bool entered, enum divemode_t);
void removePoints(const QVector<int> &rows);
void removePoints(const std::vector<int> &rows);
void setupStartTime();
void setupCylinders();
int lastEnteredPoint() const;