More sync from quickmods

Also a small VersionSelectDialog refactor
This commit is contained in:
Petr Mrázek
2014-09-06 21:01:23 +02:00
parent 20cb97a35a
commit b00e63dbe8
10 changed files with 378 additions and 28 deletions

View File

@ -71,7 +71,7 @@ int ProgressDialog::exec(ProgressProvider *task)
if(task->isRunning())
return QDialog::exec();
else
return 0;
return QDialog::Accepted;
}
ProgressProvider *ProgressDialog::getTask()

View File

@ -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"

View File

@ -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;
};

View File

@ -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) ||