Verified Commit ea51795e authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

libtaskmanager: consolidate group parent adjacent to the moved task

If the task exchanges position with a group parent, the group parent
also needs to be consolidated.

Test:

1. Open many Konsole windows
2. Open Firefox (One window)
3. Now the task order is [Firefox] [Konsole Group Parent]
4. Move Firefox to the right of Konsole group parent.
5. Open group dialog of Konsole group parent
6. Move the first Konsole window down to the second position
7. Before this change, Firefox and Konsole group parent will exchange
   positions, which is incorrect. After this change, the Konsole task in
   the group dialog can be moved as expected.
parent 73657e91
Pipeline #230903 passed with stage
in 8 minutes and 32 seconds
......@@ -1698,6 +1698,17 @@ bool TasksModel::move(int row, int newPos, const QModelIndex &parent)
// Translate to sort map indices.
const QModelIndex &groupingRowIndex = mapToSource(index(row, 0, parent));
const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex);
const bool groupNotDisabled = !parent.isValid() && groupMode() != GroupDisabled;
QModelIndex adjacentGroupingRowIndex; // Also consolidate the adjacent group parent
if (groupNotDisabled) {
if (newPos > row && row + 1 < rowCount(parent)) {
adjacentGroupingRowIndex = mapToSource(index(row + 1, 0, parent) /* task on the right */);
} else if (newPos < row && row - 1 >= 0) {
adjacentGroupingRowIndex = mapToSource(index(row - 1, 0, parent) /* task on the left */);
}
}
row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row());
newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0, parent))).row());
......@@ -1705,8 +1716,16 @@ bool TasksModel::move(int row, int newPos, const QModelIndex &parent)
d->sortedPreFilterRows.move(row, newPos);
// If we moved a group parent, consolidate sort map for children.
if (!parent.isValid() && groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) {
d->consolidateManualSortMapForGroup(groupingRowIndex);
if (groupNotDisabled) {
if (d->groupingProxyModel->rowCount(groupingRowIndex)) {
d->consolidateManualSortMapForGroup(groupingRowIndex);
}
// Special case: Before moving, the task at newPos is a group parent
// Before moving: [Task] [Group parent]
// After moving: [Group parent (not consolidated yet)] [Task]
if (adjacentGroupingRowIndex.isValid() && d->groupingProxyModel->rowCount(adjacentGroupingRowIndex)) {
d->consolidateManualSortMapForGroup(adjacentGroupingRowIndex);
}
}
endMoveRows();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment