summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-05-06 12:48:01 -0500
committerAndrew <forkk@forkk.net>2013-05-06 12:48:29 -0500
commit74133bb17282dc2df2fcf4e754318122a7a5e6f8 (patch)
tree0d3e070d06f228944b4dcb58bb9671d625679b50
parent857a4e4dbed88b647619c213d731dc460d034820 (diff)
downloadMultiMC-74133bb17282dc2df2fcf4e754318122a7a5e6f8.tar
MultiMC-74133bb17282dc2df2fcf4e754318122a7a5e6f8.tar.gz
MultiMC-74133bb17282dc2df2fcf4e754318122a7a5e6f8.tar.lz
MultiMC-74133bb17282dc2df2fcf4e754318122a7a5e6f8.tar.xz
MultiMC-74133bb17282dc2df2fcf4e754318122a7a5e6f8.zip
Allow users to filter out MCNostalgia and Snapshots from the version list.
Resolves JIRA issue MMC-9: https://jira.forkk.net/browse/MMC-9
-rw-r--r--gui/versionselectdialog.cpp38
-rw-r--r--gui/versionselectdialog.h6
-rw-r--r--gui/versionselectdialog.ui18
-rw-r--r--libmultimc/include/instversionlist.h12
-rw-r--r--libmultimc/src/instversionlist.cpp18
-rw-r--r--libmultimc/src/minecraftversion.cpp2
6 files changed, 72 insertions, 22 deletions
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 <QHeaderView>
+#include <QDebug>
+
#include <gui/taskdialog.h>
#include <instversionlist.h>
@@ -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<void *>();
+ m_proxyModel->data(ui->listView->selectionModel()->currentIndex(),
+ InstVersionList::VersionPointerRole).value<void *>();
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 <QDialog>
+#include <QSortFilterProxyModel>
+
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
@@ -37,6 +37,24 @@
</widget>
</item>
<item>
+ <layout class="QHBoxLayout" name="filterCheckboxLayout1">
+ <item>
+ <widget class="QCheckBox" name="filterSnapshotsCheckbox">
+ <property name="text">
+ <string>Show &amp;snapshots?</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="filterMCNostalgiaCheckbox">
+ <property name="text">
+ <string>Show MC&amp;Nostalgia?</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="refreshButton">
diff --git a/libmultimc/include/instversionlist.h b/libmultimc/include/instversionlist.h
index e28bd96f..61b459d7 100644
--- a/libmultimc/include/instversionlist.h
+++ b/libmultimc/include/instversionlist.h
@@ -46,6 +46,18 @@ public:
VersionPointerRole = 0x34B1CB48
};
+ enum VListColumns
+ {
+ // First column - Name
+ NameColumn = 0,
+
+ // Second column - Type
+ TypeColumn,
+
+ // Third column - Timestamp
+ TimeColumn
+ };
+
explicit InstVersionList(QObject *parent = 0);
/*!
diff --git a/libmultimc/src/instversionlist.cpp b/libmultimc/src/instversionlist.cpp
index 7d1bfdb7..fa05efdd 100644
--- a/libmultimc/src/instversionlist.cpp
+++ b/libmultimc/src/instversionlist.cpp
@@ -39,22 +39,6 @@ const InstVersion *InstVersionList::getLatestStable()
return at(0);
}
-// Column Enum
-enum VListColumns
-{
- // First column - Name
- NameColumn = 0,
-
- // Second column - Type
- TypeColumn,
-
- // Third column - Timestamp
- TimeColumn,
-
- // Column count
- ColCount
-};
-
QVariant InstVersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
@@ -141,5 +125,5 @@ int InstVersionList::rowCount(const QModelIndex &parent) const
int InstVersionList::columnCount(const QModelIndex &parent) const
{
- return ColCount;
+ return 2;
}
diff --git a/libmultimc/src/minecraftversion.cpp b/libmultimc/src/minecraftversion.cpp
index 896c2e18..2e8b4a9b 100644
--- a/libmultimc/src/minecraftversion.cpp
+++ b/libmultimc/src/minecraftversion.cpp
@@ -63,7 +63,7 @@ QString MinecraftVersion::typeName() const
switch (versionType())
{
case OldSnapshot:
- return "Old Snapshot";
+ return "Snapshot";
case Stable:
return "Stable";