NOISSUE when there is a version added already, preselect it in the version select dialog

This commit is contained in:
Petr Mrázek 2017-12-09 01:30:23 +01:00
parent 57accb1cbb
commit ef2cbe16e6
7 changed files with 73 additions and 3 deletions

View File

@ -369,6 +369,24 @@ QModelIndex VersionProxyModel::getRecommended() const
return index(recommended, 0);
}
QModelIndex VersionProxyModel::getVersion(const QString& version) const
{
int found = -1;
for (int i = 0; i < rowCount(); i++)
{
auto value = sourceModel()->data(mapToSource(index(i, 0)), BaseVersionList::VersionRole);
if (value.toString() == version)
{
found = i;
}
}
if(found == -1)
{
return QModelIndex();
}
return index(found, 0);
}
void VersionProxyModel::clearFilters()
{
m_filters.clear();

View File

@ -42,6 +42,7 @@ public:
void setFilter(const BaseVersionList::ModelRoles column, const QString &filter, const bool exact);
void clearFilters();
QModelIndex getRecommended() const;
QModelIndex getVersion(const QString & version) const;
private slots:
void sourceDataChanged(const QModelIndex &source_top_left,const QModelIndex &source_bottom_right);

View File

@ -83,6 +83,12 @@ void VersionSelectDialog::retranslate()
m_refreshButton->setText(tr("&Refresh"));
}
void VersionSelectDialog::setCurrentVersion(const QString& version)
{
m_currentVersion = version;
m_versionWidget->setCurrentVersion(version);
}
void VersionSelectDialog::setEmptyString(QString emptyString)
{
m_versionWidget->setEmptyString(emptyString);

View File

@ -46,12 +46,12 @@ public:
BaseVersionPtr selectedVersion() const;
void setCurrentVersion(const QString & version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
void setEmptyString(QString emptyString);
void setEmptyErrorString(QString emptyErrorString);
void setResizeOn(int column);
void setUseLatest(const bool useLatest);
private slots:
void on_refreshButton_clicked();
@ -61,6 +61,7 @@ private:
void selectRecommended();
private:
QString m_currentVersion;
VersionSelectWidget *m_versionWidget = nullptr;
QVBoxLayout *m_verticalLayout = nullptr;
QHBoxLayout *m_horizontalLayout = nullptr;

View File

@ -315,6 +315,11 @@ void VersionPage::on_changeVersionBtn_clicked()
return;
}
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
auto currentVersion = patch->getVersion();
if(!currentVersion.isEmpty())
{
vselect.setCurrentVersion(currentVersion);
}
if (!vselect.exec() || !vselect.selectedVersion())
return;
@ -379,6 +384,13 @@ void VersionPage::on_forgeBtn_clicked()
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyErrorString(tr("Couldn't load or download the Forge version lists!"));
auto currentVersion = m_profile->getComponentVersion("net.minecraftforge");
if(!currentVersion.isEmpty())
{
vselect.setCurrentVersion(currentVersion);
}
if (vselect.exec() && vselect.selectedVersion())
{
auto vsn = vselect.selectedVersion();
@ -439,6 +451,13 @@ void VersionPage::on_liteloaderBtn_clicked()
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") + m_profile->getComponentVersion("net.minecraft"));
vselect.setEmptyErrorString(tr("Couldn't load or download the LiteLoader version lists!"));
auto currentVersion = m_profile->getComponentVersion("com.mumfrey.liteloader");
if(!currentVersion.isEmpty())
{
vselect.setCurrentVersion(currentVersion);
}
if (vselect.exec() && vselect.selectedVersion())
{
auto vsn = vselect.selectedVersion();

View File

@ -41,6 +41,11 @@ VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent
QMetaObject::connectSlotsByName(this);
}
void VersionSelectWidget::setCurrentVersion(const QString& version)
{
m_currentVersion = version;
}
void VersionSelectWidget::setEmptyString(QString emptyString)
{
listView->setEmptyString(emptyString);
@ -134,15 +139,33 @@ void VersionSelectWidget::preselect()
{
if(preselectedAlready)
return;
preselectedAlready = true;
selectCurrent();
if(preselectedAlready)
return;
selectRecommended();
}
void VersionSelectWidget::selectCurrent()
{
if(m_currentVersion.isEmpty())
{
return;
}
auto idx = m_proxyModel->getVersion(m_currentVersion);
if(idx.isValid())
{
preselectedAlready = true;
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
}
}
void VersionSelectWidget::selectRecommended()
{
auto idx = m_proxyModel->getRecommended();
if(idx.isValid())
{
preselectedAlready = true;
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
}

View File

@ -40,13 +40,14 @@ public:
bool hasVersions() const;
BaseVersionPtr selectedVersion() const;
void selectRecommended();
void selectCurrent();
void setCurrentVersion(const QString & version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
void setEmptyString(QString emptyString);
void setEmptyErrorString(QString emptyErrorString);
void setResizeOn(int column);
void setUseLatest(const bool useLatest);
signals:
void selectedVersionChanged(BaseVersionPtr version);
@ -64,6 +65,7 @@ private:
void preselect();
private:
QString m_currentVersion;
BaseVersionList *m_vlist = nullptr;
VersionProxyModel *m_proxyModel = nullptr;
int resizeOnColumn = 0;