mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
dfea10fbb8
commit
5346b78e6c
1 changed files with 23 additions and 58 deletions
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue