diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-01-30 20:12:11 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-02-11 20:37:09 -0800 |
commit | 6622f42aab937e72cc11cb5512012394aa687767 (patch) | |
tree | 42302a42594b78b99111e98c6fd9325a0b9c5959 /qt-models/cylindermodel.h | |
parent | b37c261c95761cb5762e91b5d43277d2b0181678 (diff) | |
download | subsurface-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 'qt-models/cylindermodel.h')
-rw-r--r-- | qt-models/cylindermodel.h | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h index 9f9abc836..66f51acca 100644 --- a/qt-models/cylindermodel.h +++ b/qt-models/cylindermodel.h @@ -2,6 +2,8 @@ #ifndef CYLINDERMODEL_H #define CYLINDERMODEL_H +#include <QSortFilterProxyModel> + #include "cleanertablemodel.h" #include "core/dive.h" @@ -27,7 +29,6 @@ public: }; explicit CylindersModel(QObject *parent = 0); - static CylindersModel *instance(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; @@ -44,6 +45,7 @@ public: bool changed; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; bool updateBestMixes(); + bool cylinderUsed(int i) const; public slots: @@ -54,4 +56,25 @@ private: int rows; }; +// Cylinder model that hides unused cylinders if the pref.show_unused_cylinders flag is not set +class CylindersModelFiltered : public QSortFilterProxyModel { + Q_OBJECT +public: + CylindersModelFiltered(QObject *parent = 0); + static CylindersModelFiltered *instance(); + CylindersModel *model(); // Access to unfiltered base model + + void clear(); + void add(); + void updateDive(); + cylinder_t *cylinderAt(const QModelIndex &index); + void passInData(const QModelIndex &index, const QVariant &value); +public +slots: + void remove(QModelIndex index); +private: + CylindersModel source; + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; +}; + #endif |