From 97b74ef56ae3f9ff3215477eb8b0cf0f2a19ef25 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Fri, 6 Apr 2018 15:08:59 +0200 Subject: [PATCH] NOISSUE Fixed code for PR --- application/FtbListModel.cpp | 19 ++++++------------- application/FtbListModel.h | 7 +++---- application/pages/modplatform/FTBPage.cpp | 3 +++ application/pages/modplatform/FTBPage.h | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/application/FtbListModel.cpp b/application/FtbListModel.cpp index 41e49b65..7bf0a601 100644 --- a/application/FtbListModel.cpp +++ b/application/FtbListModel.cpp @@ -64,14 +64,10 @@ FtbFilterModel::Sorting FtbFilterModel::getCurrentSorting() FtbListModel::FtbListModel(QObject *parent) : QAbstractListModel(parent) { - m_logoPool = new QThreadPool(this); - m_logoPool->setMaxThreadCount(4); } FtbListModel::~FtbListModel() { - m_logoPool->waitForDone(500); - m_logoPool->deleteLater(); } QString FtbListModel::translatePackType(FtbPackType type) const @@ -100,7 +96,7 @@ int FtbListModel::columnCount(const QModelIndex &parent) const QVariant FtbListModel::data(const QModelIndex &index, int role) const { int pos = index.row(); - if(modpacks.size() <= pos || pos < 0 || !index.isValid()) { + if(pos >= modpacks.size() || pos < 0 || !index.isValid()) { return QString("INVALID INDEX %1").arg(pos); } @@ -120,9 +116,9 @@ QVariant FtbListModel::data(const QModelIndex &index, int role) const if(m_logoMap.contains(pack.logo)) { return (m_logoMap.value(pack.logo)); } - QPixmap pixmap = MMC->getThemedIcon("screenshot-placeholder").pixmap(QSize(42, 42)); + QIcon icon = MMC->getThemedIcon("screenshot-placeholder"); ((FtbListModel *)this)->requestLogo(pack.logo); - return pixmap; + return icon; } else if(role == Qt::TextColorRole) { if(pack.broken) { //FIXME: Hardcoded color @@ -153,11 +149,11 @@ FtbModpack FtbListModel::at(int row) return modpacks.at(row); } -void FtbListModel::logoLoaded(QString logo, QPixmap out) +void FtbListModel::logoLoaded(QString logo, QIcon out) { m_loadingLogos.removeAll(logo); m_logoMap.insert(logo, out); - emit dataChanged(createIndex(0, 0), createIndex(modpacks.size(), 0)); + emit dataChanged(createIndex(0, 0), createIndex(1, 0)); } void FtbListModel::logoFailed(QString logo) @@ -178,10 +174,7 @@ void FtbListModel::requestLogo(QString file) auto fullPath = entry->getFullPath(); QObject::connect(job, &NetJob::finished, this, [this, file, fullPath]{ - QPixmap pixmap; - pixmap.load(fullPath); - pixmap = pixmap.scaled(QSize(42, 42)); - emit logoLoaded(file, pixmap); + emit logoLoaded(file, QIcon(fullPath)); }); QObject::connect(job, &NetJob::failed, this, [this, file]{ diff --git a/application/FtbListModel.h b/application/FtbListModel.h index 747c65bd..12b26be1 100644 --- a/application/FtbListModel.h +++ b/application/FtbListModel.h @@ -7,9 +7,9 @@ #include -#include +#include -typedef QMap FtbLogoMap; +typedef QMap FtbLogoMap; class FtbFilterModel : public QSortFilterProxyModel { @@ -39,7 +39,6 @@ class FtbListModel : public QAbstractListModel Q_OBJECT private: FtbModpackList modpacks; - QThreadPool *m_logoPool; QStringList m_failedLogos; QStringList m_loadingLogos; FtbLogoMap m_logoMap; @@ -50,7 +49,7 @@ private: private slots: void logoFailed(QString logo); - void logoLoaded(QString logo, QPixmap out); + void logoLoaded(QString logo, QIcon out); public: FtbListModel(QObject *parent); diff --git a/application/pages/modplatform/FTBPage.cpp b/application/pages/modplatform/FTBPage.cpp index 8c8d8a7d..2cc8c4fd 100644 --- a/application/pages/modplatform/FTBPage.cpp +++ b/application/pages/modplatform/FTBPage.cpp @@ -26,6 +26,7 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) ui->publicPackList->setSortingEnabled(true); ui->publicPackList->header()->hide(); ui->publicPackList->setIndentation(0); + ui->publicPackList->setIconSize(QSize(42, 42)); for(int i = 0; i < publicFilterModel->getAvailableSortings().size(); i++) { @@ -44,6 +45,8 @@ FTBPage::FTBPage(NewInstanceDialog* dialog, QWidget *parent) ui->thirdPartyPackList->setSortingEnabled(true); ui->thirdPartyPackList->header()->hide(); ui->thirdPartyPackList->setIndentation(0); + ui->thirdPartyPackList->setIconSize(QSize(42, 42)); + thirdPartyFilterModel->setSorting(publicFilterModel->getCurrentSorting()); } diff --git a/application/pages/modplatform/FTBPage.h b/application/pages/modplatform/FTBPage.h index 413f5e28..a5327d31 100644 --- a/application/pages/modplatform/FTBPage.h +++ b/application/pages/modplatform/FTBPage.h @@ -89,7 +89,7 @@ private: FtbListModel *thirdPartyModel = nullptr; FtbFilterModel *thirdPartyFilterModel = nullptr; - FtbPackFetchTask *ftbFetchTask; + FtbPackFetchTask *ftbFetchTask = nullptr; NewInstanceDialog* dialog = nullptr; Ui::FTBPage *ui = nullptr;