- Removed unnecessary std::future from game_grid_frame(populate/resize) Thanks SachinVin!

This commit is contained in:
Jonah 2024-03-31 12:24:08 -06:00
parent c5e68ab819
commit 9af38c3309
1 changed files with 4 additions and 18 deletions

View File

@ -54,22 +54,7 @@ void GameGridFrame::PopulateGameGrid(QVector<GameInfo> m_games_search, bool from
if (m_games_.size() % gamesPerRow != 0) { if (m_games_.size() % gamesPerRow != 0) {
rowCount += 1; // Add an extra row for the remainder rowCount += 1; // Add an extra row for the remainder
} }
std::vector<int> indices;
for (int i = 0; i < m_games_.size(); i++) {
indices.push_back(i);
}
std::vector<std::future<QPixmap>> futures;
for (int index : indices) {
futures.push_back(std::async(std::launch::async, [=, this]() {
return m_games_[index].icon.scaled(QSize(icon_size, icon_size), Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
}));
}
std::vector<QPixmap> scaledPixmaps;
for (auto& future : futures) {
scaledPixmaps.push_back(future.get());
}
int column = 0; int column = 0;
this->setColumnCount(gamesPerRow); this->setColumnCount(gamesPerRow);
this->setRowCount(rowCount); this->setRowCount(rowCount);
@ -77,9 +62,10 @@ void GameGridFrame::PopulateGameGrid(QVector<GameInfo> m_games_search, bool from
QWidget* widget = new QWidget(); QWidget* widget = new QWidget();
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout();
QLabel* image_label = new QLabel(); QLabel* image_label = new QLabel();
image_label->setFixedSize(scaledPixmaps[gameCounter].width(), QPixmap icon = m_games_[gameCounter].icon.scaled(
scaledPixmaps[gameCounter].height()); QSize(icon_size, icon_size), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
image_label->setPixmap(scaledPixmaps[gameCounter]); image_label->setFixedSize(icon.width(), icon.height());
image_label->setPixmap(icon);
QLabel* name_label = new QLabel(QString::fromStdString(m_games_[gameCounter].serial)); QLabel* name_label = new QLabel(QString::fromStdString(m_games_[gameCounter].serial));
name_label->setAlignment(Qt::AlignHCenter); name_label->setAlignment(Qt::AlignHCenter);
layout->addWidget(image_label); layout->addWidget(image_label);