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>
This commit is contained in:
Berthold Stoeger 2019-02-23 22:09:34 +01:00 committed by Dirk Hohndel
parent 9ed5cf16a4
commit 9fd87fa080
8 changed files with 52 additions and 5 deletions

View file

@ -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();
}