diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-08 19:29:47 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-11 16:25:32 -0700 |
commit | 6137e0bc60691f4b6542cd6bc97fe0106126f728 (patch) | |
tree | 5912a9f5d74757f4aaeb38faeefea7d7e933d9f2 | |
parent | f39596df0628c567f2ffd45cfa5fe809fbb7cf75 (diff) | |
download | subsurface-6137e0bc60691f4b6542cd6bc97fe0106126f728.tar.gz |
Cleanup: Remove SsrfFilterSortProxyModel
SsrfFilterSortProxyModel was a thin wrapper around QFilterSortProxyModel,
which was intended as a convenience class to avoid deriving from the
latter. The filter and sort functions were replaced by simple function
pointers.
Unfortunately, by using function-pointers, the whole thing was rather
weak as these functions do not have state. The last user was removed
in ac8dcd7f65b78958587ba025280ed4c529b0b519. Therefore, remove the
whole class.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | qt-models/CMakeLists.txt | 1 | ||||
-rw-r--r-- | qt-models/divelocationmodel.h | 2 | ||||
-rw-r--r-- | qt-models/ssrfsortfilterproxymodel.cpp | 45 | ||||
-rw-r--r-- | qt-models/ssrfsortfilterproxymodel.h | 34 |
4 files changed, 1 insertions, 81 deletions
diff --git a/qt-models/CMakeLists.txt b/qt-models/CMakeLists.txt index dc840e059..896ee9930 100644 --- a/qt-models/CMakeLists.txt +++ b/qt-models/CMakeLists.txt @@ -26,7 +26,6 @@ set(SUBSURFACE_DESKTOP_MODELS_LIB_SRCS divetripmodel.cpp diveplannermodel.cpp divecomputerextradatamodel.cpp - ssrfsortfilterproxymodel.cpp ) # models exclusively used in mobile builds diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 048b2c0a3..fe78854b9 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -4,9 +4,9 @@ #include <QAbstractTableModel> #include <QStringListModel> +#include <QSortFilterProxyModel> #include <stdint.h> #include "core/units.h" -#include "ssrfsortfilterproxymodel.h" #define RECENTLY_ADDED_DIVESITE 1 diff --git a/qt-models/ssrfsortfilterproxymodel.cpp b/qt-models/ssrfsortfilterproxymodel.cpp deleted file mode 100644 index e11b7f569..000000000 --- a/qt-models/ssrfsortfilterproxymodel.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include "ssrfsortfilterproxymodel.h" - -SsrfSortFilterProxyModel::SsrfSortFilterProxyModel(QObject *parent) -: QSortFilterProxyModel(parent), less_than(0), accepts_col(0), accepts_row(0) -{ -} - -bool SsrfSortFilterProxyModel::lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const -{ - Q_ASSERT(less_than); - const QAbstractItemModel *self = this; - return less_than(const_cast<QAbstractItemModel*>(self), source_left, source_right); -} - -bool SsrfSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const -{ - if (!accepts_row) - return true; - const QAbstractItemModel *self = this; - return accepts_row(const_cast<QAbstractItemModel*>(self), source_row, source_parent); -} - -bool SsrfSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex& source_parent) const -{ - if (!accepts_col) - return true; - const QAbstractItemModel *self = this; - return accepts_col(const_cast<QAbstractItemModel*>(self), source_column, source_parent); -} - -void SsrfSortFilterProxyModel::setLessThan(less_than_cb func) -{ - less_than = func; -} - -void SsrfSortFilterProxyModel::setFilterRow(filter_accepts_row_cb func) -{ - accepts_row = func; -} - -void SsrfSortFilterProxyModel::setFilterCol(filter_accepts_col_cb func) -{ - accepts_col = func; -} diff --git a/qt-models/ssrfsortfilterproxymodel.h b/qt-models/ssrfsortfilterproxymodel.h deleted file mode 100644 index 0fb76d91e..000000000 --- a/qt-models/ssrfsortfilterproxymodel.h +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef SSRFSORTFILTERPROXYMODEL_H -#define SSRFSORTFILTERPROXYMODEL_H - -#include <QSortFilterProxyModel> - -typedef bool (*filter_accepts_col_cb) (QAbstractItemModel *model,int sourceRow, const QModelIndex& parent); -typedef bool (*filter_accepts_row_cb) (QAbstractItemModel *model,int sourceRow, const QModelIndex& parent); -typedef bool (*less_than_cb) (QAbstractItemModel *model, const QModelIndex& left, const QModelIndex& right); - -/* Use this class when you wanna a quick filter. - * instead of creating a new class, just create a new instance of this class - * and plug your callback. - */ -class SsrfSortFilterProxyModel : public QSortFilterProxyModel { - Q_OBJECT - -public: - SsrfSortFilterProxyModel(QObject *parent = 0); - bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override; - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; - bool filterAcceptsColumn(int source_column, const QModelIndex& source_parent) const override; - - void setLessThan(less_than_cb func); - void setFilterRow(filter_accepts_row_cb func); - void setFilterCol(filter_accepts_col_cb func); - -private: - less_than_cb less_than; - filter_accepts_col_cb accepts_col; - filter_accepts_row_cb accepts_row; -}; - -#endif |