From 175132539b14be2681bfbaf3f380f0a9b8a69a26 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sat, 16 Oct 2021 23:31:27 +0100 Subject: [PATCH 1/3] NOISSUE Filter all pack's by name to search for modpacks.ch modpacks.ch searching has changed, and while likely a bug - we may as well make this change while we fetch all packs anyway. This makes MMC more reactive for searchs for the platform. This should be reverted if/when the modpacks.ch hits a size where we need to restrict how many packs are fetched. --- .../pages/modplatform/ftb/FtbFilterModel.cpp | 14 +++++- .../pages/modplatform/ftb/FtbFilterModel.h | 2 + .../pages/modplatform/ftb/FtbListModel.cpp | 47 +++++-------------- launcher/pages/modplatform/ftb/FtbListModel.h | 16 ++----- launcher/pages/modplatform/ftb/FtbPage.cpp | 9 +++- launcher/pages/modplatform/ftb/FtbPage.h | 2 + 6 files changed, 39 insertions(+), 51 deletions(-) diff --git a/launcher/pages/modplatform/ftb/FtbFilterModel.cpp b/launcher/pages/modplatform/ftb/FtbFilterModel.cpp index dec3a017..793b8769 100644 --- a/launcher/pages/modplatform/ftb/FtbFilterModel.cpp +++ b/launcher/pages/modplatform/ftb/FtbFilterModel.cpp @@ -36,9 +36,21 @@ FilterModel::Sorting FilterModel::getCurrentSorting() return currentSorting; } +void FilterModel::setSearchTerm(const QString& term) +{ + searchTerm = term.trimmed(); + invalidate(); +} + bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - return true; + if (searchTerm.isEmpty()) { + return true; + } + + auto index = sourceModel()->index(sourceRow, 0, sourceParent); + auto pack = sourceModel()->data(index, Qt::UserRole).value(); + return pack.name.contains(searchTerm, Qt::CaseInsensitive); } bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const diff --git a/launcher/pages/modplatform/ftb/FtbFilterModel.h b/launcher/pages/modplatform/ftb/FtbFilterModel.h index 4fe2a274..2e712c7d 100644 --- a/launcher/pages/modplatform/ftb/FtbFilterModel.h +++ b/launcher/pages/modplatform/ftb/FtbFilterModel.h @@ -19,6 +19,7 @@ public: QString translateCurrentSorting(); void setSorting(Sorting sorting); Sorting getCurrentSorting(); + void setSearchTerm(const QString& term); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -27,6 +28,7 @@ protected: private: QMap sortings; Sorting currentSorting; + QString searchTerm { "" }; }; diff --git a/launcher/pages/modplatform/ftb/FtbListModel.cpp b/launcher/pages/modplatform/ftb/FtbListModel.cpp index 98973f2e..f5ed106b 100644 --- a/launcher/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/pages/modplatform/ftb/FtbListModel.cpp @@ -74,24 +74,6 @@ QVariant ListModel::data(const QModelIndex &index, int role) const return QVariant(); } -void ListModel::performSearch() -{ - auto *netJob = new NetJob("Ftb::Search"); - QString searchUrl; - if(currentSearchTerm.isEmpty()) { - searchUrl = BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"; - } - else { - searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/search/25?term=%1") - .arg(currentSearchTerm); - } - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); - jobPtr = netJob; - jobPtr->start(); - QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::searchRequestFinished); - QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed); -} - void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback) { if(m_logoMap.contains(logo)) @@ -104,28 +86,23 @@ void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallbac } } -void ListModel::searchWithTerm(const QString &term) +void ListModel::request() { - if(searchState != Failed && currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull()) { - // unless the search has failed, then there is no need to perform an identical search. - return; - } - currentSearchTerm = term; - - if(jobPtr) { - jobPtr->abort(); - jobPtr.reset(); - } - beginResetModel(); modpacks.clear(); endResetModel(); - searchState = None; - performSearch(); + auto *netJob = new NetJob("Ftb::Request"); + auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); + jobPtr = netJob; + jobPtr->start(); + + QObject::connect(netJob, &NetJob::succeeded, this, &ListModel::requestFinished); + QObject::connect(netJob, &NetJob::failed, this, &ListModel::requestFailed); } -void ListModel::searchRequestFinished() +void ListModel::requestFinished() { jobPtr.reset(); remainingPacks.clear(); @@ -150,12 +127,10 @@ void ListModel::searchRequestFinished() } } -void ListModel::searchRequestFailed(QString reason) +void ListModel::requestFailed(QString reason) { jobPtr.reset(); remainingPacks.clear(); - - searchState = Failed; } void ListModel::requestPack() diff --git a/launcher/pages/modplatform/ftb/FtbListModel.h b/launcher/pages/modplatform/ftb/FtbListModel.h index de94e6ba..2d6e91da 100644 --- a/launcher/pages/modplatform/ftb/FtbListModel.h +++ b/launcher/pages/modplatform/ftb/FtbListModel.h @@ -30,13 +30,13 @@ public: int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; + void request(); + void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback); - void searchWithTerm(const QString & term); private slots: - void performSearch(); - void searchRequestFinished(); - void searchRequestFailed(QString reason); + void requestFinished(); + void requestFailed(QString reason); void requestPack(); void packRequestFinished(); @@ -52,14 +52,6 @@ private: QList modpacks; LogoMap m_logoMap; - QString currentSearchTerm; - enum SearchState { - None, - CanPossiblyFetchMore, - ResetRequested, - Finished, - Failed, - } searchState = None; NetJobPtr jobPtr; int currentPack; QList remainingPacks; diff --git a/launcher/pages/modplatform/ftb/FtbPage.cpp b/launcher/pages/modplatform/ftb/FtbPage.cpp index b7f35c5d..5917b979 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.cpp +++ b/launcher/pages/modplatform/ftb/FtbPage.cpp @@ -63,7 +63,12 @@ bool FtbPage::shouldDisplay() const void FtbPage::openedImpl() { - triggerSearch(); + if(!initialised) + { + listModel->request(); + initialised = true; + } + suggestCurrent(); } @@ -96,7 +101,7 @@ void FtbPage::suggestCurrent() void FtbPage::triggerSearch() { - listModel->searchWithTerm(ui->searchEdit->text()); + filterModel->setSearchTerm(ui->searchEdit->text()); } void FtbPage::onSortingSelectionChanged(QString data) diff --git a/launcher/pages/modplatform/ftb/FtbPage.h b/launcher/pages/modplatform/ftb/FtbPage.h index c9c93897..bca09e25 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.h +++ b/launcher/pages/modplatform/ftb/FtbPage.h @@ -77,4 +77,6 @@ private: ModpacksCH::Modpack selected; QString selectedVersion; + + bool initialised { false }; }; From 1869dd0de3bf490abb0fe789236dd6f6909ecf8d Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sat, 16 Oct 2021 23:36:31 +0100 Subject: [PATCH 2/3] NOISSUE Search as you type for modpacks.ch Since we just filter data locally now, this isn't painfully slow - indeed it's very quick. This also matches other platforms, such as ATLauncher. --- launcher/pages/modplatform/ftb/FtbPage.cpp | 8 +++++++- launcher/pages/modplatform/ftb/FtbPage.h | 2 ++ launcher/pages/modplatform/ftb/FtbPage.ui | 12 ++++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/launcher/pages/modplatform/ftb/FtbPage.cpp b/launcher/pages/modplatform/ftb/FtbPage.cpp index 5917b979..aca93cfe 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.cpp +++ b/launcher/pages/modplatform/ftb/FtbPage.cpp @@ -32,7 +32,8 @@ FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent) } ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); - connect(ui->searchButton, &QPushButton::clicked, this, &FtbPage::triggerSearch); + connect(ui->searchEdit, &QLineEdit::textChanged, this, &FtbPage::triggerSearch); + connect(ui->resetButton, &QPushButton::clicked, this, &FtbPage::resetSearch); connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FtbPage::onSortingSelectionChanged); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FtbPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FtbPage::onVersionSelectionChanged); @@ -104,6 +105,11 @@ void FtbPage::triggerSearch() filterModel->setSearchTerm(ui->searchEdit->text()); } +void FtbPage::resetSearch() +{ + ui->searchEdit->setText(""); +} + void FtbPage::onSortingSelectionChanged(QString data) { auto toSet = filterModel->getAvailableSortings().value(data); diff --git a/launcher/pages/modplatform/ftb/FtbPage.h b/launcher/pages/modplatform/ftb/FtbPage.h index bca09e25..0dfac1a4 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.h +++ b/launcher/pages/modplatform/ftb/FtbPage.h @@ -65,6 +65,8 @@ private: private slots: void triggerSearch(); + void resetSearch(); + void onSortingSelectionChanged(QString data); void onSelectionChanged(QModelIndex first, QModelIndex second); void onVersionSelectionChanged(QString data); diff --git a/launcher/pages/modplatform/ftb/FtbPage.ui b/launcher/pages/modplatform/ftb/FtbPage.ui index 135afc6d..dc800497 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.ui +++ b/launcher/pages/modplatform/ftb/FtbPage.ui @@ -39,9 +39,9 @@ - + - Search + Reset @@ -49,15 +49,15 @@ + + true + 48 48 - - true - @@ -76,7 +76,7 @@ searchEdit - searchButton + resetButton versionSelectionBox From b93997501d3c18832d0511abaf1514e73494bf56 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sun, 17 Oct 2021 20:14:16 +0100 Subject: [PATCH 3/3] NOISSUE Use Qt's clear button for modpacks.ch page This replaces our 'Reset' button. --- launcher/pages/modplatform/ftb/FtbPage.cpp | 6 ------ launcher/pages/modplatform/ftb/FtbPage.h | 1 - launcher/pages/modplatform/ftb/FtbPage.ui | 9 ++------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/launcher/pages/modplatform/ftb/FtbPage.cpp b/launcher/pages/modplatform/ftb/FtbPage.cpp index aca93cfe..bafcfac9 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.cpp +++ b/launcher/pages/modplatform/ftb/FtbPage.cpp @@ -33,7 +33,6 @@ FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent) ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); connect(ui->searchEdit, &QLineEdit::textChanged, this, &FtbPage::triggerSearch); - connect(ui->resetButton, &QPushButton::clicked, this, &FtbPage::resetSearch); connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FtbPage::onSortingSelectionChanged); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FtbPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FtbPage::onVersionSelectionChanged); @@ -105,11 +104,6 @@ void FtbPage::triggerSearch() filterModel->setSearchTerm(ui->searchEdit->text()); } -void FtbPage::resetSearch() -{ - ui->searchEdit->setText(""); -} - void FtbPage::onSortingSelectionChanged(QString data) { auto toSet = filterModel->getAvailableSortings().value(data); diff --git a/launcher/pages/modplatform/ftb/FtbPage.h b/launcher/pages/modplatform/ftb/FtbPage.h index 0dfac1a4..25b531fb 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.h +++ b/launcher/pages/modplatform/ftb/FtbPage.h @@ -65,7 +65,6 @@ private: private slots: void triggerSearch(); - void resetSearch(); void onSortingSelectionChanged(QString data); void onSelectionChanged(QModelIndex first, QModelIndex second); diff --git a/launcher/pages/modplatform/ftb/FtbPage.ui b/launcher/pages/modplatform/ftb/FtbPage.ui index dc800497..e9c783e3 100644 --- a/launcher/pages/modplatform/ftb/FtbPage.ui +++ b/launcher/pages/modplatform/ftb/FtbPage.ui @@ -36,12 +36,8 @@ Search and filter ... - - - - - - Reset + + true @@ -76,7 +72,6 @@ searchEdit - resetButton versionSelectionBox