Changeset View
Changeset View
Standalone View
Standalone View
tabbox/clientmodel.cpp
Show All 33 Lines | |||||
34 | namespace KWin | 34 | namespace KWin | ||
35 | { | 35 | { | ||
36 | namespace TabBox | 36 | namespace TabBox | ||
37 | { | 37 | { | ||
38 | 38 | | |||
39 | ClientModel::ClientModel(QObject* parent) | 39 | ClientModel::ClientModel(QObject* parent) | ||
40 | : QAbstractItemModel(parent) | 40 | : QAbstractItemModel(parent) | ||
41 | { | 41 | { | ||
42 | QHash<int, QByteArray> roles; | | |||
43 | roles[CaptionRole] = "caption"; | | |||
44 | roles[DesktopNameRole] = "desktopName"; | | |||
45 | roles[MinimizedRole] = "minimized"; | | |||
46 | roles[WIdRole] = "windowId"; | | |||
47 | roles[CloseableRole] = "closeable"; | | |||
48 | roles[IconRole] = "icon"; | | |||
49 | setRoleNames(roles); | | |||
50 | } | 42 | } | ||
51 | 43 | | |||
52 | ClientModel::~ClientModel() | 44 | ClientModel::~ClientModel() | ||
53 | { | 45 | { | ||
54 | } | 46 | } | ||
55 | 47 | | |||
56 | QVariant ClientModel::data(const QModelIndex& index, int role) const | 48 | QVariant ClientModel::data(const QModelIndex& index, int role) const | ||
57 | { | 49 | { | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 129 | if (row < 0 || column != 0 || parent.isValid()) { | |||
138 | return QModelIndex(); | 130 | return QModelIndex(); | ||
139 | } | 131 | } | ||
140 | int index = row * columnCount(); | 132 | int index = row * columnCount(); | ||
141 | if (index >= m_clientList.count() && !m_clientList.isEmpty()) | 133 | if (index >= m_clientList.count() && !m_clientList.isEmpty()) | ||
142 | return QModelIndex(); | 134 | return QModelIndex(); | ||
143 | return createIndex(row, 0); | 135 | return createIndex(row, 0); | ||
144 | } | 136 | } | ||
145 | 137 | | |||
138 | QHash<int, QByteArray> ClientModel::roleNames() const | ||||
139 | { | ||||
140 | return { | ||||
141 | { CaptionRole, QByteArrayLiteral("caption") }, | ||||
142 | { DesktopNameRole, QByteArrayLiteral("desktopName") }, | ||||
143 | { MinimizedRole, QByteArrayLiteral("minimized") }, | ||||
144 | { WIdRole, QByteArrayLiteral("windowId") }, | ||||
145 | { CloseableRole, QByteArrayLiteral("closeable") }, | ||||
146 | { IconRole, QByteArrayLiteral("icon") }, | ||||
147 | }; | ||||
148 | } | ||||
149 | | ||||
146 | QModelIndex ClientModel::index(QWeakPointer<TabBoxClient> client) const | 150 | QModelIndex ClientModel::index(QWeakPointer<TabBoxClient> client) const | ||
147 | { | 151 | { | ||
148 | if (!m_clientList.contains(client)) | 152 | if (!m_clientList.contains(client)) | ||
149 | return QModelIndex(); | 153 | return QModelIndex(); | ||
150 | int index = m_clientList.indexOf(client); | 154 | int index = m_clientList.indexOf(client); | ||
151 | int row = index / columnCount(); | 155 | int row = index / columnCount(); | ||
152 | int column = index % columnCount(); | 156 | int column = index % columnCount(); | ||
153 | return createIndex(row, column); | 157 | return createIndex(row, column); | ||
▲ Show 20 Lines • Show All 110 Lines • Show Last 20 Lines |