fixed sorting on game grid after using search bar

This commit is contained in:
David Antunes 2025-06-17 19:11:10 +01:00
parent b176a61d26
commit dd905a7239
2 changed files with 10 additions and 8 deletions

View File

@ -90,11 +90,13 @@ void GameGridFrame::PopulateGameGrid(QVector<GameInfo> m_games_search, bool from
this->crtColumn = -1; this->crtColumn = -1;
QVector<GameInfo> m_games_; QVector<GameInfo> m_games_;
this->clearContents(); this->clearContents();
SortByFavorite(); if (fromSearch) {
if (fromSearch) SortByFavorite(&m_games_search);
m_games_ = m_games_search; m_games_ = m_games_search;
else } else {
SortByFavorite(&(m_game_info->m_games));
m_games_ = m_game_info->m_games; m_games_ = m_game_info->m_games;
}
m_games_shared = std::make_shared<QVector<GameInfo>>(m_games_); m_games_shared = std::make_shared<QVector<GameInfo>>(m_games_);
icon_size = icon_size =
m_gui_settings->GetValue(gui::gg_icon_size).toInt(); // update icon size for resize event. m_gui_settings->GetValue(gui::gg_icon_size).toInt(); // update icon size for resize event.
@ -251,10 +253,10 @@ void GameGridFrame::SetFavoriteIcon(QWidget* parentWidget, QVector<GameInfo> m_g
label->setObjectName("favoriteIcon"); label->setObjectName("favoriteIcon");
} }
void GameGridFrame::SortByFavorite() { void GameGridFrame::SortByFavorite(QVector<GameInfo>* game_list) {
std::sort( std::sort(game_list->begin(), game_list->end(), [this](const GameInfo& a, const GameInfo& b) {
m_game_info->m_games.begin(), m_game_info->m_games.end(), return this->CompareWithFavorite(a, b);
[this](const GameInfo& a, const GameInfo& b) { return this->CompareWithFavorite(a, b); }); });
} }
bool GameGridFrame::CompareWithFavorite(GameInfo a, GameInfo b) { bool GameGridFrame::CompareWithFavorite(GameInfo a, GameInfo b) {

View File

@ -49,7 +49,7 @@ public:
QWidget* parent = nullptr); QWidget* parent = nullptr);
void PopulateGameGrid(QVector<GameInfo> m_games, bool fromSearch); void PopulateGameGrid(QVector<GameInfo> m_games, bool fromSearch);
bool IsValidCellSelected(); bool IsValidCellSelected();
void SortByFavorite(); void SortByFavorite(QVector<GameInfo>* game_list);
bool cellClicked = false; bool cellClicked = false;
int icon_size; int icon_size;