Plasma-workspace

taskgroupingproxymodel.h
1/*
2 SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include <QAbstractProxyModel>
10
11#include <memory>
12
13#include "abstracttasksmodeliface.h"
14#include "tasksmodel.h"
15
16#include "taskmanager_export.h"
17
18namespace TaskManager
19{
20/**
21 * @short A proxy tasks model for grouping tasks, forming a tree.
22 *
23 * This proxy model groups tasks in its source tasks model, forming a tree
24 * of tasks. Gouping behavior is influenced by various properties set on
25 * the proxy model instance.
26 *
27 * @author Eike Hein <hein@kde.org>
28 **/
29
31{
32 Q_OBJECT
33
34 Q_PROPERTY(TasksModel::GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged)
35 Q_PROPERTY(bool groupDemandingAttention READ groupDemandingAttention WRITE setGroupDemandingAttention NOTIFY groupDemandingAttentionChanged)
36 Q_PROPERTY(int windowTasksThreshold READ windowTasksThreshold WRITE setWindowTasksThreshold NOTIFY windowTasksThresholdChanged)
37 Q_PROPERTY(QStringList blacklistedAppIds READ blacklistedAppIds WRITE setBlacklistedAppIds NOTIFY blacklistedAppIdsChanged)
38 Q_PROPERTY(QStringList blacklistedLauncherUrls READ blacklistedLauncherUrls WRITE setBlacklistedLauncherUrls NOTIFY blacklistedLauncherUrlsChanged)
39
40public:
41 explicit TaskGroupingProxyModel(QObject *parent = nullptr);
42 ~TaskGroupingProxyModel() override;
43
44 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
45 QModelIndex parent(const QModelIndex &child) const override;
46
47 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
48 QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
49
50 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
51 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
52 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
53
54 QVariant data(const QModelIndex &proxyIndex, int role) const override;
55
56 void setSourceModel(QAbstractItemModel *sourceModel) override;
57
58 /**
59 * Returns the current group mode, i.e. the criteria by which tasks should
60 * be grouped.
61 *
62 * Defaults to TasksModel::GroupApplication, which groups tasks backed by
63 * the same application.
64 *
65 * If the group mode is TasksModel::GroupDisabled, no grouping is done.
66 *
67 * @see TasksModel
68 * @see setGroupMode
69 * @returns the active group mode.
70 **/
71 TasksModel::GroupMode groupMode() const;
72
73 /**
74 * Sets the group mode, i.e. the criteria by which tasks should be grouped.
75 *
76 * The group mode can be set to TasksModel::GroupDisabled to disable grouping
77 * entirely, breaking apart any existing groups.
78 *
79 * @see TasksModel
80 * @see groupMode
81 * @param mode A TasksModel group mode.
82 **/
83 void setGroupMode(TasksModel::GroupMode mode);
84
85 /**
86 * Whether new tasks which demand attention
87 * (AbstractTasksModel::IsDemandingAttention) should be grouped immediately,
88 * or only once they have stopped demanding attention. Defaults to @c false.
89 *
90 * @see setGroupDemandingAttention
91 * @returns whether tasks which demand attention are grouped immediately.
92 **/
93 bool groupDemandingAttention() const;
94
95 /**
96 * Sets whether new tasks which demand attention
97 * (AbstractTasksModel::IsDemandingAttention) should be grouped immediately,
98 * or only once they have stopped demanding attention.
99 *
100 * @see groupDemandingAttention
101 * @param group Whether tasks with demand attention should be grouped immediately.
102 **/
103 void setGroupDemandingAttention(bool group);
104
105 /**
106 * As window tasks (AbstractTasksModel::IsWindow) come and go in the source
107 * model, groups will be formed when this threshold value is exceeded, and
108 * broken apart when it matches or falls below.
109 *
110 * Defaults to @c -1, which means grouping is done regardless of the number
111 * of window tasks in the source model.
112 *
113 * @see setWindowTasksThreshold
114 * @return the threshold number of source window tasks used in grouping
115 * decisions.
116 **/
117 int windowTasksThreshold() const;
118
119 /**
120 * Sets the number of source model window tasks (AbstractTasksModel::IsWindow)
121 * above which groups will be formed, and at or below which groups will be broken
122 * apart.
123 *
124 * If set to -1, grouping will be done regardless of the number of window tasks
125 * in the source model.
126 *
127 * @see windowTasksThreshold
128 * @param threshold A threshold number of source window tasks used in grouping
129 * decisions.
130 **/
131 void setWindowTasksThreshold(int threshold);
132
133 /**
134 * A blacklist of app ids (AbstractTasksModel::AppId) that is consulted before
135 * grouping a task. If a task's app id is found on the blacklist, it is not
136 * grouped.
137 *
138 * The default app id blacklist is empty.
139 *
140 * @see setBlacklistedAppIds
141 * @returns the blacklist of app ids consulted before grouping a task.
142 **/
143 QStringList blacklistedAppIds() const;
144
145 /**
146 * Sets the blacklist of app ids (AbstractTasksModel::AppId) that is consulted
147 * before grouping a task. If a task's app id is found on the blacklist, it is
148 * not grouped.
149 *
150 * When set, groups will be formed and broken apart as necessary.
151 *
152 * @see blacklistedAppIds
153 * @param list a blacklist of app ids to be consulted before grouping a task.
154 **/
155 void setBlacklistedAppIds(const QStringList &list);
156
157 /**
158 * A blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that is
159 * consulted before grouping a task. If a task's launcher URL is found on the
160 * blacklist, it is not grouped.
161 *
162 * The default launcher URL blacklist is empty.
163 *
164 * @see setBlacklistedLauncherUrls
165 * @returns the blacklist of launcher URLs consulted before grouping a task.
166 **/
167 QStringList blacklistedLauncherUrls() const;
168
169 /**
170 * Sets the blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that
171 * is consulted before grouping a task. If a task's launcher URL is found on
172 * the blacklist, it is not grouped.
173 *
174 * When set, groups will be formed and broken apart as necessary.
175 *
176 * @see blacklistedLauncherUrls
177 * @param list a blacklist of launcher URLs to be consulted before grouping a task.
178 **/
179 void setBlacklistedLauncherUrls(const QStringList &list);
180
181 /**
182 * Request activation of the task at the given index. Derived classes are
183 * free to interpret the meaning of "activate" themselves depending on
184 * the nature and state of the task, e.g. launch or raise a window task.
185 *
186 * @param index An index in this tasks model.
187 **/
188 void requestActivate(const QModelIndex &index) override;
189
190 /**
191 * Request an additional instance of the application backing the task
192 * at the given index.
193 *
194 * @param index An index in this tasks model.
195 **/
196 void requestNewInstance(const QModelIndex &index) override;
197
198 /**
199 * Requests to open the given URLs with the application backing the task
200 * at the given index.
201 *
202 * @param index An index in this tasks model.
203 * @param urls The URLs to be passed to the application.
204 **/
205 void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) override;
206
207 /**
208 * Request the task at the given index be closed.
209 *
210 * @param index An index in this tasks model.
211 **/
212 void requestClose(const QModelIndex &index) override;
213
214 /**
215 * Request starting an interactive move for the task at the given index.
216 *
217 * This is meant for tasks that have an associated window, and may be
218 * a no-op when there is no window.
219 *
220 * This base implementation does nothing.
221 *
222 * @param index An index in this tasks model.
223 **/
224 void requestMove(const QModelIndex &index) override;
225
226 /**
227 * Request starting an interactive resize for the task at the given index.
228 *
229 * This is meant for tasks that have an associated window, and may be a
230 * no-op when there is no window.
231 *
232 * @param index An index in this tasks model.
233 **/
234 void requestResize(const QModelIndex &index) override;
235
236 /**
237 * Request toggling the minimized state of the task at the given index.
238 *
239 * This is meant for tasks that have an associated window, and may be
240 * a no-op when there is no window.
241 *
242 * This base implementation does nothing.
243 *
244 * @param index An index in this tasks model.
245 **/
246 void requestToggleMinimized(const QModelIndex &index) override;
247
248 /**
249 * Request toggling the maximized state of the task at the given index.
250 *
251 * This is meant for tasks that have an associated window, and may be
252 * a no-op when there is no window.
253 *
254 * @param index An index in this tasks model.
255 **/
256 void requestToggleMaximized(const QModelIndex &index) override;
257
258 /**
259 * Request toggling the keep-above state of the task at the given index.
260 *
261 * This is meant for tasks that have an associated window, and may be
262 * a no-op when there is no window.
263 *
264 * @param index An index in this tasks model.
265 **/
266 void requestToggleKeepAbove(const QModelIndex &index) override;
267
268 /**
269 * Request toggling the keep-below state of the task at the given index.
270 *
271 * This is meant for tasks that have an associated window, and may be
272 * a no-op when there is no window.
273 *
274 * @param index An index in this tasks model.
275 **/
276 void requestToggleKeepBelow(const QModelIndex &index) override;
277
278 /**
279 * Request toggling the fullscreen state of the task at the given index.
280 *
281 * This is meant for tasks that have an associated window, and may be
282 * a no-op when there is no window.
283 *
284 * This base implementation does nothing.
285 *
286 * @param index An index in this tasks model.
287 **/
288 void requestToggleFullScreen(const QModelIndex &index) override;
289
290 /**
291 * Request toggling the shaded state of the task at the given index.
292 *
293 * This is meant for tasks that have an associated window, and may be
294 * a no-op when there is no window.
295 *
296 * @param index An index in this tasks model.
297 **/
298 void requestToggleShaded(const QModelIndex &index) override;
299
300 /**
301 * Request entering the window at the given index on the specified virtual desktops,
302 * leaving any other desktops.
303 *
304 * On Wayland, virtual desktop ids are QStrings. On X11, they are uint >0.
305 *
306 * An empty list has a special meaning: The window is entered on all virtual desktops
307 * in the session.
308 *
309 * On X11, a window can only be on one or all virtual desktops. Therefore, only the
310 * first list entry is actually used.
311 *
312 * On X11, the id 0 has a special meaning: The window is entered on all virtual
313 * desktops in the session.
314 *
315 * @param index An index in this window tasks model.
316 * @param desktops A list of virtual desktop ids.
317 **/
318 void requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) override;
319
320 /**
321 * Request entering the window at the given index on a new virtual desktop,
322 * which is created in response to this request.
323 *
324 * @param index An index in this window tasks model.
325 **/
326 void requestNewVirtualDesktop(const QModelIndex &index) override;
327
328 /**
329 * Request moving the task at the given index to the specified activities.
330 *
331 * This is meant for tasks that have an associated window, and may be
332 * a no-op when there is no window.
333 *
334 * This base implementation does nothing.
335 *
336 * @param index An index in this tasks model.
337 * @param activities The new list of activities.
338 **/
339 void requestActivities(const QModelIndex &index, const QStringList &activities) override;
340
341 /**
342 * Request informing the window manager of new geometry for a visual
343 * delegate for the task at the given index. The geometry should be in
344 * screen coordinates.
345 *
346 * If the task at the given index is a group parent, the geometry is
347 * set for all of its children. If the task at the given index is a
348 * group member, the geometry is set for all of its siblings.
349 *
350 * @param index An index in this tasks model.
351 * @param geometry Visual delegate geometry in screen coordinates.
352 * @param delegate The delegate. Implementations are on their own with
353 * regard to extracting information from this, and should take care to
354 * reject invalid objects.
355 **/
356 void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) override;
357
358 /**
359 * Request toggling whether the task at the given index, along with any
360 * tasks matching its kind, should be grouped or not. Task groups will be
361 * formed or broken apart as needed, along with affecting future grouping
362 * decisions as new tasks appear in the source model.
363 *
364 * As grouping is toggled for a task, updates are made to the blacklisted*
365 * properties of the model instance.
366 *
367 * @see blacklistedAppIds
368 * @see blacklistedLauncherUrls
369 *
370 * @param index An index in this tasks model.
371 **/
372 void requestToggleGrouping(const QModelIndex &index);
373
374Q_SIGNALS:
375 void groupModeChanged() const;
376 void groupDemandingAttentionChanged() const;
377 void windowTasksThresholdChanged() const;
378 void blacklistedAppIdsChanged() const;
379 void blacklistedLauncherUrlsChanged() const;
380
381private:
382 class Private;
383 std::unique_ptr<Private> d;
384
385 Q_PRIVATE_SLOT(d, void sourceRowsAboutToBeInserted(const QModelIndex &parent, int first, int last))
386 Q_PRIVATE_SLOT(d, void sourceRowsInserted(const QModelIndex &parent, int start, int end))
387 Q_PRIVATE_SLOT(d, void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last))
388 Q_PRIVATE_SLOT(d, void sourceRowsRemoved(const QModelIndex &parent, int start, int end))
389 Q_PRIVATE_SLOT(d, void sourceModelAboutToBeReset())
390 Q_PRIVATE_SLOT(d, void sourceModelReset())
391 Q_PRIVATE_SLOT(d, void sourceDataChanged(QModelIndex, QModelIndex, QList<int>))
392};
393
394}
Pure virtual method interface for tasks model implementations.
A proxy tasks model for grouping tasks, forming a tree.
Q_SCRIPTABLE Q_NOREPLY void start()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.