mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
51f8010c9b
commit
16e44b31d3
1 changed files with 19 additions and 41 deletions
|
@ -44,33 +44,35 @@ Qt::ItemFlags CLASS::flags(const QModelIndex &index) const \
|
||||||
return QStringListModel::flags(index) | Qt::ItemIsUserCheckable; \
|
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_FLAGS_METHOD( CLASS ); \
|
||||||
CREATE_CLEAR_FILTER_METHOD( CLASS ); \
|
CREATE_CLEAR_FILTER_METHOD( CLASS ); \
|
||||||
CREATE_MODEL_SET_DATA_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(TagFilterModel, count_dives_with_tag);
|
||||||
CREATE_COMMON_METHODS_FOR_FILTER(BuddyFilterModel);
|
CREATE_COMMON_METHODS_FOR_FILTER(BuddyFilterModel, count_dives_with_person);
|
||||||
CREATE_COMMON_METHODS_FOR_FILTER(LocationFilterModel);
|
CREATE_COMMON_METHODS_FOR_FILTER(LocationFilterModel, count_dives_with_location);
|
||||||
CREATE_INSTANCE_METHOD(MultiFilterSortModel);
|
CREATE_INSTANCE_METHOD(MultiFilterSortModel);
|
||||||
|
|
||||||
TagFilterModel::TagFilterModel(QObject *parent) : QStringListModel(parent)
|
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()
|
void TagFilterModel::repopulate()
|
||||||
{
|
{
|
||||||
if (g_tag_list == NULL)
|
if (g_tag_list == NULL)
|
||||||
|
@ -225,34 +227,10 @@ void BuddyFilterModel::repopulate()
|
||||||
anyChecked = false;
|
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)
|
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
|
bool LocationFilterModel::doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const
|
||||||
{
|
{
|
||||||
if (!anyChecked) {
|
if (!anyChecked) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue