Fix settings window crash on close

This commit is contained in:
GriffinR 2023-12-19 11:42:46 -05:00
parent 7f871efccb
commit cd1c3fef94
3 changed files with 14 additions and 8 deletions

View file

@ -23,6 +23,7 @@ public:
static const int eventsTab;
void setTab(int index);
void closeQuietly();
signals:
void reloadProject();

View file

@ -2905,8 +2905,8 @@ void MainWindow::closeSupplementaryWindows() {
delete this->mapImageExporter;
delete this->newMapPrompt;
delete this->shortcutsEditor;
delete this->projectSettingsEditor;
delete this->customScriptsEditor;
if (this->projectSettingsEditor) this->projectSettingsEditor->closeQuietly();
}
void MainWindow::closeEvent(QCloseEvent *event) {

View file

@ -639,18 +639,24 @@ void ProjectSettingsEditor::dialogButtonClicked(QAbstractButton *button) {
if (buttonRole == QDialogButtonBox::AcceptRole) {
// "OK" button
this->save();
close();
this->close();
} else if (buttonRole == QDialogButtonBox::RejectRole) {
// "Cancel" button
if (!this->promptSaveChanges())
return;
close();
this->close();
} else if (buttonRole == QDialogButtonBox::ResetRole) {
// "Restore Defaults" button
this->promptRestoreDefaults();
}
}
// Close event triggered by a project reload. User doesn't need any prompts, just close the window.
void ProjectSettingsEditor::closeQuietly() {
// Turn off flags that trigger prompts
this->hasUnsavedChanges = false;
this->projectNeedsReload = false;
this->close();
}
void ProjectSettingsEditor::closeEvent(QCloseEvent* event) {
if (!this->promptSaveChanges()) {
event->ignore();
@ -664,9 +670,8 @@ void ProjectSettingsEditor::closeEvent(QCloseEvent* event) {
if (this->projectNeedsReload) {
// Note: Declining this prompt with changes that need a reload may cause problems
if (this->prompt("Settings changed, reload project to apply changes?") == QMessageBox::Yes){
// Reloading the project will destroy this window, no other work should happen after this signal is emitted
if (this->prompt("Settings changed, reload project to apply changes?") == QMessageBox::Yes)
emit this->reloadProject();
}
}
QMainWindow::closeEvent(event);
}