From b00e63dbe8d0acaae503e63d614ee20b9e9ede2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 6 Sep 2014 21:01:23 +0200 Subject: More sync from quickmods Also a small VersionSelectDialog refactor --- gui/dialogs/ProgressDialog.cpp | 2 +- gui/dialogs/VersionSelectDialog.cpp | 101 ++++++++++++++++++++++++++++++++---- gui/dialogs/VersionSelectDialog.h | 6 ++- gui/groupview/InstanceDelegate.cpp | 4 ++ 4 files changed, 102 insertions(+), 11 deletions(-) (limited to 'gui') 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 #include #include +#include +#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 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 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; }; diff --git a/gui/groupview/InstanceDelegate.cpp b/gui/groupview/InstanceDelegate.cpp index e49e1552..a8e5ee83 100644 --- a/gui/groupview/InstanceDelegate.cpp +++ b/gui/groupview/InstanceDelegate.cpp @@ -118,6 +118,10 @@ void drawBadges(QPainter *painter, const QStyleOptionViewItemV4 &option, BaseIns { pixmaps.append("broken"); } + if (flags & BaseInstance::UpdateAvailable) + { + pixmaps.append("updateavailable"); + } // begin easter eggs if (instance->name().contains("btw", Qt::CaseInsensitive) || -- cgit v1.2.3