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 | beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newPos > row) ? newPos + 1 : newPos); | 1526 | beginMoveRows(parent, row, row, parent, (newPos > row) ? newPos + 1 : newPos); | ||
1527 | 1527 | | |||
1528 | // Translate to sort map indices. | 1528 | // Translate to sort map indices. | ||
1529 | const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); | 1529 | const QModelIndex &groupingRowIndex = mapToSource(index(row, 0)); | ||
1530 | const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); | 1530 | const QModelIndex &preFilterRowIndex = d->preFilterIndex(groupingRowIndex); | ||
1531 | row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); | 1531 | row = d->sortedPreFilterRows.indexOf(preFilterRowIndex.row()); | ||
1532 | newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0))).row()); | 1532 | newPos = d->sortedPreFilterRows.indexOf(d->preFilterIndex(mapToSource(index(newPos, 0))).row()); | ||
1533 | 1533 | | |||
1534 | // Update sort mapping. | 1534 | // Update sort mapping. | ||
1535 | d->sortedPreFilterRows.move(row, newPos); | 1535 | d->sortedPreFilterRows.move(row, newPos); | ||
1536 | 1536 | | |||
1537 | // If we moved a group parent, consolidate sort map for children. | 1537 | // If we moved a group parent, consolidate sort map for children. | ||
1538 | if (groupMode() != GroupDisabled && d->groupingProxyModel->rowCount(groupingRowIndex)) { | 1538 | if (!parent.isValid() && groupMode() != GroupDisabled | ||
1539 | && d->groupingProxyModel->rowCount(groupingRowIndex)) { | ||||
1539 | d->consolidateManualSortMapForGroup(groupingRowIndex); | 1540 | d->consolidateManualSortMapForGroup(groupingRowIndex); | ||
1540 | } | 1541 | } | ||
1541 | 1542 | | |||
1542 | endMoveRows(); | 1543 | endMoveRows(); | ||
1543 | } | 1544 | } | ||
1544 | 1545 | | |||
1545 | // Resort. | 1546 | // Resort. | ||
1546 | d->forceResort(); | 1547 | d->forceResort(); | ||
1547 | 1548 | | |||
1548 | if (!d->separateLaunchers && isLauncherMove) { | 1549 | if (!d->separateLaunchers && isLauncherMove) { | ||
1549 | const QModelIndex &idx = d->concatProxyModel->index(d->sortedPreFilterRows.at(newPos), 0); | 1550 | const QModelIndex &idx = d->concatProxyModel->index(d->sortedPreFilterRows.at(newPos), 0); | ||
1550 | const QUrl &launcherUrl = idx.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl(); | 1551 | const QUrl &launcherUrl = idx.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl(); | ||
1551 | 1552 | | |||
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… | |||||
1552 | // Move launcher for launcher-backed task along with task if launchers | 1553 | // Move launcher for launcher-backed task along with task if launchers | ||
1553 | // are not being kept separate. | 1554 | // are not being kept separate. | ||
1554 | // We don't need to resort again because the launcher is implictly hidden | 1555 | // We don't need to resort again because the launcher is implictly hidden | ||
1555 | // at this time. | 1556 | // at this time. | ||
1556 | if (!idx.data(AbstractTasksModel::IsLauncher).toBool()) { | 1557 | if (!idx.data(AbstractTasksModel::IsLauncher).toBool()) { | ||
1557 | const int launcherPos = d->launcherTasksModel->launcherPosition(launcherUrl); | 1558 | const int launcherPos = d->launcherTasksModel->launcherPosition(launcherUrl); | ||
1558 | const QModelIndex &launcherIndex = d->launcherTasksModel->index(launcherPos, 0); | 1559 | const QModelIndex &launcherIndex = d->launcherTasksModel->index(launcherPos, 0); | ||
1559 | const int sortIndex = d->sortedPreFilterRows.indexOf(d->concatProxyModel->mapFromSource(launcherIndex).row()); | 1560 | const int sortIndex = d->sortedPreFilterRows.indexOf(d->concatProxyModel->mapFromSource(launcherIndex).row()); | ||
▲ Show 20 Lines • Show All 194 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)