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>
This commit is contained in:
Berthold Stoeger 2020-01-30 20:12:11 +01:00 committed by Dirk Hohndel
parent b37c261c95
commit 6622f42aab
9 changed files with 140 additions and 78 deletions

View file

@ -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