add of save function with default value
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user