Port to QEvent::ApplicationPaletteChange

The paletteChanged on QGuiApplication is deprecated in Qt6
This commit is contained in:
Joshua Goins
2023-11-10 12:01:52 -05:00
parent ffa2d5dc0e
commit 555d23863e
8 changed files with 44 additions and 13 deletions

View File

@@ -45,10 +45,6 @@ LocationsModel::LocationsModel(QObject *parent)
});
connect(this, &LocationsModel::rowsInserted, this, &LocationsModel::boundingBoxChanged);
connect(static_cast<QGuiApplication *>(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"

View File

@@ -46,6 +46,9 @@ Q_SIGNALS:
void roomChanged();
void boundingBoxChanged();
protected:
bool event(QEvent *event) override;
private:
QPointer<NeoChatRoom> m_room;

View File

@@ -71,9 +71,6 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
MessageEventModel::MessageEventModel(QObject *parent)
: QAbstractListModel(parent)
{
connect(static_cast<QGuiApplication *>(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"

View File

@@ -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);

View File

@@ -21,9 +21,6 @@ using namespace Quotient;
SearchModel::SearchModel(QObject *parent)
: QAbstractListModel(parent)
{
connect(static_cast<QGuiApplication *>(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;

View File

@@ -132,6 +132,9 @@ Q_SIGNALS:
void roomChanged();
void searchingChanged();
protected:
bool event(QEvent *event) override;
private:
void setSearching(bool searching);

View File

@@ -16,9 +16,6 @@ UserListModel::UserListModel(QObject *parent)
: QAbstractListModel(parent)
, m_currentRoom(nullptr)
{
connect(static_cast<QGuiApplication *>(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);

View File

@@ -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);