diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h --- a/libtaskmanager/tasksmodel.h +++ b/libtaskmanager/tasksmodel.h @@ -769,8 +769,8 @@ 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 @@ * @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 diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp --- a/libtaskmanager/tasksmodel.cpp +++ b/libtaskmanager/tasksmodel.cpp @@ -1430,9 +1430,9 @@ } } -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,23 +1523,40 @@ endMoveRows(); } else { - beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newPos > row) ? newPos + 1 : newPos); + // Move a group member. + if (parent.isValid()) { + beginMoveRows(parent, row, row, parent, (newPos > row) ? newPos + 1 : newPos); - // Translate to sort map indices. - const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); - const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); - row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); - newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0))).row()); + // Translate to sort map indices. + const QModelIndex &groupingRowIndex = mapToSource(index(row, 0, parent)); + const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); + row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); + newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0, parent))).row()); - // Update sort mapping. - d->sortedPreFilterRows.move(row, newPos); + // Update sort mapping. + d->sortedPreFilterRows.move(row, newPos); - // If we moved a group parent, consolidate sort map for children. - if (groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) { - d->consolidateManualSortMapForGroup(groupingRowIndex); - } + endMoveRows(); + // Move a top-level item. + } else { + beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newPos > row) ? newPos + 1 : newPos); - endMoveRows(); + // Translate to sort map indices. + const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); + const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); + row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); + newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0))).row()); + + // Update sort mapping. + d->sortedPreFilterRows.move(row, newPos); + + // If we moved a group parent, consolidate sort map for children. + if (groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) { + d->consolidateManualSortMapForGroup(groupingRowIndex); + } + + endMoveRows(); + } } // Resort.