Merge pull request #302 from garakmon/fix827

Should Fix Project Open?
This commit is contained in:
huderlem 2020-12-14 18:16:33 -06:00 committed by GitHub
commit 53b9fa5dc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 63 additions and 26 deletions

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef CONFIG_H
#define CONFIG_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef BLOCK_H
#define BLOCK_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef BLOCKDATA_H
#define BLOCKDATA_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef EDITCOMMANDS_H
#define EDITCOMMANDS_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef EVENT_H
#define EVENT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef HEALLOCATION_H
#define HEALLOCATION_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef HISTORY_H
#define HISTORY_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef IMAGEEXPORT_H
#define IMAGEEXPORT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAP_H
#define MAP_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAPCONNECTION_H
#define MAPCONNECTION_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAPLAYOUT_H
#define MAPLAYOUT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef METATILE_H
#define METATILE_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef METATILEPARSER_H
#define METATILEPARSER_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef PALETTEUTIL_H
#define PALETTEUTIL_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef PARSEUTIL_H
#define PARSEUTIL_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef REGIONMAP_H
#define REGIONMAP_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef TILE_H
#define TILE_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef TILESET_H
#define TILESET_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef GUARD_WILDMONINFO_H
#define GUARD_WILDMONINFO_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef EDITOR_H
#define EDITOR_H

View file

@ -52,6 +52,8 @@
*/
#pragma once
#ifndef ORDERED_JSON_H
#define ORDERED_JSON_H
#include <QString>
#include <QVector>
@ -240,3 +242,4 @@ protected:
} // namespace poryjson
#endif // ORDERED_JSON_H

View file

@ -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

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef QSTRINGHASH_H
#define QSTRINGHASH_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef LOG_H
#define LOG_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
@ -271,6 +272,7 @@ private:
bool isProgrammaticEventTabChange;
bool projectHasUnsavedChanges;
bool projectOpenFailure = false;
MapSortOrder mapSortOrder;

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef PROJECT_H
#define PROJECT_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef SCRIPTING_H
#define SCRIPTING_H

View file

@ -1,3 +1,4 @@
#pragma once
#ifndef SETTINGS_H
#define SETTINGS_H

View file

@ -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()
@ -173,6 +174,7 @@ void MainWindow::applyUserShortcuts() {
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");
@ -180,12 +182,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<int>::of(&QComboBox::currentIndexChanged), [=](int index){
@ -217,11 +226,6 @@ void MainWindow::initCustomUI() {
label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse);
}
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()));
@ -461,11 +465,12 @@ bool MainWindow::openRecentProject() {
return openProject(default_dir);
}
return true;
return false;
}
bool MainWindow::openProject(QString dir) {
if (dir.isNull()) {
projectOpenFailure = true;
return false;
}
@ -522,13 +527,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() {
@ -572,9 +576,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));
}
}
@ -1556,6 +1558,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);
@ -2827,19 +2830,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(