mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
a431840075
commit
e46b1e88d9
3 changed files with 44 additions and 32 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue