Changeset View
Changeset View
Standalone View
Standalone View
applets/kicker/plugin/recentusagemodel.cpp
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | GroupSortProxy::~GroupSortProxy() | 61 | GroupSortProxy::~GroupSortProxy() | ||
62 | { | 62 | { | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | InvalidAppsFilterProxy::InvalidAppsFilterProxy(AbstractModel *parentModel, QAbstractItemModel *sourceModel) : QSortFilterProxyModel(parentModel) | 65 | InvalidAppsFilterProxy::InvalidAppsFilterProxy(AbstractModel *parentModel, QAbstractItemModel *sourceModel) : QSortFilterProxyModel(parentModel) | ||
66 | , m_parentModel(parentModel) | 66 | , m_parentModel(parentModel) | ||
67 | , m_showAllRecents(false) | ||||
67 | { | 68 | { | ||
68 | connect(parentModel, &AbstractModel::favoritesModelChanged, this, &InvalidAppsFilterProxy::connectNewFavoritesModel); | 69 | connect(parentModel, &AbstractModel::favoritesModelChanged, this, &InvalidAppsFilterProxy::connectNewFavoritesModel); | ||
69 | connectNewFavoritesModel(); | 70 | connectNewFavoritesModel(); | ||
70 | 71 | | |||
71 | sourceModel->setParent(this); | 72 | sourceModel->setParent(this); | ||
72 | setSourceModel(sourceModel); | 73 | setSourceModel(sourceModel); | ||
73 | } | 74 | } | ||
74 | 75 | | |||
75 | InvalidAppsFilterProxy::~InvalidAppsFilterProxy() | 76 | InvalidAppsFilterProxy::~InvalidAppsFilterProxy() | ||
76 | { | 77 | { | ||
77 | } | 78 | } | ||
78 | 79 | | |||
80 | bool InvalidAppsFilterProxy::showAllRecents() const | ||||
81 | { | ||||
82 | return m_showAllRecents; | ||||
83 | } | ||||
84 | | ||||
85 | void InvalidAppsFilterProxy::setShowAllRecents(bool showAllRecents) | ||||
86 | { | ||||
87 | if (m_showAllRecents != showAllRecents) { | ||||
88 | m_showAllRecents = showAllRecents; | ||||
89 | Q_EMIT showAllRecentsChanged(showAllRecents); | ||||
90 | invalidate(); | ||||
91 | } | ||||
92 | } | ||||
93 | | ||||
79 | void InvalidAppsFilterProxy::connectNewFavoritesModel() | 94 | void InvalidAppsFilterProxy::connectNewFavoritesModel() | ||
80 | { | 95 | { | ||
81 | KAStatsFavoritesModel* favoritesModel = static_cast<KAStatsFavoritesModel *>(m_parentModel->favoritesModel()); | 96 | KAStatsFavoritesModel* favoritesModel = static_cast<KAStatsFavoritesModel *>(m_parentModel->favoritesModel()); | ||
82 | connect(favoritesModel, &KAStatsFavoritesModel::favoritesChanged, this, &QSortFilterProxyModel::invalidate); | 97 | connect(favoritesModel, &KAStatsFavoritesModel::favoritesChanged, this, &QSortFilterProxyModel::invalidate); | ||
83 | 98 | | |||
84 | invalidate(); | 99 | invalidate(); | ||
85 | } | 100 | } | ||
86 | 101 | | |||
87 | bool InvalidAppsFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | 102 | bool InvalidAppsFilterProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | ||
88 | { | 103 | { | ||
89 | Q_UNUSED(source_parent); | 104 | Q_UNUSED(source_parent); | ||
90 | 105 | | |||
91 | const QString resource = sourceModel()->index(source_row, 0).data(ResultModel::ResourceRole).toString(); | 106 | const QString resource = sourceModel()->index(source_row, 0).data(ResultModel::ResourceRole).toString(); | ||
92 | 107 | | |||
93 | if (resource.startsWith(QLatin1String("applications:"))) { | 108 | if (resource.startsWith(QLatin1String("applications:"))) { | ||
94 | KService::Ptr service = KService::serviceByStorageId(resource.section(QLatin1Char(':'), 1)); | 109 | KService::Ptr service = KService::serviceByStorageId(resource.section(QLatin1Char(':'), 1)); | ||
95 | 110 | | |||
96 | KAStatsFavoritesModel* favoritesModel = m_parentModel ? static_cast<KAStatsFavoritesModel *>(m_parentModel->favoritesModel()) : nullptr; | 111 | KAStatsFavoritesModel* favoritesModel = m_parentModel ? static_cast<KAStatsFavoritesModel *>(m_parentModel->favoritesModel()) : nullptr; | ||
112 | if (m_showAllRecents) { | ||||
113 | return service; | ||||
114 | } | ||||
97 | 115 | | |||
98 | return (service && (!favoritesModel || !favoritesModel->isFavorite(service->storageId()))); | 116 | return (service && (!favoritesModel || !favoritesModel->isFavorite(service->storageId()))); | ||
davidedmundson: This is doing two things.
1) It's removing any favourite in the history that returns a defunct… | |||||
99 | } | 117 | } | ||
100 | 118 | | |||
101 | return true; | 119 | return true; | ||
102 | } | 120 | } | ||
103 | 121 | | |||
104 | bool InvalidAppsFilterProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const | 122 | bool InvalidAppsFilterProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const | ||
105 | { | 123 | { | ||
106 | return (left.row() < right.row()); | 124 | return (left.row() < right.row()); | ||
Show All 15 Lines | 128 | { | |||
122 | return (left.row() < right.row()); | 140 | return (left.row() < right.row()); | ||
123 | } | 141 | } | ||
124 | 142 | | |||
125 | RecentUsageModel::RecentUsageModel(QObject *parent, IncludeUsage usage, int ordering) | 143 | RecentUsageModel::RecentUsageModel(QObject *parent, IncludeUsage usage, int ordering) | ||
126 | : ForwardingModel(parent) | 144 | : ForwardingModel(parent) | ||
127 | , m_usage(usage) | 145 | , m_usage(usage) | ||
128 | , m_ordering((Ordering)ordering) | 146 | , m_ordering((Ordering)ordering) | ||
129 | , m_complete(false) | 147 | , m_complete(false) | ||
148 | , m_showAllRecents(false) | ||||
130 | { | 149 | { | ||
131 | refresh(); | 150 | refresh(); | ||
132 | } | 151 | } | ||
133 | 152 | | |||
134 | RecentUsageModel::~RecentUsageModel() | 153 | RecentUsageModel::~RecentUsageModel() | ||
135 | { | 154 | { | ||
136 | } | 155 | } | ||
137 | 156 | | |||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Line(s) | 458 | { | |||
475 | 494 | | |||
476 | QModelIndex index; | 495 | QModelIndex index; | ||
477 | 496 | | |||
478 | if (model->canFetchMore(index)) { | 497 | if (model->canFetchMore(index)) { | ||
479 | model->fetchMore(index); | 498 | model->fetchMore(index); | ||
480 | } | 499 | } | ||
481 | 500 | | |||
482 | if (m_usage != OnlyDocs) { | 501 | if (m_usage != OnlyDocs) { | ||
483 | model = new InvalidAppsFilterProxy(this, model); | 502 | auto* invalidAppsFilterModel = new InvalidAppsFilterProxy(this, model); | ||
503 | invalidAppsFilterModel->setShowAllRecents(m_showAllRecents); | ||||
484 | } | 504 | } | ||
485 | 505 | | |||
486 | if (m_usage == AppsAndDocs) { | 506 | if (m_usage == AppsAndDocs) { | ||
487 | model = new GroupSortProxy(this, model); | 507 | model = new GroupSortProxy(this, model); | ||
488 | } | 508 | } | ||
489 | 509 | | |||
490 | setSourceModel(model); | 510 | setSourceModel(model); | ||
491 | } | 511 | } | ||
512 | | ||||
513 | bool RecentUsageModel::showAllRecents() const | ||||
514 | { | ||||
515 | return m_showAllRecents; | ||||
516 | } | ||||
517 | | ||||
518 | void RecentUsageModel::setShowAllRecents(bool recents) | ||||
519 | { | ||||
520 | if (m_showAllRecents != recents) { | ||||
521 | if (auto model = qobject_cast<InvalidAppsFilterProxy*>(sourceModel())) { | ||||
522 | model->setShowAllRecents(m_showAllRecents); | ||||
If this is called before refresh model will be null, and then we don't update m_showAllRecent This needs to be outside the if statement. Or you can simplify the whole thing and just use refresh() davidedmundson: If this is called before refresh model will be null, and then we don't update m_showAllRecent… | |||||
523 | m_showAllRecents = recents; | ||||
524 | Q_EMIT showAllRecentsChanged(recents); | ||||
525 | } | ||||
526 | } | ||||
527 | } |
This is doing two things.
We definitely still want 1.
2 definitely makes sense to be optional, even off by default, but simply removing it will change kicker.
Is there a reason to change kicker? If not, it needs to be a property.