From 6622f42aab937e72cc11cb5512012394aa687767 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 30 Jan 2020 20:12:11 +0100 Subject: 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 --- qt-models/cylindermodel.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'qt-models/cylindermodel.h') 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 + #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 -- cgit v1.2.3-70-g09d2