From 555d23863e2c17dfdef6fea01679c432910aa285 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 10 Nov 2023 12:01:52 -0500 Subject: [PATCH] Port to QEvent::ApplicationPaletteChange The paletteChanged on QGuiApplication is deprecated in Qt6 --- src/models/locationsmodel.cpp | 12 ++++++++---- src/models/locationsmodel.h | 3 +++ src/models/messageeventmodel.cpp | 11 ++++++++--- src/models/messageeventmodel.h | 3 +++ src/models/searchmodel.cpp | 11 ++++++++--- src/models/searchmodel.h | 3 +++ src/models/userlistmodel.cpp | 11 ++++++++--- src/models/userlistmodel.h | 3 +++ 8 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/models/locationsmodel.cpp b/src/models/locationsmodel.cpp index 4541a37d0..1f15f12bd 100644 --- a/src/models/locationsmodel.cpp +++ b/src/models/locationsmodel.cpp @@ -45,10 +45,6 @@ LocationsModel::LocationsModel(QObject *parent) }); connect(this, &LocationsModel::rowsInserted, this, &LocationsModel::boundingBoxChanged); - - connect(static_cast(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, [this] { - Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AuthorRole}); - }); } void LocationsModel::addLocation(const RoomMessageEvent *event) @@ -135,4 +131,12 @@ QRectF LocationsModel::boundingBox() const return bbox; } +bool LocationsModel::event(QEvent *event) +{ + if (event->type() == QEvent::ApplicationPaletteChange) { + Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AuthorRole}); + } + return QObject::event(event); +} + #include "moc_locationsmodel.cpp" diff --git a/src/models/locationsmodel.h b/src/models/locationsmodel.h index 3f99b6dd6..7f7b1fb97 100644 --- a/src/models/locationsmodel.h +++ b/src/models/locationsmodel.h @@ -46,6 +46,9 @@ Q_SIGNALS: void roomChanged(); void boundingBoxChanged(); +protected: + bool event(QEvent *event) override; + private: QPointer m_room; diff --git a/src/models/messageeventmodel.cpp b/src/models/messageeventmodel.cpp index 6e55aa656..02ea3655f 100644 --- a/src/models/messageeventmodel.cpp +++ b/src/models/messageeventmodel.cpp @@ -71,9 +71,6 @@ QHash MessageEventModel::roleNames() const MessageEventModel::MessageEventModel(QObject *parent) : QAbstractListModel(parent) { - connect(static_cast(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, [this] { - Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AuthorRole, ReplyAuthor, ReadMarkersRole}); - }); } NeoChatRoom *MessageEventModel::room() const @@ -726,4 +723,12 @@ void MessageEventModel::createEventObjects(const Quotient::RoomMessageEvent *eve } } +bool MessageEventModel::event(QEvent *event) +{ + if (event->type() == QEvent::ApplicationPaletteChange) { + Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AuthorRole, ReplyAuthor, ReadMarkersRole}); + } + return QObject::event(event); +} + #include "moc_messageeventmodel.cpp" diff --git a/src/models/messageeventmodel.h b/src/models/messageeventmodel.h index 4fa5cd45d..9f4d2e7ae 100644 --- a/src/models/messageeventmodel.h +++ b/src/models/messageeventmodel.h @@ -118,6 +118,9 @@ public: */ Q_INVOKABLE [[nodiscard]] int eventIdToRow(const QString &eventID) const; +protected: + bool event(QEvent *event) override; + private Q_SLOTS: int refreshEvent(const QString &eventId); void refreshRow(int row); diff --git a/src/models/searchmodel.cpp b/src/models/searchmodel.cpp index 707c3b4d6..1fd524426 100644 --- a/src/models/searchmodel.cpp +++ b/src/models/searchmodel.cpp @@ -21,9 +21,6 @@ using namespace Quotient; SearchModel::SearchModel(QObject *parent) : QAbstractListModel(parent) { - connect(static_cast(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, [this] { - Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AuthorRole, ReadMarkersRole}); - }); } QString SearchModel::searchText() const @@ -219,6 +216,14 @@ bool SearchModel::searching() const return m_searching; } +bool SearchModel::event(QEvent *event) +{ + if (event->type() == QEvent::ApplicationPaletteChange) { + Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), {AuthorRole, ReadMarkersRole}); + } + return QObject::event(event); +} + void SearchModel::setSearching(bool searching) { m_searching = searching; diff --git a/src/models/searchmodel.h b/src/models/searchmodel.h index 4f31b21bb..00c434437 100644 --- a/src/models/searchmodel.h +++ b/src/models/searchmodel.h @@ -132,6 +132,9 @@ Q_SIGNALS: void roomChanged(); void searchingChanged(); +protected: + bool event(QEvent *event) override; + private: void setSearching(bool searching); diff --git a/src/models/userlistmodel.cpp b/src/models/userlistmodel.cpp index 85bc8e497..40a5ff8ad 100644 --- a/src/models/userlistmodel.cpp +++ b/src/models/userlistmodel.cpp @@ -16,9 +16,6 @@ UserListModel::UserListModel(QObject *parent) : QAbstractListModel(parent) , m_currentRoom(nullptr) { - connect(static_cast(QGuiApplication::instance()), &QGuiApplication::paletteChanged, this, [this]() { - refreshAllUsers(); - }); } void UserListModel::setRoom(NeoChatRoom *room) @@ -121,6 +118,14 @@ int UserListModel::rowCount(const QModelIndex &parent) const return m_users.count(); } +bool UserListModel::event(QEvent *event) +{ + if (event->type() == QEvent::ApplicationPaletteChange) { + refreshAllUsers(); + } + return QObject::event(event); +} + void UserListModel::userAdded(Quotient::User *user) { auto pos = findUserPos(user); diff --git a/src/models/userlistmodel.h b/src/models/userlistmodel.h index 99c5b46b4..cc0fd73f4 100644 --- a/src/models/userlistmodel.h +++ b/src/models/userlistmodel.h @@ -86,6 +86,9 @@ Q_SIGNALS: void roomChanged(); void usersRefreshed(); +protected: + bool event(QEvent *event) override; + private Q_SLOTS: void userAdded(Quotient::User *user); void userRemoved(Quotient::User *user);