From 592dc9e0bc79e11664c880eb9385ab1b76188af5 Mon Sep 17 00:00:00 2001 From: Eike Hein Date: Sat, 12 Aug 2017 09:30:12 +0900 Subject: [PATCH] Add support for moving group members within a group. Summary: BUG:383405 Reviewers: #plasma, davidedmundson, argonel Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D7267 --- libtaskmanager/tasksmodel.cpp | 9 +++++---- libtaskmanager/tasksmodel.h | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp index 0ca4e8642..cf6f95f89 100644 --- a/libtaskmanager/tasksmodel.cpp +++ b/libtaskmanager/tasksmodel.cpp @@ -1430,9 +1430,9 @@ void TasksModel::requestToggleGrouping(const QModelIndex &index) } } -bool TasksModel::move(int row, int newPos) +bool TasksModel::move(int row, int newPos, const QModelIndex &parent) { - if (d->sortMode != SortManual || row == newPos || newPos < 0 || newPos >= rowCount()) { + if (d->sortMode != SortManual || row == newPos || newPos < 0 || newPos >= rowCount(parent)) { return false; } @@ -1523,7 +1523,7 @@ bool TasksModel::move(int row, int newPos) endMoveRows(); } else { - beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newPos > row) ? newPos + 1 : newPos); + beginMoveRows(parent, row, row, parent, (newPos > row) ? newPos + 1 : newPos); // Translate to sort map indices. const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); @@ -1535,7 +1535,8 @@ bool TasksModel::move(int row, int newPos) d->sortedPreFilterRows.move(row, newPos); // If we moved a group parent, consolidate sort map for children. - if (groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) { + if (!parent.isValid() && groupMode() != GroupDisabled + && d->groupingProxyModel->rowCount(groupingRowIndex)) { d->consolidateManualSortMapForGroup(groupingRowIndex); } diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h index 4eb2000ef..1ad4c5583 100644 --- a/libtaskmanager/tasksmodel.h +++ b/libtaskmanager/tasksmodel.h @@ -769,8 +769,8 @@ public: Q_INVOKABLE void requestToggleGrouping(const QModelIndex &index); /** - * Moves a (top-level) task to a new position in the list. The insert - * position is bounded to the list start and end. + * Moves a task to a new position in the list. The insert position is + * is bounded to the list start and end. * * syncLaunchers() should be called after a set of move operations to * update the launcherList property to reflect the new order. @@ -784,7 +784,8 @@ public: * @param index An index in this tasks model. * @param newPos The new list position to move the task to. */ - Q_INVOKABLE bool move(int row, int newPos); + Q_INVOKABLE bool move(int row, int newPos, + const QModelIndex &parent = QModelIndex()); /** * Updates the launcher list to reflect the new order after calls to