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.
wilder-5.26
Fushan Wen 4 years ago
parent 73657e9185
commit ea51795e8c
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
  1. 23
      libtaskmanager/tasksmodel.cpp

@ -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();

Loading…
Cancel
Save