Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasksmodel.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "tasksmodel.h" | 21 | #include "tasksmodel.h" | ||
22 | #include "activityinfo.h" | 22 | #include "activityinfo.h" | ||
23 | #include "concatenatetasksproxymodel.h" | 23 | #include "concatenatetasksproxymodel.h" | ||
24 | #include "flattentaskgroupsproxymodel.h" | 24 | #include "flattentaskgroupsproxymodel.h" | ||
25 | #include "taskfilterproxymodel.h" | 25 | #include "taskfilterproxymodel.h" | ||
26 | #include "taskgroupingproxymodel.h" | 26 | #include "taskgroupingproxymodel.h" | ||
27 | #include "tasktools.h" | 27 | #include "tasktools.h" | ||
28 | #include "virtualdesktopinfo.h" | ||||
28 | 29 | | |||
29 | #include "launchertasksmodel.h" | 30 | #include "launchertasksmodel.h" | ||
30 | #include "startuptasksmodel.h" | 31 | #include "startuptasksmodel.h" | ||
31 | #include "windowtasksmodel.h" | 32 | #include "windowtasksmodel.h" | ||
32 | 33 | | |||
33 | #include "launchertasksmodel_p.h" | 34 | #include "launchertasksmodel_p.h" | ||
34 | 35 | | |||
35 | #include <QGuiApplication> | 36 | #include <QGuiApplication> | ||
Show All 20 Lines | 47 | public: | |||
56 | TaskFilterProxyModel* filterProxyModel = nullptr; | 57 | TaskFilterProxyModel* filterProxyModel = nullptr; | ||
57 | TaskGroupingProxyModel* groupingProxyModel = nullptr; | 58 | TaskGroupingProxyModel* groupingProxyModel = nullptr; | ||
58 | FlattenTaskGroupsProxyModel* flattenGroupsProxyModel = nullptr; | 59 | FlattenTaskGroupsProxyModel* flattenGroupsProxyModel = nullptr; | ||
59 | AbstractTasksModelIface *abstractTasksSourceModel = nullptr; | 60 | AbstractTasksModelIface *abstractTasksSourceModel = nullptr; | ||
60 | 61 | | |||
61 | bool anyTaskDemandsAttention = false; | 62 | bool anyTaskDemandsAttention = false; | ||
62 | 63 | | |||
63 | int launcherCount = 0; | 64 | int launcherCount = 0; | ||
64 | int virtualDesktop = -1; | | |||
65 | int screen = -1; | | |||
66 | QString activity; | | |||
67 | 65 | | |||
68 | SortMode sortMode = SortAlpha; | 66 | SortMode sortMode = SortAlpha; | ||
69 | bool separateLaunchers = true; | 67 | bool separateLaunchers = true; | ||
70 | bool launchInPlace = false; | 68 | bool launchInPlace = false; | ||
71 | bool launchersEverSet = false; | 69 | bool launchersEverSet = false; | ||
72 | bool launcherSortingDirty = false; | 70 | bool launcherSortingDirty = false; | ||
73 | bool launcherCheckNeeded = false; | 71 | bool launcherCheckNeeded = false; | ||
74 | QList<int> sortedPreFilterRows; | 72 | QList<int> sortedPreFilterRows; | ||
75 | QVector<int> sortRowInsertQueue; | 73 | QVector<int> sortRowInsertQueue; | ||
76 | QHash<QString, int> activityTaskCounts; | 74 | QHash<QString, int> activityTaskCounts; | ||
75 | static VirtualDesktopInfo *virtualDesktopInfo; | ||||
76 | static int virtualDesktopInfoUsers; | ||||
77 | static ActivityInfo* activityInfo; | 77 | static ActivityInfo* activityInfo; | ||
78 | static int activityInfoUsers; | 78 | static int activityInfoUsers; | ||
79 | 79 | | |||
80 | bool groupInline = false; | 80 | bool groupInline = false; | ||
81 | int groupingWindowTasksThreshold = -1; | 81 | int groupingWindowTasksThreshold = -1; | ||
82 | 82 | | |||
83 | bool usedByQml = false; | 83 | bool usedByQml = false; | ||
84 | bool componentComplete = false; | 84 | bool componentComplete = false; | ||
Show All 31 Lines | 115 | private: | |||
116 | const QAbstractItemModel *sourceModel; | 116 | const QAbstractItemModel *sourceModel; | ||
117 | const TasksModel *tasksModel; | 117 | const TasksModel *tasksModel; | ||
118 | bool sortOnlyLaunchers; | 118 | bool sortOnlyLaunchers; | ||
119 | }; | 119 | }; | ||
120 | 120 | | |||
121 | int TasksModel::Private::instanceCount = 0; | 121 | int TasksModel::Private::instanceCount = 0; | ||
122 | WindowTasksModel* TasksModel::Private::windowTasksModel = nullptr; | 122 | WindowTasksModel* TasksModel::Private::windowTasksModel = nullptr; | ||
123 | StartupTasksModel* TasksModel::Private::startupTasksModel = nullptr; | 123 | StartupTasksModel* TasksModel::Private::startupTasksModel = nullptr; | ||
124 | VirtualDesktopInfo* TasksModel::Private::virtualDesktopInfo = nullptr; | ||||
125 | int TasksModel::Private::virtualDesktopInfoUsers = 0; | ||||
124 | ActivityInfo* TasksModel::Private::activityInfo = nullptr; | 126 | ActivityInfo* TasksModel::Private::activityInfo = nullptr; | ||
125 | int TasksModel::Private::activityInfoUsers = 0; | 127 | int TasksModel::Private::activityInfoUsers = 0; | ||
126 | 128 | | |||
127 | TasksModel::Private::Private(TasksModel *q) | 129 | TasksModel::Private::Private(TasksModel *q) | ||
128 | : q(q) | 130 | : q(q) | ||
129 | { | 131 | { | ||
130 | ++instanceCount; | 132 | ++instanceCount; | ||
131 | } | 133 | } | ||
132 | 134 | | |||
133 | TasksModel::Private::~Private() | 135 | TasksModel::Private::~Private() | ||
134 | { | 136 | { | ||
135 | --instanceCount; | 137 | --instanceCount; | ||
136 | 138 | | |||
137 | if (sortMode == SortActivity) { | 139 | if (sortMode == SortActivity) { | ||
138 | --activityInfoUsers; | 140 | --activityInfoUsers; | ||
139 | } | 141 | } | ||
140 | 142 | | |||
141 | if (!instanceCount) { | 143 | if (!instanceCount) { | ||
142 | delete windowTasksModel; | 144 | delete windowTasksModel; | ||
143 | windowTasksModel = nullptr; | 145 | windowTasksModel = nullptr; | ||
144 | delete startupTasksModel; | 146 | delete startupTasksModel; | ||
145 | startupTasksModel = nullptr; | 147 | startupTasksModel = nullptr; | ||
148 | delete virtualDesktopInfo; | ||||
149 | virtualDesktopInfo = nullptr; | ||||
146 | delete activityInfo; | 150 | delete activityInfo; | ||
147 | activityInfo = nullptr; | 151 | activityInfo = nullptr; | ||
148 | } | 152 | } | ||
149 | } | 153 | } | ||
150 | 154 | | |||
151 | void TasksModel::Private::initModels() | 155 | void TasksModel::Private::initModels() | ||
152 | { | 156 | { | ||
153 | // NOTE: Overview over the entire model chain assembled here: | 157 | // NOTE: Overview over the entire model chain assembled here: | ||
▲ Show 20 Lines • Show All 640 Lines • ▼ Show 20 Line(s) | 754 | { | |||
794 | // If told to stop after launchers we fall through to the existing map if it exists. | 798 | // If told to stop after launchers we fall through to the existing map if it exists. | ||
795 | if (sortOnlyLaunchers && !sortedPreFilterRows.isEmpty()) { | 799 | if (sortOnlyLaunchers && !sortedPreFilterRows.isEmpty()) { | ||
796 | return (sortedPreFilterRows.indexOf(left.row()) < sortedPreFilterRows.indexOf(right.row())); | 800 | return (sortedPreFilterRows.indexOf(left.row()) < sortedPreFilterRows.indexOf(right.row())); | ||
797 | } | 801 | } | ||
798 | 802 | | |||
799 | // Sort other cases by sort mode. | 803 | // Sort other cases by sort mode. | ||
800 | switch (sortMode) { | 804 | switch (sortMode) { | ||
801 | case SortVirtualDesktop: { | 805 | case SortVirtualDesktop: { | ||
802 | const QVariant &leftDesktopVariant = left.data(AbstractTasksModel::VirtualDesktop); | 806 | const bool leftAll = left.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool(); | ||
803 | bool leftOk = false; | 807 | const bool rightAll = right.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool(); | ||
804 | const int leftDesktop = leftDesktopVariant.toInt(&leftOk); | 808 | | ||
805 | 809 | if (leftAll && !rightAll) { | |||
806 | const QVariant &rightDesktopVariant = right.data(AbstractTasksModel::VirtualDesktop); | 810 | return true; | ||
807 | bool rightOk = false; | 811 | } else if (rightAll && !leftAll) { | ||
808 | const int rightDesktop = rightDesktopVariant.toInt(&rightOk); | 812 | return true; | ||
809 | 813 | } | |||
810 | if (leftOk && rightOk && (leftDesktop != rightDesktop)) { | 814 | | ||
811 | return (leftDesktop < rightDesktop); | 815 | const QVariantList &leftDesktops = left.data(AbstractTasksModel::VirtualDesktops).toList(); | ||
812 | } else if (leftOk && !rightOk) { | 816 | QVariant leftDesktop; | ||
817 | int leftDesktopPos = virtualDesktopInfo->numberOfDesktops(); | ||||
818 | | ||||
819 | for (const QVariant &desktop : leftDesktops) { | ||||
820 | const int desktopPos = virtualDesktopInfo->position(desktop); | ||||
821 | | ||||
822 | if (desktopPos < leftDesktopPos) { | ||||
823 | leftDesktop = desktop; | ||||
824 | leftDesktopPos = desktopPos; | ||||
825 | } | ||||
826 | } | ||||
827 | | ||||
828 | const QVariantList &rightDesktops = right.data(AbstractTasksModel::VirtualDesktops).toList(); | ||||
829 | QVariant rightDesktop; | ||||
830 | int rightDesktopPos = virtualDesktopInfo->numberOfDesktops(); | ||||
831 | | ||||
832 | for (const QVariant &desktop : rightDesktops) { | ||||
833 | const int desktopPos = virtualDesktopInfo->position(desktop); | ||||
834 | | ||||
835 | if (desktopPos < rightDesktopPos) { | ||||
836 | rightDesktop = desktop; | ||||
837 | rightDesktopPos = desktopPos; | ||||
838 | } | ||||
839 | } | ||||
840 | | ||||
841 | if (!leftDesktop.isNull() && !rightDesktop.isNull() && (leftDesktop != rightDesktop)) { | ||||
842 | return (virtualDesktopInfo->position(leftDesktop) < virtualDesktopInfo->position(rightDesktop)); | ||||
843 | } else if (!leftDesktop.isNull() && rightDesktop.isNull()) { | ||||
813 | return false; | 844 | return false; | ||
814 | } else if (!leftOk && rightOk) { | 845 | } else if (leftDesktop.isNull() && !rightDesktop.isNull()) { | ||
815 | return true; | 846 | return true; | ||
816 | } | 847 | } | ||
848 | | ||||
849 | return false; | ||||
817 | } | 850 | } | ||
818 | case SortActivity: { | 851 | case SortActivity: { | ||
819 | // updateActivityTaskCounts() counts the number of window tasks on each | 852 | // updateActivityTaskCounts() counts the number of window tasks on each | ||
820 | // activity. This will sort tasks by comparing a cumulative score made | 853 | // activity. This will sort tasks by comparing a cumulative score made | ||
821 | // up of the task counts for each acvtivity a task is assigned to, and | 854 | // up of the task counts for each acvtivity a task is assigned to, and | ||
822 | // otherwise fall through to alphabetical sorting. | 855 | // otherwise fall through to alphabetical sorting. | ||
823 | int leftScore = -1; | 856 | int leftScore = -1; | ||
824 | int rightScore = -1; | 857 | int rightScore = -1; | ||
Show All 26 Lines | 875 | if (leftScore == -1 || rightScore == -1) { | |||
851 | } | 884 | } | ||
852 | } | 885 | } | ||
853 | 886 | | |||
854 | if (leftScore != rightScore) { | 887 | if (leftScore != rightScore) { | ||
855 | return (leftScore > rightScore); | 888 | return (leftScore > rightScore); | ||
856 | } | 889 | } | ||
857 | } | 890 | } | ||
858 | // Fall through to source order if sorting is disabled or manual, or alphabetical by app name otherwise. | 891 | // Fall through to source order if sorting is disabled or manual, or alphabetical by app name otherwise. | ||
892 | // This marker comment makes gcc/clang happy: | ||||
893 | // fall through | ||||
859 | default: { | 894 | default: { | ||
860 | if (sortMode == SortDisabled) { | 895 | if (sortMode == SortDisabled) { | ||
861 | return (left.row() < right.row()); | 896 | return (left.row() < right.row()); | ||
862 | } else { | 897 | } else { | ||
863 | // The overall goal of alphabetic sorting is to sort tasks belonging to the | 898 | // The overall goal of alphabetic sorting is to sort tasks belonging to the | ||
864 | // same app together, while sorting the resulting sets alphabetically among | 899 | // same app together, while sorting the resulting sets alphabetically among | ||
865 | // themselves by the app name. The following code tries to achieve this by | 900 | // themselves by the app name. The following code tries to achieve this by | ||
866 | // going for AppName first, and falling back to DisplayRole - which for | 901 | // going for AppName first, and falling back to DisplayRole - which for | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 989 | for (int i = 0; i < d->launcherTasksModel->rowCount(); ++i) { | |||
956 | 991 | | |||
957 | if (appsMatch(proxyIndex, launcherIndex)) { | 992 | if (appsMatch(proxyIndex, launcherIndex)) { | ||
958 | return true; | 993 | return true; | ||
959 | } | 994 | } | ||
960 | } | 995 | } | ||
961 | 996 | | |||
962 | return false; | 997 | return false; | ||
963 | } | 998 | } | ||
964 | } else if (rowCount(proxyIndex) && role == AbstractTasksModel::LegacyWinIdList) { | 999 | } else if (rowCount(proxyIndex) && role == AbstractTasksModel::WinIdList) { | ||
965 | QVariantList winIds; | 1000 | QVariantList winIds; | ||
966 | 1001 | | |||
967 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 1002 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
968 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | 1003 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::WinIdList).toList()); | ||
969 | } | 1004 | } | ||
970 | 1005 | | |||
971 | return winIds; | 1006 | return winIds; | ||
972 | } | 1007 | } | ||
973 | 1008 | | |||
974 | return QSortFilterProxyModel::data(proxyIndex, role); | 1009 | return QSortFilterProxyModel::data(proxyIndex, role); | ||
975 | } | 1010 | } | ||
976 | 1011 | | |||
Show All 22 Lines | 1033 | { | |||
999 | return d->launcherCount; | 1034 | return d->launcherCount; | ||
1000 | } | 1035 | } | ||
1001 | 1036 | | |||
1002 | bool TasksModel::anyTaskDemandsAttention() const | 1037 | bool TasksModel::anyTaskDemandsAttention() const | ||
1003 | { | 1038 | { | ||
1004 | return d->anyTaskDemandsAttention; | 1039 | return d->anyTaskDemandsAttention; | ||
1005 | } | 1040 | } | ||
1006 | 1041 | | |||
1007 | int TasksModel::virtualDesktop() const | 1042 | QVariant TasksModel::virtualDesktop() const | ||
1008 | { | 1043 | { | ||
1009 | return d->filterProxyModel->virtualDesktop(); | 1044 | return d->filterProxyModel->virtualDesktop(); | ||
1010 | } | 1045 | } | ||
1011 | 1046 | | |||
1012 | void TasksModel::setVirtualDesktop(int virtualDesktop) | 1047 | void TasksModel::setVirtualDesktop(const QVariant &desktop) | ||
1013 | { | 1048 | { | ||
1014 | d->filterProxyModel->setVirtualDesktop(virtualDesktop); | 1049 | d->filterProxyModel->setVirtualDesktop(desktop); | ||
davidedmundson: leftover | |||||
1015 | } | 1050 | } | ||
1016 | 1051 | | |||
1017 | QRect TasksModel::screenGeometry() const | 1052 | QRect TasksModel::screenGeometry() const | ||
1018 | { | 1053 | { | ||
1019 | return d->filterProxyModel->screenGeometry(); | 1054 | return d->filterProxyModel->screenGeometry(); | ||
1020 | } | 1055 | } | ||
1021 | 1056 | | |||
1022 | void TasksModel::setScreenGeometry(const QRect &geometry) | 1057 | void TasksModel::setScreenGeometry(const QRect &geometry) | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
1083 | { | 1118 | { | ||
1084 | if (d->sortMode != mode) { | 1119 | if (d->sortMode != mode) { | ||
1085 | if (mode == SortManual) { | 1120 | if (mode == SortManual) { | ||
1086 | d->updateManualSortMap(); | 1121 | d->updateManualSortMap(); | ||
1087 | } else if (d->sortMode == SortManual) { | 1122 | } else if (d->sortMode == SortManual) { | ||
1088 | d->sortedPreFilterRows.clear(); | 1123 | d->sortedPreFilterRows.clear(); | ||
1089 | } | 1124 | } | ||
1090 | 1125 | | |||
1126 | if (mode == SortVirtualDesktop) { | ||||
1127 | if (!d->virtualDesktopInfo) { | ||||
1128 | d->virtualDesktopInfo = new VirtualDesktopInfo(); | ||||
1129 | } | ||||
1130 | | ||||
1131 | ++d->virtualDesktopInfoUsers; | ||||
1132 | | ||||
1133 | setSortRole(AbstractTasksModel::VirtualDesktops); | ||||
1134 | } else if (d->sortMode == SortVirtualDesktop) { | ||||
1135 | --d->virtualDesktopInfoUsers; | ||||
1136 | | ||||
1137 | if (!d->virtualDesktopInfoUsers) { | ||||
1138 | delete d->virtualDesktopInfo; | ||||
1139 | d->virtualDesktopInfo = nullptr; | ||||
1140 | } | ||||
1141 | | ||||
1142 | setSortRole(Qt::DisplayRole); | ||||
1143 | } | ||||
1144 | | ||||
1091 | if (mode == SortActivity) { | 1145 | if (mode == SortActivity) { | ||
1092 | if (!d->activityInfo) { | 1146 | if (!d->activityInfo) { | ||
1093 | d->activityInfo = new ActivityInfo(); | 1147 | d->activityInfo = new ActivityInfo(); | ||
1094 | } | 1148 | } | ||
1095 | 1149 | | |||
1096 | ++d->activityInfoUsers; | 1150 | ++d->activityInfoUsers; | ||
1097 | 1151 | | |||
1098 | d->updateActivityTaskCounts(); | 1152 | d->updateActivityTaskCounts(); | ||
▲ Show 20 Lines • Show All 323 Lines • ▼ Show 20 Line(s) | |||||
1422 | 1476 | | |||
1423 | void TasksModel::requestToggleShaded(const QModelIndex &index) | 1477 | void TasksModel::requestToggleShaded(const QModelIndex &index) | ||
1424 | { | 1478 | { | ||
1425 | if (index.isValid() && index.model() == this) { | 1479 | if (index.isValid() && index.model() == this) { | ||
1426 | d->abstractTasksSourceModel->requestToggleShaded(mapToSource(index)); | 1480 | d->abstractTasksSourceModel->requestToggleShaded(mapToSource(index)); | ||
1427 | } | 1481 | } | ||
1428 | } | 1482 | } | ||
1429 | 1483 | | |||
1430 | void TasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 desktop) | 1484 | void TasksModel::requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) | ||
1485 | { | ||||
1486 | if (index.isValid() && index.model() == this) { | ||||
1487 | d->abstractTasksSourceModel->requestVirtualDesktops(mapToSource(index), desktops); | ||||
1488 | } | ||||
1489 | } | ||||
1490 | | ||||
1491 | void TasksModel::requestNewVirtualDesktop(const QModelIndex &index) | ||||
1431 | { | 1492 | { | ||
1432 | if (index.isValid() && index.model() == this) { | 1493 | if (index.isValid() && index.model() == this) { | ||
1433 | d->abstractTasksSourceModel->requestVirtualDesktop(mapToSource(index), desktop); | 1494 | d->abstractTasksSourceModel->requestNewVirtualDesktop(mapToSource(index)); | ||
1434 | } | 1495 | } | ||
1435 | } | 1496 | } | ||
1436 | 1497 | | |||
1437 | void TasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) | 1498 | void TasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) | ||
1438 | { | 1499 | { | ||
1439 | if (index.isValid() && index.model() == this) { | 1500 | if (index.isValid() && index.model() == this) { | ||
1440 | d->groupingProxyModel->requestActivities(mapToSource(index), activities); | 1501 | d->groupingProxyModel->requestActivities(mapToSource(index), activities); | ||
1441 | } | 1502 | } | ||
▲ Show 20 Lines • Show All 358 Lines • Show Last 20 Lines |
leftover