From c0f72488d042b8f7503b7f13fdcc53ea9e185b76 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Fri, 18 Jun 2021 23:21:12 +0100 Subject: [PATCH] GH-3033 Add filtering for version components --- application/pages/instance/ModFolderPage.cpp | 2 +- application/pages/instance/VersionPage.cpp | 20 +++++++++++++++++--- application/pages/instance/VersionPage.h | 4 +++- application/pages/instance/VersionPage.ui | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp index c3d6483a..98f20e77 100644 --- a/application/pages/instance/ModFolderPage.cpp +++ b/application/pages/instance/ModFolderPage.cpp @@ -163,7 +163,7 @@ ModFolderPage::ModFolderPage( auto smodel = ui->modTreeView->selectionModel(); connect(smodel, &QItemSelectionModel::currentChanged, this, &ModFolderPage::modCurrent); - connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged ); + connect(ui->filterEdit, &QLineEdit::textChanged, this, &ModFolderPage::on_filterTextChanged); connect(m_inst, &BaseInstance::runningStatusChanged, this, &ModFolderPage::on_RunningState_changed); } diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp index 7f7ba860..eff12c9c 100644 --- a/application/pages/instance/VersionPage.cpp +++ b/application/pages/instance/VersionPage.cpp @@ -120,7 +120,15 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) auto proxy = new IconProxy(ui->packageView); proxy->setSourceModel(m_profile.get()); - ui->packageView->setModel(proxy); + + m_filterModel = new QSortFilterProxyModel(); + m_filterModel->setDynamicSortFilter(true); + m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive); + m_filterModel->setSourceModel(proxy); + m_filterModel->setFilterKeyColumn(-1); + + ui->packageView->setModel(m_filterModel); ui->packageView->installEventFilter(this); ui->packageView->setSelectionMode(QAbstractItemView::SingleSelection); ui->packageView->setContextMenuPolicy(Qt::CustomContextMenu); @@ -134,7 +142,8 @@ VersionPage::VersionPage(MinecraftInstance *inst, QWidget *parent) updateVersionControls(); preselect(0); connect(m_inst, &BaseInstance::runningStatusChanged, this, &VersionPage::updateRunningStatus); - connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::ShowContextMenu); + connect(ui->packageView, &ModListView::customContextMenuRequested, this, &VersionPage::showContextMenu); + connect(ui->filterEdit, &QLineEdit::textChanged, this, &VersionPage::onFilterTextChanged); } VersionPage::~VersionPage() @@ -142,7 +151,7 @@ VersionPage::~VersionPage() delete ui; } -void VersionPage::ShowContextMenu(const QPoint& pos) +void VersionPage::showContextMenu(const QPoint& pos) { auto menu = ui->toolBar->createContextMenu(this, tr("Context menu")); menu->exec(ui->packageView->mapToGlobal(pos)); @@ -620,5 +629,10 @@ void VersionPage::on_actionRevert_triggered() m_container->refreshContainer(); } +void VersionPage::onFilterTextChanged(const QString &newContents) +{ + m_filterModel->setFilterFixedString(newContents); +} + #include "VersionPage.moc" diff --git a/application/pages/instance/VersionPage.h b/application/pages/instance/VersionPage.h index dbd9c1ee..b5b4a6f5 100644 --- a/application/pages/instance/VersionPage.h +++ b/application/pages/instance/VersionPage.h @@ -86,6 +86,7 @@ protected: private: Ui::VersionPage *ui; + QSortFilterProxyModel *m_filterModel; std::shared_ptr m_profile; MinecraftInstance *m_inst; int currentIdx = 0; @@ -98,5 +99,6 @@ private slots: void updateRunningStatus(bool running); void onGameUpdateError(QString error); void packageCurrent(const QModelIndex ¤t, const QModelIndex &previous); - void ShowContextMenu(const QPoint &pos); + void showContextMenu(const QPoint &pos); + void onFilterTextChanged(const QString & newContents); }; diff --git a/application/pages/instance/VersionPage.ui b/application/pages/instance/VersionPage.ui index 718ad067..84d06e2e 100644 --- a/application/pages/instance/VersionPage.ui +++ b/application/pages/instance/VersionPage.ui @@ -45,6 +45,24 @@ + + + + + + true + + + + + + + Filter: + + + + +