Don't use deprecated QAbstractItemModel::setRoleNames
Summary: setRoleNames() method is deprecated since Qt 5.0. It is strongly advised to reimplement roleNames() method instead. Reviewers: #kwin, apol Reviewed By: apol Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D22358
This commit is contained in:
parent
5e0e708a76
commit
0be5bc45a7
8 changed files with 49 additions and 28 deletions
|
@ -116,13 +116,6 @@ bool LayoutPreview::eventFilter(QObject *object, QEvent *event)
|
|||
ExampleClientModel::ExampleClientModel (QObject* parent)
|
||||
: QAbstractListModel (parent)
|
||||
{
|
||||
QHash<int, QByteArray> 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 @@ int ExampleClientModel::rowCount(const QModelIndex &parent) const
|
|||
return m_services.size();
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> 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))
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual QHash<int, QByteArray> roleNames() const;
|
||||
Q_INVOKABLE QString longestCaption() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -655,13 +655,6 @@ ClientModel::ClientModel(QObject *parent)
|
|||
, m_root(nullptr)
|
||||
, m_exclusions(NoExclusion)
|
||||
{
|
||||
QHash<int, QByteArray> 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 @@ int ClientModel::rowCount(const QModelIndex &parent) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> 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) {
|
||||
|
|
|
@ -74,6 +74,7 @@ public:
|
|||
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<int, QByteArray> roleNames() const;
|
||||
|
||||
void setExclusions(ClientModel::Exclusions exclusions);
|
||||
Exclusions exclusions() const;
|
||||
|
|
|
@ -39,14 +39,6 @@ namespace TabBox
|
|||
ClientModel::ClientModel(QObject* parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
QHash<int, QByteArray> 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 @@ QModelIndex ClientModel::index(int row, int column, const QModelIndex& parent) c
|
|||
return createIndex(row, 0);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> 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<TabBoxClient> client) const
|
||||
{
|
||||
if (!m_clientList.contains(client))
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
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<int, QByteArray> roleNames() const;
|
||||
Q_INVOKABLE QString longestCaption() const;
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,12 +34,6 @@ namespace TabBox
|
|||
DesktopModel::DesktopModel(QObject* parent)
|
||||
: QAbstractItemModel(parent)
|
||||
{
|
||||
QHash<int, QByteArray> 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 @@ QModelIndex DesktopModel::index(int row, int column, const QModelIndex& parent)
|
|||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> 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())
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
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<int, QByteArray> roleNames() const;
|
||||
Q_INVOKABLE QString longestCaption() const;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue