Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasksmodel.cpp
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 180 | [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) { | |||
---|---|---|---|---|---|
183 | 183 | | |||
184 | if (sortMode == SortActivity && roles.contains(AbstractTasksModel::Activities)) { | 184 | if (sortMode == SortActivity && roles.contains(AbstractTasksModel::Activities)) { | ||
185 | updateActivityTaskCounts(); | 185 | updateActivityTaskCounts(); | ||
186 | } | 186 | } | ||
187 | 187 | | |||
188 | if (roles.contains(AbstractTasksModel::IsActive)) { | 188 | if (roles.contains(AbstractTasksModel::IsActive)) { | ||
189 | emit q->activeTaskChanged(); | 189 | emit q->activeTaskChanged(); | ||
190 | } | 190 | } | ||
191 | | ||||
192 | // data() implements AbstractTasksModel::HasLauncher by checking with | ||||
193 | // TaskTools::appsMatch, which evaluates ::AppId and ::LauncherUrlWithoutIcon. | ||||
194 | if (roles.contains(AbstractTasksModel::AppId) || roles.contains(AbstractTasksModel::LauncherUrlWithoutIcon)) { | ||||
195 | q->dataChanged(q->index(0, 0), q->index(q->rowCount() - 1, 0), | ||||
196 | QVector<int>{AbstractTasksModel::HasLauncher}); | ||||
197 | } | ||||
191 | } | 198 | } | ||
192 | ); | 199 | ); | ||
193 | 200 | | |||
194 | if (!startupTasksModel) { | 201 | if (!startupTasksModel) { | ||
195 | startupTasksModel = new StartupTasksModel(); | 202 | startupTasksModel = new StartupTasksModel(); | ||
196 | } | 203 | } | ||
197 | 204 | | |||
205 | // data() implements AbstractTasksModel::HasLauncher by checking with | ||||
206 | // TaskTools::appsMatch, which evaluates ::AppId and ::LauncherUrlWithoutIcon. | ||||
207 | QObject::connect(startupTasksModel, &QAbstractItemModel::dataChanged, q, | ||||
208 | [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) { | ||||
209 | Q_UNUSED(topLeft) | ||||
210 | Q_UNUSED(bottomRight) | ||||
211 | | ||||
212 | if (roles.contains(AbstractTasksModel::AppId) || roles.contains(AbstractTasksModel::LauncherUrlWithoutIcon)) { | ||||
213 | q->dataChanged(q->index(0, 0), q->index(q->rowCount() - 1, 0), | ||||
davidedmundson: Edit:
Can't your just connect to "this" for the dataChanged
and then you can re-use the… | |||||
214 | QVector<int>{AbstractTasksModel::HasLauncher}); | ||||
215 | } | ||||
216 | } | ||||
217 | ); | ||||
218 | | ||||
198 | concatProxyModel = new ConcatenateTasksProxyModel(q); | 219 | concatProxyModel = new ConcatenateTasksProxyModel(q); | ||
199 | 220 | | |||
200 | concatProxyModel->addSourceModel(windowTasksModel); | 221 | concatProxyModel->addSourceModel(windowTasksModel); | ||
201 | concatProxyModel->addSourceModel(startupTasksModel); | 222 | concatProxyModel->addSourceModel(startupTasksModel); | ||
202 | 223 | | |||
203 | // If we're in manual sort mode, we need to seed the sort map on pending row | 224 | // If we're in manual sort mode, we need to seed the sort map on pending row | ||
204 | // insertions. | 225 | // insertions. | ||
205 | QObject::connect(concatProxyModel, &QAbstractItemModel::rowsAboutToBeInserted, q, | 226 | QObject::connect(concatProxyModel, &QAbstractItemModel::rowsAboutToBeInserted, q, | ||
▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Line(s) | 493 | { | |||
475 | } | 496 | } | ||
476 | 497 | | |||
477 | launcherTasksModel = new LauncherTasksModel(q); | 498 | launcherTasksModel = new LauncherTasksModel(q); | ||
478 | QObject::connect(launcherTasksModel, &LauncherTasksModel::launcherListChanged, | 499 | QObject::connect(launcherTasksModel, &LauncherTasksModel::launcherListChanged, | ||
479 | q, &TasksModel::launcherListChanged); | 500 | q, &TasksModel::launcherListChanged); | ||
480 | QObject::connect(launcherTasksModel, &LauncherTasksModel::launcherListChanged, | 501 | QObject::connect(launcherTasksModel, &LauncherTasksModel::launcherListChanged, | ||
481 | q, &TasksModel::updateLauncherCount); | 502 | q, &TasksModel::updateLauncherCount); | ||
482 | 503 | | |||
504 | // TODO: On the assumptions that adding/removing launchers is a rare event and | ||||
505 | // the HasLaunchers data role is rarely used, this refreshes it for all rows in | ||||
506 | // the model. If those assumptions are proven wrong later, this could be | ||||
507 | // optimized to only refresh non-launcher rows matching the inserted or about- | ||||
508 | // to-be-removed launcherTasksModel rows using TaskTools::appsMatch(). | ||||
509 | QObject::connect(launcherTasksModel, &LauncherTasksModel::launcherListChanged, | ||||
510 | q, [this]() { | ||||
511 | q->dataChanged(q->index(0, 0), q->index(q->rowCount() - 1, 0), | ||||
512 | QVector<int>{AbstractTasksModel::HasLauncher}); | ||||
513 | } | ||||
514 | ); | ||||
515 | | ||||
483 | concatProxyModel->addSourceModel(launcherTasksModel); | 516 | concatProxyModel->addSourceModel(launcherTasksModel); | ||
484 | } | 517 | } | ||
485 | 518 | | |||
486 | void TasksModel::Private::updateManualSortMap() | 519 | void TasksModel::Private::updateManualSortMap() | ||
487 | { | 520 | { | ||
488 | // Empty map; full sort. | 521 | // Empty map; full sort. | ||
489 | if (sortedPreFilterRows.isEmpty()) { | 522 | if (sortedPreFilterRows.isEmpty()) { | ||
490 | sortedPreFilterRows.reserve(concatProxyModel->rowCount()); | 523 | sortedPreFilterRows.reserve(concatProxyModel->rowCount()); | ||
▲ Show 20 Lines • Show All 392 Lines • ▼ Show 20 Line(s) | |||||
883 | 916 | | |||
884 | int TasksModel::rowCount(const QModelIndex &parent) const | 917 | int TasksModel::rowCount(const QModelIndex &parent) const | ||
885 | { | 918 | { | ||
886 | return QSortFilterProxyModel::rowCount(parent); | 919 | return QSortFilterProxyModel::rowCount(parent); | ||
887 | } | 920 | } | ||
888 | 921 | | |||
889 | QVariant TasksModel::data(const QModelIndex &proxyIndex, int role) const | 922 | QVariant TasksModel::data(const QModelIndex &proxyIndex, int role) const | ||
890 | { | 923 | { | ||
891 | if (rowCount(proxyIndex) && role == AbstractTasksModel::LegacyWinIdList) { | 924 | if (role == AbstractTasksModel::HasLauncher | ||
925 | && proxyIndex.isValid() && proxyIndex.row() < rowCount()) { | ||||
926 | if (proxyIndex.data(AbstractTasksModel::IsLauncher).toBool()) { | ||||
927 | return true; | ||||
928 | } else { | ||||
929 | for (int i = 0; i < d->launcherTasksModel->rowCount(); ++i) { | ||||
930 | const QModelIndex &launcherIndex = d->launcherTasksModel->index(i, 0); | ||||
931 | | ||||
932 | if (appsMatch(proxyIndex, launcherIndex)) { | ||||
933 | return true; | ||||
934 | } | ||||
935 | } | ||||
936 | | ||||
937 | return false; | ||||
938 | } | ||||
939 | } else if (rowCount(proxyIndex) && role == AbstractTasksModel::LegacyWinIdList) { | ||||
892 | QVariantList winIds; | 940 | QVariantList winIds; | ||
893 | 941 | | |||
894 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 942 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
895 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | 943 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | ||
896 | } | 944 | } | ||
897 | 945 | | |||
898 | return winIds; | 946 | return winIds; | ||
899 | } | 947 | } | ||
▲ Show 20 Lines • Show All 805 Lines • Show Last 20 Lines |
Edit:
Can't your just connect to "this" for the dataChanged
and then you can re-use the topLeft and bottomRight indexes