aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-09-06 22:03:03 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-11 16:22:27 -0700
commite0fcf99d0ac3ec23e6009a55b6e59c47c668081b (patch)
tree276310243cf588df6dfef2f4bf515a3b4e5ec53c /qt-models
parent7150d1c6f61631079e7620901fd1939bbc54e621 (diff)
downloadsubsurface-e0fcf99d0ac3ec23e6009a55b6e59c47c668081b.tar.gz
Filter: reload only when checkstate changed
Currently, the filter is recalculated if a filter-entry is changed. This also happens if the counts of a filter-entry changes. This is to be avoided, as it causes unnecessary churn. Therefore, send the proper role with the dataChanged() signal and add a new slot, which invalidates only if a field with the Qt::CheckStateRole is changed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/filtermodels.cpp12
-rw-r--r--qt-models/filtermodels.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 1491dbacf..c8ed16274 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -228,7 +228,7 @@ bool FilterModelBase::setData(const QModelIndex &index, const QVariant &value, i
break;
}
}
- dataChanged(index, index);
+ dataChanged(index, index, { role });
return true;
}
return false;
@@ -631,6 +631,14 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s
return false;
}
+void MultiFilterSortModel::filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles)
+{
+ // Only redo the filter if a checkbox changed. If the count of an entry changed,
+ // we do *not* want to recalculate the filters.
+ if (roles.contains(Qt::CheckStateRole))
+ myInvalidate();
+}
+
void MultiFilterSortModel::myInvalidate()
{
#if !defined(SUBSURFACE_MOBILE)
@@ -683,7 +691,7 @@ void MultiFilterSortModel::myInvalidate()
void MultiFilterSortModel::addFilterModel(FilterModelBase *model)
{
models.append(model);
- connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(myInvalidate()));
+ connect(model, &FilterModelBase::dataChanged, this, &MultiFilterSortModel::filterChanged);
}
void MultiFilterSortModel::removeFilterModel(FilterModelBase *model)
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h
index 3f5ca5f01..2fd5ef2b2 100644
--- a/qt-models/filtermodels.h
+++ b/qt-models/filtermodels.h
@@ -131,6 +131,7 @@ slots:
void clearFilter();
void startFilterDiveSite(uint32_t uuid);
void stopFilterDiveSite();
+ void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
signals:
void filterFinished();