summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-02 21:19:29 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-05 10:14:25 -0800
commit147a36647ce6148ef2eccbe393faa658d0fe6834 (patch)
tree853ff1272cfdb8859a81a60f886dbf55dbd29bbc /qt-models
parent76a5a38f5e8aad339061f534df8130b426079a03 (diff)
downloadsubsurface-147a36647ce6148ef2eccbe393faa658d0fe6834.tar.gz
Undo: make adding of weights an undoable action
Introduce an AddWeight undo command. This is modelled after the numerous dive-edit undo commands. The redo and undo actions are connected to the WeightModel via two new signals, weightAdded and weightRemoved. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/weightmodel.cpp35
-rw-r--r--qt-models/weightmodel.h3
2 files changed, 26 insertions, 12 deletions
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index dafd9d277..ceac7617c 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -15,6 +15,8 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
//enum Column {REMOVE, TYPE, WEIGHT};
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
connect(&diveListNotifier, &DiveListNotifier::weightsystemsReset, this, &WeightModel::weightsystemsReset);
+ connect(&diveListNotifier, &DiveListNotifier::weightAdded, this, &WeightModel::weightAdded);
+ connect(&diveListNotifier, &DiveListNotifier::weightRemoved, this, &WeightModel::weightRemoved);
}
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
@@ -146,17 +148,6 @@ int WeightModel::rowCount(const QModelIndex&) const
return rows;
}
-void WeightModel::add()
-{
- int row = rows;
- weightsystem_t ws { {0}, "" };
- beginInsertRows(QModelIndex(), row, row);
- add_cloned_weightsystem(&d->weightsystems, ws);
- rows++;
- changed = true;
- endInsertRows();
-}
-
void WeightModel::updateDive(dive *dIn)
{
beginResetModel();
@@ -175,3 +166,25 @@ void WeightModel::weightsystemsReset(const QVector<dive *> &dives)
// And update the model..
updateDive(d);
}
+
+void WeightModel::weightAdded(struct dive *changed, int pos)
+{
+ if (d != changed)
+ return;
+
+ // The last row was already inserted by the undo command. Just inform the model.
+ beginInsertRows(QModelIndex(), pos, pos);
+ rows++;
+ endInsertRows();
+}
+
+void WeightModel::weightRemoved(struct dive *changed, int pos)
+{
+ if (d != changed)
+ return;
+
+ // The row was already deleted by the undo command. Just inform the model.
+ beginRemoveRows(QModelIndex(), pos, pos);
+ rows--;
+ endRemoveRows();
+}
diff --git a/qt-models/weightmodel.h b/qt-models/weightmodel.h
index 444d8611e..bb2c63778 100644
--- a/qt-models/weightmodel.h
+++ b/qt-models/weightmodel.h
@@ -23,7 +23,6 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void passInData(const QModelIndex &index, const QVariant &value);
- void add();
void clear();
void updateDive(dive *d);
weightsystem_t *weightSystemAt(const QModelIndex &index);
@@ -33,6 +32,8 @@ public
slots:
void remove(QModelIndex index);
void weightsystemsReset(const QVector<dive *> &dives);
+ void weightAdded(dive *d, int pos);
+ void weightRemoved(dive *d, int pos);
private:
dive *d;