Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasksmodel.cpp
Show First 20 Lines • Show All 1424 Lines • ▼ Show 20 Line(s) | |||||
1425 | { | 1425 | { | ||
1426 | if (index.isValid() && index.model() == this) { | 1426 | if (index.isValid() && index.model() == this) { | ||
1427 | const QModelIndex &target = (d->flattenGroupsProxyModel | 1427 | const QModelIndex &target = (d->flattenGroupsProxyModel | ||
1428 | ? d->flattenGroupsProxyModel->mapToSource(mapToSource(index)) : mapToSource(index)); | 1428 | ? d->flattenGroupsProxyModel->mapToSource(mapToSource(index)) : mapToSource(index)); | ||
1429 | d->groupingProxyModel->requestToggleGrouping(target); | 1429 | d->groupingProxyModel->requestToggleGrouping(target); | ||
1430 | } | 1430 | } | ||
1431 | } | 1431 | } | ||
1432 | 1432 | | |||
1433 | bool TasksModel::move(int row, int newPos) | 1433 | bool TasksModel::move(int row, int newPos, const QModelIndex &parent) | ||
1434 | { | 1434 | { | ||
1435 | if (d->sortMode != SortManual || row == newPos || newPos < 0 || newPos >= rowCount()) { | 1435 | if (d->sortMode != SortManual || row == newPos || newPos < 0 || newPos >= rowCount(parent)) { | ||
1436 | return false; | 1436 | return false; | ||
1437 | } | 1437 | } | ||
1438 | 1438 | | |||
1439 | const QModelIndex &idx = index(row, 0); | 1439 | const QModelIndex &idx = index(row, 0); | ||
1440 | bool isLauncherMove = false; | 1440 | bool isLauncherMove = false; | ||
1441 | 1441 | | |||
1442 | // Figure out if we're moving a launcher so we can run barrier checks. | 1442 | // Figure out if we're moving a launcher so we can run barrier checks. | ||
1443 | if (idx.isValid()) { | 1443 | if (idx.isValid()) { | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | 1476 | if (d->flattenGroupsProxyModel) { | |||
1518 | d->sortedPreFilterRows.move(row, newPos); | 1518 | d->sortedPreFilterRows.move(row, newPos); | ||
1519 | 1519 | | |||
1520 | if (groupingRowIndexParent.isValid()) { | 1520 | if (groupingRowIndexParent.isValid()) { | ||
1521 | d->consolidateManualSortMapForGroup(groupingRowIndexParent); | 1521 | d->consolidateManualSortMapForGroup(groupingRowIndexParent); | ||
1522 | } | 1522 | } | ||
1523 | 1523 | | |||
1524 | endMoveRows(); | 1524 | endMoveRows(); | ||
1525 | } else { | 1525 | } else { | ||
1526 | // Move a group member. | ||||
1527 | if (parent.isValid()) { | ||||
1528 | beginMoveRows(parent, row, row, parent, (newPos > row) ? newPos + 1 : newPos); | ||||
1529 | | ||||
1530 | // Translate to sort map indices. | ||||
1531 | const QModelIndex &groupingRowIndex = mapToSource(index(row, 0, parent)); | ||||
1532 | const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); | ||||
1533 | row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); | ||||
1534 | newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0, parent))).row()); | ||||
1535 | | ||||
1536 | // Update sort mapping. | ||||
1537 | d->sortedPreFilterRows.move(row, newPos); | ||||
1538 | | ||||
1539 | endMoveRows(); | ||||
1540 | // Move a top-level item. | ||||
1541 | } else { | ||||
1526 | beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newPos > row) ? newPos + 1 : newPos); | 1542 | beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newPos > row) ? newPos + 1 : newPos); | ||
1527 | 1543 | | |||
1528 | // Translate to sort map indices. | 1544 | // Translate to sort map indices. | ||
1529 | const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); | 1545 | const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); | ||
1530 | const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); | 1546 | const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); | ||
1531 | row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); | 1547 | row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); | ||
1532 | newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0))).row()); | 1548 | newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0))).row()); | ||
1533 | 1549 | | |||
1534 | // Update sort mapping. | 1550 | // Update sort mapping. | ||
1535 | d->sortedPreFilterRows.move(row, newPos); | 1551 | d->sortedPreFilterRows.move(row, newPos); | ||
1536 | 1552 | | |||
1537 | // If we moved a group parent, consolidate sort map for children. | 1553 | // If we moved a group parent, consolidate sort map for children. | ||
davidedmundson: This is the only bit that's different from the new code.
Can we share the above and guard this… | |||||
I was uncomfortable just always passing parent through in beginMoveRows without guarding that with a check, too, but OK ... hein: I was uncomfortable just always passing parent through in beginMoveRows without guarding that… | |||||
1538 | if (groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) { | 1554 | if (groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) { | ||
1539 | d->consolidateManualSortMapForGroup(groupingRowIndex); | 1555 | d->consolidateManualSortMapForGroup(groupingRowIndex); | ||
1540 | } | 1556 | } | ||
1541 | 1557 | | |||
1542 | endMoveRows(); | 1558 | endMoveRows(); | ||
1543 | } | 1559 | } | ||
1560 | } | ||||
1544 | 1561 | | |||
1545 | // Resort. | 1562 | // Resort. | ||
1546 | d->forceResort(); | 1563 | d->forceResort(); | ||
1547 | 1564 | | |||
1548 | if (!d->separateLaunchers && isLauncherMove) { | 1565 | if (!d->separateLaunchers && isLauncherMove) { | ||
1549 | const QModelIndex &idx = d->concatProxyModel->index(d->sortedPreFilterRows.at(newPos), 0); | 1566 | const QModelIndex &idx = d->concatProxyModel->index(d->sortedPreFilterRows.at(newPos), 0); | ||
1550 | const QUrl &launcherUrl = idx.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl(); | 1567 | const QUrl &launcherUrl = idx.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl(); | ||
1551 | 1568 | | |||
▲ Show 20 Lines • Show All 202 Lines • Show Last 20 Lines |
This is the only bit that's different from the new code.
Can we share the above and guard this with if(!parent)