diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-11-13 16:59:00 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-13 12:04:28 -0800 |
commit | 16e44b31d3403588041bc1498371cb5db629b0bc (patch) | |
tree | b67249ff875f697bbbccf8e6bf05a72a21b22d32 /qt-ui/filtermodels.cpp | |
parent | 51f8010c9b21f75aa5a51c1d3bcd85c22c8793cf (diff) | |
download | subsurface-16e44b31d3403588041bc1498371cb5db629b0bc.tar.gz |
Last one: Common 'data' method for StringList based Filters.
This is the last of the series of Macros that I'll do to ease
the creation of a QStringListModel based filter.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/filtermodels.cpp')
-rw-r--r-- | qt-ui/filtermodels.cpp | 60 |
1 files changed, 19 insertions, 41 deletions
diff --git a/qt-ui/filtermodels.cpp b/qt-ui/filtermodels.cpp index 71fa8f8cd..35f9b4103 100644 --- a/qt-ui/filtermodels.cpp +++ b/qt-ui/filtermodels.cpp @@ -44,33 +44,35 @@ Qt::ItemFlags CLASS::flags(const QModelIndex &index) const \ return QStringListModel::flags(index) | Qt::ItemIsUserCheckable; \ } -#define CREATE_COMMON_METHODS_FOR_FILTER( CLASS ) \ +#define CREATE_DATA_METHOD( CLASS, COUNTER_FUNCTION ) \ +QVariant CLASS::data(const QModelIndex &index, int role) const \ +{ \ + if (role == Qt::CheckStateRole) { \ + return checkState[index.row()] ? Qt::Checked : Qt::Unchecked; \ + } else if (role == Qt::DisplayRole) { \ + QString value = stringList()[index.row()]; \ + int count = COUNTER_FUNCTION(value.toUtf8().data()); \ + return value + QString(" (%1)").arg(count); \ + } \ + return QVariant(); \ +} + +#define CREATE_COMMON_METHODS_FOR_FILTER( CLASS, COUNTER_FUNCTION ) \ CREATE_FLAGS_METHOD( CLASS ); \ CREATE_CLEAR_FILTER_METHOD( CLASS ); \ CREATE_MODEL_SET_DATA_METHOD( CLASS ); \ -CREATE_INSTANCE_METHOD( CLASS ) +CREATE_INSTANCE_METHOD( CLASS ); \ +CREATE_DATA_METHOD( CLASS, COUNTER_FUNCTION ) -CREATE_COMMON_METHODS_FOR_FILTER(TagFilterModel); -CREATE_COMMON_METHODS_FOR_FILTER(BuddyFilterModel); -CREATE_COMMON_METHODS_FOR_FILTER(LocationFilterModel); +CREATE_COMMON_METHODS_FOR_FILTER(TagFilterModel, count_dives_with_tag); +CREATE_COMMON_METHODS_FOR_FILTER(BuddyFilterModel, count_dives_with_person); +CREATE_COMMON_METHODS_FOR_FILTER(LocationFilterModel, count_dives_with_location); CREATE_INSTANCE_METHOD(MultiFilterSortModel); TagFilterModel::TagFilterModel(QObject *parent) : QStringListModel(parent) { } -QVariant TagFilterModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::CheckStateRole) { - return checkState[index.row()] ? Qt::Checked : Qt::Unchecked; - } else if (role == Qt::DisplayRole) { - QString tag = stringList()[index.row()]; - int count = count_dives_with_tag(tag.toUtf8().data()); - return tag + QString(" (%1)").arg(count); - } - return QVariant(); -} - void TagFilterModel::repopulate() { if (g_tag_list == NULL) @@ -225,34 +227,10 @@ void BuddyFilterModel::repopulate() anyChecked = false; } -QVariant BuddyFilterModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::CheckStateRole) { - return checkState[index.row()] ? Qt::Checked : Qt::Unchecked; - } else if (role == Qt::DisplayRole) { - QString person = stringList()[index.row()]; - int count = count_dives_with_person(person.toUtf8().data()); - return person + QString(" (%1)").arg(count); - } - return QVariant(); -} - LocationFilterModel::LocationFilterModel(QObject *parent) : QStringListModel(parent) { } -QVariant LocationFilterModel::data(const QModelIndex &index, int role) const -{ - if (role == Qt::CheckStateRole) { - return checkState[index.row()] ? Qt::Checked : Qt::Unchecked; - } else if (role == Qt::DisplayRole) { - QString location = stringList()[index.row()]; - int count = count_dives_with_location(location.toUtf8().data()); - return location + QString(" (%1)").arg(count); - } - return QVariant(); -} - bool LocationFilterModel::doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const { if (!anyChecked) { |