From 4b1332609e8b325687dbfaff0941f75bc6b18ad2 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 14 Mar 2025 23:23:40 -0400 Subject: [PATCH] Restore layout selector if left in invalid state --- include/mainwindow.h | 1 + src/mainwindow.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/mainwindow.h b/include/mainwindow.h index 8e57621a..1320f649 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -204,6 +204,7 @@ private slots: void on_actionNew_Tileset_triggered(); void on_action_Save_triggered(); void on_action_Exit_triggered(); + void onLayoutSelectorEditingFinished(); void on_comboBox_LayoutSelector_currentTextChanged(const QString &text); void on_actionShortcuts_triggered(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 840c2920..6195025c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -298,6 +298,7 @@ void MainWindow::initExtraSignals() { connect(ui->action_NewMap, &QAction::triggered, this, &MainWindow::openNewMapDialog); connect(ui->action_NewLayout, &QAction::triggered, this, &MainWindow::openNewLayoutDialog); connect(ui->actionDuplicate_Current_Map_Layout, &QAction::triggered, this, &MainWindow::openDuplicateMapOrLayoutDialog); + connect(ui->comboBox_LayoutSelector->lineEdit(), &QLineEdit::editingFinished, this, &MainWindow::onLayoutSelectorEditingFinished); } void MainWindow::on_actionCheck_for_Updates_triggered() { @@ -1090,6 +1091,18 @@ void MainWindow::on_comboBox_LayoutSelector_currentTextChanged(const QString &te markMapEdited(); } +void MainWindow::onLayoutSelectorEditingFinished() { + if (!this->editor || !this->editor->project || !this->editor->layout) + return; + + // If the user left the layout selector in an invalid state, restore it so that it displays the current layout. + const QString text = ui->comboBox_LayoutSelector->currentText(); + if (!this->editor->project->mapLayouts.contains(text)) { + const QSignalBlocker b(ui->comboBox_LayoutSelector); + ui->comboBox_LayoutSelector->setCurrentText(this->editor->layout->id); + } +} + // Update the UI using information we've read from the user's project files. bool MainWindow::setProjectUI() { Project *project = editor->project;