diff --git a/mainwindow.cpp b/mainwindow.cpp index 5570c48..eef3d8e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -8,6 +8,13 @@ #include #include + +#include +#include +#include +#include + + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -106,6 +113,7 @@ void MainWindow::loadPath(Path* p) { ui->lengthSpin->setValue(p->getLength()); ui->durationSpin->setValue(p->getDuration()); ui->imagePath->setText(p->getImage()); + ui->depSpin->setValue(p->getDepartement()); loadImage(p->getImage()); ui->dialogEdit->clear(); @@ -208,6 +216,61 @@ void MainWindow::on_toolButton_clicked() } +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; + 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; isaveFile(); +} + void MainWindow::on_actionopenFile_triggered() { this->loadNewPath(); diff --git a/mainwindow.h b/mainwindow.h index 7b9cccc..1472ed3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -28,6 +28,7 @@ public: void addNewPath(); void addNewStep(); void exportHTMLMap(); + void saveFile(); private slots: void on_pushButton_clicked(); @@ -36,8 +37,9 @@ private slots: void on_toolButton_clicked(); - void on_actionopenFile_triggered(); + void on_actionSave_triggered(); + void on_actionopenFile_triggered(); void on_actionEditCopy_triggered(); diff --git a/mainwindow.ui b/mainwindow.ui index eef97a1..4aa46f1 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -50,9 +50,6 @@ Path information - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - @@ -64,10 +61,7 @@ - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised + QFrame::NoFrame @@ -122,7 +116,11 @@ - + + + 1 + + @@ -297,9 +295,6 @@ Step information - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - @@ -311,10 +306,7 @@ - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised + QFrame::NoFrame @@ -455,7 +447,7 @@ 0 0 800 - 23 + 21 @@ -531,7 +523,7 @@ New File - QAction::MenuRole::NoRole + QAction::NoRole @@ -543,7 +535,7 @@ Save - QAction::MenuRole::NoRole + QAction::NoRole @@ -555,7 +547,7 @@ Save as - QAction::MenuRole::NoRole + QAction::NoRole @@ -567,7 +559,7 @@ Print - QAction::MenuRole::NoRole + QAction::NoRole @@ -579,7 +571,7 @@ Copy - QAction::MenuRole::NoRole + QAction::NoRole @@ -591,7 +583,7 @@ Paste - QAction::MenuRole::NoRole + QAction::NoRole @@ -603,7 +595,7 @@ Cut - QAction::MenuRole::NoRole + QAction::NoRole @@ -615,7 +607,7 @@ Undo - QAction::MenuRole::NoRole + QAction::NoRole @@ -627,7 +619,7 @@ Redo - QAction::MenuRole::NoRole + QAction::NoRole @@ -639,7 +631,7 @@ Open file - QAction::MenuRole::NoRole + QAction::NoRole diff --git a/step.cpp b/step.cpp index 1398647..93d9ec8 100644 --- a/step.cpp +++ b/step.cpp @@ -90,3 +90,33 @@ void Step::setLongitude(int degree, float minute, QChar EW) if (EW.toUpper() == 'W') longitude = -longitude; } + + +QList Step::getListeDialogue(){ + return texte; +} +QList Step::getListePersonnage(){ + return personnage; +} + +QString Step::toGPSFormat(){ + int latDeg = static_cast(latitude); + float latMin = (latitude - latDeg) * 60.0; + QChar latDir = latitude >= 0 ? 'N' : 'S'; + latDeg = abs(latDeg); + + int lonDeg = static_cast(longitude); + float lonMin = (longitude - lonDeg) * 60.0; + QChar lonDir = longitude >= 0 ? 'E' : 'W'; + lonDeg = abs(lonDeg); + + QString gpsString = QString("%1 %2 %3 %4 %5 %6") + .arg(latDir) + .arg(latDeg, 2) + .arg(latMin, 5, 'f', 3) + .arg(lonDir) + .arg(lonDeg, 2) + .arg(lonMin, 5, 'f', 3); + + return gpsString; +} diff --git a/step.h b/step.h index 1607679..fc6ffd3 100644 --- a/step.h +++ b/step.h @@ -26,6 +26,7 @@ public: float getLatitude() const; float getLongitude() const; int getResponse() const; + QString toGPSFormat(); QList getPersonnage() const; QList getTexte() const; };