From 7286dbab51f6e3bfa50ec74e700b50dd61375603 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 6 Sep 2020 17:55:08 +1000 Subject: [PATCH] Qt: Fix sorting game list by title being case sensitive --- src/duckstation-qt/gamelistmodel.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/duckstation-qt/gamelistmodel.cpp b/src/duckstation-qt/gamelistmodel.cpp index 7946dbeba..62dc163ba 100644 --- a/src/duckstation-qt/gamelistmodel.cpp +++ b/src/duckstation-qt/gamelistmodel.cpp @@ -188,7 +188,8 @@ bool GameListModel::titlesLessThan(int left_row, int right_row, bool ascending) const GameListEntry& left = m_game_list->GetEntries().at(left_row); const GameListEntry& right = m_game_list->GetEntries().at(right_row); - return ascending ? (left.title < right.title) : (right.title < left.title); + return ascending ? (StringUtil::Strcasecmp(left.title.c_str(), right.title.c_str()) < 0) : + (StringUtil::Strcasecmp(right.title.c_str(), left.title.c_str()) > 0); } bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& right_index, int column, @@ -222,15 +223,13 @@ bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& r { if (left.code == right.code) return titlesLessThan(left_row, right_row, ascending); - return ascending ? (left.code < right.code) : (right.code > left.code); + return ascending ? (StringUtil::Strcasecmp(left.code.c_str(), right.code.c_str()) < 0) : + (StringUtil::Strcasecmp(right.code.c_str(), left.code.c_str()) > 0); } case Column_Title: { - if (left.title == right.title) - return titlesLessThan(left_row, right_row, ascending); - - return ascending ? (left.title < right.title) : (right.title > left.title); + return titlesLessThan(left_row, right_row, ascending); } case Column_FileTitle: @@ -240,7 +239,9 @@ bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& r if (file_title_left == file_title_right) return titlesLessThan(left_row, right_row, ascending); - return ascending ? (file_title_left < file_title_right) : (file_title_right > file_title_left); + const std::size_t smallest = std::min(file_title_left.size(), file_title_right.size()); + return ascending ? (StringUtil::Strncasecmp(file_title_left.data(), file_title_right.data(), smallest) < 0) : + (StringUtil::Strncasecmp(file_title_right.data(), file_title_left.data(), smallest) > 0); } case Column_Region: