Attempting to change QMatrixClient::Room to MatriqueRoom.
This commit is contained in:
parent
788b17e06f
commit
d3b5d1d0dc
|
@ -18,21 +18,28 @@ void RoomListModel::setConnection(QMatrixClient::Connection *conn) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_rooms.clear();
|
m_rooms.clear();
|
||||||
connect(m_connection, &QMatrixClient::Connection::newRoom, this, &RoomListModel::addRoom);
|
connect(m_connection, &QMatrixClient::Connection::newRoom, this, &RoomListModel::addRoom);
|
||||||
for(QMatrixClient::Room* room: m_connection->roomMap().values()) {
|
for(QMatrixClient::Room* r: m_connection->roomMap().values()) {
|
||||||
connect(room, &QMatrixClient::Room::namesChanged, this, &RoomListModel::namesChanged);
|
if (auto* room = static_cast<MatriqueRoom*>(r))
|
||||||
m_rooms.append(room);
|
{
|
||||||
|
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();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMatrixClient::Room* RoomListModel::roomAt(int row) {
|
MatriqueRoom* RoomListModel::roomAt(int row) {
|
||||||
return m_rooms.at(row);
|
return m_rooms.at(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::addRoom(QMatrixClient::Room* room) {
|
void RoomListModel::addRoom(MatriqueRoom* room) {
|
||||||
qDebug() << "Adding room.";
|
qDebug() << "Adding room.";
|
||||||
beginInsertRows(QModelIndex(), m_rooms.count(), m_rooms.count());
|
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);
|
m_rooms.append(room);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
@ -51,7 +58,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
|
||||||
qDebug() << "UserListModel: something wrong here...";
|
qDebug() << "UserListModel: something wrong here...";
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
QMatrixClient::Room* room = m_rooms.at(index.row());
|
MatriqueRoom* room = m_rooms.at(index.row());
|
||||||
if(role == NameRole) {
|
if(role == NameRole) {
|
||||||
return room->displayName();
|
return room->displayName();
|
||||||
}
|
}
|
||||||
|
@ -69,6 +76,11 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex RoomListModel::indexOf(MatriqueRoom* room) const
|
||||||
|
{
|
||||||
|
return index(m_rooms.indexOf(room), 0);
|
||||||
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> RoomListModel::roleNames() const {
|
QHash<int, QByteArray> RoomListModel::roleNames() const {
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[NameRole] = "name";
|
roles[NameRole] = "name";
|
||||||
|
@ -77,11 +89,11 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::namesChanged(QMatrixClient::Room* room) {
|
void RoomListModel::namesChanged(MatriqueRoom* room) {
|
||||||
int row = m_rooms.indexOf(room);
|
int row = m_rooms.indexOf(room);
|
||||||
emit dataChanged(index(row), index(row));
|
emit dataChanged(index(row), index(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::unreadMessagesChanged(QMatrixClient::Room* room) {
|
void RoomListModel::unreadMessagesChanged(MatriqueRoom* room) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "libqmatrixclient/connection.h"
|
||||||
#include "libqmatrixclient/room.h"
|
#include "libqmatrixclient/room.h"
|
||||||
|
|
||||||
|
#include "matriqueroom.h"
|
||||||
|
|
||||||
namespace QMatrixClient {
|
namespace QMatrixClient {
|
||||||
class Connection;
|
class Connection;
|
||||||
class Room;
|
class Room;
|
||||||
|
@ -32,9 +34,10 @@ class RoomListModel : public QAbstractListModel
|
||||||
|
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
Q_INVOKABLE QMatrixClient::Room* roomAt(int row);
|
Q_INVOKABLE MatriqueRoom* roomAt(int row);
|
||||||
|
|
||||||
QVariant data(const QModelIndex& index, int role) const override;
|
QVariant data(const QModelIndex& index, int role) const override;
|
||||||
|
QModelIndex indexOf(MatriqueRoom* room) const;
|
||||||
Q_INVOKABLE int rowCount(const QModelIndex& parent=QModelIndex()) const override;
|
Q_INVOKABLE int rowCount(const QModelIndex& parent=QModelIndex()) const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -43,12 +46,12 @@ class RoomListModel : public QAbstractListModel
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void namesChanged(QMatrixClient::Room* room);
|
void namesChanged(MatriqueRoom* room);
|
||||||
void unreadMessagesChanged(QMatrixClient::Room* room);
|
void unreadMessagesChanged(MatriqueRoom* room);
|
||||||
void addRoom(QMatrixClient::Room* room);
|
void addRoom(MatriqueRoom* room);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QMatrixClient::Room*> m_rooms;
|
QList<MatriqueRoom*> m_rooms;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ROOMLISTMODEL_H
|
#endif // ROOMLISTMODEL_H
|
||||||
|
|
Loading…
Reference in New Issue