add File>Reload Project

This commit is contained in:
garakmon 2020-04-07 20:25:09 -04:00
parent ca5a0247f7
commit 6026266afd
5 changed files with 46 additions and 4 deletions

View file

@ -561,7 +561,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>545</width> <width>542</width>
<height>628</height> <height>628</height>
</rect> </rect>
</property> </property>
@ -767,7 +767,7 @@
<rect> <rect>
<x>8</x> <x>8</x>
<y>0</y> <y>0</y>
<width>221</width> <width>224</width>
<height>324</height> <height>324</height>
</rect> </rect>
</property> </property>
@ -1118,7 +1118,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>231</width> <width>234</width>
<height>83</height> <height>83</height>
</rect> </rect>
</property> </property>
@ -2886,6 +2886,7 @@
<string>File</string> <string>File</string>
</property> </property>
<addaction name="action_Open_Project"/> <addaction name="action_Open_Project"/>
<addaction name="action_Reload_Project"/>
<addaction name="action_Save"/> <addaction name="action_Save"/>
<addaction name="action_Save_Project"/> <addaction name="action_Save_Project"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -3172,6 +3173,11 @@
<string>Themes...</string> <string>Themes...</string>
</property> </property>
</action> </action>
<action name="action_Reload_Project">
<property name="text">
<string>Reload Project</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>

View file

@ -42,6 +42,7 @@ public slots:
private slots: private slots:
void on_action_Open_Project_triggered(); void on_action_Open_Project_triggered();
void on_action_Reload_Project_triggered();
void on_mapList_activated(const QModelIndex &index); void on_mapList_activated(const QModelIndex &index);
void on_action_Save_Project_triggered(); void on_action_Save_Project_triggered();
void openWarpMap(QString map_name, QString warp_num); void openWarpMap(QString map_name, QString warp_num);

View file

@ -64,6 +64,9 @@ public:
void set_root(QString); void set_root(QString);
void clearMapCache();
void clearTilesetCache();
struct DataQualifiers struct DataQualifiers
{ {
bool isStatic; bool isStatic;

View file

@ -306,7 +306,10 @@ bool MainWindow::openProject(QString dir) {
&& populateMapList() && populateMapList()
&& setMap(getDefaultMap(), true); && setMap(getDefaultMap(), true);
} else { } else {
success = loadDataStructures() && populateMapList() && setMap(editor->map->name, true); QString open_map = editor->map->name;
editor->project->clearMapCache();
editor->project->clearTilesetCache();
success = loadDataStructures() && populateMapList() && setMap(open_map, true);
} }
if (success) { if (success) {
@ -373,6 +376,19 @@ void MainWindow::on_action_Open_Project_triggered()
} }
} }
void MainWindow::on_action_Reload_Project_triggered() {
// TODO: when undo history is complete show only if has unsaved changes
QMessageBox warning(this);
warning.setText("WARNING");
warning.setInformativeText("Reloading this project will discard any unsaved changes.");
warning.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
warning.setIcon(QMessageBox::Warning);
if (warning.exec() == QMessageBox::Ok) {
openProject(editor->project->root);
}
}
bool MainWindow::setMap(QString map_name, bool scrollTreeView) { bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
logInfo(QString("Setting map to '%1'").arg(map_name)); logInfo(QString("Setting map to '%1'").arg(map_name));
if (map_name.isEmpty()) { if (map_name.isEmpty()) {

View file

@ -77,7 +77,9 @@ Project::~Project()
delete this->mapConstantsToMapNames; delete this->mapConstantsToMapNames;
delete this->mapNamesToMapConstants; delete this->mapNamesToMapConstants;
clearMapCache();
delete this->mapCache; delete this->mapCache;
clearTilesetCache();
delete this->tilesetCache; delete this->tilesetCache;
} }
@ -94,6 +96,20 @@ QString Project::getProjectTitle() {
} }
} }
void Project::clearMapCache() {
for (QString mapName : mapCache->keys()) {
Map *map = mapCache->take(mapName);
if (map) delete map;
}
}
void Project::clearTilesetCache() {
for (QString tilesetName : tilesetCache->keys()) {
Tileset *tileset = tilesetCache->take(tilesetName);
if (tileset) delete tileset;
}
}
Map* Project::loadMap(QString map_name) { Map* Project::loadMap(QString map_name) {
Map *map; Map *map;
if (mapCache->contains(map_name)) { if (mapCache->contains(map_name)) {