summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-11-13 16:41:37 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-13 12:02:24 -0800
commit5346b78e6cea83cec23056d4fe9ce4a3168b0cc0 (patch)
tree76f4f80d1c907772ecda32b8d63eacd930b75abc /qt-ui
parentdfea10fbb80710d7faf8fe7a1cee1ab8eea57384 (diff)
downloadsubsurface-5346b78e6cea83cec23056d4fe9ce4a3168b0cc0.tar.gz
More cleanup using Macros.
The setData of any filter based on a StringList with checkboxes should be the same, so let's use the same codebase for it. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/filtermodels.cpp81
1 files changed, 23 insertions, 58 deletions
diff --git a/qt-ui/filtermodels.cpp b/qt-ui/filtermodels.cpp
index a60b2c04f..eaf15f4ce 100644
--- a/qt-ui/filtermodels.cpp
+++ b/qt-ui/filtermodels.cpp
@@ -14,9 +14,32 @@ CLASS *CLASS::instance() \
CREATE_INSTANCE_METHOD(TagFilterModel);
CREATE_INSTANCE_METHOD(BuddyFilterModel);
CREATE_INSTANCE_METHOD(LocationFilterModel);
+CREATE_INSTANCE_METHOD(MultiFilterSortModel);
#undef CREATE_INSTANCE_METHOD
+#define CREATE_MODEL_SET_DATA_METHOD( CLASS ) \
+bool CLASS::setData(const QModelIndex &index, const QVariant &value, int role) \
+{ \
+ if (role == Qt::CheckStateRole) { \
+ checkState[index.row()] = value.toBool(); \
+ anyChecked = false; \
+ for (int i = 0; i < rowCount(); i++) { \
+ if (checkState[i] == true) { \
+ anyChecked = true; \
+ break; \
+ } \
+ } \
+ dataChanged(index, index); \
+ return true; \
+ } \
+ return false; \
+}
+
+CREATE_MODEL_SET_DATA_METHOD(TagFilterModel);
+CREATE_MODEL_SET_DATA_METHOD(BuddyFilterModel);
+CREATE_MODEL_SET_DATA_METHOD(LocationFilterModel);
+
TagFilterModel::TagFilterModel(QObject *parent) : QStringListModel(parent)
{
}
@@ -58,23 +81,6 @@ void TagFilterModel::repopulate()
anyChecked = false;
}
-bool TagFilterModel::setData(const QModelIndex &index, const QVariant &value, int role)
-{
- if (role == Qt::CheckStateRole) {
- checkState[index.row()] = value.toBool();
- anyChecked = false;
- for (int i = 0; i < rowCount(); i++) {
- if (checkState[i] == true) {
- anyChecked = true;
- break;
- }
- }
- dataChanged(index, index);
- return true;
- }
- return false;
-}
-
bool TagFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const
{
// If there's nothing checked, this should show everything
@@ -226,24 +232,6 @@ QVariant BuddyFilterModel::data(const QModelIndex &index, int role) const
return QVariant();
}
-
-bool BuddyFilterModel::setData(const QModelIndex &index, const QVariant &value, int role)
-{
- if (role == Qt::CheckStateRole) {
- checkState[index.row()] = value.toBool();
- anyChecked = false;
- for (int i = 0; i < rowCount(); i++) {
- if (checkState[i] == true) {
- anyChecked = true;
- break;
- }
- }
- dataChanged(index, index);
- return true;
- }
- return false;
-}
-
LocationFilterModel::LocationFilterModel(QObject *parent) : QStringListModel(parent)
{
}
@@ -338,29 +326,6 @@ void LocationFilterModel::repopulate()
anyChecked = false;
}
-bool LocationFilterModel::setData(const QModelIndex &index, const QVariant &value, int role)
-{
- if (role == Qt::CheckStateRole) {
- checkState[index.row()] = value.toBool();
- anyChecked = false;
- for (int i = 0; i < rowCount(); i++) {
- if (checkState[i] == true) {
- anyChecked = true;
- break;
- }
- }
- dataChanged(index, index);
- return true;
- }
- return false;
-}
-
-MultiFilterSortModel *MultiFilterSortModel::instance()
-{
- static MultiFilterSortModel *self = new MultiFilterSortModel();
- return self;
-}
-
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent), justCleared(false)
{
}