Skip to content

Commit

Permalink
DolphinQt: Replace unusual Qt::InitialSortOrderRole usage with a cust…
Browse files Browse the repository at this point in the history
…om role.
  • Loading branch information
jordan-woyak committed Jul 17, 2020
1 parent a7e475e commit 8b3e9e6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/GameList/GameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent)
m_model = Settings::Instance().GetGameListModel();
m_list_proxy = new ListProxyModel(this);
m_list_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_list_proxy->setSortRole(Qt::InitialSortOrderRole);
m_list_proxy->setSortRole(GameListModel::SORT_ROLE);
m_list_proxy->setSourceModel(m_model);
m_grid_proxy = new GridProxyModel(this);
m_grid_proxy->setSourceModel(m_model);
Expand Down
28 changes: 14 additions & 14 deletions Source/Core/DolphinQt/GameList/GameListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
case COL_PLATFORM:
if (role == Qt::DecorationRole)
return Resources::GetPlatform(game.GetPlatform());
if (role == Qt::InitialSortOrderRole)
if (role == SORT_ROLE)
return static_cast<int>(game.GetPlatform());
break;
case COL_COUNTRY:
if (role == Qt::DecorationRole)
return Resources::GetCountry(game.GetCountry());
if (role == Qt::InitialSortOrderRole)
if (role == SORT_ROLE)
return static_cast<int>(game.GetCountry());
break;
case COL_BANNER:
Expand All @@ -88,7 +88,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
}
break;
case COL_TITLE:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
QString name = QString::fromStdString(game.GetName(m_title_database));

Expand All @@ -103,7 +103,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
}

// For natural sorting, pad all numbers to the same length.
if (Qt::InitialSortOrderRole == role)
if (SORT_ROLE == role)
{
constexpr int MAX_NUMBER_LENGTH = 10;

Expand All @@ -120,30 +120,30 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
}
break;
case COL_ID:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
return QString::fromStdString(game.GetGameID());
break;
case COL_DESCRIPTION:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
return QString::fromStdString(
game.GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom))
.replace(QLatin1Char('\n'), QLatin1Char(' '));
}
break;
case COL_MAKER:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
return QString::fromStdString(
game.GetMaker(UICommon::GameFile::Variant::LongAndPossiblyCustom));
}
break;
case COL_FILE_NAME:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
return QString::fromStdString(game.GetFileName());
break;
case COL_FILE_PATH:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
QString file_path = QDir::toNativeSeparators(
QFileInfo(QString::fromStdString(game.GetFilePath())).absolutePath());
Expand All @@ -163,11 +163,11 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const

return QString::fromStdString(str);
}
if (role == Qt::InitialSortOrderRole)
if (role == SORT_ROLE)
return static_cast<quint64>(game.GetFileSize());
break;
case COL_FILE_FORMAT:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
if (game.ShouldShowFileFormatDetails())
return QString::fromStdString(DiscIO::GetName(game.GetBlobType(), true));
Expand All @@ -178,18 +178,18 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
case COL_BLOCK_SIZE:
if (role == Qt::DisplayRole)
return QString::fromStdString(UICommon::FormatSize(game.GetBlockSize()));
if (role == Qt::InitialSortOrderRole)
if (role == SORT_ROLE)
return static_cast<quint64>(game.GetBlockSize());
break;
case COL_COMPRESSION:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
const QString compression = QString::fromStdString(game.GetCompressionMethod());
return compression.isEmpty() ? tr("No Compression") : compression;
}
break;
case COL_TAGS:
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
if (role == Qt::DisplayRole || role == SORT_ROLE)
{
auto tags = GetGameTags(game.GetFilePath());
tags.sort();
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/GameList/GameListModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class GameListModel final : public QAbstractTableModel
bool ShouldDisplayGameListItem(int index) const;
void SetSearchTerm(const QString& term);

// Using a custom sort role as it sometimes differs slightly from the default Qt::DisplayRole.
static constexpr int SORT_ROLE = Qt::UserRole;

enum
{
COL_PLATFORM = 0,
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/GameList/ListProxyModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_

bool ListProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
{
if (left.data(Qt::InitialSortOrderRole) != right.data(Qt::InitialSortOrderRole))
if (left.data(GameListModel::SORT_ROLE) != right.data(GameListModel::SORT_ROLE))
return QSortFilterProxyModel::lessThan(left, right);

// If two items are otherwise equal, compare them by their title
Expand Down

0 comments on commit 8b3e9e6

Please sign in to comment.