From f443691ad031ae15b145f7c7bdcc0c573b07a529 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 31 Jul 2020 03:40:51 +1000 Subject: [PATCH] Qt: Fix deprecreated errors with 5.15 --- src/duckstation-qt/gamelistwidget.cpp | 90 ++++++++++++++++++++++++-- src/duckstation-qt/qthostinterface.cpp | 5 +- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index 381673b14..623e49317 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -208,6 +208,88 @@ public: return ascending ? (left.title < right.title) : (right.title < left.title); } + bool lessThan(const QModelIndex& left_index, const QModelIndex& right_index, int column, bool ascending) const + { + if (!left_index.isValid() || !right_index.isValid()) + return false; + + const int left_row = left_index.row(); + const int right_row = right_index.row(); + if (left_row < 0 || left_row >= static_cast(m_game_list->GetEntryCount()) || right_row < 0 || + right_row >= static_cast(m_game_list->GetEntryCount())) + { + return false; + } + + const GameListEntry& left = m_game_list->GetEntries()[left_row]; + const GameListEntry& right = m_game_list->GetEntries()[right_row]; + switch (column) + { + case Column_Type: + { + if (left.type == right.type) + return titlesLessThan(left_row, right_row, ascending); + + return ascending ? (static_cast(left.type) < static_cast(right.type)) : + (static_cast(right.type) > static_cast(left.type)); + } + + case Column_Code: + { + if (left.code == right.code) + return titlesLessThan(left_row, right_row, ascending); + return ascending ? (left.code < right.code) : (right.code > left.code); + } + + 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); + } + + case Column_FileTitle: + { + const std::string_view file_title_left(GameList::GetTitleForPath(left.path.c_str())); + const std::string_view file_title_right(GameList::GetTitleForPath(right.path.c_str())); + 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); + } + + case Column_Region: + { + if (left.region == right.region) + return titlesLessThan(left_row, right_row, ascending); + return ascending ? (static_cast(left.region) < static_cast(right.region)) : + (static_cast(right.region) > static_cast(left.region)); + } + + case Column_Compatibility: + { + if (left.compatibility_rating == right.compatibility_rating) + return titlesLessThan(left_row, right_row, ascending); + + return ascending ? + (static_cast(left.compatibility_rating) < static_cast(right.compatibility_rating)) : + (static_cast(right.compatibility_rating) > static_cast(left.compatibility_rating)); + } + + case Column_Size: + { + if (left.total_size == right.total_size) + return titlesLessThan(left_row, right_row, ascending); + + return ascending ? (left.total_size < right.total_size) : (right.total_size > left.total_size); + } + + default: + return false; + } + } + private: void loadCommonImages() { @@ -262,13 +344,7 @@ public: bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override { const bool ascending = sortOrder() == Qt::AscendingOrder; - const QVariant left = source_left.data(Qt::InitialSortOrderRole); - const QVariant right = source_right.data(Qt::InitialSortOrderRole); - if (left != right) - return ascending ? (left < right) : (right > left); - - // fallback to sorting by title for equal items - return m_model->titlesLessThan(source_left.row(), source_right.row(), ascending); + return m_model->lessThan(source_left, source_right, source_left.column(), ascending); } private: diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 1642329fa..b08b2d496 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -796,7 +796,7 @@ void QtHostInterface::changeDisc(const QString& new_disc_filename) static QString FormatTimestampForSaveStateMenu(u64 timestamp) { const QDateTime qtime(QDateTime::fromSecsSinceEpoch(static_cast(timestamp))); - return qtime.toString(Qt::SystemLocaleShortDate); + return qtime.toString(QLocale::system().dateTimeFormat(QLocale::ShortFormat)); } void QtHostInterface::populateSaveStateMenus(const char* game_code, QMenu* load_menu, QMenu* save_menu) @@ -846,6 +846,7 @@ void QtHostInterface::populateGameListContextMenu(const char* game_code, QWidget load_state_menu->setEnabled(false); const std::vector available_states(GetAvailableSaveStates(game_code)); + const QString timestamp_format = QLocale::system().dateTimeFormat(QLocale::ShortFormat); for (const SaveStateInfo& ssi : available_states) { if (ssi.global) @@ -853,7 +854,7 @@ void QtHostInterface::populateGameListContextMenu(const char* game_code, QWidget const s32 slot = ssi.slot; const QDateTime timestamp(QDateTime::fromSecsSinceEpoch(static_cast(ssi.timestamp))); - const QString timestamp_str(timestamp.toString(Qt::SystemLocaleShortDate)); + const QString timestamp_str(timestamp.toString(timestamp_format)); const QString path(QString::fromStdString(ssi.path)); QAction* action;