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 /desktop-widgets/tab-widgets | |
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 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 12 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveEquipment.h | 4 |
2 files changed, 8 insertions, 8 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index f731631eb..0a5786e50 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -17,7 +17,7 @@ #include <QCompleter> TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent), - cylindersModel(new CylindersModel(this)), + cylindersModel(new CylindersModelFiltered(this)), weightModel(new WeightModel(this)) { QCompleter *suitCompleter; @@ -33,7 +33,7 @@ TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent), ui.weights->setModel(weightModel); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveEquipment::divesChanged); - connect(ui.cylinders, &TableView::itemClicked, cylindersModel, &CylindersModel::remove); + connect(ui.cylinders, &TableView::itemClicked, cylindersModel, &CylindersModelFiltered::remove); connect(ui.cylinders, &TableView::itemClicked, this, &TabDiveEquipment::editCylinderWidget); connect(ui.weights, &TableView::itemClicked, this, &TabDiveEquipment::editWeightWidget); @@ -164,7 +164,7 @@ void TabDiveEquipment::addWeight_clicked() void TabDiveEquipment::editCylinderWidget(const QModelIndex &index) { - if (cylindersModel->changed && !MainWindow::instance()->mainTab->isEditing()) { + if (cylindersModel->model()->changed && !MainWindow::instance()->mainTab->isEditing()) { MainWindow::instance()->mainTab->enableEdition(); return; } @@ -228,7 +228,7 @@ void TabDiveEquipment::acceptChanges() // to the original value in current_dive like it should QVector<dive *> selectedDives = getSelectedDivesCurrentLast(); - if (cylindersModel->changed) { + if (cylindersModel->model()->changed) { mark_divelist_changed(true); MODIFY_DIVES(selectedDives, // if we started out with the same cylinder description (for multi-edit) or if we do copt & paste @@ -257,12 +257,12 @@ void TabDiveEquipment::acceptChanges() if (do_replot) MainWindow::instance()->graphics->replot(); - cylindersModel->changed = false; + cylindersModel->model()->changed = false; } void TabDiveEquipment::rejectChanges() { - cylindersModel->changed = false; + cylindersModel->model()->changed = false; cylindersModel->updateDive(); weightModel->updateDive(current_dive); } diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.h b/desktop-widgets/tab-widgets/TabDiveEquipment.h index 1edc20cef..28e6235d1 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.h +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.h @@ -12,7 +12,7 @@ namespace Ui { }; class WeightModel; -class CylindersModel; +class CylindersModelFiltered; class TabDiveEquipment : public TabBase { Q_OBJECT @@ -38,7 +38,7 @@ private slots: private: Ui::TabDiveEquipment ui; SuitCompletionModel suitModel; - CylindersModel *cylindersModel; + CylindersModelFiltered *cylindersModel; WeightModel *weightModel; }; |