From 152d476f20d06dff6aecca057c3d01776f3ac975 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 11 Feb 2021 00:19:49 +0000 Subject: [PATCH] NOISSUE Add search to ATLauncher --- .../modplatform/atlauncher/AtlFilterModel.cpp | 16 ++++- .../modplatform/atlauncher/AtlFilterModel.h | 2 + .../pages/modplatform/atlauncher/AtlPage.cpp | 12 ++++ .../pages/modplatform/atlauncher/AtlPage.h | 3 + .../pages/modplatform/atlauncher/AtlPage.ui | 63 ++++++++++++------- 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/application/pages/modplatform/atlauncher/AtlFilterModel.cpp b/application/pages/modplatform/atlauncher/AtlFilterModel.cpp index 8ea1546ae..b5d8f22b1 100644 --- a/application/pages/modplatform/atlauncher/AtlFilterModel.cpp +++ b/application/pages/modplatform/atlauncher/AtlFilterModel.cpp @@ -14,6 +14,8 @@ FilterModel::FilterModel(QObject *parent) : QSortFilterProxyModel(parent) sortings.insert(tr("Sort by popularity"), Sorting::ByPopularity); sortings.insert(tr("Sort by name"), Sorting::ByName); sortings.insert(tr("Sort by game version"), Sorting::ByGameVersion); + + searchTerm = ""; } const QMap FilterModel::getAvailableSortings() @@ -37,9 +39,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; + } + + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + ATLauncher::IndexedPack 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/application/pages/modplatform/atlauncher/AtlFilterModel.h b/application/pages/modplatform/atlauncher/AtlFilterModel.h index 2aef81fb6..bd72ad91c 100644 --- a/application/pages/modplatform/atlauncher/AtlFilterModel.h +++ b/application/pages/modplatform/atlauncher/AtlFilterModel.h @@ -18,6 +18,7 @@ public: QString translateCurrentSorting(); void setSorting(Sorting sorting); Sorting getCurrentSorting(); + void setSearchTerm(QString term); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; @@ -26,6 +27,7 @@ protected: private: QMap sortings; Sorting currentSorting; + QString searchTerm; }; diff --git a/application/pages/modplatform/atlauncher/AtlPage.cpp b/application/pages/modplatform/atlauncher/AtlPage.cpp index 4518248d2..f90d734cd 100644 --- a/application/pages/modplatform/atlauncher/AtlPage.cpp +++ b/application/pages/modplatform/atlauncher/AtlPage.cpp @@ -25,6 +25,8 @@ AtlPage::AtlPage(NewInstanceDialog* dialog, QWidget *parent) } ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); + connect(ui->searchEdit, &QLineEdit::textChanged, this, &AtlPage::triggerSearch); + connect(ui->resetButton, &QPushButton::clicked, this, &AtlPage::resetSearch); connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &AtlPage::onSortingSelectionChanged); connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &AtlPage::onSelectionChanged); connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &AtlPage::onVersionSelectionChanged); @@ -59,6 +61,16 @@ void AtlPage::suggestCurrent() }); } +void AtlPage::triggerSearch() +{ + filterModel->setSearchTerm(ui->searchEdit->text()); +} + +void AtlPage::resetSearch() +{ + ui->searchEdit->setText(""); +} + void AtlPage::onSortingSelectionChanged(QString data) { auto toSet = filterModel->getAvailableSortings().value(data); diff --git a/application/pages/modplatform/atlauncher/AtlPage.h b/application/pages/modplatform/atlauncher/AtlPage.h index fceb0abfe..368de666f 100644 --- a/application/pages/modplatform/atlauncher/AtlPage.h +++ b/application/pages/modplatform/atlauncher/AtlPage.h @@ -62,6 +62,9 @@ private: void suggestCurrent(); private slots: + void triggerSearch(); + void resetSearch(); + void onSortingSelectionChanged(QString data); void onSelectionChanged(QModelIndex first, QModelIndex second); diff --git a/application/pages/modplatform/atlauncher/AtlPage.ui b/application/pages/modplatform/atlauncher/AtlPage.ui index dd17283ca..1a5a450d6 100644 --- a/application/pages/modplatform/atlauncher/AtlPage.ui +++ b/application/pages/modplatform/atlauncher/AtlPage.ui @@ -11,30 +11,11 @@ - - - - true - - - - 96 - 48 - - - - - - - - - + + - - - @@ -45,12 +26,50 @@ + + + + + + + + + + + + Reset + + + + + + + + + + 96 + 48 + + + + + + + + true + + + true + + + - packView + searchEdit + resetButton versionSelectionBox