From 781bb3426978661112e9ac7fef3574ca7d73bae7 Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Thu, 24 Nov 2016 18:30:17 +0900 Subject: [PATCH] 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 --- libtaskmanager/abstracttasksmodel.h | 1 + libtaskmanager/taskgroupingproxymodel.cpp | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/libtaskmanager/abstracttasksmodel.h b/libtaskmanager/abstracttasksmodel.h index b0b10dbdc..82d140d56 100644 --- a/libtaskmanager/abstracttasksmodel.h +++ b/libtaskmanager/abstracttasksmodel.h @@ -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. */ diff --git a/libtaskmanager/taskgroupingproxymodel.cpp b/libtaskmanager/taskgroupingproxymodel.cpp index 85e94e4a2..ae1d6cfb7 100644 --- a/libtaskmanager/taskgroupingproxymodel.cpp +++ b/libtaskmanager/taskgroupingproxymodel.cpp @@ -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) {