libnotificationmanager: Port to QConcatenateTablesProxyModel for notificationsAndJobsModel

wilder-5.26
Fushan Wen 4 years ago
parent 53fdac77ec
commit 91f486ea68
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
  1. 2
      libnotificationmanager/CMakeLists.txt
  2. 17
      libnotificationmanager/notifications.cpp
  3. 7
      libnotificationmanager/utils.cpp

@ -78,11 +78,11 @@ target_link_libraries(notificationmanager
Qt::Gui Qt::Gui
Qt::Quick Qt::Quick
KF5::ConfigCore KF5::ConfigCore
KF5::ItemModels
PRIVATE PRIVATE
Qt::DBus Qt::DBus
KF5::ConfigGui KF5::ConfigGui
KF5::I18n KF5::I18n
KF5::ItemModels # KDescendantsProxyModel
KF5::KIOFileWidgets KF5::KIOFileWidgets
KF5::Plasma KF5::Plasma
KF5::Screen KF5::Screen

@ -6,11 +6,11 @@
#include "notifications.h" #include "notifications.h"
#include <QConcatenateTablesProxyModel>
#include <QDebug> #include <QDebug>
#include <QMetaEnum> #include <QMetaEnum>
#include <QSharedPointer> #include <QSharedPointer>
#include <KConcatenateRowsProxyModel>
#include <KDescendantsProxyModel> #include <KDescendantsProxyModel>
#include "limitedrowcountproxymodel_p.h" #include "limitedrowcountproxymodel_p.h"
@ -67,7 +67,7 @@ public:
JobsModel::Ptr jobsModel; JobsModel::Ptr jobsModel;
QSharedPointer<Settings> settings() const; QSharedPointer<Settings> settings() const;
KConcatenateRowsProxyModel *notificationsAndJobsModel = nullptr; QConcatenateTablesProxyModel *notificationsAndJobsModel = nullptr;
NotificationFilterProxyModel *filterModel = nullptr; NotificationFilterProxyModel *filterModel = nullptr;
NotificationSortProxyModel *sortModel = nullptr; NotificationSortProxyModel *sortModel = nullptr;
@ -96,11 +96,11 @@ void Notifications::Private::initSourceModels()
if (showNotifications && !notificationsModel) { if (showNotifications && !notificationsModel) {
notificationsModel = NotificationsModel::createNotificationsModel(); notificationsModel = NotificationsModel::createNotificationsModel();
notificationsAndJobsModel->addSourceModel(notificationsModel.data());
connect(notificationsModel.data(), &NotificationsModel::lastReadChanged, q, [this] { connect(notificationsModel.data(), &NotificationsModel::lastReadChanged, q, [this] {
updateCount(); updateCount();
Q_EMIT q->lastReadChanged(); Q_EMIT q->lastReadChanged();
}); });
notificationsAndJobsModel->addSourceModel(notificationsModel.data());
} else if (!showNotifications && notificationsModel) { } else if (!showNotifications && notificationsModel) {
notificationsAndJobsModel->removeSourceModel(notificationsModel.data()); notificationsAndJobsModel->removeSourceModel(notificationsModel.data());
disconnect(notificationsModel.data(), nullptr, q, nullptr); // disconnect all disconnect(notificationsModel.data(), nullptr, q, nullptr); // disconnect all
@ -125,7 +125,7 @@ void Notifications::Private::initProxyModels()
* NotificationsModel JobsModel * NotificationsModel JobsModel
* \\ / * \\ /
* \\ / * \\ /
* KConcatenateRowsProxyModel * QConcatenateTablesProxyModel
* ||| * |||
* ||| * |||
* NotificationFilterProxyModel * NotificationFilterProxyModel
@ -158,7 +158,7 @@ void Notifications::Private::initProxyModels()
*/ */
if (!notificationsAndJobsModel) { if (!notificationsAndJobsModel) {
notificationsAndJobsModel = new KConcatenateRowsProxyModel(q); notificationsAndJobsModel = new QConcatenateTablesProxyModel(q);
} }
if (!filterModel) { if (!filterModel) {
@ -169,6 +169,8 @@ void Notifications::Private::initProxyModels()
connect(filterModel, &NotificationFilterProxyModel::blacklistedDesktopEntriesChanged, q, &Notifications::blacklistedDesktopEntriesChanged); connect(filterModel, &NotificationFilterProxyModel::blacklistedDesktopEntriesChanged, q, &Notifications::blacklistedDesktopEntriesChanged);
connect(filterModel, &NotificationFilterProxyModel::blacklistedNotifyRcNamesChanged, q, &Notifications::blacklistedNotifyRcNamesChanged); connect(filterModel, &NotificationFilterProxyModel::blacklistedNotifyRcNamesChanged, q, &Notifications::blacklistedNotifyRcNamesChanged);
filterModel->setSourceModel(notificationsAndJobsModel);
connect(filterModel, &QAbstractItemModel::rowsInserted, q, [this] { connect(filterModel, &QAbstractItemModel::rowsInserted, q, [this] {
updateCount(); updateCount();
}); });
@ -187,8 +189,6 @@ void Notifications::Private::initProxyModels()
updateCount(); updateCount();
} }
}); });
filterModel->setSourceModel(notificationsAndJobsModel);
} }
if (!sortModel) { if (!sortModel) {
@ -344,8 +344,7 @@ QModelIndex Notifications::Private::mapFromModel(const QModelIndex &idx) const
found = true; found = true;
break; break;
} }
} else if (auto *concatenateModel = qobject_cast<KConcatenateRowsProxyModel *>(model)) { } else if (auto *concatenateModel = qobject_cast<QConcatenateTablesProxyModel *>(model)) {
// There's no "sourceModels()" on KConcatenateRowsProxyModel
if (idxModel == notificationsModel.data() || idxModel == jobsModel.data()) { if (idxModel == notificationsModel.data() || idxModel == jobsModel.data()) {
resolvedIdx = concatenateModel->mapFromSource(resolvedIdx); resolvedIdx = concatenateModel->mapFromSource(resolvedIdx);
found = true; found = true;

@ -10,6 +10,7 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QAbstractProxyModel> #include <QAbstractProxyModel>
#include <QConcatenateTablesProxyModel>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusConnectionInterface> #include <QDBusConnectionInterface>
@ -19,8 +20,6 @@
#include <QSettings> #include <QSettings>
#include <QTextStream> #include <QTextStream>
#include <KConcatenateRowsProxyModel>
#include <KProcessList> #include <KProcessList>
using namespace NotificationManager; using namespace NotificationManager;
@ -109,8 +108,8 @@ QModelIndex Utils::mapToModel(const QModelIndex &idx, const QAbstractItemModel *
while (resolvedIdx.isValid() && resolvedIdx.model() != sourceModel) { while (resolvedIdx.isValid() && resolvedIdx.model() != sourceModel) {
if (auto *proxyModel = qobject_cast<const QAbstractProxyModel *>(resolvedIdx.model())) { if (auto *proxyModel = qobject_cast<const QAbstractProxyModel *>(resolvedIdx.model())) {
resolvedIdx = proxyModel->mapToSource(resolvedIdx); resolvedIdx = proxyModel->mapToSource(resolvedIdx);
// KConcatenateRowsProxyModel isn't a "real" proxy model, so we need to special case for it :( // QConcatenateTablesProxyModel isn't a "real" proxy model, so we need to special case for it :(
} else if (auto *concatenateModel = qobject_cast<const KConcatenateRowsProxyModel *>(resolvedIdx.model())) { } else if (auto *concatenateModel = qobject_cast<const QConcatenateTablesProxyModel *>(resolvedIdx.model())) {
resolvedIdx = concatenateModel->mapToSource(resolvedIdx); resolvedIdx = concatenateModel->mapToSource(resolvedIdx);
} else { } else {
if (resolvedIdx.model() != sourceModel) { if (resolvedIdx.model() != sourceModel) {

Loading…
Cancel
Save