diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-29 20:17:53 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-11-01 07:28:15 -0700 |
commit | ab894c9b64ca5cceef87d1835f3a84103668ffc9 (patch) | |
tree | 0e61eb8ea4af3895713351d76419566a9c183e7d /qt-models/filtermodels.cpp | |
parent | 6fb3a499e67bc5375e66faef5969afee99a74d25 (diff) | |
download | subsurface-ab894c9b64ca5cceef87d1835f3a84103668ffc9.tar.gz |
Dive list: implement custom lessThan function
The dive list was sorted using the default-sorter of
QSortFilterProxy model. This is mighty inflexible as it
considers only one column. This has the funky effect that
for rows with identical elements, the sort order depends
on the previous sorting.
Implement a lessThan() function in the MultiFilterSortModel,
which simply hands the sorting down to the actual model.
This might be considered a layering violation, but it makes
things so much easier.
Sadly, it seems like the column-to-be-sorted is transported
in the provided indices. Therefore, the comparison is chosen
using a switch for *every* comparison. It would seem much
more logical to set a function pointer once and use that.
Further investigations are necessary.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/filtermodels.cpp')
-rw-r--r-- | qt-models/filtermodels.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 857c5d698..d335d3f7c 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -560,12 +560,12 @@ void LocationFilterModel::addName(const QString &newName) MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent), divesDisplayed(0), - curr_dive_site(NULL) + curr_dive_site(NULL), + model(DiveTripModel::instance()) { - setSortRole(DiveTripModel::SORT_ROLE); setFilterKeyColumn(-1); // filter all columns setFilterCaseSensitivity(Qt::CaseInsensitive); - setSourceModel(DiveTripModel::instance()); + setSourceModel(model); } void MultiFilterSortModel::setLayout(DiveTripModel::Layout layout) @@ -707,3 +707,9 @@ void MultiFilterSortModel::stopFilterDiveSite() curr_dive_site = NULL; myInvalidate(); } + +bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const +{ + // Hand sorting down to the source model. + return model->lessThan(i1, i2); +} |