summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/modeldelegates.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-01-30 20:12:11 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-02-11 20:37:09 -0800
commit6622f42aab937e72cc11cb5512012394aa687767 (patch)
tree42302a42594b78b99111e98c6fd9325a0b9c5959 /desktop-widgets/modeldelegates.cpp
parentb37c261c95761cb5762e91b5d43277d2b0181678 (diff)
downloadsubsurface-6622f42aab937e72cc11cb5512012394aa687767.tar.gz
Cylinders: Add CylindersModelFiltered
When the show_unused_cylinders flag is not set, the cylinder tables in the equipment tab and the planner should not show unused cylinders. However, the code in CylindersModel is fundamentally broken if the unused cylinders are not at the end of the list: The correct number of cylinders is shown, but not the correct cylinders. Therefore, add a higher-level CylindersModelFiltered model on top of CylindersModel that does the actual filtering. Some calls are routed through to the base model (notably those that take indexes, as these have to be mapped), for some calls the caller has to get access to the source model first. We might want to adjust this. For filtering, reuse the already existing show_cylinder function and export it via CylindersModel. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/modeldelegates.cpp')
-rw-r--r--desktop-widgets/modeldelegates.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp
index ae8755292..ed4833550 100644
--- a/desktop-widgets/modeldelegates.cpp
+++ b/desktop-widgets/modeldelegates.cpp
@@ -238,7 +238,7 @@ static struct RevertCylinderData {
void TankInfoDelegate::setModelData(QWidget*, QAbstractItemModel*, const QModelIndex&) const
{
- CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
+ CylindersModelFiltered *mymodel = qobject_cast<CylindersModelFiltered *>(currCombo.model);
TankInfoModel *tanks = TankInfoModel::instance();
QModelIndexList matches = tanks->match(tanks->index(0, 0), Qt::DisplayRole, currCombo.activeText);
int row;
@@ -277,7 +277,7 @@ void TankInfoDelegate::editorClosed(QWidget*, QAbstractItemDelegate::EndEditHint
{
if (hint == QAbstractItemDelegate::NoHint ||
hint == QAbstractItemDelegate::RevertModelCache) {
- CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
+ CylindersModelFiltered *mymodel = qobject_cast<CylindersModelFiltered *>(currCombo.model);
mymodel->setData(IDX(CylindersModel::TYPE), currCylinderData.type, Qt::EditRole);
mymodel->passInData(IDX(CylindersModel::WORKINGPRESS), currCylinderData.pressure);
mymodel->passInData(IDX(CylindersModel::SIZE), currCylinderData.size);
@@ -289,7 +289,7 @@ QWidget *TankInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
// ncreate editor needs to be called before because it will populate a few
// things in the currCombo global var.
QWidget *delegate = ComboBoxDelegate::createEditor(parent, option, index);
- CylindersModel *mymodel = qobject_cast<CylindersModel *>(currCombo.model);
+ CylindersModelFiltered *mymodel = qobject_cast<CylindersModelFiltered *>(currCombo.model);
cylinder_t *cyl = mymodel->cylinderAt(index);
currCylinderData.type = cyl->type.description;
currCylinderData.pressure = cyl->type.workingpressure.mbar;