add some destructors, prevent value set on combobox update
- add destructors to Project and Editor - properly close project when opening a new one - when reloading comboboxes, do not set map values with the new first item
This commit is contained in:
parent
91f8db10a5
commit
c0bffa0107
7 changed files with 101 additions and 36 deletions
|
@ -31,6 +31,12 @@ class Editor : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Editor(Ui::MainWindow* ui);
|
Editor(Ui::MainWindow* ui);
|
||||||
|
~Editor();
|
||||||
|
|
||||||
|
Editor() = delete;
|
||||||
|
Editor(const Editor &) = delete;
|
||||||
|
Editor & operator = (const Editor &) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
QObject *parent = nullptr;
|
QObject *parent = nullptr;
|
||||||
|
|
|
@ -30,9 +30,13 @@ class MainWindow : public QMainWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
MainWindow() = delete;
|
||||||
|
MainWindow(const MainWindow &) = delete;
|
||||||
|
MainWindow & operator = (const MainWindow &) = delete;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void scaleMapView(int);
|
void scaleMapView(int);
|
||||||
|
|
||||||
|
@ -188,6 +192,7 @@ private:
|
||||||
bool setMap(QString, bool scrollTreeView = false);
|
bool setMap(QString, bool scrollTreeView = false);
|
||||||
void redrawMapScene();
|
void redrawMapScene();
|
||||||
bool loadDataStructures();
|
bool loadDataStructures();
|
||||||
|
bool loadProjectCombos();
|
||||||
bool populateMapList();
|
bool populateMapList();
|
||||||
void sortMapList();
|
void sortMapList();
|
||||||
QString getExistingDirectory(QString);
|
QString getExistingDirectory(QString);
|
||||||
|
|
|
@ -23,9 +23,15 @@ class Project
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Project();
|
Project();
|
||||||
|
~Project();
|
||||||
|
|
||||||
|
Project(const Project &) = delete;
|
||||||
|
Project & operator = (const Project &) = delete;
|
||||||
|
|
||||||
|
public:
|
||||||
QString root;
|
QString root;
|
||||||
QStringList *groupNames = nullptr;
|
QStringList *groupNames = nullptr;
|
||||||
QMap<QString, int> *map_groups;
|
QMap<QString, int> *mapGroups;
|
||||||
QList<QStringList> groupedMapNames;
|
QList<QStringList> groupedMapNames;
|
||||||
QStringList *mapNames = nullptr;
|
QStringList *mapNames = nullptr;
|
||||||
QMap<QString, QVariant> miscConstants;
|
QMap<QString, QVariant> miscConstants;
|
||||||
|
@ -66,11 +72,11 @@ public:
|
||||||
DataQualifiers getDataQualifiers(QString, QString);
|
DataQualifiers getDataQualifiers(QString, QString);
|
||||||
QMap<QString, DataQualifiers> dataQualifiers;
|
QMap<QString, DataQualifiers> dataQualifiers;
|
||||||
|
|
||||||
QMap<QString, Map*> *map_cache;
|
QMap<QString, Map*> *mapCache;
|
||||||
Map* loadMap(QString);
|
Map* loadMap(QString);
|
||||||
Map* getMap(QString);
|
Map* getMap(QString);
|
||||||
|
|
||||||
QMap<QString, Tileset*> *tileset_cache = nullptr;
|
QMap<QString, Tileset*> *tilesetCache = nullptr;
|
||||||
Tileset* loadTileset(QString, Tileset *tileset = nullptr);
|
Tileset* loadTileset(QString, Tileset *tileset = nullptr);
|
||||||
Tileset* getTileset(QString, bool forceLoad = false);
|
Tileset* getTileset(QString, bool forceLoad = false);
|
||||||
QMap<QString, QStringList> tilesetLabels;
|
QMap<QString, QStringList> tilesetLabels;
|
||||||
|
|
|
@ -23,6 +23,14 @@ Editor::Editor(Ui::MainWindow* ui)
|
||||||
this->cursorMapTileRect = new CursorTileRect(&this->settings->cursorTileRectEnabled, qRgb(255, 255, 255));
|
this->cursorMapTileRect = new CursorTileRect(&this->settings->cursorTileRectEnabled, qRgb(255, 255, 255));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Editor::~Editor()
|
||||||
|
{
|
||||||
|
delete this->selected_events;
|
||||||
|
delete this->settings;
|
||||||
|
delete this->playerViewRect;
|
||||||
|
delete this->cursorMapTileRect;
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::saveProject() {
|
void Editor::saveProject() {
|
||||||
if (project) {
|
if (project) {
|
||||||
saveUiFields();
|
saveUiFields();
|
||||||
|
|
|
@ -5,7 +5,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
a.setStyle("fusion");
|
a.setStyle("fusion");
|
||||||
MainWindow w;
|
MainWindow w(nullptr);
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMatrix>
|
#include <QMatrix>
|
||||||
|
#include <QSignalBlocker>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
|
@ -298,13 +299,14 @@ bool MainWindow::openProject(QString dir) {
|
||||||
|
|
||||||
bool already_open = isProjectOpen() && (editor->project->root == dir);
|
bool already_open = isProjectOpen() && (editor->project->root == dir);
|
||||||
if (!already_open) {
|
if (!already_open) {
|
||||||
|
editor->closeProject();
|
||||||
editor->project = new Project;
|
editor->project = new Project;
|
||||||
editor->project->set_root(dir);
|
editor->project->set_root(dir);
|
||||||
success = loadDataStructures()
|
success = loadDataStructures()
|
||||||
&& populateMapList()
|
&& populateMapList()
|
||||||
&& setMap(getDefaultMap(), true);
|
&& setMap(getDefaultMap(), true);
|
||||||
} else {
|
} else {
|
||||||
success = loadDataStructures() && populateMapList();
|
success = loadDataStructures() && populateMapList() && setMap(editor->map->name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -658,14 +660,25 @@ bool MainWindow::loadDataStructures() {
|
||||||
success = success
|
success = success
|
||||||
&& project->readSecretBaseIds()
|
&& project->readSecretBaseIds()
|
||||||
&& project->readCoordEventWeatherNames();
|
&& project->readCoordEventWeatherNames();
|
||||||
if (!success) {
|
|
||||||
return false;
|
return success && loadProjectCombos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MainWindow::loadProjectCombos() {
|
||||||
// set up project ui comboboxes
|
// set up project ui comboboxes
|
||||||
QStringList songs = project->getSongNames();
|
Project *project = editor->project;
|
||||||
|
|
||||||
|
// Block signals to the comboboxes while they are being modified
|
||||||
|
const QSignalBlocker blocker1(ui->comboBox_Song);
|
||||||
|
const QSignalBlocker blocker2(ui->comboBox_Location);
|
||||||
|
const QSignalBlocker blocker3(ui->comboBox_PrimaryTileset);
|
||||||
|
const QSignalBlocker blocker4(ui->comboBox_SecondaryTileset);
|
||||||
|
const QSignalBlocker blocker5(ui->comboBox_Weather);
|
||||||
|
const QSignalBlocker blocker6(ui->comboBox_BattleScene);
|
||||||
|
const QSignalBlocker blocker7(ui->comboBox_Type);
|
||||||
|
|
||||||
ui->comboBox_Song->clear();
|
ui->comboBox_Song->clear();
|
||||||
ui->comboBox_Song->addItems(songs);
|
ui->comboBox_Song->addItems(project->getSongNames());
|
||||||
ui->comboBox_Location->clear();
|
ui->comboBox_Location->clear();
|
||||||
ui->comboBox_Location->addItems(project->mapSectionValueToName.values());
|
ui->comboBox_Location->addItems(project->mapSectionValueToName.values());
|
||||||
|
|
||||||
|
@ -673,6 +686,7 @@ bool MainWindow::loadDataStructures() {
|
||||||
if (tilesets.isEmpty()) {
|
if (tilesets.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->comboBox_PrimaryTileset->clear();
|
ui->comboBox_PrimaryTileset->clear();
|
||||||
ui->comboBox_PrimaryTileset->addItems(tilesets.value("primary"));
|
ui->comboBox_PrimaryTileset->addItems(tilesets.value("primary"));
|
||||||
ui->comboBox_SecondaryTileset->clear();
|
ui->comboBox_SecondaryTileset->clear();
|
||||||
|
@ -683,6 +697,7 @@ bool MainWindow::loadDataStructures() {
|
||||||
ui->comboBox_BattleScene->addItems(*project->mapBattleScenes);
|
ui->comboBox_BattleScene->addItems(*project->mapBattleScenes);
|
||||||
ui->comboBox_Type->clear();
|
ui->comboBox_Type->clear();
|
||||||
ui->comboBox_Type->addItems(*project->mapTypes);
|
ui->comboBox_Type->addItems(*project->mapTypes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1099,10 +1114,10 @@ void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
|
||||||
QVariant data = index.data(Qt::UserRole);
|
QVariant data = index.data(Qt::UserRole);
|
||||||
if (!data.isNull()) {
|
if (!data.isNull()) {
|
||||||
QString map_name = data.toString();
|
QString map_name = data.toString();
|
||||||
if (editor->project && editor->project->map_cache->contains(map_name)) {
|
if (editor->project && editor->project->mapCache->contains(map_name)) {
|
||||||
QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name));
|
QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name));
|
||||||
map->setIcon(*mapIcon);
|
map->setIcon(*mapIcon);
|
||||||
if (editor->project->map_cache->value(map_name)->hasUnsavedChanges()) {
|
if (editor->project->mapCache->value(map_name)->hasUnsavedChanges()) {
|
||||||
map->setIcon(*mapEditedIcon);
|
map->setIcon(*mapEditedIcon);
|
||||||
projectHasUnsavedChanges = true;
|
projectHasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ int Project::num_pals_total = 13;
|
||||||
Project::Project()
|
Project::Project()
|
||||||
{
|
{
|
||||||
groupNames = new QStringList;
|
groupNames = new QStringList;
|
||||||
map_groups = new QMap<QString, int>;
|
mapGroups = new QMap<QString, int>;
|
||||||
mapNames = new QStringList;
|
mapNames = new QStringList;
|
||||||
itemNames = new QStringList;
|
itemNames = new QStringList;
|
||||||
flagNames = new QStringList;
|
flagNames = new QStringList;
|
||||||
|
@ -50,10 +50,35 @@ Project::Project()
|
||||||
secretBaseIds = new QStringList;
|
secretBaseIds = new QStringList;
|
||||||
bgEventFacingDirections = new QStringList;
|
bgEventFacingDirections = new QStringList;
|
||||||
trainerTypes = new QStringList;
|
trainerTypes = new QStringList;
|
||||||
map_cache = new QMap<QString, Map*>;
|
mapCache = new QMap<QString, Map*>;
|
||||||
mapConstantsToMapNames = new QMap<QString, QString>;
|
mapConstantsToMapNames = new QMap<QString, QString>;
|
||||||
mapNamesToMapConstants = new QMap<QString, QString>;
|
mapNamesToMapConstants = new QMap<QString, QString>;
|
||||||
tileset_cache = new QMap<QString, Tileset*>;
|
tilesetCache = new QMap<QString, Tileset*>;
|
||||||
|
}
|
||||||
|
|
||||||
|
Project::~Project()
|
||||||
|
{
|
||||||
|
delete this->groupNames;
|
||||||
|
delete this->mapGroups;
|
||||||
|
delete this->mapNames;
|
||||||
|
delete this->itemNames;
|
||||||
|
delete this->flagNames;
|
||||||
|
delete this->varNames;
|
||||||
|
delete this->weatherNames;
|
||||||
|
delete this->coordEventWeatherNames;
|
||||||
|
|
||||||
|
delete this->secretBaseIds;
|
||||||
|
delete this->movementTypes;
|
||||||
|
delete this->bgEventFacingDirections;
|
||||||
|
delete this->mapBattleScenes;
|
||||||
|
delete this->trainerTypes;
|
||||||
|
delete this->mapTypes;
|
||||||
|
|
||||||
|
delete this->mapConstantsToMapNames;
|
||||||
|
delete this->mapNamesToMapConstants;
|
||||||
|
|
||||||
|
delete this->mapCache;
|
||||||
|
delete this->tilesetCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::set_root(QString dir) {
|
void Project::set_root(QString dir) {
|
||||||
|
@ -71,8 +96,8 @@ QString Project::getProjectTitle() {
|
||||||
|
|
||||||
Map* Project::loadMap(QString map_name) {
|
Map* Project::loadMap(QString map_name) {
|
||||||
Map *map;
|
Map *map;
|
||||||
if (map_cache->contains(map_name)) {
|
if (mapCache->contains(map_name)) {
|
||||||
map = map_cache->value(map_name);
|
map = mapCache->value(map_name);
|
||||||
// TODO: uncomment when undo/redo history is fully implemented for all actions.
|
// TODO: uncomment when undo/redo history is fully implemented for all actions.
|
||||||
if (true/*map->hasUnsavedChanges()*/) {
|
if (true/*map->hasUnsavedChanges()*/) {
|
||||||
return map;
|
return map;
|
||||||
|
@ -87,7 +112,7 @@ Map* Project::loadMap(QString map_name) {
|
||||||
|
|
||||||
map->commit();
|
map->commit();
|
||||||
map->metatileHistory.save();
|
map->metatileHistory.save();
|
||||||
map_cache->insert(map_name, map);
|
mapCache->insert(map_name, map);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +415,8 @@ bool Project::loadMapData(Map* map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::readMapLayoutId(QString map_name) {
|
QString Project::readMapLayoutId(QString map_name) {
|
||||||
if (map_cache->contains(map_name)) {
|
if (mapCache->contains(map_name)) {
|
||||||
return map_cache->value(map_name)->layoutId;
|
return mapCache->value(map_name)->layoutId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name);
|
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name);
|
||||||
|
@ -406,8 +431,8 @@ QString Project::readMapLayoutId(QString map_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::readMapLocation(QString map_name) {
|
QString Project::readMapLocation(QString map_name) {
|
||||||
if (map_cache->contains(map_name)) {
|
if (mapCache->contains(map_name)) {
|
||||||
return map_cache->value(map_name)->location;
|
return mapCache->value(map_name)->location;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name);
|
QString mapFilepath = QString("%1/data/maps/%2/map.json").arg(root).arg(map_name);
|
||||||
|
@ -1109,7 +1134,7 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) {
|
||||||
|
|
||||||
loadTilesetAssets(tileset);
|
loadTilesetAssets(tileset);
|
||||||
|
|
||||||
tileset_cache->insert(label, tileset);
|
tilesetCache->insert(label, tileset);
|
||||||
return tileset;
|
return tileset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1199,10 +1224,10 @@ void Project::writeBlockdata(QString path, Blockdata *blockdata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::saveAllMaps() {
|
void Project::saveAllMaps() {
|
||||||
QList<QString> keys = map_cache->keys();
|
QList<QString> keys = mapCache->keys();
|
||||||
for (int i = 0; i < keys.length(); i++) {
|
for (int i = 0; i < keys.length(); i++) {
|
||||||
QString key = keys.value(i);
|
QString key = keys.value(i);
|
||||||
Map* map = map_cache->value(key);
|
Map* map = mapCache->value(key);
|
||||||
saveMap(map);
|
saveMap(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1640,8 +1665,8 @@ Blockdata* Project::readBlockdata(QString path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map* Project::getMap(QString map_name) {
|
Map* Project::getMap(QString map_name) {
|
||||||
if (map_cache->contains(map_name)) {
|
if (mapCache->contains(map_name)) {
|
||||||
return map_cache->value(map_name);
|
return mapCache->value(map_name);
|
||||||
} else {
|
} else {
|
||||||
Map *map = loadMap(map_name);
|
Map *map = loadMap(map_name);
|
||||||
return map;
|
return map;
|
||||||
|
@ -1650,12 +1675,12 @@ Map* Project::getMap(QString map_name) {
|
||||||
|
|
||||||
Tileset* Project::getTileset(QString label, bool forceLoad) {
|
Tileset* Project::getTileset(QString label, bool forceLoad) {
|
||||||
Tileset *existingTileset = nullptr;
|
Tileset *existingTileset = nullptr;
|
||||||
if (tileset_cache->contains(label)) {
|
if (tilesetCache->contains(label)) {
|
||||||
existingTileset = tileset_cache->value(label);
|
existingTileset = tilesetCache->value(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingTileset && !forceLoad) {
|
if (existingTileset && !forceLoad) {
|
||||||
return tileset_cache->value(label);
|
return tilesetCache->value(label);
|
||||||
} else {
|
} else {
|
||||||
Tileset *tileset = loadTileset(label, existingTileset);
|
Tileset *tileset = loadTileset(label, existingTileset);
|
||||||
return tileset;
|
return tileset;
|
||||||
|
@ -1762,7 +1787,7 @@ bool Project::readWildMonData() {
|
||||||
bool Project::readMapGroups() {
|
bool Project::readMapGroups() {
|
||||||
mapConstantsToMapNames->clear();
|
mapConstantsToMapNames->clear();
|
||||||
mapNamesToMapConstants->clear();
|
mapNamesToMapConstants->clear();
|
||||||
map_groups->clear();
|
mapGroups->clear();
|
||||||
|
|
||||||
QString mapGroupsFilepath = QString("%1/data/maps/map_groups.json").arg(root);
|
QString mapGroupsFilepath = QString("%1/data/maps/map_groups.json").arg(root);
|
||||||
QJsonDocument mapGroupsDoc;
|
QJsonDocument mapGroupsDoc;
|
||||||
|
@ -1784,7 +1809,7 @@ bool Project::readMapGroups() {
|
||||||
groups->append(groupName);
|
groups->append(groupName);
|
||||||
for (int j = 0; j < mapNames.size(); j++) {
|
for (int j = 0; j < mapNames.size(); j++) {
|
||||||
QString mapName = mapNames.at(j).toString();
|
QString mapName = mapNames.at(j).toString();
|
||||||
map_groups->insert(mapName, groupIndex);
|
mapGroups->insert(mapName, groupIndex);
|
||||||
groupedMaps[groupIndex].append(mapName);
|
groupedMaps[groupIndex].append(mapName);
|
||||||
maps->append(mapName);
|
maps->append(mapName);
|
||||||
|
|
||||||
|
@ -1808,7 +1833,7 @@ bool Project::readMapGroups() {
|
||||||
Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
// Setup new map in memory, but don't write to file until map is actually saved later.
|
// Setup new map in memory, but don't write to file until map is actually saved later.
|
||||||
mapNames->append(mapName);
|
mapNames->append(mapName);
|
||||||
map_groups->insert(mapName, groupNum);
|
mapGroups->insert(mapName, groupNum);
|
||||||
groupedMapNames[groupNum].append(mapName);
|
groupedMapNames[groupNum].append(mapName);
|
||||||
|
|
||||||
Map *map = new Map;
|
Map *map = new Map;
|
||||||
|
@ -1825,14 +1850,14 @@ Map* Project::addNewMapToGroup(QString mapName, int groupNum) {
|
||||||
setNewMapConnections(map);
|
setNewMapConnections(map);
|
||||||
map->commit();
|
map->commit();
|
||||||
map->metatileHistory.save();
|
map->metatileHistory.save();
|
||||||
map_cache->insert(mapName, map);
|
mapCache->insert(mapName, map);
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool existingLayout) {
|
Map* Project::addNewMapToGroup(QString mapName, int groupNum, Map *newMap, bool existingLayout) {
|
||||||
mapNames->append(mapName);
|
mapNames->append(mapName);
|
||||||
map_groups->insert(mapName, groupNum);
|
mapGroups->insert(mapName, groupNum);
|
||||||
groupedMapNames[groupNum].append(mapName);
|
groupedMapNames[groupNum].append(mapName);
|
||||||
|
|
||||||
Map *map = new Map;
|
Map *map = new Map;
|
||||||
|
|
Loading…
Reference in a new issue