From 91f486ea68ad71f701c9c442233391c0e0cff486 Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Thu, 26 May 2022 18:50:13 +0800 Subject: [PATCH] libnotificationmanager: Port to QConcatenateTablesProxyModel for notificationsAndJobsModel --- libnotificationmanager/CMakeLists.txt | 2 +- libnotificationmanager/notifications.cpp | 17 ++++++++--------- libnotificationmanager/utils.cpp | 7 +++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/libnotificationmanager/CMakeLists.txt b/libnotificationmanager/CMakeLists.txt index f7c574905..62f3b015a 100644 --- a/libnotificationmanager/CMakeLists.txt +++ b/libnotificationmanager/CMakeLists.txt @@ -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 diff --git a/libnotificationmanager/notifications.cpp b/libnotificationmanager/notifications.cpp index 9e7ad16df..1d5bd5c91 100644 --- a/libnotificationmanager/notifications.cpp +++ b/libnotificationmanager/notifications.cpp @@ -6,11 +6,11 @@ #include "notifications.h" +#include #include #include #include -#include #include #include "limitedrowcountproxymodel_p.h" @@ -67,7 +67,7 @@ public: JobsModel::Ptr jobsModel; QSharedPointer 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(model)) { - // There's no "sourceModels()" on KConcatenateRowsProxyModel + } else if (auto *concatenateModel = qobject_cast(model)) { if (idxModel == notificationsModel.data() || idxModel == jobsModel.data()) { resolvedIdx = concatenateModel->mapFromSource(resolvedIdx); found = true; diff --git a/libnotificationmanager/utils.cpp b/libnotificationmanager/utils.cpp index d39b65313..c28effba9 100644 --- a/libnotificationmanager/utils.cpp +++ b/libnotificationmanager/utils.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -19,8 +20,6 @@ #include #include -#include - #include 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(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(resolvedIdx.model())) { + // QConcatenateTablesProxyModel isn't a "real" proxy model, so we need to special case for it :( + } else if (auto *concatenateModel = qobject_cast(resolvedIdx.model())) { resolvedIdx = concatenateModel->mapToSource(resolvedIdx); } else { if (resolvedIdx.model() != sourceModel) {