summary refs log tree commit diff
path: root/src/timeline/RoomlistModel.cpp
diff options
context:
space:
mode:
authorSateallia <mail@satealliasdomain.net>2023-04-13 11:45:00 +0000
committerNicolas Werner <nicolas.werner@hotmail.de>2023-04-14 18:59:06 +0200
commit4b2bf9680cbde81ba3fd66272a3f29a7715d1bd4 (patch)
treeb437578205ad1235a79e0cb00247a0ba49799f3e /src/timeline/RoomlistModel.cpp
parentMeasure ram usage during compilation (diff)
downloadnheko-4b2bf9680cbde81ba3fd66272a3f29a7715d1bd4.tar.xz
Alphabetical ordering option
Diffstat (limited to 'src/timeline/RoomlistModel.cpp')
-rw-r--r--src/timeline/RoomlistModel.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp

index 12fee262..0801289c 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp
@@ -886,15 +886,26 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ return a_importance > b_importance; } - // Now sort by recency + // Now sort by recency or room name // Zero if empty, otherwise the time that the event occured - uint64_t a_recency = sourceModel()->data(left_idx, RoomlistModel::Timestamp).toULongLong(); - uint64_t b_recency = sourceModel()->data(right_idx, RoomlistModel::Timestamp).toULongLong(); - if (a_recency != b_recency) - return a_recency > b_recency; - else - return left.row() < right.row(); + if (!this->sortByAlphabet) { + uint64_t a_order = sourceModel()->data(left_idx, RoomlistModel::Timestamp).toULongLong(); + uint64_t b_order = sourceModel()->data(right_idx, RoomlistModel::Timestamp).toULongLong(); + + if (a_order != b_order) + return a_order > b_order; + } else { + QString a_order = + sourceModel()->data(left_idx, RoomlistModel::RoomName).toString().toLower(); + QString b_order = + sourceModel()->data(right_idx, RoomlistModel::RoomName).toString().toLower(); + + if (a_order != b_order) + return a_order < b_order; + } + + return left.row() < right.row(); } FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *parent) @@ -902,17 +913,27 @@ FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *pare , roomlistmodel(model) { this->sortByImportance = UserSettings::instance()->sortByImportance(); + this->sortByAlphabet = UserSettings::instance()->sortByAlphabet(); setSourceModel(model); setDynamicSortFilter(true); + setSortCaseSensitivity(Qt::CaseInsensitive); QObject::connect(UserSettings::instance().get(), - &UserSettings::roomSortingChanged, + &UserSettings::roomSortingChangedImportance, this, [this](bool sortByImportance_) { this->sortByImportance = sortByImportance_; invalidate(); }); + QObject::connect(UserSettings::instance().get(), + &UserSettings::roomSortingChangedAlphabetical, + this, + [this](bool sortByAlphabet_) { + this->sortByAlphabet = sortByAlphabet_; + invalidate(); + }); + connect(roomlistmodel, &RoomlistModel::currentRoomChanged, this,