From 4d2e64cb80b044faef28b467d376b12e89f1fea5 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 15 May 2023 00:14:38 +0200 Subject: [PATCH] Cleanup name handling in RoomListModel Replace NameRole with DisplayNameRole entirely. --- src/models/roomlistmodel.cpp | 6 +----- src/models/roomlistmodel.h | 3 +-- src/models/sortfilterroomlistmodel.cpp | 5 +++-- src/qml/Component/Devtools/RoomData.qml | 2 +- src/qml/Component/QuickSwitcher.qml | 6 +++--- src/qml/Page/RoomList/CollapsedRoomDelegate.qml | 6 +++--- src/qml/Page/RoomList/RoomDelegate.qml | 6 +++--- src/qml/Page/RoomList/SpaceDrawer.qml | 4 ++-- 8 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index aa1b5a056..3129b90de 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -158,7 +158,7 @@ void RoomListModel::doAddRoom(Room *r) void RoomListModel::connectRoomSignals(NeoChatRoom *room) { connect(room, &Room::displaynameChanged, this, [this, room] { - refresh(room, {DisplayNameRole, NameRole}); + refresh(room, {DisplayNameRole}); }); connect(room, &Room::unreadMessagesChanged, this, [this, room] { refresh(room, {NotificationCountRole, HighlightCountRole}); @@ -333,9 +333,6 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const return QVariant(); } NeoChatRoom *room = m_rooms.at(index.row()); - if (role == NameRole) { - return !room->name().isEmpty() ? room->name() : room->displayName(); - } if (role == DisplayNameRole) { return room->displayName(); } @@ -434,7 +431,6 @@ void RoomListModel::refresh(NeoChatRoom *room, const QVector &roles) QHash RoomListModel::roleNames() const { QHash roles; - roles[NameRole] = "name"; roles[DisplayNameRole] = "displayName"; roles[AvatarRole] = "avatar"; roles[CanonicalAliasRole] = "canonicalAlias"; diff --git a/src/models/roomlistmodel.h b/src/models/roomlistmodel.h index 9a1617d76..fe249cd14 100644 --- a/src/models/roomlistmodel.h +++ b/src/models/roomlistmodel.h @@ -58,8 +58,7 @@ public: * @brief Defines the model roles. */ enum EventRoles { - NameRole = Qt::UserRole + 1, /**< The name of the room. */ - DisplayNameRole, /**< The display name of the room. */ + DisplayNameRole = Qt::DisplayRole, /**< The display name of the room. */ AvatarRole, /**< The source URL for the room's avatar. */ CanonicalAliasRole, /**< The room canonical alias. */ TopicRole, /**< The room topic. */ diff --git a/src/models/sortfilterroomlistmodel.cpp b/src/models/sortfilterroomlistmodel.cpp index bddc638db..02834fbf6 100644 --- a/src/models/sortfilterroomlistmodel.cpp +++ b/src/models/sortfilterroomlistmodel.cpp @@ -21,7 +21,7 @@ void SortFilterRoomListModel::setRoomSortOrder(SortFilterRoomListModel::RoomSort m_sortOrder = sortOrder; Q_EMIT roomSortOrderChanged(); if (sortOrder == SortFilterRoomListModel::Alphabetical) { - setSortRole(RoomListModel::NameRole); + setSortRole(RoomListModel::DisplayNameRole); } else if (sortOrder == SortFilterRoomListModel::LastActivity) { setSortRole(RoomListModel::LastActiveTimeRole); } @@ -78,7 +78,8 @@ bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex { Q_UNUSED(source_parent); - bool acceptRoom = sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::NameRole).toString().contains(m_filterText, Qt::CaseInsensitive) + bool acceptRoom = + sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive) && sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::JoinStateRole).toString() != "upgraded" && sourceModel()->data(sourceModel()->index(source_row, 0), RoomListModel::IsSpaceRole).toBool() == false; diff --git a/src/qml/Component/Devtools/RoomData.qml b/src/qml/Component/Devtools/RoomData.qml index 8dfe89ce4..42a0f2e14 100644 --- a/src/qml/Component/Devtools/RoomData.qml +++ b/src/qml/Component/Devtools/RoomData.qml @@ -18,7 +18,7 @@ ColumnLayout { spacing: 0 MobileForm.FormComboBoxDelegate { text: i18n("Room") - textRole: "name" + textRole: "displayName" valueRole: "id" model: RoomListModel { id: roomListModel diff --git a/src/qml/Component/QuickSwitcher.qml b/src/qml/Component/QuickSwitcher.qml index 8471f6d01..9823aed2f 100644 --- a/src/qml/Component/QuickSwitcher.qml +++ b/src/qml/Component/QuickSwitcher.qml @@ -90,7 +90,7 @@ QQC2.Dialog { id: roomListItem required property var currentRoom - required property string name + required property string displayName required property int index required property int notificationCount required property string subtitleText @@ -114,7 +114,7 @@ QQC2.Dialog { root.close(); } bold: roomListItem.notificationCount > 0 - label: roomListItem.name ?? "" + label: roomListItem.displayName ?? "" labelItem.textFormat: Text.PlainText subtitle: roomListItem.subtitleText subtitleItem.textFormat: Text.PlainText @@ -124,7 +124,7 @@ QQC2.Dialog { leading: Kirigami.Avatar { source: roomListItem.avatar ? "image://mxc/" + roomListItem.avatar : "" - name: roomListItem.name || i18n("No Name") + name: roomListItem.displayName implicitWidth: height sourceSize.width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2 sourceSize.height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2 diff --git a/src/qml/Page/RoomList/CollapsedRoomDelegate.qml b/src/qml/Page/RoomList/CollapsedRoomDelegate.qml index d5a30208c..3092d0f7a 100644 --- a/src/qml/Page/RoomList/CollapsedRoomDelegate.qml +++ b/src/qml/Page/RoomList/CollapsedRoomDelegate.qml @@ -20,7 +20,7 @@ QQC2.ItemDelegate { required property bool categoryVisible required property string filterText required property string avatar - required property string name + required property string displayName topPadding: Kirigami.Units.largeSpacing leftPadding: Kirigami.Units.largeSpacing @@ -34,7 +34,7 @@ QQC2.ItemDelegate { contentItem: Kirigami.Avatar { source: root.avatar ? `image://mxc/${root.avatar}` : "" - name: root.name || i18n("No Name") + name: root.displayName sourceSize { width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2 @@ -48,6 +48,6 @@ QQC2.ItemDelegate { Keys.onReturnPressed: RoomManager.enterRoom(root.currentRoom) QQC2.ToolTip.visible: text.length > 0 && hovered - QQC2.ToolTip.text: root.name ?? "" + QQC2.ToolTip.text: root.displayName ?? "" QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay } diff --git a/src/qml/Page/RoomList/RoomDelegate.qml b/src/qml/Page/RoomList/RoomDelegate.qml index 0aa20e525..48fff1b3e 100644 --- a/src/qml/Page/RoomList/RoomDelegate.qml +++ b/src/qml/Page/RoomList/RoomDelegate.qml @@ -25,7 +25,7 @@ Kirigami.BasicListItem { required property string avatar required property string subtitleText - required property string name + required property string displayName readonly property bool hasNotifications: notificationCount > 0 @@ -38,7 +38,7 @@ Kirigami.BasicListItem { icon: undefined bold: root.hasNotifications - label: root.name ?? "" + label: root.displayName labelItem.textFormat: Text.PlainText subtitle: root.subtitleText @@ -61,7 +61,7 @@ Kirigami.BasicListItem { leading: Kirigami.Avatar { source: root.avatar ? `image://mxc/${root.avatar}` : "" - name: root.name || i18n("No Name") + name: root.displayName implicitWidth: visible ? height : 0 visible: Config.showAvatarInRoomDrawer sourceSize { diff --git a/src/qml/Page/RoomList/SpaceDrawer.qml b/src/qml/Page/RoomList/SpaceDrawer.qml index 753ecc8db..aba695f68 100644 --- a/src/qml/Page/RoomList/SpaceDrawer.qml +++ b/src/qml/Page/RoomList/SpaceDrawer.qml @@ -81,9 +81,9 @@ QQC2.Control { Layout.fillWidth: true Layout.preferredHeight: width display: Kirigami.NavigationTabButton.IconOnly - text: model.name + text: model.displayName source: model.avatar ? ("image://mxc/" + model.avatar) : "" - name: model.name + name: model.displayName onClicked: root.selectedSpaceId = model.id QQC2.ToolTip.visible: hovered QQC2.ToolTip.text: text