summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2017-07-05 15:05:05 +0200
committerJustus Winter <[email protected]>2017-07-11 10:58:45 +0200
commitcc2cb7461f0acbd89c3d3da5432470a9bbf3b935 (patch)
treee91ad4afd4558d188a407005892a8e040268f388
parent48e4eb1967589c8dc42bfc15388d4056b381bd35 (diff)
Rework the keyfilter model
Rework the 'data(..)' method, use the filter ids as UserRole, so that we can match on them. Signed-off-by: Justus Winter <[email protected]>
-rw-r--r--src/kleo/keyfiltermanager.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/kleo/keyfiltermanager.cpp b/src/kleo/keyfiltermanager.cpp
index d6193cc..7f013a2 100644
--- a/src/kleo/keyfiltermanager.cpp
+++ b/src/kleo/keyfiltermanager.cpp
@@ -382,16 +382,28 @@ int Model::rowCount(const QModelIndex &) const
QVariant Model::data(const QModelIndex &idx, int role) const
{
- if ((role != Qt::DisplayRole && role != Qt::EditRole &&
- role != Qt::ToolTipRole && role != Qt::DecorationRole) ||
- !idx.isValid() || idx.model() != this ||
- idx.row() < 0 || static_cast<unsigned>(idx.row()) > m_keyFilterManagerPrivate->filters.size()) {
+ if (!idx.isValid()
+ || idx.model() != this
+ || idx.row() < 0
+ || static_cast<unsigned>(idx.row()) > m_keyFilterManagerPrivate->filters.size()) {
return QVariant();
}
- if (role == Qt::DecorationRole) {
- return m_keyFilterManagerPrivate->filters[idx.row()]->icon();
- } else {
- return m_keyFilterManagerPrivate->filters[idx.row()]->name();
+
+ const auto filter = m_keyFilterManagerPrivate->filters[idx.row()];
+ switch (role) {
+ case Qt::DecorationRole:
+ return filter->icon();
+
+ case Qt::DisplayRole:
+ case Qt::EditRole:
+ case Qt::ToolTipRole: /* Most useless tooltip ever. */
+ return filter->name();
+
+ case Qt::UserRole:
+ return filter->id();
+
+ default:
+ return QVariant();
}
}