mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
01fa983182
commit
24a7dbde16
3 changed files with 15 additions and 11 deletions
|
@ -11,8 +11,9 @@
|
||||||
#include "core/subsurface-string.h"
|
#include "core/subsurface-string.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent),
|
CylindersModel::CylindersModel(bool planner, QObject *parent) : CleanerTableModel(parent),
|
||||||
d(nullptr),
|
d(nullptr),
|
||||||
|
inPlanner(planner),
|
||||||
tempRow(-1),
|
tempRow(-1),
|
||||||
tempCyl(empty_cylinder)
|
tempCyl(empty_cylinder)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +29,7 @@ CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent),
|
||||||
|
|
||||||
QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const
|
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.");
|
return tr("Start press.");
|
||||||
else
|
else
|
||||||
return CleanerTableModel::headerData(section, orientation, role);
|
return CleanerTableModel::headerData(section, orientation, role);
|
||||||
|
@ -249,8 +250,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
case Qt::SizeHintRole:
|
case Qt::SizeHintRole:
|
||||||
if (index.column() == REMOVE) {
|
if (index.column() == REMOVE) {
|
||||||
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
if ((inPlanner && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
||||||
(!in_planner() && is_cylinder_prot(d, index.row()))) {
|
(!inPlanner && is_cylinder_prot(d, index.row()))) {
|
||||||
return trashForbiddenIcon();
|
return trashForbiddenIcon();
|
||||||
}
|
}
|
||||||
return trashIcon();
|
return trashIcon();
|
||||||
|
@ -259,8 +260,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
if ((in_planner() && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
if ((inPlanner && DivePlannerPointsModel::instance()->tankInUse(index.row())) ||
|
||||||
(!in_planner() && is_cylinder_prot(d, 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("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.");
|
return tr("Clicking here will remove this cylinder.");
|
||||||
|
@ -450,7 +451,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_planner()) {
|
if (inPlanner) {
|
||||||
// In the planner - simply overwrite the cylinder in the dive with the modified cylinder.
|
// 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.
|
// We have only made a shallow copy, therefore copy the new cylinder first.
|
||||||
cylinder_t copy = clone_cylinder(cyl);
|
cylinder_t copy = clone_cylinder(cyl);
|
||||||
|
@ -590,7 +591,7 @@ void CylindersModel::moveAtFirst(int cylid)
|
||||||
mapping[cylid] = 0;
|
mapping[cylid] = 0;
|
||||||
std::iota(mapping.begin() + (cylid + 1), mapping.end(), cylid);
|
std::iota(mapping.begin() + (cylid + 1), mapping.end(), cylid);
|
||||||
cylinder_renumber(d, &mapping[0]);
|
cylinder_renumber(d, &mapping[0]);
|
||||||
if (in_planner())
|
if (inPlanner)
|
||||||
DivePlannerPointsModel::instance()->cylinderRenumber(&mapping[0]);
|
DivePlannerPointsModel::instance()->cylinderRenumber(&mapping[0]);
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
}
|
}
|
||||||
|
@ -705,7 +706,7 @@ void CylindersModel::commitTempCyl(int row)
|
||||||
return;
|
return;
|
||||||
// Only submit a command if the type changed
|
// 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 (!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);
|
std::swap(*cyl, tempCyl);
|
||||||
else
|
else
|
||||||
Command::editCylinder(tempRow, tempCyl, false);
|
Command::editCylinder(tempRow, tempCyl, false);
|
||||||
|
@ -715,7 +716,8 @@ void CylindersModel::commitTempCyl(int row)
|
||||||
#endif
|
#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);
|
setSourceModel(&source);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
COMMIT_ROLE, // Save the temporary data to the dive. Must be set with Column == TYPE.
|
COMMIT_ROLE, // Save the temporary data to the dive. Must be set with Column == TYPE.
|
||||||
REVERT_ROLE // Revert to original data from dive. Must be set with Column == TYPE.
|
REVERT_ROLE // Revert to original data from dive. Must be set with Column == TYPE.
|
||||||
};
|
};
|
||||||
explicit CylindersModel(QObject *parent = 0);
|
explicit CylindersModel(bool planner, QObject *parent = 0); // First argument: true if this model is used for the planner
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
@ -61,6 +61,7 @@ slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
dive *d;
|
dive *d;
|
||||||
|
bool inPlanner;
|
||||||
// Used if we temporarily change a line because the user is selecting a weight type
|
// Used if we temporarily change a line because the user is selecting a weight type
|
||||||
int tempRow;
|
int tempRow;
|
||||||
cylinder_t tempCyl;
|
cylinder_t tempCyl;
|
||||||
|
|
|
@ -415,6 +415,7 @@ int DivePlannerPointsModel::rowCount(const QModelIndex&) const
|
||||||
}
|
}
|
||||||
|
|
||||||
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent),
|
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent),
|
||||||
|
cylinders(true),
|
||||||
mode(NOTHING),
|
mode(NOTHING),
|
||||||
recalc(false)
|
recalc(false)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue