Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/taskgroupingproxymodel.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Eike Hein <hein.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 | | ||||
21 | #ifndef TASKGROUPINGPROXYMODEL_H | ||||
22 | #define TASKGROUPINGPROXYMODEL_H | ||||
23 | | ||||
24 | #include <QAbstractProxyModel> | ||||
25 | | ||||
26 | #include "abstracttasksmodeliface.h" | ||||
27 | #include "tasksmodel.h" | ||||
28 | | ||||
29 | #include "taskmanager_export.h" | ||||
30 | | ||||
31 | namespace TaskManager | ||||
32 | { | ||||
33 | | ||||
34 | /** | ||||
35 | * @short A proxy tasks model for grouping tasks, forming a tree. | ||||
36 | * | ||||
37 | * This proxy model groups tasks in its source tasks model, forming a tree | ||||
38 | * of tasks. Gouping behavior is influenced by various properties set on | ||||
39 | * the proxy model instance. | ||||
40 | * | ||||
41 | * @author Eike Hein <hein@kde.org> | ||||
42 | **/ | ||||
43 | | ||||
44 | class TASKMANAGER_EXPORT TaskGroupingProxyModel : public QAbstractProxyModel, public AbstractTasksModelIface | ||||
45 | { | ||||
46 | Q_OBJECT | ||||
47 | | ||||
48 | Q_PROPERTY(TasksModel::GroupMode groupMode READ groupMode WRITE setGroupMode NOTIFY groupModeChanged) | ||||
49 | Q_PROPERTY(int windowTasksThreshold READ windowTasksThreshold WRITE setWindowTasksThreshold NOTIFY windowTasksThresholdChanged) | ||||
50 | Q_PROPERTY(QStringList blacklistedAppIds READ blacklistedAppIds WRITE setBlacklistedAppIds NOTIFY blacklistedAppIdsChanged) | ||||
51 | Q_PROPERTY(QStringList blacklistedLauncherUrls READ blacklistedLauncherUrls WRITE setBlacklistedLauncherUrls | ||||
52 | NOTIFY blacklistedLauncherUrlsChanged) | ||||
53 | | ||||
54 | public: | ||||
55 | explicit TaskGroupingProxyModel(QObject *parent = 0); | ||||
56 | virtual ~TaskGroupingProxyModel(); | ||||
57 | | ||||
58 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; | ||||
59 | QModelIndex parent(const QModelIndex &child) const override; | ||||
60 | | ||||
61 | QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; | ||||
62 | QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; | ||||
63 | | ||||
64 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
65 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; | ||||
66 | | ||||
67 | QVariant data(const QModelIndex &proxyIndex, int role) const override; | ||||
68 | | ||||
69 | void setSourceModel(QAbstractItemModel *sourceModel) override; | ||||
70 | | ||||
71 | /** | ||||
72 | * Returns the current group mode, i.e. the criteria by which tasks should | ||||
73 | * be grouped. | ||||
74 | * | ||||
75 | * Defaults to TasksModel::GroupApplication, which groups tasks backed by | ||||
76 | * the same application. | ||||
77 | * | ||||
78 | * If the group mode is TasksModel::GroupDisabled, no grouping is done. | ||||
79 | * | ||||
80 | * @see TasksModel | ||||
81 | * @see setGroupMode | ||||
82 | * @returns the active group mode. | ||||
83 | **/ | ||||
84 | TasksModel::GroupMode groupMode() const; | ||||
85 | | ||||
86 | /** | ||||
87 | * Sets the group mode, i.e. the criteria by which tasks should be grouped. | ||||
88 | * | ||||
89 | * The group mode can be set to TasksModel::GroupDisabled to disable grouping | ||||
90 | * entirely, breaking apart any existing groups. | ||||
91 | * | ||||
92 | * @see TasksModel | ||||
93 | * @see groupMode | ||||
94 | * @param mode A TasksModel group mode. | ||||
95 | **/ | ||||
96 | void setGroupMode(TasksModel::GroupMode mode); | ||||
97 | | ||||
98 | /** | ||||
99 | * As window tasks (AbstractTasksModel::IsWindow) come and go in the source | ||||
100 | * model, groups will be formed when this threshold value is exceeded, and | ||||
101 | * broken apart when it matches or falls below. | ||||
102 | * | ||||
103 | * Defaults to @c -1, which means grouping is done regardless of the number | ||||
104 | * of window tasks in the source model. | ||||
105 | * | ||||
106 | * @see setWindowTasksThreshold | ||||
107 | * @return the threshold number of source window tasks used in grouping | ||||
108 | * decisions. | ||||
109 | **/ | ||||
110 | int windowTasksThreshold() const; | ||||
111 | | ||||
112 | /** | ||||
113 | * Sets the number of source model window tasks (AbstractTasksModel::IsWindow) | ||||
114 | * above which groups will be formed, and at or below which groups will be broken | ||||
115 | * apart. | ||||
116 | * | ||||
117 | * If set to -1, grouping will be done regardless of the number of window tasks | ||||
118 | * in the source model. | ||||
119 | * | ||||
120 | * @see windowTasksThreshold | ||||
121 | * @param threshold A threshold number of source window tasks used in grouping | ||||
122 | * decisions. | ||||
123 | **/ | ||||
124 | void setWindowTasksThreshold(int threshold); | ||||
125 | | ||||
126 | /** | ||||
127 | * A blacklist of app ids (AbstractTasksModel::AppId) that is consulted before | ||||
128 | * grouping a task. If a task's app id is found on the blacklist, it is not | ||||
129 | * grouped. | ||||
130 | * | ||||
131 | * The default app id blacklist is empty. | ||||
132 | * | ||||
133 | * @see setBlacklistedAppIds | ||||
134 | * @returns the blacklist of app ids consulted before grouping a task. | ||||
135 | **/ | ||||
136 | QStringList blacklistedAppIds() const; | ||||
137 | | ||||
138 | /** | ||||
139 | * Sets the blacklist of app ids (AbstractTasksModel::AppId) that is consulted | ||||
140 | * before grouping a task. If a task's app id is found on the blacklist, it is | ||||
141 | * not grouped. | ||||
142 | * | ||||
143 | * When set, groups will be formed and broken apart as necessary. | ||||
144 | * | ||||
145 | * @see blacklistedAppIds | ||||
146 | * @param list a blacklist of app ids to be consulted before grouping a task. | ||||
147 | **/ | ||||
148 | void setBlacklistedAppIds(const QStringList &list); | ||||
149 | | ||||
150 | /** | ||||
151 | * A blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that is | ||||
152 | * consulted before grouping a task. If a task's launcher URL is found on the | ||||
153 | * blacklist, it is not grouped. | ||||
154 | * | ||||
155 | * The default launcher URL blacklist is empty. | ||||
156 | * | ||||
157 | * @see setBlacklistedLauncherUrls | ||||
158 | * @returns the blacklist of launcher URLs consulted before grouping a task. | ||||
159 | **/ | ||||
160 | QStringList blacklistedLauncherUrls() const; | ||||
161 | | ||||
162 | /** | ||||
163 | * Sets the blacklist of launcher URLs (AbstractTasksModel::LauncherUrl) that | ||||
164 | * is consulted before grouping a task. If a task's launcher URL is found on | ||||
165 | * the blacklist, it is not grouped. | ||||
166 | * | ||||
167 | * When set, groups will be formed and broken apart as necessary. | ||||
168 | * | ||||
169 | * @see blacklistedLauncherUrls | ||||
170 | * @param list a blacklist of launcher URLs to be consulted before grouping a task. | ||||
171 | **/ | ||||
172 | void setBlacklistedLauncherUrls(const QStringList &list); | ||||
173 | | ||||
174 | /** | ||||
175 | * Request activation of the task at the given index. Derived classes are | ||||
176 | * free to interpret the meaning of "activate" themselves depending on | ||||
177 | * the nature and state of the task, e.g. launch or raise a window task. | ||||
178 | * | ||||
179 | * @param index An index in this tasks model. | ||||
180 | **/ | ||||
181 | void requestActivate(const QModelIndex &index); | ||||
182 | | ||||
183 | /** | ||||
184 | * Request an additional instance of the application backing the task | ||||
185 | * at the given index. | ||||
186 | * | ||||
187 | * @param index An index in this tasks model. | ||||
188 | **/ | ||||
189 | void requestNewInstance(const QModelIndex &index); | ||||
190 | | ||||
191 | /** | ||||
192 | * Request the task at the given index be closed. | ||||
193 | * | ||||
194 | * @param index An index in this tasks model. | ||||
195 | **/ | ||||
196 | void requestClose(const QModelIndex &index); | ||||
197 | | ||||
198 | /** | ||||
199 | * Request starting an interactive move for the task at the given index. | ||||
200 | * | ||||
201 | * This is meant for tasks that have an associated window, and may be | ||||
202 | * a no-op when there is no window. | ||||
203 | * | ||||
204 | * This base implementation does nothing. | ||||
205 | * | ||||
206 | * @param index An index in this tasks model. | ||||
207 | **/ | ||||
208 | void requestMove(const QModelIndex &index); | ||||
209 | | ||||
210 | /** | ||||
211 | * Request starting an interactive resize for the task at the given index. | ||||
212 | * | ||||
213 | * This is meant for tasks that have an associated window, and may be a | ||||
214 | * no-op when there is no window. | ||||
215 | * | ||||
216 | * @param index An index in this tasks model. | ||||
217 | **/ | ||||
218 | void requestResize(const QModelIndex &index); | ||||
219 | | ||||
220 | /** | ||||
221 | * Request toggling the minimized state of the task at the given index. | ||||
222 | * | ||||
223 | * This is meant for tasks that have an associated window, and may be | ||||
224 | * a no-op when there is no window. | ||||
225 | * | ||||
226 | * This base implementation does nothing. | ||||
227 | * | ||||
228 | * @param index An index in this tasks model. | ||||
229 | **/ | ||||
230 | void requestToggleMinimized(const QModelIndex &index); | ||||
231 | | ||||
232 | /** | ||||
233 | * Request toggling the maximized state of the task at the given index. | ||||
234 | * | ||||
235 | * This is meant for tasks that have an associated window, and may be | ||||
236 | * a no-op when there is no window. | ||||
237 | * | ||||
238 | * @param index An index in this tasks model. | ||||
239 | **/ | ||||
240 | void requestToggleMaximized(const QModelIndex &index); | ||||
241 | | ||||
242 | /** | ||||
243 | * Request toggling the keep-above state of the task at the given index. | ||||
244 | * | ||||
245 | * This is meant for tasks that have an associated window, and may be | ||||
246 | * a no-op when there is no window. | ||||
247 | * | ||||
248 | * @param index An index in this tasks model. | ||||
249 | **/ | ||||
250 | void requestToggleKeepAbove(const QModelIndex &index); | ||||
251 | | ||||
252 | /** | ||||
253 | * Request toggling the keep-below state of the task at the given index. | ||||
254 | * | ||||
255 | * This is meant for tasks that have an associated window, and may be | ||||
256 | * a no-op when there is no window. | ||||
257 | * | ||||
258 | * @param index An index in this tasks model. | ||||
259 | **/ | ||||
260 | void requestToggleKeepBelow(const QModelIndex &index); | ||||
261 | | ||||
262 | /** | ||||
263 | * Request toggling the fullscreen state of the task at the given index. | ||||
264 | * | ||||
265 | * This is meant for tasks that have an associated window, and may be | ||||
266 | * a no-op when there is no window. | ||||
267 | * | ||||
268 | * This base implementation does nothing. | ||||
269 | * | ||||
270 | * @param index An index in this tasks model. | ||||
271 | **/ | ||||
272 | void requestToggleFullScreen(const QModelIndex &index); | ||||
273 | | ||||
274 | /** | ||||
275 | * Request toggling the shaded state of the task at the given index. | ||||
276 | * | ||||
277 | * This is meant for tasks that have an associated window, and may be | ||||
278 | * a no-op when there is no window. | ||||
279 | * | ||||
280 | * @param index An index in this tasks model. | ||||
281 | **/ | ||||
282 | void requestToggleShaded(const QModelIndex &index); | ||||
283 | | ||||
284 | /** | ||||
285 | * Request moving the task at the given index to the specified virtual | ||||
286 | * desktop. | ||||
287 | * | ||||
288 | * This is meant for tasks that have an associated window, and may be | ||||
289 | * a no-op when there is no window. | ||||
290 | * | ||||
291 | * @param index An index in this tasks model. | ||||
292 | * @param desktop A virtual desktop number. | ||||
293 | **/ | ||||
294 | void requestVirtualDesktop(const QModelIndex &index, qint32 desktop); | ||||
295 | | ||||
296 | /** | ||||
297 | * Request informing the window manager of new geometry for a visual | ||||
298 | * delegate for the task at the given index. The geometry should be in | ||||
299 | * screen coordinates. | ||||
300 | * | ||||
301 | * If the task at the given index is a group parent, the geometry is | ||||
302 | * set for all of its children. If the task at the given index is a | ||||
303 | * group member, the geometry is set for all of its siblings. | ||||
304 | * | ||||
305 | * @param index An index in this tasks model. | ||||
306 | * @param geometry Visual delegate geometry in screen coordinates. | ||||
307 | * @param delegate The delegate. Implementations are on their own with | ||||
308 | * regard to extracting information from this, and should take care to | ||||
309 | * reject invalid objects. | ||||
310 | **/ | ||||
311 | void requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, | ||||
312 | QObject *delegate = nullptr); | ||||
313 | | ||||
314 | /** | ||||
315 | * Request toggling whether the task at the given index, along with any | ||||
316 | * tasks matching its kind, should be grouped or not. Task groups will be | ||||
317 | * formed or broken apart as needed, along with affecting future grouping | ||||
318 | * decisions as new tasks appear in the source model. | ||||
319 | * | ||||
320 | * As grouping is toggled for a task, updates are made to the blacklisted* | ||||
321 | * properties of the model instance. | ||||
322 | * | ||||
323 | * @see blacklistedAppIds | ||||
324 | * @see blacklistedLauncherUrls | ||||
325 | * | ||||
326 | * @param index An index in this tasks model. | ||||
327 | **/ | ||||
328 | void requestToggleGrouping(const QModelIndex &index); | ||||
329 | | ||||
330 | Q_SIGNALS: | ||||
331 | void groupModeChanged() const; | ||||
332 | void windowTasksThresholdChanged() const; | ||||
333 | void blacklistedAppIdsChanged() const; | ||||
334 | void blacklistedLauncherUrlsChanged() const; | ||||
335 | | ||||
336 | private: | ||||
337 | class Private; | ||||
338 | QScopedPointer<Private> d; | ||||
339 | | ||||
340 | Q_PRIVATE_SLOT(d, void sourceRowsAboutToBeInserted(const QModelIndex &parent, int first, int last)) | ||||
341 | Q_PRIVATE_SLOT(d, void sourceRowsInserted(const QModelIndex &parent, int start, int end)) | ||||
342 | Q_PRIVATE_SLOT(d, void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)) | ||||
343 | Q_PRIVATE_SLOT(d, void sourceRowsRemoved(const QModelIndex &parent, int start, int end)) | ||||
344 | Q_PRIVATE_SLOT(d, void sourceModelAboutToBeReset()) | ||||
345 | Q_PRIVATE_SLOT(d, void sourceModelReset()) | ||||
346 | Q_PRIVATE_SLOT(d, void sourceDataChanged(QModelIndex,QModelIndex,QVector<int>)) | ||||
347 | }; | ||||
348 | | ||||
349 | } | ||||
350 | | ||||
351 | #endif |