From d3b5d1d0dcf1c6910de9b1b01af9e2b7785fc30a Mon Sep 17 00:00:00 2001 From: Black Hat Date: Wed, 7 Mar 2018 16:48:27 +0800 Subject: [PATCH] Attempting to change QMatrixClient::Room to MatriqueRoom. --- matrix/roomlistmodel.cpp | 30 +++++++++++++++++++++--------- matrix/roomlistmodel.h | 13 ++++++++----- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/matrix/roomlistmodel.cpp b/matrix/roomlistmodel.cpp index fb45a7d..e5e02a6 100644 --- a/matrix/roomlistmodel.cpp +++ b/matrix/roomlistmodel.cpp @@ -18,21 +18,28 @@ void RoomListModel::setConnection(QMatrixClient::Connection *conn) { beginResetModel(); m_rooms.clear(); connect(m_connection, &QMatrixClient::Connection::newRoom, this, &RoomListModel::addRoom); - for(QMatrixClient::Room* room: m_connection->roomMap().values()) { - connect(room, &QMatrixClient::Room::namesChanged, this, &RoomListModel::namesChanged); - m_rooms.append(room); + for(QMatrixClient::Room* r: m_connection->roomMap().values()) { + if (auto* room = static_cast(r)) + { + connect(room, &MatriqueRoom::namesChanged, this, &RoomListModel::namesChanged); + m_rooms.append(room); + } else + { + qCritical() << "Attempt to add nullptr to the room list"; + Q_ASSERT(false); + } } endResetModel(); } -QMatrixClient::Room* RoomListModel::roomAt(int row) { +MatriqueRoom* RoomListModel::roomAt(int row) { return m_rooms.at(row); } -void RoomListModel::addRoom(QMatrixClient::Room* room) { +void RoomListModel::addRoom(MatriqueRoom* room) { qDebug() << "Adding room."; beginInsertRows(QModelIndex(), m_rooms.count(), m_rooms.count()); - connect(room, &QMatrixClient::Room::namesChanged, this, &RoomListModel::namesChanged ); + connect(room, &MatriqueRoom::namesChanged, this, &RoomListModel::namesChanged ); m_rooms.append(room); endInsertRows(); } @@ -51,7 +58,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const { qDebug() << "UserListModel: something wrong here..."; return QVariant(); } - QMatrixClient::Room* room = m_rooms.at(index.row()); + MatriqueRoom* room = m_rooms.at(index.row()); if(role == NameRole) { return room->displayName(); } @@ -69,6 +76,11 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const { return QVariant(); } +QModelIndex RoomListModel::indexOf(MatriqueRoom* room) const +{ + return index(m_rooms.indexOf(room), 0); +} + QHash RoomListModel::roleNames() const { QHash roles; roles[NameRole] = "name"; @@ -77,11 +89,11 @@ QHash RoomListModel::roleNames() const { return roles; } -void RoomListModel::namesChanged(QMatrixClient::Room* room) { +void RoomListModel::namesChanged(MatriqueRoom* room) { int row = m_rooms.indexOf(room); emit dataChanged(index(row), index(row)); } -void RoomListModel::unreadMessagesChanged(QMatrixClient::Room* room) { +void RoomListModel::unreadMessagesChanged(MatriqueRoom* room) { } diff --git a/matrix/roomlistmodel.h b/matrix/roomlistmodel.h index 96b74c9..e99550c 100644 --- a/matrix/roomlistmodel.h +++ b/matrix/roomlistmodel.h @@ -7,6 +7,8 @@ #include "libqmatrixclient/connection.h" #include "libqmatrixclient/room.h" +#include "matriqueroom.h" + namespace QMatrixClient { class Connection; class Room; @@ -32,9 +34,10 @@ class RoomListModel : public QAbstractListModel QHash roleNames() const; - Q_INVOKABLE QMatrixClient::Room* roomAt(int row); + Q_INVOKABLE MatriqueRoom* roomAt(int row); QVariant data(const QModelIndex& index, int role) const override; + QModelIndex indexOf(MatriqueRoom* room) const; Q_INVOKABLE int rowCount(const QModelIndex& parent=QModelIndex()) const override; signals: @@ -43,12 +46,12 @@ class RoomListModel : public QAbstractListModel public slots: private slots: - void namesChanged(QMatrixClient::Room* room); - void unreadMessagesChanged(QMatrixClient::Room* room); - void addRoom(QMatrixClient::Room* room); + void namesChanged(MatriqueRoom* room); + void unreadMessagesChanged(MatriqueRoom* room); + void addRoom(MatriqueRoom* room); private: - QList m_rooms; + QList m_rooms; }; #endif // ROOMLISTMODEL_H