NOISSUE when there is a version added already, preselect it in the version select dialog
This commit is contained in:
parent
57accb1cbb
commit
ef2cbe16e6
@ -369,6 +369,24 @@ QModelIndex VersionProxyModel::getRecommended() const
|
|||||||
return index(recommended, 0);
|
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()
|
void VersionProxyModel::clearFilters()
|
||||||
{
|
{
|
||||||
m_filters.clear();
|
m_filters.clear();
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
void setFilter(const BaseVersionList::ModelRoles column, const QString &filter, const bool exact);
|
void setFilter(const BaseVersionList::ModelRoles column, const QString &filter, const bool exact);
|
||||||
void clearFilters();
|
void clearFilters();
|
||||||
QModelIndex getRecommended() const;
|
QModelIndex getRecommended() const;
|
||||||
|
QModelIndex getVersion(const QString & version) const;
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void sourceDataChanged(const QModelIndex &source_top_left,const QModelIndex &source_bottom_right);
|
void sourceDataChanged(const QModelIndex &source_top_left,const QModelIndex &source_bottom_right);
|
||||||
|
@ -83,6 +83,12 @@ void VersionSelectDialog::retranslate()
|
|||||||
m_refreshButton->setText(tr("&Refresh"));
|
m_refreshButton->setText(tr("&Refresh"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VersionSelectDialog::setCurrentVersion(const QString& version)
|
||||||
|
{
|
||||||
|
m_currentVersion = version;
|
||||||
|
m_versionWidget->setCurrentVersion(version);
|
||||||
|
}
|
||||||
|
|
||||||
void VersionSelectDialog::setEmptyString(QString emptyString)
|
void VersionSelectDialog::setEmptyString(QString emptyString)
|
||||||
{
|
{
|
||||||
m_versionWidget->setEmptyString(emptyString);
|
m_versionWidget->setEmptyString(emptyString);
|
||||||
|
@ -46,12 +46,12 @@ public:
|
|||||||
|
|
||||||
BaseVersionPtr selectedVersion() const;
|
BaseVersionPtr selectedVersion() const;
|
||||||
|
|
||||||
|
void setCurrentVersion(const QString & version);
|
||||||
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
|
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||||
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
|
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||||
void setEmptyString(QString emptyString);
|
void setEmptyString(QString emptyString);
|
||||||
void setEmptyErrorString(QString emptyErrorString);
|
void setEmptyErrorString(QString emptyErrorString);
|
||||||
void setResizeOn(int column);
|
void setResizeOn(int column);
|
||||||
void setUseLatest(const bool useLatest);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_refreshButton_clicked();
|
void on_refreshButton_clicked();
|
||||||
@ -61,6 +61,7 @@ private:
|
|||||||
void selectRecommended();
|
void selectRecommended();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString m_currentVersion;
|
||||||
VersionSelectWidget *m_versionWidget = nullptr;
|
VersionSelectWidget *m_versionWidget = nullptr;
|
||||||
QVBoxLayout *m_verticalLayout = nullptr;
|
QVBoxLayout *m_verticalLayout = nullptr;
|
||||||
QHBoxLayout *m_horizontalLayout = nullptr;
|
QHBoxLayout *m_horizontalLayout = nullptr;
|
||||||
|
@ -315,6 +315,11 @@ void VersionPage::on_changeVersionBtn_clicked()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
|
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())
|
if (!vselect.exec() || !vselect.selectedVersion())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -379,6 +384,13 @@ void VersionPage::on_forgeBtn_clicked()
|
|||||||
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
|
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.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!"));
|
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())
|
if (vselect.exec() && vselect.selectedVersion())
|
||||||
{
|
{
|
||||||
auto vsn = 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.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.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!"));
|
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())
|
if (vselect.exec() && vselect.selectedVersion())
|
||||||
{
|
{
|
||||||
auto vsn = vselect.selectedVersion();
|
auto vsn = vselect.selectedVersion();
|
||||||
|
@ -41,6 +41,11 @@ VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent
|
|||||||
QMetaObject::connectSlotsByName(this);
|
QMetaObject::connectSlotsByName(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VersionSelectWidget::setCurrentVersion(const QString& version)
|
||||||
|
{
|
||||||
|
m_currentVersion = version;
|
||||||
|
}
|
||||||
|
|
||||||
void VersionSelectWidget::setEmptyString(QString emptyString)
|
void VersionSelectWidget::setEmptyString(QString emptyString)
|
||||||
{
|
{
|
||||||
listView->setEmptyString(emptyString);
|
listView->setEmptyString(emptyString);
|
||||||
@ -134,15 +139,33 @@ void VersionSelectWidget::preselect()
|
|||||||
{
|
{
|
||||||
if(preselectedAlready)
|
if(preselectedAlready)
|
||||||
return;
|
return;
|
||||||
preselectedAlready = true;
|
selectCurrent();
|
||||||
|
if(preselectedAlready)
|
||||||
|
return;
|
||||||
selectRecommended();
|
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()
|
void VersionSelectWidget::selectRecommended()
|
||||||
{
|
{
|
||||||
auto idx = m_proxyModel->getRecommended();
|
auto idx = m_proxyModel->getRecommended();
|
||||||
if(idx.isValid())
|
if(idx.isValid())
|
||||||
{
|
{
|
||||||
|
preselectedAlready = true;
|
||||||
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||||
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
listView->scrollTo(idx, QAbstractItemView::PositionAtCenter);
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,14 @@ public:
|
|||||||
bool hasVersions() const;
|
bool hasVersions() const;
|
||||||
BaseVersionPtr selectedVersion() const;
|
BaseVersionPtr selectedVersion() const;
|
||||||
void selectRecommended();
|
void selectRecommended();
|
||||||
|
void selectCurrent();
|
||||||
|
|
||||||
|
void setCurrentVersion(const QString & version);
|
||||||
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
|
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||||
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
|
void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
|
||||||
void setEmptyString(QString emptyString);
|
void setEmptyString(QString emptyString);
|
||||||
void setEmptyErrorString(QString emptyErrorString);
|
void setEmptyErrorString(QString emptyErrorString);
|
||||||
void setResizeOn(int column);
|
void setResizeOn(int column);
|
||||||
void setUseLatest(const bool useLatest);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selectedVersionChanged(BaseVersionPtr version);
|
void selectedVersionChanged(BaseVersionPtr version);
|
||||||
@ -64,6 +65,7 @@ private:
|
|||||||
void preselect();
|
void preselect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString m_currentVersion;
|
||||||
BaseVersionList *m_vlist = nullptr;
|
BaseVersionList *m_vlist = nullptr;
|
||||||
VersionProxyModel *m_proxyModel = nullptr;
|
VersionProxyModel *m_proxyModel = nullptr;
|
||||||
int resizeOnColumn = 0;
|
int resizeOnColumn = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user