diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-03-01 16:12:13 +0100 |
---|---|---|
committer | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-07 00:13:35 +0200 |
commit | 24a7dbde16ce5f024f6137a2318e54815a495a94 (patch) | |
tree | 13c62fa14c6f03e6cb74abaec40536de990e215a /qt-models/cylindermodel.cpp | |
parent | 01fa983182062e00b2e661a963384289e4de1beb (diff) | |
download | subsurface-24a7dbde16ce5f024f6137a2318e54815a495a94.tar.gz |
CylindersModel: use flag to decide whether we are in planner
On desktop, we have two CylindersModel concurrently: One in the
planner and one on the equipment-tab. They act differently, because
the former modifies displayed_dive directly, the latter issues
undo commands.
To differentiate, we used the in_planner() function. However, that
appears extremely brittle, especially when combined with undo-commands.
Therefore when generating the model, pass in a parameter that says
whether this is for the planner or the equipment tab and use
that flag to decide how to act.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/cylindermodel.cpp')
-rw-r--r-- | qt-models/cylindermodel.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index c2bd0198a..8a79ff1e5 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -11,8 +11,9 @@ #include "core/subsurface-string.h" #include <string> -CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent), +CylindersModel::CylindersModel(bool planner, QObject *parent) : CleanerTableModel(parent), d(nullptr), + inPlanner(planner), tempRow(-1), tempCyl(empty_cylinder) { @@ -28,7 +29,7 @@ CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent), QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (role == Qt::DisplayRole && orientation == Qt::Horizontal && in_planner() && section == WORKINGPRESS) + if (role == Qt::DisplayRole && orientation == Qt::Horizontal && inPlanner && section == WORKINGPRESS) return tr("Start press."); else return CleanerTableModel::headerData(section, orientation, role); @@ -249,8 +250,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const case Qt::DecorationRole: case Qt::SizeHintRole: if (index.column() == REMOVE) { - if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) || - (!in_planner() && is_cylinder_prot(d, index.row()))) { + if ((inPlanner && DivePlannerPointsModel::instance()->tankInUse(index.row())) || + (!inPlanner && is_cylinder_prot(d, index.row()))) { return trashForbiddenIcon(); } return trashIcon(); @@ -259,8 +260,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const case Qt::ToolTipRole: switch (index.column()) { case REMOVE: - if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) || - (!in_planner() && is_cylinder_prot(d, index.row()))) { + if ((inPlanner && DivePlannerPointsModel::instance()->tankInUse(index.row())) || + (!inPlanner && is_cylinder_prot(d, index.row()))) { return tr("This gas is in use. Only cylinders that are not used in the dive can be removed."); } return tr("Clicking here will remove this cylinder."); @@ -450,7 +451,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in break; } - if (in_planner()) { + if (inPlanner) { // In the planner - simply overwrite the cylinder in the dive with the modified cylinder. // We have only made a shallow copy, therefore copy the new cylinder first. cylinder_t copy = clone_cylinder(cyl); @@ -590,7 +591,7 @@ void CylindersModel::moveAtFirst(int cylid) mapping[cylid] = 0; std::iota(mapping.begin() + (cylid + 1), mapping.end(), cylid); cylinder_renumber(d, &mapping[0]); - if (in_planner()) + if (inPlanner) DivePlannerPointsModel::instance()->cylinderRenumber(&mapping[0]); endMoveRows(); } @@ -705,7 +706,7 @@ void CylindersModel::commitTempCyl(int row) return; // Only submit a command if the type changed if (!same_string(cyl->type.description, tempCyl.type.description) || gettextFromC::tr(cyl->type.description) != QString(tempCyl.type.description)) { - if (in_planner()) + if (inPlanner) std::swap(*cyl, tempCyl); else Command::editCylinder(tempRow, tempCyl, false); @@ -715,7 +716,8 @@ void CylindersModel::commitTempCyl(int row) #endif } -CylindersModelFiltered::CylindersModelFiltered(QObject *parent) : QSortFilterProxyModel(parent) +CylindersModelFiltered::CylindersModelFiltered(QObject *parent) : QSortFilterProxyModel(parent), + source(false) // Currently, only the EquipmentTab uses the filtered model. { setSourceModel(&source); } |