closeProject() (#34 & #35)

This commit is contained in:
garak 2018-09-20 00:45:11 -04:00
parent d7641b4e9f
commit 20b1836ced
3 changed files with 44 additions and 17 deletions

View file

@ -54,9 +54,16 @@ MainWindow::MainWindow(QWidget *parent) :
if (settings.contains(key)) { if (settings.contains(key)) {
QString default_dir = settings.value(key).toStringList().last(); QString default_dir = settings.value(key).toStringList().last();
if (!default_dir.isNull()) { if (!default_dir.isNull()) {
QDir dir(default_dir);
if (dir.exists()) {
qDebug() << QString("default_dir: '%1'").arg(default_dir); qDebug() << QString("default_dir: '%1'").arg(default_dir);
openProject(default_dir); openProject(default_dir);
} }
else {
qDebug() << "No project found at" << default_dir;
closeProject();
}
}
} }
if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") { if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") {
@ -101,6 +108,12 @@ void MainWindow::openProject(QString dir) {
setStatusBarMessage(QString("Opened project %1").arg(dir)); setStatusBarMessage(QString("Opened project %1").arg(dir));
} }
void MainWindow::closeProject() {
QSettings settings;
settings.remove("recent_projects");
//ui->setupUi(this);
}
QString MainWindow::getDefaultMap() { QString MainWindow::getDefaultMap() {
if (editor && editor->project) { if (editor && editor->project) {
QList<QStringList> names = editor->project->groupedMapNames; QList<QStringList> names = editor->project->groupedMapNames;
@ -156,6 +169,12 @@ void MainWindow::on_action_Open_Project_triggered()
} }
} }
void MainWindow::on_action_Close_Project_triggered()
{
closeProject();
QApplication::quit();
}
void MainWindow::setMap(QString map_name) { void MainWindow::setMap(QString map_name) {
// if clicking on map group, open first map in group // if clicking on map group, open first map in group
if (map_name.startsWith("gMapGroup")) { if (map_name.startsWith("gMapGroup")) {

View file

@ -30,6 +30,7 @@ public slots:
private slots: private slots:
void on_action_Open_Project_triggered(); void on_action_Open_Project_triggered();
void on_action_Close_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);
@ -133,6 +134,7 @@ private:
void populateMapList(); void populateMapList();
QString getExistingDirectory(QString); QString getExistingDirectory(QString);
void openProject(QString dir); void openProject(QString dir);
void closeProject();
QString getDefaultMap(); QString getDefaultMap();
void setRecentMap(QString map_name); void setRecentMap(QString map_name);
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum); QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);

View file

@ -378,8 +378,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>469</width> <width>545</width>
<height>608</height> <height>587</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
@ -687,8 +687,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>324</width> <width>256</width>
<height>77</height> <height>74</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
@ -797,10 +797,10 @@
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>8</x>
<y>0</y> <y>0</y>
<width>307</width> <width>222</width>
<height>387</height> <height>353</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -1116,8 +1116,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>381</width> <width>371</width>
<height>657</height> <height>643</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
@ -1294,8 +1294,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>432</width> <width>428</width>
<height>596</height> <height>578</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -1914,8 +1914,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>826</width> <width>818</width>
<height>557</height> <height>539</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_14"> <layout class="QGridLayout" name="gridLayout_14">
@ -2087,7 +2087,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1117</width> <width>1117</width>
<height>21</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -2095,6 +2095,7 @@
<string>File</string> <string>File</string>
</property> </property>
<addaction name="action_Open_Project"/> <addaction name="action_Open_Project"/>
<addaction name="action_Close_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"/>
@ -2268,6 +2269,11 @@
<string>P</string> <string>P</string>
</property> </property>
</action> </action>
<action name="action_Close_Project">
<property name="text">
<string>Close Project</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets> <customwidgets>