diff --git a/kcmkwin/kwintabbox/layoutpreview.h b/kcmkwin/kwintabbox/layoutpreview.h --- a/kcmkwin/kwintabbox/layoutpreview.h +++ b/kcmkwin/kwintabbox/layoutpreview.h @@ -54,6 +54,7 @@ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual QHash roleNames() const; Q_INVOKABLE QString longestCaption() const; private: diff --git a/kcmkwin/kwintabbox/layoutpreview.cpp b/kcmkwin/kwintabbox/layoutpreview.cpp --- a/kcmkwin/kwintabbox/layoutpreview.cpp +++ b/kcmkwin/kwintabbox/layoutpreview.cpp @@ -116,13 +116,6 @@ ExampleClientModel::ExampleClientModel (QObject* parent) : QAbstractListModel (parent) { - QHash roles; - roles[Qt::UserRole] = "caption"; - roles[Qt::UserRole+1] = "minimized"; - roles[Qt::UserRole + 3] = "icon"; - roles[Qt::UserRole+2] = "desktopName"; - roles[Qt::UserRole+4] = "windowId"; - setRoleNames(roles); init(); } @@ -199,6 +192,18 @@ return m_services.size(); } +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") }, + }; +} + SwitcherItem::SwitcherItem(QObject *parent) : QObject(parent) , m_model(new ExampleClientModel(this)) diff --git a/scripting/scripting_model.h b/scripting/scripting_model.h --- a/scripting/scripting_model.h +++ b/scripting/scripting_model.h @@ -74,6 +74,7 @@ virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex &child) const; virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual QHash roleNames() const; void setExclusions(ClientModel::Exclusions exclusions); Exclusions exclusions() const; diff --git a/scripting/scripting_model.cpp b/scripting/scripting_model.cpp --- a/scripting/scripting_model.cpp +++ b/scripting/scripting_model.cpp @@ -655,13 +655,6 @@ , m_root(nullptr) , m_exclusions(NoExclusion) { - QHash roleNames; - roleNames.insert(Qt::DisplayRole, "display"); - roleNames.insert(ClientRole, "client"); - roleNames.insert(ScreenRole, "screen"); - roleNames.insert(DesktopRole, "desktop"); - roleNames.insert(ActivityRole, "activity"); - setRoleNames(roleNames); } ClientModel::~ClientModel() @@ -741,6 +734,17 @@ return 0; } +QHash ClientModel::roleNames() const +{ + return { + { Qt::DisplayRole, QByteArrayLiteral("display") }, + { ClientRole, QByteArrayLiteral("client") }, + { ScreenRole, QByteArrayLiteral("screen") }, + { DesktopRole, QByteArrayLiteral("desktop") }, + { ActivityRole, QByteArrayLiteral("activity") }, + }; +} + QModelIndex ClientModel::parent(const QModelIndex &child) const { if (!child.isValid() || child.column() != 0) { diff --git a/tabbox/clientmodel.h b/tabbox/clientmodel.h --- a/tabbox/clientmodel.h +++ b/tabbox/clientmodel.h @@ -64,6 +64,7 @@ virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex& child) const; virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; + virtual QHash roleNames() const; Q_INVOKABLE QString longestCaption() const; /** diff --git a/tabbox/clientmodel.cpp b/tabbox/clientmodel.cpp --- a/tabbox/clientmodel.cpp +++ b/tabbox/clientmodel.cpp @@ -39,14 +39,6 @@ ClientModel::ClientModel(QObject* parent) : QAbstractItemModel(parent) { - QHash roles; - roles[CaptionRole] = "caption"; - roles[DesktopNameRole] = "desktopName"; - roles[MinimizedRole] = "minimized"; - roles[WIdRole] = "windowId"; - roles[CloseableRole] = "closeable"; - roles[IconRole] = "icon"; - setRoleNames(roles); } ClientModel::~ClientModel() @@ -143,6 +135,18 @@ return createIndex(row, 0); } +QHash ClientModel::roleNames() const +{ + return { + { CaptionRole, QByteArrayLiteral("caption") }, + { DesktopNameRole, QByteArrayLiteral("desktopName") }, + { MinimizedRole, QByteArrayLiteral("minimized") }, + { WIdRole, QByteArrayLiteral("windowId") }, + { CloseableRole, QByteArrayLiteral("closeable") }, + { IconRole, QByteArrayLiteral("icon") }, + }; +} + QModelIndex ClientModel::index(QWeakPointer client) const { if (!m_clientList.contains(client)) diff --git a/tabbox/desktopmodel.h b/tabbox/desktopmodel.h --- a/tabbox/desktopmodel.h +++ b/tabbox/desktopmodel.h @@ -59,6 +59,7 @@ virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex& child) const; virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; + virtual QHash roleNames() const; Q_INVOKABLE QString longestCaption() const; /** diff --git a/tabbox/desktopmodel.cpp b/tabbox/desktopmodel.cpp --- a/tabbox/desktopmodel.cpp +++ b/tabbox/desktopmodel.cpp @@ -34,12 +34,6 @@ DesktopModel::DesktopModel(QObject* parent) : QAbstractItemModel(parent) { - QHash roleNames; - roleNames.insert(Qt::DisplayRole, "display"); - roleNames.insert(DesktopNameRole, "caption"); - roleNames.insert(DesktopRole, "desktop"); - roleNames.insert(ClientModelRole, "client"); - setRoleNames(roleNames); } DesktopModel::~DesktopModel() @@ -140,6 +134,16 @@ return createIndex(row, column); } +QHash DesktopModel::roleNames() const +{ + return { + { Qt::DisplayRole, QByteArrayLiteral("display") }, + { DesktopNameRole, QByteArrayLiteral("caption") }, + { DesktopRole, QByteArrayLiteral("desktop") }, + { ClientModelRole, QByteArrayLiteral("client") }, + }; +} + QModelIndex DesktopModel::desktopIndex(int desktop) const { if (desktop > m_desktopList.count())