diff --git a/mainwindow.cpp b/mainwindow.cpp index 617be1b..ebe10ad 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -586,3 +586,53 @@ void MainWindow::loadAndExportPaths(QStringList fichiers) { exportHTMLMap(exportIndex++); } } + + +void MainWindow::saveAsFile(){ + QString fileName = QFileDialog::getSaveFileName(this, "Save as"); + QFile file(fileName); + + if (!file.open(QFile::WriteOnly | QFile::Text)) { + QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString()); + return; + } + setWindowTitle(fileName); + currentFile = 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; + int cpt=0; + for(Step step: currentPath->getStep()){ + cpt++; + QJsonObject stepObject; + stepObject["numero"] = cpt; + stepObject["title"] = step.getTitle(); + stepObject["GPS"] = step.toGPSFormat(); + stepObject["reponse"] = step.getResponse(); + QJsonArray dialogues; + for(int i=0; isaveAsFile(); +} + diff --git a/mainwindow.h b/mainwindow.h index 191d6f7..ab5359c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,7 @@ public: void setPath(const QList &newPath); Path *getCurrentPath() const; void setCurrentPath(Path *newCurrentPath); + void saveAsFile(); int getIndexPath() const; void setIndexPath(int newIndexPath); @@ -64,6 +65,8 @@ private slots: void on_validateBtn_clicked(); + void on_actionSave_as_triggered(); + private: Ui::MainWindow *ui; QString currentFile;