summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-02-23 22:09:34 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit9fd87fa08081116ba12812ddea0a43be61019cbb (patch)
treeeaaa75a9455bdb82a1174208d2ed352e44e91f32 /qt-models
parent9ed5cf16a4a0f982f0fae170740ee2886f634a14 (diff)
downloadsubsurface-9fd87fa08081116ba12812ddea0a43be61019cbb.tar.gz
Undo: update cylinder and weight models on paste
When pasting (or undoing paste) the cylinders or weights may change. Send the appropriate signals and update the models accordingly. Currently, this means copying from current dive to displayed dive, but hopefully we can get rid of "displayed_dive" in the not so distant future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/cylindermodel.cpp16
-rw-r--r--qt-models/cylindermodel.h1
-rw-r--r--qt-models/weightmodel.cpp16
-rw-r--r--qt-models/weightmodel.h1
4 files changed, 34 insertions, 0 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 9796907cf..83c520634 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -6,6 +6,7 @@
#include "core/color.h"
#include "qt-models/diveplannermodel.h"
#include "core/gettextfromc.h"
+#include "core/subsurface-qt/DiveListNotifier.h"
CylindersModel::CylindersModel(QObject *parent) :
CleanerTableModel(parent),
@@ -16,6 +17,7 @@ CylindersModel::CylindersModel(QObject *parent) :
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
<< tr("Deco switch at") <<tr("Bot. MOD") <<tr("MND") << tr("Use"));
+ connect(&diveListNotifier, &DiveListNotifier::cylindersReset, this, &CylindersModel::cylindersReset);
}
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -630,3 +632,17 @@ bool CylindersModel::updateBestMixes()
emit dataChanged(createIndex(0, 0), createIndex(MAX_CYLINDERS - 1, COLUMNS - 1));
return gasUpdated;
}
+
+void CylindersModel::cylindersReset(dive_trip *trip, const QVector<dive *> &dives)
+{
+ // This model only concerns the currently displayed dive. If this is not among the
+ // dives that had their cylinders reset, exit.
+ if (!current_dive || std::find(dives.begin(), dives.end(), current_dive) == dives.end())
+ return;
+
+ // Copy the cylinders from the current dive to the displayed dive.
+ copy_cylinders(current_dive, &displayed_dive, false);
+
+ // And update the model..
+ updateDive();
+}
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h
index c97eac179..d53aaa564 100644
--- a/qt-models/cylindermodel.h
+++ b/qt-models/cylindermodel.h
@@ -48,6 +48,7 @@ public:
public
slots:
void remove(const QModelIndex &index);
+ void cylindersReset(dive_trip *trip, const QVector<dive *> &dives);
bool updateBestMixes();
private:
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index b8e9ffa5d..6f913c63b 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -4,6 +4,7 @@
#include "core/gettextfromc.h"
#include "core/metrics.h"
#include "core/qthelper.h"
+#include "core/subsurface-qt/DiveListNotifier.h"
#include "qt-models/weightsysteminfomodel.h"
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
@@ -12,6 +13,7 @@ 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);
}
weightsystem_t *WeightModel::weightSystemAt(const QModelIndex &index)
@@ -173,3 +175,17 @@ void WeightModel::updateDive()
endInsertRows();
}
}
+
+void WeightModel::weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives)
+{
+ // This model only concerns the currently displayed dive. If this is not among the
+ // dives that had their cylinders reset, exit.
+ if (!current_dive || std::find(dives.begin(), dives.end(), current_dive) == dives.end())
+ return;
+
+ // Copy the cylinders from the current dive to the displayed dive.
+ copy_weights(current_dive, &displayed_dive);
+
+ // And update the model..
+ updateDive();
+}
diff --git a/qt-models/weightmodel.h b/qt-models/weightmodel.h
index 574a40c29..ec43bbbb8 100644
--- a/qt-models/weightmodel.h
+++ b/qt-models/weightmodel.h
@@ -32,6 +32,7 @@ public:
public
slots:
void remove(const QModelIndex &index);
+ void weightsystemsReset(dive_trip *trip, const QVector<dive *> &dives);
private:
int rows;