DolphinQt: Replace unusual Qt::InitialSortOrderRole usage with a custom role.
This commit is contained in:
parent
a7e475e57b
commit
8b3e9e6a81
|
@ -59,7 +59,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent)
|
||||||
m_model = Settings::Instance().GetGameListModel();
|
m_model = Settings::Instance().GetGameListModel();
|
||||||
m_list_proxy = new ListProxyModel(this);
|
m_list_proxy = new ListProxyModel(this);
|
||||||
m_list_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
|
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_list_proxy->setSourceModel(m_model);
|
||||||
m_grid_proxy = new GridProxyModel(this);
|
m_grid_proxy = new GridProxyModel(this);
|
||||||
m_grid_proxy->setSourceModel(m_model);
|
m_grid_proxy->setSourceModel(m_model);
|
||||||
|
|
|
@ -63,13 +63,13 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
case COL_PLATFORM:
|
case COL_PLATFORM:
|
||||||
if (role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole)
|
||||||
return Resources::GetPlatform(game.GetPlatform());
|
return Resources::GetPlatform(game.GetPlatform());
|
||||||
if (role == Qt::InitialSortOrderRole)
|
if (role == SORT_ROLE)
|
||||||
return static_cast<int>(game.GetPlatform());
|
return static_cast<int>(game.GetPlatform());
|
||||||
break;
|
break;
|
||||||
case COL_COUNTRY:
|
case COL_COUNTRY:
|
||||||
if (role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole)
|
||||||
return Resources::GetCountry(game.GetCountry());
|
return Resources::GetCountry(game.GetCountry());
|
||||||
if (role == Qt::InitialSortOrderRole)
|
if (role == SORT_ROLE)
|
||||||
return static_cast<int>(game.GetCountry());
|
return static_cast<int>(game.GetCountry());
|
||||||
break;
|
break;
|
||||||
case COL_BANNER:
|
case COL_BANNER:
|
||||||
|
@ -88,7 +88,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COL_TITLE:
|
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));
|
QString name = QString::fromStdString(game.GetName(m_title_database));
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// For natural sorting, pad all numbers to the same length.
|
// For natural sorting, pad all numbers to the same length.
|
||||||
if (Qt::InitialSortOrderRole == role)
|
if (SORT_ROLE == role)
|
||||||
{
|
{
|
||||||
constexpr int MAX_NUMBER_LENGTH = 10;
|
constexpr int MAX_NUMBER_LENGTH = 10;
|
||||||
|
|
||||||
|
@ -120,11 +120,11 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COL_ID:
|
case COL_ID:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
return QString::fromStdString(game.GetGameID());
|
return QString::fromStdString(game.GetGameID());
|
||||||
break;
|
break;
|
||||||
case COL_DESCRIPTION:
|
case COL_DESCRIPTION:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
{
|
{
|
||||||
return QString::fromStdString(
|
return QString::fromStdString(
|
||||||
game.GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom))
|
game.GetDescription(UICommon::GameFile::Variant::LongAndPossiblyCustom))
|
||||||
|
@ -132,18 +132,18 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COL_MAKER:
|
case COL_MAKER:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
{
|
{
|
||||||
return QString::fromStdString(
|
return QString::fromStdString(
|
||||||
game.GetMaker(UICommon::GameFile::Variant::LongAndPossiblyCustom));
|
game.GetMaker(UICommon::GameFile::Variant::LongAndPossiblyCustom));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COL_FILE_NAME:
|
case COL_FILE_NAME:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
return QString::fromStdString(game.GetFileName());
|
return QString::fromStdString(game.GetFileName());
|
||||||
break;
|
break;
|
||||||
case COL_FILE_PATH:
|
case COL_FILE_PATH:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
{
|
{
|
||||||
QString file_path = QDir::toNativeSeparators(
|
QString file_path = QDir::toNativeSeparators(
|
||||||
QFileInfo(QString::fromStdString(game.GetFilePath())).absolutePath());
|
QFileInfo(QString::fromStdString(game.GetFilePath())).absolutePath());
|
||||||
|
@ -163,11 +163,11 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
return QString::fromStdString(str);
|
return QString::fromStdString(str);
|
||||||
}
|
}
|
||||||
if (role == Qt::InitialSortOrderRole)
|
if (role == SORT_ROLE)
|
||||||
return static_cast<quint64>(game.GetFileSize());
|
return static_cast<quint64>(game.GetFileSize());
|
||||||
break;
|
break;
|
||||||
case COL_FILE_FORMAT:
|
case COL_FILE_FORMAT:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
{
|
{
|
||||||
if (game.ShouldShowFileFormatDetails())
|
if (game.ShouldShowFileFormatDetails())
|
||||||
return QString::fromStdString(DiscIO::GetName(game.GetBlobType(), true));
|
return QString::fromStdString(DiscIO::GetName(game.GetBlobType(), true));
|
||||||
|
@ -178,18 +178,18 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||||
case COL_BLOCK_SIZE:
|
case COL_BLOCK_SIZE:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
return QString::fromStdString(UICommon::FormatSize(game.GetBlockSize()));
|
return QString::fromStdString(UICommon::FormatSize(game.GetBlockSize()));
|
||||||
if (role == Qt::InitialSortOrderRole)
|
if (role == SORT_ROLE)
|
||||||
return static_cast<quint64>(game.GetBlockSize());
|
return static_cast<quint64>(game.GetBlockSize());
|
||||||
break;
|
break;
|
||||||
case COL_COMPRESSION:
|
case COL_COMPRESSION:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
{
|
{
|
||||||
const QString compression = QString::fromStdString(game.GetCompressionMethod());
|
const QString compression = QString::fromStdString(game.GetCompressionMethod());
|
||||||
return compression.isEmpty() ? tr("No Compression") : compression;
|
return compression.isEmpty() ? tr("No Compression") : compression;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COL_TAGS:
|
case COL_TAGS:
|
||||||
if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
|
if (role == Qt::DisplayRole || role == SORT_ROLE)
|
||||||
{
|
{
|
||||||
auto tags = GetGameTags(game.GetFilePath());
|
auto tags = GetGameTags(game.GetFilePath());
|
||||||
tags.sort();
|
tags.sort();
|
||||||
|
|
|
@ -44,6 +44,9 @@ public:
|
||||||
bool ShouldDisplayGameListItem(int index) const;
|
bool ShouldDisplayGameListItem(int index) const;
|
||||||
void SetSearchTerm(const QString& term);
|
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
|
enum
|
||||||
{
|
{
|
||||||
COL_PLATFORM = 0,
|
COL_PLATFORM = 0,
|
||||||
|
|
|
@ -18,7 +18,7 @@ bool ListProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_
|
||||||
|
|
||||||
bool ListProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
|
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);
|
return QSortFilterProxyModel::lessThan(left, right);
|
||||||
|
|
||||||
// If two items are otherwise equal, compare them by their title
|
// If two items are otherwise equal, compare them by their title
|
||||||
|
|
Loading…
Reference in New Issue