add of save function with default value
This commit is contained in:
parent
730d0850f3
commit
4fe0884432
@ -5,6 +5,13 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
@ -58,6 +65,7 @@ void MainWindow::loadPath()
|
|||||||
ui->lengthSpin->setValue(p->getLength());
|
ui->lengthSpin->setValue(p->getLength());
|
||||||
ui->durationSpin->setValue(p->getDuration());
|
ui->durationSpin->setValue(p->getDuration());
|
||||||
ui->imagePath->setText(p->getImage());
|
ui->imagePath->setText(p->getImage());
|
||||||
|
ui->depSpin->setValue(p->getDepartement());
|
||||||
|
|
||||||
loadImage(p->getImage());
|
loadImage(p->getImage());
|
||||||
}
|
}
|
||||||
@ -131,3 +139,55 @@ void MainWindow::on_toolButton_clicked()
|
|||||||
loadImage(fileName);
|
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 addNewPath();
|
||||||
void addNewStep();
|
void addNewStep();
|
||||||
void exportHTMLMap();
|
void exportHTMLMap();
|
||||||
|
void saveFile();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_pushButton_clicked();
|
||||||
@ -33,6 +34,8 @@ private slots:
|
|||||||
|
|
||||||
void on_toolButton_clicked();
|
void on_toolButton_clicked();
|
||||||
|
|
||||||
|
void on_actionSave_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QString currentFile;
|
QString currentFile;
|
||||||
|
|||||||
@ -38,9 +38,6 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Path information</string>
|
<string>Path information</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -52,10 +49,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::Shape::StyledPanel</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Shadow::Raised</enum>
|
|
||||||
</property>
|
</property>
|
||||||
<widget class="QSpinBox" name="spinBox">
|
<widget class="QSpinBox" name="spinBox">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -104,7 +98,11 @@
|
|||||||
<widget class="QLineEdit" name="locEdit"/>
|
<widget class="QLineEdit" name="locEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="spinBox_2"/>
|
<widget class="QSpinBox" name="depSpin">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -120,6 +118,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="scaledContents">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="widget_5" native="true">
|
<widget class="QWidget" name="widget_5" native="true">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -249,7 +250,7 @@
|
|||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/add.png</normaloff>:/data/images/data/images/add.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -276,18 +277,12 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Step information</string>
|
<string>Step information</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QFrame" name="frame_2">
|
<widget class="QFrame" name="frame_2">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::Shape::StyledPanel</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Shadow::Raised</enum>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -299,7 +294,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>23</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
@ -368,127 +363,127 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionNewFile">
|
<action name="actionNewFile">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/new.png</normaloff>:/data/images/data/images/new.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>NewFile</string>
|
<string>NewFile</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSaveFile">
|
<action name="actionSaveFile">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/save_as.png</normaloff>:/data/images/data/images/save_as.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>SaveFile</string>
|
<string>SaveFile</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSaveAsFile">
|
<action name="actionSaveAsFile">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/save.png</normaloff>:/data/images/data/images/save.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>SaveAsFile</string>
|
<string>SaveAsFile</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionPrintFile">
|
<action name="actionPrintFile">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/print.png</normaloff>:/data/images/data/images/print.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>PrintFile</string>
|
<string>PrintFile</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditCopy">
|
<action name="actionEditCopy">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/copy.png</normaloff>:/data/images/data/images/copy.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>EditCopy</string>
|
<string>EditCopy</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditPaste">
|
<action name="actionEditPaste">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/paste.png</normaloff>:/data/images/data/images/paste.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>EditPaste</string>
|
<string>EditPaste</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditCut">
|
<action name="actionEditCut">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/cut.png</normaloff>:/data/images/data/images/cut.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>EditCut</string>
|
<string>EditCut</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditUndo">
|
<action name="actionEditUndo">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/edit_undo.png</normaloff>:/data/images/data/images/edit_undo.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>EditUndo</string>
|
<string>EditUndo</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditRedo">
|
<action name="actionEditRedo">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/edit_redo.png</normaloff>:/data/images/data/images/edit_redo.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>EditRedo</string>
|
<string>EditRedo</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionNew">
|
<action name="actionNew">
|
||||||
<property name="icon">
|
<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>
|
<normaloff>:/data/images/data/images/new.png</normaloff>:/data/images/data/images/new.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>New</string>
|
<string>New</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="build/Desktop_Qt_6_9_1-Debug/data.qrc"/>
|
<include location="data.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
2
path.cpp
2
path.cpp
@ -75,7 +75,7 @@ Path::Path(QFile *file){
|
|||||||
QJsonArray stepsArray = json["steps"].toArray();
|
QJsonArray stepsArray = json["steps"].toArray();
|
||||||
for (const QJsonValue &stepValue : stepsArray) {
|
for (const QJsonValue &stepValue : stepsArray) {
|
||||||
QJsonObject stepObj = stepValue.toObject();
|
QJsonObject stepObj = stepValue.toObject();
|
||||||
//step.append(Step(stepObj));
|
step.append(Step(stepObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user