From d1af93f3b5083010ca7215f87560993b558cce1f Mon Sep 17 00:00:00 2001 From: garakmon Date: Sun, 13 Sep 2020 18:34:18 -0400 Subject: [PATCH 1/4] do not call initWindow() on failed load --- include/lib/orderedjson.h | 4 ++- include/mainwindow.h | 1 + src/mainwindow.cpp | 56 +++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/include/lib/orderedjson.h b/include/lib/orderedjson.h index fb68527d..5f791286 100644 --- a/include/lib/orderedjson.h +++ b/include/lib/orderedjson.h @@ -51,7 +51,8 @@ * THE SOFTWARE. */ -#pragma once +#ifndef ORDERED_JSON_H +#define ORDERED_JSON_H #include #include @@ -240,3 +241,4 @@ protected: } // namespace poryjson +#endif // ORDERED_JSON_H diff --git a/include/mainwindow.h b/include/mainwindow.h index a9180402..fbb6af6b 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -262,6 +262,7 @@ private: bool isProgrammaticEventTabChange; bool projectHasUnsavedChanges; + bool projectOpenFailure = false; MapSortOrder mapSortOrder; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 45037f10..7b947db3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -58,10 +58,11 @@ MainWindow::MainWindow(QWidget *parent) : this->initWindow(); if (!this->openRecentProject()) { - // Re-initialize everything to a blank slate if opening the recent project failed. - this->initWindow(); + setWindowDisabled(true); + } else { + setWindowDisabled(false); + on_toolButton_Paint_clicked(); } - on_toolButton_Paint_clicked(); } MainWindow::~MainWindow() @@ -118,6 +119,7 @@ void MainWindow::initExtraShortcuts() { void MainWindow::initCustomUI() { // Set up the tab bar + while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0); ui->mainTabBar->addTab("Map"); ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); ui->mainTabBar->addTab("Events"); @@ -125,12 +127,19 @@ void MainWindow::initCustomUI() { ui->mainTabBar->addTab("Connections"); ui->mainTabBar->addTab("Wild Pokemon"); ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico"))); +} +void MainWindow::initExtraSignals() { // Right-clicking on items in the map list tree view brings up a context menu. ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onOpenMapListContextMenu(const QPoint &))); + // other signals + connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString))); + connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged); + + // Change pages on wild encounter groups QStackedWidget *stack = ui->stackedWidget_WildMons; QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; connect(labelCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ @@ -151,11 +160,6 @@ void MainWindow::initCustomUI() { ui->frame_mapTools->setLayout(flowLayout); } -void MainWindow::initExtraSignals() { - connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString))); - connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged); -} - void MainWindow::initEditor() { this->editor = new Editor(ui); connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects())); @@ -394,6 +398,7 @@ bool MainWindow::openRecentProject() { bool MainWindow::openProject(QString dir) { if (dir.isNull()) { + projectOpenFailure = true; return false; } @@ -450,13 +455,12 @@ bool MainWindow::openProject(QString dir) { Scripting::cb_ProjectOpened(dir); } - setWindowDisabled(false); - + projectOpenFailure = !success; return success; } bool MainWindow::isProjectOpen() { - return editor != nullptr && editor->project != nullptr; + return !projectOpenFailure && editor && editor->project; } QString MainWindow::getDefaultMap() { @@ -500,9 +504,7 @@ void MainWindow::on_action_Open_Project_triggered() this->ui->graphicsView_Map->overlay.clearItems(); } porymapConfig.setRecentProject(dir); - if (!openProject(dir)) { - this->initWindow(); - } + setWindowDisabled(!openProject(dir)); } } @@ -2666,19 +2668,22 @@ void MainWindow::closeSupplementaryWindows() { } void MainWindow::closeEvent(QCloseEvent *event) { - if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) { - QMessageBox::StandardButton result = QMessageBox::question( - this, "porymap", "The project has been modified, save changes?", - QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); + if (isProjectOpen()) { + if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) { + QMessageBox::StandardButton result = QMessageBox::question( + this, "porymap", "The project has been modified, save changes?", + QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - if (result == QMessageBox::Yes) { - editor->saveProject(); - } else if (result == QMessageBox::No) { - logWarn("Closing porymap with unsaved changes."); - } else if (result == QMessageBox::Cancel) { - event->ignore(); - return; + if (result == QMessageBox::Yes) { + editor->saveProject(); + } else if (result == QMessageBox::No) { + logWarn("Closing porymap with unsaved changes."); + } else if (result == QMessageBox::Cancel) { + event->ignore(); + return; + } } + projectConfig.save(); } porymapConfig.setMainGeometry( @@ -2688,7 +2693,6 @@ void MainWindow::closeEvent(QCloseEvent *event) { this->ui->splitter_main->saveState() ); porymapConfig.save(); - projectConfig.save(); QMainWindow::closeEvent(event); } From f791157adc0b8632c335b03ec807ad8749de5ed4 Mon Sep 17 00:00:00 2001 From: garakmon Date: Sun, 13 Sep 2020 18:37:55 -0400 Subject: [PATCH 2/4] add #pragma once to include files --- include/config.h | 1 + include/core/block.h | 1 + include/core/blockdata.h | 1 + include/core/editcommands.h | 1 + include/core/event.h | 1 + include/core/heallocation.h | 1 + include/core/history.h | 1 + include/core/imageexport.h | 1 + include/core/map.h | 1 + include/core/mapconnection.h | 1 + include/core/maplayout.h | 1 + include/core/metatile.h | 1 + include/core/metatileparser.h | 1 + include/core/paletteutil.h | 1 + include/core/parseutil.h | 1 + include/core/regionmap.h | 1 + include/core/tile.h | 1 + include/core/tileset.h | 1 + include/core/wildmoninfo.h | 1 + include/editor.h | 1 + include/lib/orderedjson.h | 1 + include/lib/orderedmap.h | 1 + include/lib/qstringhash.h | 1 + include/log.h | 1 + include/mainwindow.h | 1 + include/project.h | 1 + include/scripting.h | 1 + include/settings.h | 1 + 28 files changed, 28 insertions(+) diff --git a/include/config.h b/include/config.h index 008eeeb7..28c4dfa8 100644 --- a/include/config.h +++ b/include/config.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CONFIG_H #define CONFIG_H diff --git a/include/core/block.h b/include/core/block.h index 798e179c..6a787265 100644 --- a/include/core/block.h +++ b/include/core/block.h @@ -1,3 +1,4 @@ +#pragma once #ifndef BLOCK_H #define BLOCK_H diff --git a/include/core/blockdata.h b/include/core/blockdata.h index 35c071fb..a8e29d36 100644 --- a/include/core/blockdata.h +++ b/include/core/blockdata.h @@ -1,3 +1,4 @@ +#pragma once #ifndef BLOCKDATA_H #define BLOCKDATA_H diff --git a/include/core/editcommands.h b/include/core/editcommands.h index 69d2f14f..cbc98415 100644 --- a/include/core/editcommands.h +++ b/include/core/editcommands.h @@ -1,3 +1,4 @@ +#pragma once #ifndef EDITCOMMANDS_H #define EDITCOMMANDS_H diff --git a/include/core/event.h b/include/core/event.h index 48d13253..c46d95eb 100644 --- a/include/core/event.h +++ b/include/core/event.h @@ -1,3 +1,4 @@ +#pragma once #ifndef EVENT_H #define EVENT_H diff --git a/include/core/heallocation.h b/include/core/heallocation.h index fd00a22b..a39386c1 100644 --- a/include/core/heallocation.h +++ b/include/core/heallocation.h @@ -1,3 +1,4 @@ +#pragma once #ifndef HEALLOCATION_H #define HEALLOCATION_H diff --git a/include/core/history.h b/include/core/history.h index 40576ff2..75883d2d 100644 --- a/include/core/history.h +++ b/include/core/history.h @@ -1,3 +1,4 @@ +#pragma once #ifndef HISTORY_H #define HISTORY_H diff --git a/include/core/imageexport.h b/include/core/imageexport.h index e6552323..d195e471 100644 --- a/include/core/imageexport.h +++ b/include/core/imageexport.h @@ -1,3 +1,4 @@ +#pragma once #ifndef IMAGEEXPORT_H #define IMAGEEXPORT_H diff --git a/include/core/map.h b/include/core/map.h index 4d34a071..639d7a02 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAP_H #define MAP_H diff --git a/include/core/mapconnection.h b/include/core/mapconnection.h index 8823e7bc..b6be238e 100644 --- a/include/core/mapconnection.h +++ b/include/core/mapconnection.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAPCONNECTION_H #define MAPCONNECTION_H diff --git a/include/core/maplayout.h b/include/core/maplayout.h index e44a3646..d04fbab5 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAPLAYOUT_H #define MAPLAYOUT_H diff --git a/include/core/metatile.h b/include/core/metatile.h index 27d515ba..c016ae7c 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -1,3 +1,4 @@ +#pragma once #ifndef METATILE_H #define METATILE_H diff --git a/include/core/metatileparser.h b/include/core/metatileparser.h index 1d423a72..7bf0b096 100644 --- a/include/core/metatileparser.h +++ b/include/core/metatileparser.h @@ -1,3 +1,4 @@ +#pragma once #ifndef METATILEPARSER_H #define METATILEPARSER_H diff --git a/include/core/paletteutil.h b/include/core/paletteutil.h index a067dea3..abc1700a 100644 --- a/include/core/paletteutil.h +++ b/include/core/paletteutil.h @@ -1,3 +1,4 @@ +#pragma once #ifndef PALETTEUTIL_H #define PALETTEUTIL_H diff --git a/include/core/parseutil.h b/include/core/parseutil.h index 22abe367..d3b7ee54 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -1,3 +1,4 @@ +#pragma once #ifndef PARSEUTIL_H #define PARSEUTIL_H diff --git a/include/core/regionmap.h b/include/core/regionmap.h index a8158395..a24ae1ea 100644 --- a/include/core/regionmap.h +++ b/include/core/regionmap.h @@ -1,3 +1,4 @@ +#pragma once #ifndef REGIONMAP_H #define REGIONMAP_H diff --git a/include/core/tile.h b/include/core/tile.h index 05349c4a..e2b1ec4d 100644 --- a/include/core/tile.h +++ b/include/core/tile.h @@ -1,3 +1,4 @@ +#pragma once #ifndef TILE_H #define TILE_H diff --git a/include/core/tileset.h b/include/core/tileset.h index 9113788a..c6349cfe 100644 --- a/include/core/tileset.h +++ b/include/core/tileset.h @@ -1,3 +1,4 @@ +#pragma once #ifndef TILESET_H #define TILESET_H diff --git a/include/core/wildmoninfo.h b/include/core/wildmoninfo.h index f0868f7f..06877622 100644 --- a/include/core/wildmoninfo.h +++ b/include/core/wildmoninfo.h @@ -1,3 +1,4 @@ +#pragma once #ifndef GUARD_WILDMONINFO_H #define GUARD_WILDMONINFO_H diff --git a/include/editor.h b/include/editor.h index fc8cfe26..a24a1bca 100644 --- a/include/editor.h +++ b/include/editor.h @@ -1,3 +1,4 @@ +#pragma once #ifndef EDITOR_H #define EDITOR_H diff --git a/include/lib/orderedjson.h b/include/lib/orderedjson.h index 5f791286..20463cee 100644 --- a/include/lib/orderedjson.h +++ b/include/lib/orderedjson.h @@ -51,6 +51,7 @@ * THE SOFTWARE. */ +#pragma once #ifndef ORDERED_JSON_H #define ORDERED_JSON_H diff --git a/include/lib/orderedmap.h b/include/lib/orderedmap.h index 40fe08b8..40882d9f 100644 --- a/include/lib/orderedmap.h +++ b/include/lib/orderedmap.h @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#pragma once #ifndef TSL_ORDERED_MAP_H #define TSL_ORDERED_MAP_H diff --git a/include/lib/qstringhash.h b/include/lib/qstringhash.h index 10947d6f..a9affaf7 100644 --- a/include/lib/qstringhash.h +++ b/include/lib/qstringhash.h @@ -1,3 +1,4 @@ +#pragma once #ifndef QSTRINGHASH_H #define QSTRINGHASH_H diff --git a/include/log.h b/include/log.h index 87e0ae01..37571dae 100644 --- a/include/log.h +++ b/include/log.h @@ -1,3 +1,4 @@ +#pragma once #ifndef LOG_H #define LOG_H diff --git a/include/mainwindow.h b/include/mainwindow.h index fbb6af6b..bee4222d 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAINWINDOW_H #define MAINWINDOW_H diff --git a/include/project.h b/include/project.h index 179a5a93..fda3ea8f 100644 --- a/include/project.h +++ b/include/project.h @@ -1,3 +1,4 @@ +#pragma once #ifndef PROJECT_H #define PROJECT_H diff --git a/include/scripting.h b/include/scripting.h index 99daac89..6f3b0d16 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -1,3 +1,4 @@ +#pragma once #ifndef SCRIPTING_H #define SCRIPTING_H diff --git a/include/settings.h b/include/settings.h index 5b989ed5..d37283cd 100644 --- a/include/settings.h +++ b/include/settings.h @@ -1,3 +1,4 @@ +#pragma once #ifndef SETTINGS_H #define SETTINGS_H From 19633253f843c54f83e85ab71f23c3fcf521a5d5 Mon Sep 17 00:00:00 2001 From: garakmon Date: Sun, 13 Sep 2020 18:48:03 -0400 Subject: [PATCH 3/4] update objects when adding new event with button, closes #297 --- src/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7b947db3..4bc85bd6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1454,6 +1454,7 @@ void MainWindow::addNewEvent(QString event_type) if (editor && editor->project) { DraggablePixmapItem *object = editor->addNewEvent(event_type); if (object) { + updateObjects(); editor->selectMapEvent(object, false); } else { QMessageBox msgBox(this); From 9c0876e4c0d4a53696396004e8de36f5de5a4292 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Mon, 14 Dec 2020 18:06:38 -0600 Subject: [PATCH 4/4] Fix disabling of UI when failing to open project --- src/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cfb97719..f87d04a5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -465,7 +465,7 @@ bool MainWindow::openRecentProject() { return openProject(default_dir); } - return true; + return false; } bool MainWindow::openProject(QString dir) {