diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-09-06 21:01:23 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-09-06 21:01:23 +0200 |
commit | b00e63dbe8d0acaae503e63d614ee20b9e9ede2e (patch) | |
tree | adc9a8442d20fe717879224036ee0b768dfa392d /gui/dialogs | |
parent | 20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c (diff) | |
download | MultiMC-b00e63dbe8d0acaae503e63d614ee20b9e9ede2e.tar MultiMC-b00e63dbe8d0acaae503e63d614ee20b9e9ede2e.tar.gz MultiMC-b00e63dbe8d0acaae503e63d614ee20b9e9ede2e.tar.lz MultiMC-b00e63dbe8d0acaae503e63d614ee20b9e9ede2e.tar.xz MultiMC-b00e63dbe8d0acaae503e63d614ee20b9e9ede2e.zip |
More sync from quickmods
Also a small VersionSelectDialog refactor
Diffstat (limited to 'gui/dialogs')
-rw-r--r-- | gui/dialogs/ProgressDialog.cpp | 2 | ||||
-rw-r--r-- | gui/dialogs/VersionSelectDialog.cpp | 101 | ||||
-rw-r--r-- | gui/dialogs/VersionSelectDialog.h | 6 |
3 files changed, 98 insertions, 11 deletions
diff --git a/gui/dialogs/ProgressDialog.cpp b/gui/dialogs/ProgressDialog.cpp index ba14cca2..8adaace5 100644 --- a/gui/dialogs/ProgressDialog.cpp +++ b/gui/dialogs/ProgressDialog.cpp @@ -71,7 +71,7 @@ int ProgressDialog::exec(ProgressProvider *task) if(task->isRunning()) return QDialog::exec(); else - return 0; + return QDialog::Accepted; } ProgressProvider *ProgressDialog::getTask() diff --git a/gui/dialogs/VersionSelectDialog.cpp b/gui/dialogs/VersionSelectDialog.cpp index 2745eccc..83a1993f 100644 --- a/gui/dialogs/VersionSelectDialog.cpp +++ b/gui/dialogs/VersionSelectDialog.cpp @@ -24,10 +24,72 @@ #include <logic/BaseVersion.h> #include <logic/BaseVersionList.h> #include <logic/tasks/Task.h> +#include <depends/util/include/modutils.h> +#include "logger/QsLog.h" + +class VersionSelectProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: + VersionSelectProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) + { + } + + struct Filter + { + QString string; + bool exact = false; + }; + + QHash<int, Filter> filters() const + { + return m_filters; + } + void setFilter(const int column, const QString &filter, const bool exact) + { + Filter f; + f.string = filter; + f.exact = exact; + m_filters[column] = f; + invalidateFilter(); + } + void clearFilters() + { + m_filters.clear(); + invalidateFilter(); + } + +protected: + bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const + { + for (auto it = m_filters.begin(); it != m_filters.end(); ++it) + { + const QString version = + sourceModel()->index(source_row, it.key()).data().toString(); + + if (it.value().exact) + { + if (version != it.value().string) + { + return false; + } + continue; + } + + if (!Util::versionIsInInterval(version, it.value().string)) + { + return false; + } + } + return true; + } + + QHash<int, Filter> m_filters; +}; VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, QWidget *parent, bool cancelable) - : QDialog(parent), ui(new Ui::VersionSelectDialog) + : QDialog(parent), ui(new Ui::VersionSelectDialog), m_useLatest(false) { MultiMCPlatform::fixWM_CLASS(this); ui->setupUi(this); @@ -36,7 +98,7 @@ VersionSelectDialog::VersionSelectDialog(BaseVersionList *vlist, QString title, m_vlist = vlist; - m_proxyModel = new QSortFilterProxyModel(this); + m_proxyModel = new VersionSelectProxyModel(this); m_proxyModel->setSourceModel(vlist); ui->listView->setModel(m_proxyModel); @@ -66,18 +128,41 @@ void VersionSelectDialog::setResizeOn(int column) ui->listView->header()->setSectionResizeMode(resizeOnColumn, QHeaderView::Stretch); } +void VersionSelectDialog::setUseLatest(const bool useLatest) +{ + m_useLatest = useLatest; +} + int VersionSelectDialog::exec() { QDialog::open(); if (!m_vlist->isLoaded()) + { loadList(); + } + m_proxyModel->invalidate(); + if (m_proxyModel->rowCount() == 0) + { + QLOG_DEBUG() << "No rows in version list"; + return QDialog::Rejected; + } + if (m_proxyModel->rowCount() == 1 || m_useLatest) + { + ui->listView->selectionModel()->setCurrentIndex(m_proxyModel->index(0, 0), + QItemSelectionModel::ClearAndSelect); + return QDialog::Accepted; + } return QDialog::exec(); } void VersionSelectDialog::loadList() { - ProgressDialog *taskDlg = new ProgressDialog(this); Task *loadTask = m_vlist->getLoadTask(); + if (!loadTask) + { + return; + } + ProgressDialog *taskDlg = new ProgressDialog(this); loadTask->setParent(taskDlg); taskDlg->exec(loadTask); delete taskDlg; @@ -97,14 +182,12 @@ void VersionSelectDialog::on_refreshButton_clicked() void VersionSelectDialog::setExactFilter(int column, QString filter) { - m_proxyModel->setFilterKeyColumn(column); - // m_proxyModel->setFilterFixedString(filter); - m_proxyModel->setFilterRegExp(QRegExp(QString("^%1$").arg(filter.replace(".", "\\.")), - Qt::CaseInsensitive, QRegExp::RegExp)); + m_proxyModel->setFilter(column, filter, true); } void VersionSelectDialog::setFuzzyFilter(int column, QString filter) { - m_proxyModel->setFilterKeyColumn(column); - m_proxyModel->setFilterWildcard(filter); + m_proxyModel->setFilter(column, filter, false); } + +#include "VersionSelectDialog.moc" diff --git a/gui/dialogs/VersionSelectDialog.h b/gui/dialogs/VersionSelectDialog.h index 34df4d23..70ee9635 100644 --- a/gui/dialogs/VersionSelectDialog.h +++ b/gui/dialogs/VersionSelectDialog.h @@ -27,6 +27,8 @@ namespace Ui class VersionSelectDialog; } +class VersionSelectProxyModel; + class VersionSelectDialog : public QDialog { Q_OBJECT @@ -47,6 +49,7 @@ public: void setExactFilter(int column, QString filter); void setEmptyString(QString emptyString); void setResizeOn(int column); + void setUseLatest(const bool useLatest); private slots: @@ -57,7 +60,8 @@ private: BaseVersionList *m_vlist; - QSortFilterProxyModel *m_proxyModel; + VersionSelectProxyModel *m_proxyModel; int resizeOnColumn = 0; + bool m_useLatest; }; |