add of save function with default value
This commit is contained in:
parent
730d0850f3
commit
4fe0884432
@ -5,6 +5,13 @@
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
@ -58,6 +65,7 @@ void MainWindow::loadPath()
|
||||
ui->lengthSpin->setValue(p->getLength());
|
||||
ui->durationSpin->setValue(p->getDuration());
|
||||
ui->imagePath->setText(p->getImage());
|
||||
ui->depSpin->setValue(p->getDepartement());
|
||||
|
||||
loadImage(p->getImage());
|
||||
}
|
||||
@ -131,3 +139,55 @@ void MainWindow::on_toolButton_clicked()
|
||||
loadImage(fileName);
|
||||
}
|
||||
|
||||
void MainWindow::saveFile(){
|
||||
QString fileName;
|
||||
if (currentFile.isEmpty()) {
|
||||
fileName = QFileDialog::getSaveFileName(this, "Save");
|
||||
currentFile = fileName;
|
||||
} else {
|
||||
fileName = currentFile;
|
||||
}
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
||||
return;
|
||||
}
|
||||
setWindowTitle(fileName);
|
||||
QJsonObject json;
|
||||
json["name"] = ui->titleEdit->text();
|
||||
json["city"] =ui->locEdit->text();
|
||||
json["departement"] = ui->depSpin->text();
|
||||
json["difficulty"] = ui->diffSpin->value();
|
||||
json["duration"] = ui->durationSpin->value();
|
||||
json["length"] = ui->lengthSpin->value();
|
||||
json["image"] = ui->imagePath->text();
|
||||
|
||||
|
||||
QJsonArray steps;
|
||||
QJsonObject step1;
|
||||
step1["numero"] = "3";
|
||||
step1["title"] = "ok ca marche";
|
||||
step1["GPS"] = "S 45 37.199 E 1 2.009";
|
||||
step1["reponse"] = "34";
|
||||
|
||||
QJsonArray dialogues;
|
||||
QJsonObject dialogue1;
|
||||
dialogue1["personnage"] = "Quentin";
|
||||
dialogue1["texte"] = "ok c'est cool";
|
||||
|
||||
dialogues.append(dialogue1);
|
||||
step1["dialogue"] = dialogues;
|
||||
steps.append(step1);
|
||||
json["steps"] = steps;
|
||||
|
||||
QJsonDocument doc(json);
|
||||
file.write(doc.toJson());
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionSave_triggered()
|
||||
{
|
||||
this->saveFile();
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ public:
|
||||
void addNewPath();
|
||||
void addNewStep();
|
||||
void exportHTMLMap();
|
||||
void saveFile();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
@ -33,6 +34,8 @@ private slots:
|
||||
|
||||
void on_toolButton_clicked();
|
||||
|
||||
void on_actionSave_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QString currentFile;
|
||||
|
||||
@ -38,9 +38,6 @@
|
||||
<property name="text">
|
||||
<string>Path information</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -52,10 +49,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="geometry">
|
||||
@ -104,7 +98,11 @@
|
||||
<widget class="QLineEdit" name="locEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_2"/>
|
||||
<widget class="QSpinBox" name="depSpin">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -120,6 +118,9 @@
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="widget_5" native="true">
|
||||
<property name="geometry">
|
||||
@ -249,7 +250,7 @@
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/add.png</normaloff>:/data/images/data/images/add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@ -276,18 +277,12 @@
|
||||
<property name="text">
|
||||
<string>Step information</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -299,7 +294,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>23</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@ -368,127 +363,127 @@
|
||||
</action>
|
||||
<action name="actionNewFile">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/new.png</normaloff>:/data/images/data/images/new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>NewFile</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveFile">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/save_as.png</normaloff>:/data/images/data/images/save_as.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SaveFile</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveAsFile">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/save.png</normaloff>:/data/images/data/images/save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SaveAsFile</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPrintFile">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/print.png</normaloff>:/data/images/data/images/print.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PrintFile</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditCopy">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/copy.png</normaloff>:/data/images/data/images/copy.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditCopy</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditPaste">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/paste.png</normaloff>:/data/images/data/images/paste.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditPaste</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditCut">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/cut.png</normaloff>:/data/images/data/images/cut.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditCut</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditUndo">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/edit_undo.png</normaloff>:/data/images/data/images/edit_undo.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditUndo</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditRedo">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/edit_redo.png</normaloff>:/data/images/data/images/edit_redo.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditRedo</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNew">
|
||||
<property name="icon">
|
||||
<iconset resource="build/Desktop_Qt_6_9_1-Debug/data.qrc">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/new.png</normaloff>:/data/images/data/images/new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="build/Desktop_Qt_6_9_1-Debug/data.qrc"/>
|
||||
<include location="data.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user