Skip to content

Commit

Permalink
Fixed version list bug
Browse files Browse the repository at this point in the history
Previous versions would stay highlighted as currently selected after clicking "Save"
  • Loading branch information
Moresteck committed May 24, 2024
1 parent ab0fd6c commit 0087aec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ui/AboutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ void AboutWidget::initAboutLayout() {
_aboutSectionLayout->addWidget(_links, 0, 0, Qt::AlignCenter);
_aboutSectionLayout->addWidget(new QLabel(versionString), 1, 0,
Qt::AlignCenter);
_aboutSectionLayout->addWidget(new QLabel("© Betacraft 2018-2023"), 2, 0,
QString copyyear = QString("© Betacraft 2018-") + QString::number(QDate::currentDate().year());
_aboutSectionLayout->addWidget(new QLabel(copyyear), 2, 0,
Qt::AlignCenter);

_aboutSectionLayout->setAlignment(Qt::AlignTop);
Expand Down
18 changes: 18 additions & 0 deletions src/ui/instances/InstanceEditVersionWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ InstanceEditVersionWidget::InstanceEditVersionWidget(QWidget *parent)
bc_versionlist_instance =
(bc_versionlist *)_versionListWatcher.future().result();
populateVersionList();
setSelectedInstance();
_instanceVersionListFetchPending = false;
});
}
Expand Down Expand Up @@ -167,10 +168,27 @@ void InstanceEditVersionWidget::setSelectedInstance() {
}

void InstanceEditVersionWidget::setInstance(bc_instance instance) {
if (_version != nullptr) {
resetVersionBackground(_version);
}

_version = QString(instance.version);
setSelectedInstance();
}

void InstanceEditVersionWidget::resetVersionBackground(QString version) {
QStandardItemModel *model =
static_cast<QStandardItemModel *>(_versionsTreeView->model());

for (int i = 0; i < model->rowCount(); i++) {
if (model->item(i)->text().compare(version) == 0) {
model->item(i, 0)->setBackground(QBrush());
model->item(i, 1)->setBackground(QBrush());
break;
}
}
}

QString InstanceEditVersionWidget::getSettings() {
QModelIndexList indexes =
_versionsTreeView->selectionModel()->selectedIndexes();
Expand Down
1 change: 1 addition & 0 deletions src/ui/instances/InstanceEditVersionWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class InstanceEditVersionWidget : public QWidget {
explicit InstanceEditVersionWidget(QWidget *parent = nullptr);
QString getSettings();
void setInstance(bc_instance instance);
void resetVersionBackground(QString version);
void clean();
void versionListInit();

Expand Down

0 comments on commit 0087aec

Please sign in to comment.