Expose rowCount as data role in TaskGroupingProxyModel.

Summary:
This adds a new data role "ChildCount" to AbstractTasksModel and
implements it in TaskGroupingProxyModel.

The purpose of this data role is as a means of signalling to a Qt
Quick delegate for a top-level row that a property of the item -
namely the number of children it has - has changed. Qt Quick's poor
support for tree models makes the existing way of signaling this
(rowsInserted) prohibitive to use.

The Task Manager applet needs this info because it's in charge of
telling the window manager about the screen coordinates of window
delegates (through support code in this library). When a window is
directly added to an existing group, there is no new delegate
created, nor does the existing delegate change position. An
increase of ChildCount will be used in this case to decide to
publish delegate geo for the new window.

CCBUG:372699

Reviewers: #plasma, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D3482
wilder-5.14
Eike Hein 9 years ago
parent b072ad0ac8
commit 781bb34269
  1. 1
      libtaskmanager/abstracttasksmodel.h
  2. 13
      libtaskmanager/taskgroupingproxymodel.cpp

@ -59,6 +59,7 @@ public:
IsStartup, /**< This is a startup task. */
IsLauncher, /**< This is a launcher task. */
IsGroupParent, /**< This is a parent item for a group of child tasks. */
ChildCount, /**< The number of tasks in this group. */
IsGroupable, /**< Whether this task is being ignored by grouping or not. */
IsActive, /**< This is the currently active task. */
IsClosable, /**< requestClose (see below) available. */

@ -419,13 +419,11 @@ bool TaskGroupingProxyModel::Private::tryToGroup(const QModelIndex &sourceIndex,
if (appsMatch(sourceIndex, groupRep)) {
const QModelIndex parent = q->index(i, 0);
bool groupFormed = false;
if (!silent) {
const int newIndex = rowMap.at(i).count();
if (newIndex == 1) {
groupFormed = true;
q->beginInsertRows(parent, 0, 1);
} else {
q->beginInsertRows(parent, newIndex, newIndex);
@ -437,14 +435,7 @@ bool TaskGroupingProxyModel::Private::tryToGroup(const QModelIndex &sourceIndex,
if (!silent) {
q->endInsertRows();
// If we turned a top-level item into a group parent, we need
// to let consumers know.
// TODO: It _might_ be worth optimizing this at some point by
// adding a roles constaint (e.g. IsGroupParent, MimeType, ...);
// see data().
if (groupFormed) {
q->dataChanged(parent, parent);
}
q->dataChanged(parent, parent);
}
return true;
@ -715,6 +706,8 @@ QVariant TaskGroupingProxyModel::data(const QModelIndex &proxyIndex, int role) c
return QVariant();
} else if (role == AbstractTasksModel::IsGroupParent) {
return true;
} else if (role == AbstractTasksModel::ChildCount) {
return rowCount(proxyIndex);
} else if (role == AbstractTasksModel::IsActive) {
return d->any(proxyIndex, AbstractTasksModel::IsActive);
} else if (role == AbstractTasksModel::IsClosable) {

Loading…
Cancel
Save