From 07099676ef72622e1d9f49324889dfeee2984bf4 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 22 Nov 2019 12:39:01 +0200 Subject: [PATCH] [kcmkwin/tabbox] Use an enum for role names Summary: This way we have fewer magical constants. Reviewers: #kwin, apol Reviewed By: apol Subscribers: ngraham, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D25457 --- kcmkwin/kwintabbox/layoutpreview.cpp | 21 ++++++++++----------- kcmkwin/kwintabbox/layoutpreview.h | 8 ++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/kcmkwin/kwintabbox/layoutpreview.cpp b/kcmkwin/kwintabbox/layoutpreview.cpp index 2859d673e6..38371ddbd9 100644 --- a/kcmkwin/kwintabbox/layoutpreview.cpp +++ b/kcmkwin/kwintabbox/layoutpreview.cpp @@ -151,15 +151,15 @@ QVariant ExampleClientModel::data(const QModelIndex &index, int role) const } switch (role) { case Qt::DisplayRole: - case Qt::UserRole: + case CaptionRole: return m_services.at(index.row())->name(); - case Qt::UserRole+1: + case MinimizedRole: return false; - case Qt::UserRole+2: + case DesktopNameRole: return i18nc("An example Desktop Name", "Desktop 1"); - case Qt::UserRole+3: + case IconRole: return m_services.at(index.row())->icon(); - case Qt::UserRole+4: + case WindowIdRole: const auto s = m_services.at(index.row()); if (s == m_browser) { return WindowThumbnailItem::Konqueror; @@ -195,13 +195,12 @@ int ExampleClientModel::rowCount(const QModelIndex &parent) const QHash ExampleClientModel::roleNames() const { - // FIXME: Use an enum. return { - { Qt::UserRole, QByteArrayLiteral("caption") }, - { Qt::UserRole + 1, QByteArrayLiteral("minimized") }, - { Qt::UserRole + 2, QByteArrayLiteral("desktopName") }, - { Qt::UserRole + 3, QByteArrayLiteral("icon") }, - { Qt::UserRole + 4, QByteArrayLiteral("windowId") }, + { CaptionRole, QByteArrayLiteral("caption") }, + { MinimizedRole, QByteArrayLiteral("minimized") }, + { DesktopNameRole, QByteArrayLiteral("desktopName") }, + { IconRole, QByteArrayLiteral("icon") }, + { WindowIdRole, QByteArrayLiteral("windowId") }, }; } diff --git a/kcmkwin/kwintabbox/layoutpreview.h b/kcmkwin/kwintabbox/layoutpreview.h index 7f77a5b09a..e87651110a 100644 --- a/kcmkwin/kwintabbox/layoutpreview.h +++ b/kcmkwin/kwintabbox/layoutpreview.h @@ -49,6 +49,14 @@ class ExampleClientModel : public QAbstractListModel { Q_OBJECT public: + enum { + CaptionRole = Qt::UserRole + 1, + MinimizedRole, + DesktopNameRole, + IconRole, + WindowIdRole + }; + explicit ExampleClientModel(QObject *parent = nullptr); ~ExampleClientModel() override;