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::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) {

Loading…
Cancel
Save