GCC Code Coverage Report


Directory: ./
File: src/client/plasmawindowmodel.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 233 239 97.5%
Branches: 121 160 75.6%

Line Branch Exec Source
1 /********************************************************************
2 Copyright 2015 Eike Hein <hein@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #include "plasmawindowmodel.h"
21 #include "plasmawindowmanagement.h"
22
23 #include <QMetaEnum>
24
25 namespace Wrapland
26 {
27 namespace Client
28 {
29
30 class Q_DECL_HIDDEN PlasmaWindowModel::Private
31 {
32 public:
33 Private(PlasmaWindowModel* q);
34 QList<PlasmaWindow*> windows;
35 95 PlasmaWindow* window = nullptr;
36
37 void addWindow(PlasmaWindow* window);
38 void dataChanged(PlasmaWindow* window, int role);
39
40 private:
41 PlasmaWindowModel* q;
42 };
43
44 95 PlasmaWindowModel::Private::Private(PlasmaWindowModel* q)
45 95 : q(q)
46 {
47 95 }
48
49 70 void PlasmaWindowModel::Private::addWindow(PlasmaWindow* window)
50 {
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (windows.indexOf(window) != -1) {
52 return;
53 }
54
55 70 int const count = windows.count();
56 70 q->beginInsertRows(QModelIndex(), count, count);
57 70 windows.append(window);
58 70 q->endInsertRows();
59
60 72 auto removeWindow = [window, this] {
61 2 const int row = windows.indexOf(window);
62
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (row != -1) {
63 2 q->beginRemoveRows(QModelIndex(), row, row);
64 2 windows.removeAt(row);
65 2 q->endRemoveRows();
66 2 }
67 2 };
68
69 70 QObject::connect(window, &PlasmaWindow::unmapped, q, removeWindow);
70 70 QObject::connect(window, &QObject::destroyed, q, removeWindow);
71
72 71 QObject::connect(window, &PlasmaWindow::titleChanged, q, [window, this] {
73 1 this->dataChanged(window, Qt::DisplayRole);
74 1 });
75
76 93 QObject::connect(window, &PlasmaWindow::iconChanged, q, [window, this] {
77 23 this->dataChanged(window, Qt::DecorationRole);
78 23 });
79
80 71 QObject::connect(window, &PlasmaWindow::appIdChanged, q, [window, this] {
81 1 this->dataChanged(window, PlasmaWindowModel::AppId);
82 1 });
83
84 72 QObject::connect(window, &PlasmaWindow::activeChanged, q, [window, this] {
85 2 this->dataChanged(window, IsActive);
86 2 });
87
88 72 QObject::connect(window, &PlasmaWindow::fullscreenableChanged, q, [window, this] {
89 2 this->dataChanged(window, IsFullscreenable);
90 2 });
91
92 72 QObject::connect(window, &PlasmaWindow::fullscreenChanged, q, [window, this] {
93 2 this->dataChanged(window, IsFullscreen);
94 2 });
95
96 72 QObject::connect(window, &PlasmaWindow::maximizeableChanged, q, [window, this] {
97 2 this->dataChanged(window, IsMaximizable);
98 2 });
99
100 73 QObject::connect(window, &PlasmaWindow::maximizedChanged, q, [window, this] {
101 3 this->dataChanged(window, IsMaximized);
102 3 });
103
104 72 QObject::connect(window, &PlasmaWindow::minimizeableChanged, q, [window, this] {
105 2 this->dataChanged(window, IsMinimizable);
106 2 });
107
108 73 QObject::connect(window, &PlasmaWindow::minimizedChanged, q, [window, this] {
109 3 this->dataChanged(window, IsMinimized);
110 3 });
111
112 73 QObject::connect(window, &PlasmaWindow::keepAboveChanged, q, [window, this] {
113 3 this->dataChanged(window, IsKeepAbove);
114 3 });
115
116 73 QObject::connect(window, &PlasmaWindow::keepBelowChanged, q, [window, this] {
117 3 this->dataChanged(window, IsKeepBelow);
118 3 });
119
120 73 QObject::connect(window, &PlasmaWindow::onAllDesktopsChanged, q, [window, this] {
121 3 this->dataChanged(window, IsOnAllDesktops);
122 3 });
123
124 72 QObject::connect(window, &PlasmaWindow::demandsAttentionChanged, q, [window, this] {
125 2 this->dataChanged(window, IsDemandingAttention);
126 2 });
127
128 72 QObject::connect(window, &PlasmaWindow::skipTaskbarChanged, q, [window, this] {
129 2 this->dataChanged(window, SkipTaskbar);
130 2 });
131
132 72 QObject::connect(window, &PlasmaWindow::skipSwitcherChanged, q, [window, this] {
133 2 this->dataChanged(window, SkipSwitcher);
134 2 });
135
136 72 QObject::connect(window, &PlasmaWindow::shadeableChanged, q, [window, this] {
137 2 this->dataChanged(window, IsShadeable);
138 2 });
139
140 73 QObject::connect(window, &PlasmaWindow::shadedChanged, q, [window, this] {
141 3 this->dataChanged(window, IsShaded);
142 3 });
143
144 72 QObject::connect(window, &PlasmaWindow::movableChanged, q, [window, this] {
145 2 this->dataChanged(window, IsMovable);
146 2 });
147
148 72 QObject::connect(window, &PlasmaWindow::resizableChanged, q, [window, this] {
149 2 this->dataChanged(window, IsResizable);
150 2 });
151
152 72 QObject::connect(window, &PlasmaWindow::virtualDesktopChangeableChanged, q, [window, this] {
153 2 this->dataChanged(window, IsVirtualDesktopChangeable);
154 2 });
155
156 72 QObject::connect(window, &PlasmaWindow::closeableChanged, q, [window, this] {
157 2 this->dataChanged(window, IsCloseable);
158 2 });
159
160 71 QObject::connect(window, &PlasmaWindow::geometryChanged, q, [window, this] {
161 1 this->dataChanged(window, Geometry);
162 1 });
163
164 72 QObject::connect(window, &PlasmaWindow::plasmaVirtualDesktopEntered, q, [window, this] {
165 2 this->dataChanged(window, VirtualDesktops);
166 2 });
167
168 72 QObject::connect(window, &PlasmaWindow::plasmaVirtualDesktopLeft, q, [window, this] {
169 2 this->dataChanged(window, VirtualDesktops);
170 2 });
171 70 }
172
173 74 void PlasmaWindowModel::Private::dataChanged(PlasmaWindow* window, int role)
174 {
175 74 QModelIndex idx = q->index(windows.indexOf(window));
176
2/4
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
74 Q_EMIT q->dataChanged(idx, idx, QVector<int>() << role);
177 74 }
178
179 95 PlasmaWindowModel::PlasmaWindowModel(PlasmaWindowManagement* parent)
180 95 : QAbstractListModel(parent)
181
2/4
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 95 times.
95 , d(new Private(this))
182 95 {
183
1/2
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
168 connect(parent, &PlasmaWindowManagement::interfaceAboutToBeReleased, this, [this] {
184 73 beginResetModel();
185 73 d->windows.clear();
186 73 endResetModel();
187 73 });
188
189
1/2
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
164 connect(parent, &PlasmaWindowManagement::windowCreated, this, [this](PlasmaWindow* window) {
190 69 d->addWindow(window);
191 69 });
192
193
6/10
✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 95 times.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
96 for (auto it = parent->windows().constBegin(); it != parent->windows().constEnd(); ++it) {
194
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 d->addWindow(*it);
195 1 }
196 95 }
197
198 190 PlasmaWindowModel::~PlasmaWindowModel()
199 190 {
200 190 }
201
202 24 QHash<int, QByteArray> PlasmaWindowModel::roleNames() const
203 {
204 24 QHash<int, QByteArray> roles;
205
206
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 roles.insert(Qt::DisplayRole, "DisplayRole");
207
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 roles.insert(Qt::DecorationRole, "DecorationRole");
208
209
4/8
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
24 QMetaEnum e = metaObject()->enumerator(metaObject()->indexOfEnumerator("AdditionalRoles"));
210
211
3/4
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 552 times.
✓ Branch 3 taken 24 times.
576 for (int i = 0; i < e.keyCount(); ++i) {
212
4/8
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 552 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 552 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 552 times.
✗ Branch 7 not taken.
552 roles.insert(e.value(i), e.key(i));
213 552 }
214
215 24 return roles;
216
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 }
217
218 91 QVariant PlasmaWindowModel::data(QModelIndex const& index, int role) const
219 {
220
2/4
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 91 times.
91 if (!index.isValid() || index.row() >= d->windows.count()) {
221 return QVariant();
222 }
223
224 91 PlasmaWindow const* window = d->windows.at(index.row());
225
226
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 3 times.
91 if (role == Qt::DisplayRole) {
227 3 return window->title();
228
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 87 times.
88 } else if (role == Qt::DecorationRole) {
229
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 return window->icon();
230
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 84 times.
87 } else if (role == AppId) {
231 3 return window->appId();
232
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 82 times.
84 } else if (role == Pid) {
233 2 return window->pid();
234
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 78 times.
82 } else if (role == IsActive) {
235 4 return window->isActive();
236
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 74 times.
78 } else if (role == IsFullscreenable) {
237 4 return window->isFullscreenable();
238
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 70 times.
74 } else if (role == IsFullscreen) {
239 4 return window->isFullscreen();
240
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 66 times.
70 } else if (role == IsMaximizable) {
241 4 return window->isMaximizeable();
242
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 62 times.
66 } else if (role == IsMaximized) {
243 4 return window->isMaximized();
244
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 58 times.
62 } else if (role == IsMinimizable) {
245 4 return window->isMinimizeable();
246
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 54 times.
58 } else if (role == IsMinimized) {
247 4 return window->isMinimized();
248
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 50 times.
54 } else if (role == IsKeepAbove) {
249 4 return window->isKeepAbove();
250
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 46 times.
50 } else if (role == IsKeepBelow) {
251 4 return window->isKeepBelow();
252
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 42 times.
46 } else if (role == IsOnAllDesktops) {
253 4 return window->isOnAllDesktops();
254
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 38 times.
42 } else if (role == IsDemandingAttention) {
255 4 return window->isDemandingAttention();
256
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 34 times.
38 } else if (role == SkipTaskbar) {
257 4 return window->skipTaskbar();
258
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 31 times.
34 } else if (role == SkipSwitcher) {
259 3 return window->skipSwitcher();
260
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 27 times.
31 } else if (role == IsShadeable) {
261 4 return window->isShadeable();
262
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 23 times.
27 } else if (role == IsShaded) {
263 4 return window->isShaded();
264
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 19 times.
23 } else if (role == IsMovable) {
265 4 return window->isMovable();
266
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 15 times.
19 } else if (role == IsResizable) {
267 4 return window->isResizable();
268
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 11 times.
15 } else if (role == IsVirtualDesktopChangeable) {
269 4 return window->isVirtualDesktopChangeable();
270
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
11 } else if (role == IsCloseable) {
271 4 return window->isCloseable();
272
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
7 } else if (role == Geometry) {
273 3 return window->geometry();
274
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 } else if (role == VirtualDesktops) {
275 4 return window->plasmaVirtualDesktops();
276 }
277
278 return QVariant();
279 91 }
280
281 221 int PlasmaWindowModel::rowCount(QModelIndex const& parent) const
282 {
283
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 220 times.
221 return parent.isValid() ? 0 : d->windows.count();
284 }
285
286 124 QModelIndex PlasmaWindowModel::index(int row, int column, QModelIndex const& parent) const
287 {
288
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 2 times.
124 return hasIndex(row, column, parent) ? createIndex(row, column, d->windows.at(row))
289 2 : QModelIndex();
290 }
291
292 3 Q_INVOKABLE void PlasmaWindowModel::requestActivate(int row)
293 {
294
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
3 if (row >= 0 && row < d->windows.count()) {
295 1 d->windows.at(row)->requestActivate();
296 1 }
297 3 }
298
299 3 Q_INVOKABLE void PlasmaWindowModel::requestClose(int row)
300 {
301
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
3 if (row >= 0 && row < d->windows.count()) {
302 1 d->windows.at(row)->requestClose();
303 1 }
304 3 }
305
306 2 Q_INVOKABLE void PlasmaWindowModel::requestMove(int row)
307 {
308
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if (row >= 0 && row < d->windows.count()) {
309 1 d->windows.at(row)->requestMove();
310 1 }
311 2 }
312
313 2 Q_INVOKABLE void PlasmaWindowModel::requestResize(int row)
314 {
315
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if (row >= 0 && row < d->windows.count()) {
316 1 d->windows.at(row)->requestResize();
317 1 }
318 2 }
319
320 4 Q_INVOKABLE void PlasmaWindowModel::requestToggleKeepAbove(int row)
321 {
322
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
4 if (row >= 0 && row < d->windows.count()) {
323 2 d->windows.at(row)->requestToggleKeepAbove();
324 2 }
325 4 }
326
327 4 Q_INVOKABLE void PlasmaWindowModel::requestToggleKeepBelow(int row)
328 {
329
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
4 if (row >= 0 && row < d->windows.count()) {
330 2 d->windows.at(row)->requestToggleKeepBelow();
331 2 }
332 4 }
333
334 4 Q_INVOKABLE void PlasmaWindowModel::requestToggleMinimized(int row)
335 {
336
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
4 if (row >= 0 && row < d->windows.count()) {
337 2 d->windows.at(row)->requestToggleMinimized();
338 2 }
339 4 }
340
341 4 Q_INVOKABLE void PlasmaWindowModel::requestToggleMaximized(int row)
342 {
343
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
4 if (row >= 0 && row < d->windows.count()) {
344 2 d->windows.at(row)->requestToggleMaximized();
345 2 }
346 4 }
347
348 Q_INVOKABLE void PlasmaWindowModel::setMinimizedGeometry(int row, Surface* panel, QRect const& geom)
349 {
350 if (row >= 0 && row < d->windows.count()) {
351 d->windows.at(row)->setMinimizedGeometry(panel, geom);
352 }
353 }
354
355 3 Q_INVOKABLE void PlasmaWindowModel::requestToggleShaded(int row)
356 {
357
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
3 if (row >= 0 && row < d->windows.count()) {
358 2 d->windows.at(row)->requestToggleShaded();
359 2 }
360 3 }
361
362 }
363 }
364