From 476dcb1915be79481d045478b9f17985accb7915 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Fri, 27 Sep 2019 22:15:20 -0300 Subject: [PATCH 1/3] Use the displayed text for sorting GameListItemPath. By default, DisplayRole is used as the SortRole. This behaviour is what's expected by the user. Made it so that an access to SortRole is equivalent to one to DisplayRole. Also fixes a bug with directory sorting. --- src/citra_qt/game_list.cpp | 2 +- src/citra_qt/game_list_p.h | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 933077a7e9..1069db22ba 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -294,7 +294,7 @@ GameList::GameList(GMainWindow* parent) : QWidget{parent} { item_model->setHeaderData(COLUMN_REGION, Qt::Horizontal, tr("Region")); item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, tr("File type")); item_model->setHeaderData(COLUMN_SIZE, Qt::Horizontal, tr("Size")); - item_model->setSortRole(GameListItemPath::TitleRole); + item_model->setSortRole(GameListItemPath::SortRole); connect(main_window, &GMainWindow::UpdateThemedIcons, this, &GameList::onUpdateThemedIcons); connect(tree_view, &QTreeView::activated, this, &GameList::ValidateEntry); diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index fb64c34c0c..94b7680c69 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h @@ -146,11 +146,11 @@ static const std::unordered_map IconSizes{ */ class GameListItemPath : public GameListItem { public: - static const int TitleRole = SortRole; - static const int FullPathRole = SortRole + 1; - static const int ProgramIdRole = SortRole + 2; - static const int ExtdataIdRole = SortRole + 3; - static const int LongTitleRole = SortRole + 4; + static const int TitleRole = SortRole + 1; + static const int FullPathRole = SortRole + 2; + static const int ProgramIdRole = SortRole + 3; + static const int ExtdataIdRole = SortRole + 4; + static const int LongTitleRole = SortRole + 5; GameListItemPath() = default; GameListItemPath(const QString& game_path, const std::vector& smdh_data, u64 program_id, @@ -196,7 +196,7 @@ public: } QVariant data(int role) const override { - if (role == Qt::DisplayRole) { + if (role == Qt::DisplayRole || role == SortRole) { std::string path, filename, extension; Common::SplitPath(data(FullPathRole).toString().toStdString(), &path, &filename, &extension); @@ -374,6 +374,13 @@ public: return static_cast(dir_type); } + /** + * Override to prevent automatic sorting. + */ + bool operator<(const QStandardItem& other) const override { + return false; + } + private: GameListItemType dir_type; }; @@ -391,6 +398,10 @@ public: int type() const override { return static_cast(GameListItemType::AddDir); } + + bool operator<(const QStandardItem& other) const override { + return false; + } }; class GameList; From eb7527254fdc03271f5520ce74eaecb54fdff485 Mon Sep 17 00:00:00 2001 From: vitor-k Date: Sat, 28 Sep 2019 15:57:26 -0300 Subject: [PATCH 2/3] Sort game items after the list is populated --- src/citra_qt/game_list.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp index 1069db22ba..d5fb8ee554 100644 --- a/src/citra_qt/game_list.cpp +++ b/src/citra_qt/game_list.cpp @@ -417,6 +417,8 @@ void GameList::DonePopulating(QStringList watch_list) { if (children_total > 0) { search_field->setFocus(); } + item_model->sort(tree_view->header()->sortIndicatorSection(), + tree_view->header()->sortIndicatorOrder()); emit PopulatingCompleted(); } @@ -641,8 +643,6 @@ void GameList::LoadInterfaceLayout() { // so make it as large as possible as default. header->resizeSection(COLUMN_NAME, header->width()); } - - item_model->sort(header->sortIndicatorSection(), header->sortIndicatorOrder()); } const QStringList GameList::supported_file_extensions = {"3ds", "3dsx", "elf", "axf", From cc9bcf3e4892346790fa6db3f0e59f00770f4d5d Mon Sep 17 00:00:00 2001 From: vitor-k Date: Fri, 25 Oct 2019 18:49:13 -0300 Subject: [PATCH 3/3] fix uppercase sorting --- src/citra_qt/game_list_p.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index 94b7680c69..044c87a1e1 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h @@ -212,6 +212,9 @@ public: const QString& row1 = display_texts.at(UISettings::values.game_list_row_1).simplified(); + if (role == SortRole) + return row1.toLower(); + QString row2; auto row_2_id = UISettings::values.game_list_row_2; if (row_2_id != UISettings::GameListText::NoText) {