GameListModel: provide Qt::InitialSortOrderRole for sorting

Fixes regression where pixmap columns can't be sorted by default.
This commit is contained in:
Michael Maltese 2017-05-27 18:59:19 -07:00
parent 8bbc31e0a2
commit 1a7210aa74
2 changed files with 13 additions and 4 deletions

View File

@ -31,6 +31,7 @@ GameList::GameList(QWidget* parent) : QStackedWidget(parent)
m_model = new GameListModel(this); m_model = new GameListModel(this);
m_table_proxy = new QSortFilterProxyModel(this); m_table_proxy = new QSortFilterProxyModel(this);
m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); m_table_proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
m_table_proxy->setSortRole(Qt::InitialSortOrderRole);
m_table_proxy->setSourceModel(m_model); m_table_proxy->setSourceModel(m_model);
m_list_proxy = new ListProxyModel(this); m_list_proxy = new ListProxyModel(this);
m_list_proxy->setSourceModel(m_model); m_list_proxy->setSourceModel(m_model);

View File

@ -27,14 +27,20 @@ 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(static_cast<int>(game->GetPlatformID())); return Resources::GetPlatform(static_cast<int>(game->GetPlatformID()));
if (role == Qt::InitialSortOrderRole)
return static_cast<int>(game->GetPlatformID());
break; break;
case COL_COUNTRY: case COL_COUNTRY:
if (role == Qt::DecorationRole) if (role == Qt::DecorationRole)
return Resources::GetCountry(static_cast<int>(game->GetCountryID())); return Resources::GetCountry(static_cast<int>(game->GetCountryID()));
if (role == Qt::InitialSortOrderRole)
return static_cast<int>(game->GetCountryID());
break; break;
case COL_RATING: case COL_RATING:
if (role == Qt::DecorationRole) if (role == Qt::DecorationRole)
return Resources::GetRating(game->GetRating()); return Resources::GetRating(game->GetRating());
if (role == Qt::InitialSortOrderRole)
return game->GetRating();
break; break;
case COL_BANNER: case COL_BANNER:
if (role == Qt::DecorationRole) if (role == Qt::DecorationRole)
@ -48,24 +54,26 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
} }
break; break;
case COL_TITLE: case COL_TITLE:
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return game->GetLongName(); return game->GetLongName();
break; break;
case COL_ID: case COL_ID:
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return game->GetGameID(); return game->GetGameID();
break; break;
case COL_DESCRIPTION: case COL_DESCRIPTION:
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return game->GetDescription(); return game->GetDescription();
break; break;
case COL_MAKER: case COL_MAKER:
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole || role == Qt::InitialSortOrderRole)
return game->GetMaker(); return game->GetMaker();
break; break;
case COL_SIZE: case COL_SIZE:
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return FormatSize(game->GetFileSize()); return FormatSize(game->GetFileSize());
if (role == Qt::InitialSortOrderRole)
return game->GetFileSize();
break; break;
} }