Cleanup name handling in RoomListModel

Replace NameRole with DisplayNameRole entirely.
This commit is contained in:
Tobias Fella
2023-05-15 00:14:38 +02:00
parent dee064a758
commit 4d2e64cb80
8 changed files with 17 additions and 21 deletions

View File

@@ -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<int> &roles)
QHash<int, QByteArray> RoomListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[DisplayNameRole] = "displayName";
roles[AvatarRole] = "avatar";
roles[CanonicalAliasRole] = "canonicalAlias";

View File

@@ -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. */

View File

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