summaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-12-09 15:37:26 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-10 18:45:30 -0800
commit6ec82a3c80e0f362abc59a6df8ea793013f01c65 (patch)
treef381e928ccbc788b8302b0404f14bcb04af40de9 /qt-models/filtermodels.cpp
parent0f417a3bc1f282b34509df1c9295197522344a55 (diff)
downloadsubsurface-6ec82a3c80e0f362abc59a6df8ea793013f01c65.tar.gz
Dive list: remove global pointer to DiveTrip model
This part of the code had that horrible pattern, where reseting the model would invalidate all pointers to the DiveTrip model. Internalize these complexities in the MultiFilterSortModel. All accesses are now performed via that proxy model. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/filtermodels.cpp')
-rw-r--r--qt-models/filtermodels.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 463276e13..d07de02c0 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -15,6 +15,7 @@ MultiFilterSortModel *MultiFilterSortModel::instance()
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent)
{
+ resetModel(DiveTripModelBase::TREE);
setFilterKeyColumn(-1); // filter all columns
setFilterRole(DiveTripModelBase::SHOWN_ROLE); // Let the proxy-model known that is has to react to change events involving SHOWN_ROLE
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -22,19 +23,20 @@ MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyMo
void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
{
- DiveTripModelBase::resetModel(layout);
- // DiveTripModelBase::resetModel() generates a new instance.
- // Thus, the source model must be reset and the connections must be reset.
- DiveTripModelBase *m = DiveTripModelBase::instance();
- setSourceModel(m);
- connect(m, &DiveTripModelBase::selectionChanged, this, &MultiFilterSortModel::selectionChangedSlot);
- connect(m, &DiveTripModelBase::currentDiveChanged, this, &MultiFilterSortModel::currentDiveChangedSlot);
- m->initSelection();
+ if (layout == DiveTripModelBase::TREE)
+ model.reset(new DiveTripModelTree);
+ else
+ model.reset(new DiveTripModelList);
+
+ setSourceModel(model.get());
+ connect(model.get(), &DiveTripModelBase::selectionChanged, this, &MultiFilterSortModel::selectionChangedSlot);
+ connect(model.get(), &DiveTripModelBase::currentDiveChanged, this, &MultiFilterSortModel::currentDiveChangedSlot);
+ model->initSelection();
}
void MultiFilterSortModel::clear()
{
- DiveTripModelBase::instance()->clear();
+ model->clear();
}
// Translate selection into local indexes and re-emit signal
@@ -68,5 +70,5 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s
bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
{
// Hand sorting down to the source model.
- return DiveTripModelBase::instance()->lessThan(i1, i2);
+ return model->lessThan(i1, i2);
}