Clean up roomlistmodel.

This commit is contained in:
Black Hat
2019-05-20 13:42:18 +08:00
parent 561236e963
commit c0126cea95
2 changed files with 5 additions and 19 deletions

View File

@@ -48,7 +48,8 @@ void RoomListModel::setConnection(Connection* connection) {
Connection::DirectChatsMap removals) {
for (QString roomID : additions.values() + removals.values()) {
auto room = connection->room(roomID);
if (room) refresh(static_cast<SpectralRoom*>(room));
if (room)
refresh(static_cast<SpectralRoom*>(room));
}
});
@@ -79,11 +80,9 @@ void RoomListModel::doAddRoom(Room* r) {
}
void RoomListModel::connectRoomSignals(SpectralRoom* room) {
connect(room, &Room::displaynameChanged, this, [=] { namesChanged(room); });
connect(room, &Room::unreadMessagesChanged, this,
[=] { unreadMessagesChanged(room); });
connect(room, &Room::notificationCountChanged, this,
[=] { unreadMessagesChanged(room); });
connect(room, &Room::displaynameChanged, this, [=] { refresh(room); });
connect(room, &Room::unreadMessagesChanged, this, [=] { refresh(room); });
connect(room, &Room::notificationCountChanged, this, [=] { refresh(room); });
connect(room, &Room::avatarChanged, this,
[this, room] { refresh(room, {AvatarRole}); });
connect(room, &Room::tagsChanged, this, [=] { refresh(room); });
@@ -207,11 +206,6 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
return QVariant();
}
void RoomListModel::namesChanged(SpectralRoom* room) {
int row = m_rooms.indexOf(room);
emit dataChanged(index(row), index(row));
}
void RoomListModel::refresh(SpectralRoom* room, const QVector<int>& roles) {
const auto it = std::find(m_rooms.begin(), m_rooms.end(), room);
if (it == m_rooms.end()) {
@@ -222,11 +216,6 @@ void RoomListModel::refresh(SpectralRoom* room, const QVector<int>& roles) {
emit dataChanged(idx, idx, roles);
}
void RoomListModel::unreadMessagesChanged(SpectralRoom* room) {
int row = m_rooms.indexOf(room);
emit dataChanged(index(row), index(row));
}
QHash<int, QByteArray> RoomListModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[NameRole] = "name";