Verified Commit 91f486ea authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

libnotificationmanager: Port to QConcatenateTablesProxyModel for notificationsAndJobsModel

parent 53fdac77
Pipeline #183163 passed with stage
in 6 minutes and 14 seconds
......@@ -78,11 +78,11 @@ target_link_libraries(notificationmanager
Qt::Gui
Qt::Quick
KF5::ConfigCore
KF5::ItemModels
PRIVATE
Qt::DBus
KF5::ConfigGui
KF5::I18n
KF5::ItemModels # KDescendantsProxyModel
KF5::KIOFileWidgets
KF5::Plasma
KF5::Screen
......
......@@ -6,11 +6,11 @@
#include "notifications.h"
#include <QConcatenateTablesProxyModel>
#include <QDebug>
#include <QMetaEnum>
#include <QSharedPointer>
#include <KConcatenateRowsProxyModel>
#include <KDescendantsProxyModel>
#include "limitedrowcountproxymodel_p.h"
......@@ -67,7 +67,7 @@ public:
JobsModel::Ptr jobsModel;
QSharedPointer<Settings> settings() const;
KConcatenateRowsProxyModel *notificationsAndJobsModel = nullptr;
QConcatenateTablesProxyModel *notificationsAndJobsModel = nullptr;
NotificationFilterProxyModel *filterModel = nullptr;
NotificationSortProxyModel *sortModel = nullptr;
......@@ -96,11 +96,11 @@ void Notifications::Private::initSourceModels()
if (showNotifications && !notificationsModel) {
notificationsModel = NotificationsModel::createNotificationsModel();
notificationsAndJobsModel->addSourceModel(notificationsModel.data());
connect(notificationsModel.data(), &NotificationsModel::lastReadChanged, q, [this] {
updateCount();
Q_EMIT q->lastReadChanged();
});
notificationsAndJobsModel->addSourceModel(notificationsModel.data());
} else if (!showNotifications && notificationsModel) {
notificationsAndJobsModel->removeSourceModel(notificationsModel.data());
disconnect(notificationsModel.data(), nullptr, q, nullptr); // disconnect all
......@@ -125,7 +125,7 @@ void Notifications::Private::initProxyModels()
* NotificationsModel JobsModel
* \\ /
* \\ /
* KConcatenateRowsProxyModel
* QConcatenateTablesProxyModel
* |||
* |||
* NotificationFilterProxyModel
......@@ -158,7 +158,7 @@ void Notifications::Private::initProxyModels()
*/
if (!notificationsAndJobsModel) {
notificationsAndJobsModel = new KConcatenateRowsProxyModel(q);
notificationsAndJobsModel = new QConcatenateTablesProxyModel(q);
}
if (!filterModel) {
......@@ -169,6 +169,8 @@ void Notifications::Private::initProxyModels()
connect(filterModel, &NotificationFilterProxyModel::blacklistedDesktopEntriesChanged, q, &Notifications::blacklistedDesktopEntriesChanged);
connect(filterModel, &NotificationFilterProxyModel::blacklistedNotifyRcNamesChanged, q, &Notifications::blacklistedNotifyRcNamesChanged);
filterModel->setSourceModel(notificationsAndJobsModel);
connect(filterModel, &QAbstractItemModel::rowsInserted, q, [this] {
updateCount();
});
......@@ -187,8 +189,6 @@ void Notifications::Private::initProxyModels()
updateCount();
}
});
filterModel->setSourceModel(notificationsAndJobsModel);
}
if (!sortModel) {
......@@ -344,8 +344,7 @@ QModelIndex Notifications::Private::mapFromModel(const QModelIndex &idx) const
found = true;
break;
}
} else if (auto *concatenateModel = qobject_cast<KConcatenateRowsProxyModel *>(model)) {
// There's no "sourceModels()" on KConcatenateRowsProxyModel
} else if (auto *concatenateModel = qobject_cast<QConcatenateTablesProxyModel *>(model)) {
if (idxModel == notificationsModel.data() || idxModel == jobsModel.data()) {
resolvedIdx = concatenateModel->mapFromSource(resolvedIdx);
found = true;
......
......@@ -10,6 +10,7 @@
#include <QAbstractItemModel>
#include <QAbstractProxyModel>
#include <QConcatenateTablesProxyModel>
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
......@@ -19,8 +20,6 @@
#include <QSettings>
#include <QTextStream>
#include <KConcatenateRowsProxyModel>
#include <KProcessList>
using namespace NotificationManager;
......@@ -109,8 +108,8 @@ QModelIndex Utils::mapToModel(const QModelIndex &idx, const QAbstractItemModel *
while (resolvedIdx.isValid() && resolvedIdx.model() != sourceModel) {
if (auto *proxyModel = qobject_cast<const QAbstractProxyModel *>(resolvedIdx.model())) {
resolvedIdx = proxyModel->mapToSource(resolvedIdx);
// KConcatenateRowsProxyModel isn't a "real" proxy model, so we need to special case for it :(
} else if (auto *concatenateModel = qobject_cast<const KConcatenateRowsProxyModel *>(resolvedIdx.model())) {
// QConcatenateTablesProxyModel isn't a "real" proxy model, so we need to special case for it :(
} else if (auto *concatenateModel = qobject_cast<const QConcatenateTablesProxyModel *>(resolvedIdx.model())) {
resolvedIdx = concatenateModel->mapToSource(resolvedIdx);
} else {
if (resolvedIdx.model() != sourceModel) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment