From 74133bb17282dc2df2fcf4e754318122a7a5e6f8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 6 May 2013 12:48:01 -0500 Subject: Allow users to filter out MCNostalgia and Snapshots from the version list. Resolves JIRA issue MMC-9: https://jira.forkk.net/browse/MMC-9 --- gui/versionselectdialog.cpp | 38 ++++++++++++++++++++++++++++++++++---- gui/versionselectdialog.h | 6 ++++++ gui/versionselectdialog.ui | 18 ++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) (limited to 'gui') diff --git a/gui/versionselectdialog.cpp b/gui/versionselectdialog.cpp index 6ead83c0..63a2ac26 100644 --- a/gui/versionselectdialog.cpp +++ b/gui/versionselectdialog.cpp @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -31,9 +33,18 @@ VersionSelectDialog::VersionSelectDialog(InstVersionList *vlist, QWidget *parent ui->setupUi(this); m_vlist = vlist; - ui->listView->setModel(m_vlist); + + m_proxyModel = new QSortFilterProxyModel(this); + m_proxyModel->setSourceModel(vlist); + + ui->listView->setModel(m_proxyModel); ui->listView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->listView->header()->setSectionResizeMode(0, QHeaderView::Stretch); + + connect(ui->filterSnapshotsCheckbox, SIGNAL(clicked()), SLOT(updateFilterState())); + connect(ui->filterMCNostalgiaCheckbox, SIGNAL(clicked()), SLOT(updateFilterState())); + + updateFilterState(); } VersionSelectDialog::~VersionSelectDialog() @@ -60,13 +71,32 @@ void VersionSelectDialog::loadList() const InstVersion *VersionSelectDialog::selectedVersion() const { const InstVersion *versionPtr = (const InstVersion *) - m_vlist->data(ui->listView->selectionModel()->currentIndex(), - InstVersionList::VersionPointerRole).value(); + m_proxyModel->data(ui->listView->selectionModel()->currentIndex(), + InstVersionList::VersionPointerRole).value(); return versionPtr; } void VersionSelectDialog::on_refreshButton_clicked() { - loadList(); + loadList(); +} + +void VersionSelectDialog::updateFilterState() +{ + m_proxyModel->setFilterKeyColumn(InstVersionList::TypeColumn); + + QStringList filteredTypes; + if (!ui->filterSnapshotsCheckbox->isChecked()) + filteredTypes += "Snapshot"; + if (!ui->filterMCNostalgiaCheckbox->isChecked()) + filteredTypes += "MCNostalgia"; + + QString regexStr = "^.*$"; + if (filteredTypes.length() > 0) + regexStr = QString("^((?!%1).)*$").arg(filteredTypes.join('|')); + + qDebug() << "Filter:" << regexStr; + + m_proxyModel->setFilterRegExp(regexStr); } diff --git a/gui/versionselectdialog.h b/gui/versionselectdialog.h index 097be93f..0f45d8e5 100644 --- a/gui/versionselectdialog.h +++ b/gui/versionselectdialog.h @@ -18,6 +18,8 @@ #include +#include + class InstVersionList; class InstVersion; @@ -44,10 +46,14 @@ public: private slots: void on_refreshButton_clicked(); + void updateFilterState(); + private: Ui::VersionSelectDialog *ui; InstVersionList *m_vlist; + + QSortFilterProxyModel *m_proxyModel; }; #endif // VERSIONSELECTDIALOG_H diff --git a/gui/versionselectdialog.ui b/gui/versionselectdialog.ui index 7b94817a..2bdd4449 100644 --- a/gui/versionselectdialog.ui +++ b/gui/versionselectdialog.ui @@ -36,6 +36,24 @@ + + + + + + Show &snapshots? + + + + + + + Show MC&Nostalgia? + + + + + -- cgit v1.2.3