diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-11-27 21:55:37 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-12-04 13:00:23 +0100 |
commit | e46b1e88d92990d26d34981baf70fcf0b58ebec7 (patch) | |
tree | bccf82da75c5e1c1a7e7578109e5229d22ca1288 /qt-models | |
parent | a431840075fbba6f882627496f18a0fb80630e4f (diff) | |
download | subsurface-e46b1e88d92990d26d34981baf70fcf0b58ebec7.tar.gz |
Selection: move translation of indexes to filter model
The DiveListView caught signals from the DiveTripModel
with the corresponding indexes. However, the DiveListView
is actually connected to the MultiFilterSortModel and
thus has to translate the indexes.
Instead, catch the signals in the MultiFilterSortModel,
transform them and resend. Let the DiveListView get
its signal from the MultiFilterSortModel.
Yes, this makes things less efficient because there is
an extra signal. On the upside, the makes data-flow much
more logical. Selection will have to be fixed anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/filtermodels.cpp | 29 | ||||
-rw-r--r-- | qt-models/filtermodels.h | 6 |
2 files changed, 33 insertions, 2 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 779920a73..dcb7e69ad 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -24,8 +24,33 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout) { DiveTripModelBase::resetModel(layout); // DiveTripModelBase::resetModel() generates a new instance. - // Thus, the source model must be reset. - setSourceModel(DiveTripModelBase::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(); +} + +// Translate selection into local indexes and re-emit signal +void MultiFilterSortModel::selectionChangedSlot(const QVector<QModelIndex> &indexes) +{ + QVector<QModelIndex> indexesLocal; + indexesLocal.reserve(indexes.size()); + for (const QModelIndex &index: indexes) { + QModelIndex local = mapFromSource(index); + if (local.isValid()) + indexesLocal.push_back(local); + } + emit selectionChanged(indexesLocal); +} + +// Translate current dive into local indexes and re-emit signal +void MultiFilterSortModel::currentDiveChangedSlot(QModelIndex index) +{ + QModelIndex local = mapFromSource(index); + if (local.isValid()) + emit currentDiveChanged(mapFromSource(index)); } bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index 2dcce0fc0..6677c713d 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -14,6 +14,12 @@ public: bool lessThan(const QModelIndex &, const QModelIndex &) const override; void resetModel(DiveTripModelBase::Layout layout); +signals: + void selectionChanged(const QVector<QModelIndex> &indexes); + void currentDiveChanged(QModelIndex index); +private slots: + void selectionChangedSlot(const QVector<QModelIndex> &indexes); + void currentDiveChangedSlot(QModelIndex index); private: MultiFilterSortModel(QObject *parent = 0); }; |