Changeset View
Standalone View
libtaskmanager/taskgroupingproxymodel.cpp
Show First 20 Lines • Show All 665 Lines • ▼ Show 20 Line(s) | 663 | if (role == Qt::DisplayRole) { | |||
---|---|---|---|---|---|
666 | // Groups are formed by app id or launcher URL; neither requires | 666 | // Groups are formed by app id or launcher URL; neither requires | ||
667 | // AppName to be available. If it's not, fall back to the app id | 667 | // AppName to be available. If it's not, fall back to the app id | ||
668 | /// rather than an empty string. | 668 | /// rather than an empty string. | ||
669 | if (appName.isEmpty()) { | 669 | if (appName.isEmpty()) { | ||
670 | return sourceIndex.data(AbstractTasksModel::AppId); | 670 | return sourceIndex.data(AbstractTasksModel::AppId); | ||
671 | } | 671 | } | ||
672 | 672 | | |||
673 | return appName; | 673 | return appName; | ||
674 | } else if (role == AbstractTasksModel::LegacyWinIdList) { | 674 | } else if (role == AbstractTasksModel::WinIdList) { | ||
675 | QVariantList winIds; | 675 | QVariantList winIds; | ||
676 | 676 | | |||
677 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 677 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
678 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | 678 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::WinIdList).toList()); | ||
679 | } | 679 | } | ||
680 | 680 | | |||
681 | return winIds; | 681 | return winIds; | ||
682 | } else if (role == AbstractTasksModel::MimeType) { | 682 | } else if (role == AbstractTasksModel::MimeType) { | ||
683 | // FIXME: Legacy X11 stuff, but it's what we have for now. | | |||
684 | return QStringLiteral("windowsystem/multiple-winids"); | 683 | return QStringLiteral("windowsystem/multiple-winids"); | ||
685 | } else if (role == AbstractTasksModel::MimeData) { | 684 | } else if (role == AbstractTasksModel::MimeData) { | ||
686 | // FIXME TODO: Implement. | 685 | // FIXME TODO: Implement. | ||
687 | return QVariant(); | 686 | return QVariant(); | ||
688 | } else if (role == AbstractTasksModel::IsGroupParent) { | 687 | } else if (role == AbstractTasksModel::IsGroupParent) { | ||
689 | return true; | 688 | return true; | ||
690 | } else if (role == AbstractTasksModel::ChildCount) { | 689 | } else if (role == AbstractTasksModel::ChildCount) { | ||
691 | return rowCount(proxyIndex); | 690 | return rowCount(proxyIndex); | ||
Show All 22 Lines | |||||
714 | } else if (role == AbstractTasksModel::IsFullScreenable) { | 713 | } else if (role == AbstractTasksModel::IsFullScreenable) { | ||
715 | return d->all(proxyIndex, AbstractTasksModel::IsFullScreenable); | 714 | return d->all(proxyIndex, AbstractTasksModel::IsFullScreenable); | ||
716 | } else if (role == AbstractTasksModel::IsFullScreen) { | 715 | } else if (role == AbstractTasksModel::IsFullScreen) { | ||
717 | return d->all(proxyIndex, AbstractTasksModel::IsFullScreen); | 716 | return d->all(proxyIndex, AbstractTasksModel::IsFullScreen); | ||
718 | } else if (role == AbstractTasksModel::IsShadeable) { | 717 | } else if (role == AbstractTasksModel::IsShadeable) { | ||
719 | return d->all(proxyIndex, AbstractTasksModel::IsShadeable); | 718 | return d->all(proxyIndex, AbstractTasksModel::IsShadeable); | ||
720 | } else if (role == AbstractTasksModel::IsShaded) { | 719 | } else if (role == AbstractTasksModel::IsShaded) { | ||
721 | return d->all(proxyIndex, AbstractTasksModel::IsShaded); | 720 | return d->all(proxyIndex, AbstractTasksModel::IsShaded); | ||
722 | } else if (role == AbstractTasksModel::IsVirtualDesktopChangeable) { | 721 | } else if (role == AbstractTasksModel::IsVirtualDesktopsChangeable) { | ||
723 | return d->all(proxyIndex, AbstractTasksModel::IsVirtualDesktopChangeable); | 722 | return d->all(proxyIndex, AbstractTasksModel::IsVirtualDesktopsChangeable); | ||
724 | } else if (role == AbstractTasksModel::VirtualDesktop) { | 723 | } else if (role == AbstractTasksModel::VirtualDesktops) { | ||
725 | // Returns the lowest virtual desktop id among all children of the | 724 | QStringList desktops; | ||
726 | // group. | | |||
727 | int virtualDesktop = INT_MAX; | | |||
728 | 725 | | |||
729 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 726 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
730 | const int childVirtualDesktop = proxyIndex.child(i, 0).data(AbstractTasksModel::VirtualDesktop).toInt(); | 727 | desktops.append(proxyIndex.child(i, 0).data(AbstractTasksModel::VirtualDesktops).toStringList()); | ||
731 | | ||||
732 | if (childVirtualDesktop < virtualDesktop) { | | |||
733 | virtualDesktop = childVirtualDesktop; | | |||
734 | } | | |||
735 | } | 728 | } | ||
736 | 729 | | |||
737 | return virtualDesktop; | 730 | desktops.removeDuplicates(); | ||
731 | return desktops; | ||||
738 | } else if (role == AbstractTasksModel::ScreenGeometry) { | 732 | } else if (role == AbstractTasksModel::ScreenGeometry) { | ||
739 | // TODO: Nothing needs this for now and it would add complexity to | 733 | // TODO: Nothing needs this for now and it would add complexity to | ||
davidedmundson: should be mostly a copy/paste right? Anything holding this up? | |||||
The sorting code will look at the first desktop in practice, which is why it should be the lowest desktop. I wasn't sure if I can rely on PlasmaWindow::plasmaVirtualDesktops() to return the desktops in position-sorting order. Something for @mart to answer. hein: The sorting code will look at the first desktop in practice, which is why it should be the… | |||||
no, the desktops in plasmawindow are just in order of "last added last" mart: no, the desktops in plasmawindow are just in order of "last added last"
if is needed they… | |||||
mart: what's the rationale of this dead code? | |||||
740 | // make it a list; skip it until needed. Once it is, do it similarly | 734 | // make it a list; skip it until needed. Once it is, do it similarly | ||
741 | // to the AbstractTasksModel::VirtualDesktop case. | 735 | // to the AbstractTasksModel::VirtualDesktop case. | ||
742 | return QVariant(); | 736 | return QVariant(); | ||
743 | } else if (role == AbstractTasksModel::Activities) { | 737 | } else if (role == AbstractTasksModel::Activities) { | ||
744 | QStringList activities; | 738 | QStringList activities; | ||
745 | 739 | | |||
746 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 740 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
747 | activities.append(proxyIndex.child(i, 0).data(AbstractTasksModel::Activities).toStringList()); | 741 | activities.append(proxyIndex.child(i, 0).data(AbstractTasksModel::Activities).toStringList()); | ||
▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Line(s) | 1096 | for (int i = 0; i < rowCount(index); ++i) { | |||
1104 | 1098 | | |||
1105 | if (child.data(AbstractTasksModel::IsShaded).toBool() != goalState) { | 1099 | if (child.data(AbstractTasksModel::IsShaded).toBool() != goalState) { | ||
1106 | d->abstractTasksSourceModel->requestToggleShaded(mapToSource(child)); | 1100 | d->abstractTasksSourceModel->requestToggleShaded(mapToSource(child)); | ||
1107 | } | 1101 | } | ||
1108 | } | 1102 | } | ||
1109 | } | 1103 | } | ||
1110 | } | 1104 | } | ||
1111 | 1105 | | |||
1112 | void TaskGroupingProxyModel::requestVirtualDesktop(const QModelIndex &index, qint32 desktop) | 1106 | void TaskGroupingProxyModel::requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) | ||
1113 | { | 1107 | { | ||
1114 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | 1108 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | ||
1115 | return; | 1109 | return; | ||
1116 | } | 1110 | } | ||
1117 | 1111 | | |||
1118 | if (index.parent().isValid() || !d->isGroup(index.row())) { | 1112 | if (index.parent().isValid() || !d->isGroup(index.row())) { | ||
1119 | d->abstractTasksSourceModel->requestVirtualDesktop(mapToSource(index), desktop); | 1113 | d->abstractTasksSourceModel->requestVirtualDesktops(mapToSource(index), desktops); | ||
1120 | } else { | 1114 | } else { | ||
1121 | const int row = index.row(); | 1115 | QVector<QModelIndex> groupChildren; | ||
1122 | 1116 | | |||
1123 | for (int i = (rowCount(index) - 1); i >= 1; --i) { | 1117 | const int childCount = rowCount(index); | ||
1124 | const QModelIndex &sourceChild = mapToSource(index.child(i, 0)); | 1118 | | ||
1125 | d->abstractTasksSourceModel->requestVirtualDesktop(sourceChild, desktop); | 1119 | groupChildren.reserve(childCount); | ||
1120 | | ||||
1121 | for (int i = (childCount - 1); i >= 0; --i) { | ||||
1122 | groupChildren.append(mapToSource(index.child(i, 0))); | ||||
Am I reading this right? We iterate backwards from N -> 1 because moving the desktop /might/ filter them. I would expect this to not work if a user is sorting by virtual desktops. Would it work to generate a list of sourceIndexes from all children one loop, then go over those indexes requesting the desktops? davidedmundson: Am I reading this right?
We iterate backwards from N -> 1 because moving the desktop /might/… | |||||
Can you explain how sorting comes into this? (Sorting is done a level up in TasksModel.) hein: Can you explain how sorting comes into this? (Sorting is done a level up in TasksModel.) | |||||
1123 | } | ||||
1124 | | ||||
1125 | for (const QModelIndex &idx : groupChildren) { | ||||
1126 | d->abstractTasksSourceModel->requestVirtualDesktops(idx, desktops); | ||||
1127 | } | ||||
1128 | } | ||||
1129 | } | ||||
1130 | | ||||
1131 | void TaskGroupingProxyModel::requestNewVirtualDesktop(const QModelIndex &index) | ||||
1132 | { | ||||
1133 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | ||||
1134 | return; | ||||
1135 | } | ||||
1136 | | ||||
1137 | if (index.parent().isValid() || !d->isGroup(index.row())) { | ||||
1138 | d->abstractTasksSourceModel->requestNewVirtualDesktop(mapToSource(index)); | ||||
1139 | } else { | ||||
1140 | QVector<QModelIndex> groupChildren; | ||||
1141 | | ||||
1142 | const int childCount = rowCount(index); | ||||
1143 | | ||||
1144 | groupChildren.reserve(childCount); | ||||
1145 | | ||||
1146 | for (int i = (childCount - 1); i >= 0; --i) { | ||||
1147 | groupChildren.append(mapToSource(index.child(i, 0))); | ||||
1126 | } | 1148 | } | ||
1127 | 1149 | | |||
1128 | d->abstractTasksSourceModel->requestVirtualDesktop(mapToSource(TaskGroupingProxyModel::index(row, 0)), | 1150 | for (const QModelIndex &idx : groupChildren) { | ||
1129 | desktop); | 1151 | d->abstractTasksSourceModel->requestNewVirtualDesktop(idx); | ||
1152 | } | ||||
1130 | } | 1153 | } | ||
1131 | } | 1154 | } | ||
1132 | 1155 | | |||
1133 | void TaskGroupingProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) | 1156 | void TaskGroupingProxyModel::requestActivities(const QModelIndex &index, const QStringList &activities) | ||
1134 | { | 1157 | { | ||
1135 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | 1158 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | ||
1136 | return; | 1159 | return; | ||
1137 | } | 1160 | } | ||
1138 | 1161 | | |||
1139 | if (index.parent().isValid() || !d->isGroup(index.row())) { | 1162 | if (index.parent().isValid() || !d->isGroup(index.row())) { | ||
1140 | d->abstractTasksSourceModel->requestActivities(mapToSource(index), activities); | 1163 | d->abstractTasksSourceModel->requestActivities(mapToSource(index), activities); | ||
1141 | } else { | 1164 | } else { | ||
1142 | const int row = index.row(); | 1165 | QVector<QModelIndex> groupChildren; | ||
1143 | 1166 | | |||
1144 | for (int i = (rowCount(index) - 1); i >= 1; --i) { | 1167 | const int childCount = rowCount(index); | ||
1145 | const QModelIndex &sourceChild = mapToSource(index.child(i, 0)); | 1168 | | ||
1146 | d->abstractTasksSourceModel->requestActivities(sourceChild, activities); | 1169 | groupChildren.reserve(childCount); | ||
1170 | | ||||
1171 | for (int i = (childCount - 1); i >= 0; --i) { | ||||
1172 | groupChildren.append(mapToSource(index.child(i, 0))); | ||||
1147 | } | 1173 | } | ||
1148 | 1174 | | |||
1149 | d->abstractTasksSourceModel->requestActivities(mapToSource(TaskGroupingProxyModel::index(row, 0)), | 1175 | for (const QModelIndex &idx : groupChildren) { | ||
1150 | activities); | 1176 | d->abstractTasksSourceModel->requestActivities(idx, activities); | ||
1177 | } | ||||
1151 | } | 1178 | } | ||
1152 | } | 1179 | } | ||
1153 | 1180 | | |||
1154 | void TaskGroupingProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) | 1181 | void TaskGroupingProxyModel::requestPublishDelegateGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) | ||
1155 | { | 1182 | { | ||
1156 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | 1183 | if (!d->abstractTasksSourceModel || !index.isValid() || index.model() != this) { | ||
1157 | return; | 1184 | return; | ||
1158 | } | 1185 | } | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |
should be mostly a copy/paste right? Anything holding this up?