Qt: enable hiding on game list and optimize the game list filter

This commit is contained in:
Megamouse 2018-03-20 02:10:44 +01:00 committed by Ivan
parent 17d2124a71
commit 5492e0eae1
5 changed files with 105 additions and 59 deletions

View file

@ -33,6 +33,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
m_Icon_Color = xgui_settings->GetValue(gui::gl_iconColor).value<QColor>();
m_colSortOrder = xgui_settings->GetValue(gui::gl_sortAsc).toBool() ? Qt::AscendingOrder : Qt::DescendingOrder;
m_sortColumn = xgui_settings->GetValue(gui::gl_sortCol).toInt();
m_hidden_list = xgui_settings->GetValue(gui::gl_hidden_list).toStringList().toSet();
m_oldLayoutIsList = m_isListLayout;
@ -251,23 +252,17 @@ void game_list_frame::OnColClicked(int col)
SortGameList();
}
// Filter for Categories
void game_list_frame::FilterData()
// Get visibility of entries
bool game_list_frame::IsEntryVisible(const GUI_GameInfo& game)
{
for (auto& game : m_game_data)
auto matches_category = [&]()
{
bool match = false;
const QString category = qstr(game.info.category);
for (const auto& filter : m_categoryFilters)
{
if (category.contains(filter))
{
match = true;
break;
}
}
game.isVisible = match && SearchMatchesApp(game.info.name, game.info.serial);
}
if (m_isListLayout)
return m_categoryFilters.contains(qstr(game.info.category));
return category::CategoryInMap(game.info.category, category::cat_boot);
};
bool is_visible = m_show_hidden || !m_hidden_list.contains(qstr(game.info.serial));
return is_visible && matches_category() && SearchMatchesApp(game.info.name, game.info.serial);
}
void game_list_frame::SortGameList()
@ -314,6 +309,8 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
// Used to remove duplications from the list (serial -> set of cats)
std::map<std::string, std::set<std::string>> serial_cat;
QSet<QString> serials;
for (const auto& dir : path_list) { try
{
const std::string sfb = dir + "/PS3_DISC.SFB";
@ -344,6 +341,8 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
continue;
}
serials.insert(qstr(game.serial));
bool bootable = false;
auto cat = category::cat_boot.find(game.category);
if (cat != category::cat_boot.end())
@ -387,7 +386,7 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
QPixmap pxmap = PaintedPixmap(img, hasCustomConfig);
m_game_data.push_back({ game, m_game_compat->GetCompatibility(game.serial), img, pxmap, true, bootable, hasCustomConfig });
m_game_data.push_back({ game, m_game_compat->GetCompatibility(game.serial), img, pxmap, bootable, hasCustomConfig });
}
catch (const std::exception& e)
{
@ -403,6 +402,10 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
// Sort by name at the very least.
std::sort(m_game_data.begin(), m_game_data.end(), op);
// clean up hidden games list
m_hidden_list.intersect(serials);
xgui_settings->SetValue(gui::gl_hidden_list, QStringList(m_hidden_list.toList()));
}
// Fill Game List / Game Grid
@ -410,7 +413,6 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
if (m_isListLayout)
{
int scroll_position = m_gameList->verticalScrollBar()->value();
FilterData();
int row = PopulateGameList();
m_gameList->selectRow(row);
SortGameList();
@ -538,6 +540,7 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
}
GameInfo currGame = m_game_data[row].info;
const QString serial = qstr(currGame.serial);
// Make Actions
QMenu myMenu;
@ -547,6 +550,10 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
boot->setFont(f);
QAction* configure = myMenu.addAction(tr("&Configure"));
myMenu.addSeparator();
QAction* hide_serial = myMenu.addAction(tr("&Hide From Game List"));
hide_serial->setCheckable(true);
hide_serial->setChecked(m_hidden_list.contains(serial));
myMenu.addSeparator();
QAction* removeGame = myMenu.addAction(tr("&Remove %1").arg(qstr(currGame.category)));
QAction* removeConfig = myMenu.addAction(tr("&Remove Custom Configuration"));
QAction* deleteShadersCache = myMenu.addAction(tr("&Delete Shaders Cache"));
@ -574,6 +581,16 @@ void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row)
});
dlg.exec();
});
connect(hide_serial, &QAction::triggered, [=](bool checked)
{
if (checked)
m_hidden_list.insert(serial);
else
m_hidden_list.remove(serial);
xgui_settings->SetValue(gui::gl_hidden_list, QStringList(m_hidden_list.toList()));
Refresh();
});
connect(removeGame, &QAction::triggered, [=]
{
QMessageBox* mb = new QMessageBox(QMessageBox::Question, tr("Confirm %1 Removal").arg(qstr(currGame.category)), tr("Permanently remove %1 from drive?").arg(qstr(currGame.name)), QMessageBox::Yes | QMessageBox::No, this);
@ -785,6 +802,11 @@ void game_list_frame::RepaintIcons(const bool& fromSettings)
Refresh();
}
void game_list_frame::SetShowHidden(bool show)
{
m_show_hidden = show;
}
void game_list_frame::SetListMode(const bool& isList)
{
m_oldLayoutIsList = m_isListLayout;
@ -882,10 +904,8 @@ int game_list_frame::PopulateGameList()
{
index++;
if (!game.isVisible)
{
if (!IsEntryVisible(game))
continue;
}
// Icon
QTableWidgetItem* icon_item = new QTableWidgetItem;
@ -959,7 +979,7 @@ void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, con
for (uint i = 0; i < m_game_data.size(); i++)
{
if (category::CategoryInMap(m_game_data[i].info.category, category::cat_boot) && SearchMatchesApp(m_game_data[i].info.name, m_game_data[i].info.serial))
if (IsEntryVisible(m_game_data[i]))
{
matching_apps.append(QPair<GUI_GameInfo*, int>(&m_game_data[i], i));
}