diff --git a/data/images/d.json b/data/images/d.json new file mode 100644 index 0000000..e69de29 diff --git a/mainwindow.cpp b/mainwindow.cpp index 5eeefe6..11ca58c 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) @@ -15,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent) , Clipboard(QGuiApplication::clipboard()) { ui->setupUi(this); - + currentPath = new Path(); connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() { static QString previousText; @@ -88,6 +95,7 @@ void MainWindow::loadNewPath() currentPath = p; path.append(p); loadPath(p); + currentFile = fileName; int pathCount = path.length(); ui->pathNumber->setMaximum(pathCount); @@ -106,8 +114,10 @@ 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(); if(!steps.isEmpty()) { @@ -155,36 +165,35 @@ void MainWindow::exportHTMLMap() } void MainWindow::loadImage(QString fileName) { - QString ext[] = {"png", "jpeg", "jpg"}; QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QFile::Text)) { - QMessageBox::warning(this, "Warning", "Cannot open file: " + + QMessageBox::warning(this, "Warning", "Cannot open image: " + file.errorString()); - return; - } - QString text = file.fileName(); - bool acceptedExt = false; - for(QString e : ext) { - if(text.endsWith(e)) acceptedExt = true; + }else{ + QString text = file.fileName(); + bool acceptedExt = false; + for(QString e : ext) { + if(text.endsWith(e)) acceptedExt = true; + } + if(!acceptedExt) { + QMessageBox::warning(this, "Warning", "Format de fichier incorrect"); + return; + } + + + ui->imagePath->setText(text); + + + QPixmap px(fileName); + + ui->imageLbl->setPixmap(px); + + file.close(); } - if(!acceptedExt) { - QMessageBox::warning(this, "Warning", "Format de fichier incorrect"); - return; - } - - - ui->imagePath->setText(text); - - - QPixmap px(fileName); - - ui->imageLbl->setPixmap(px); - - file.close(); } @@ -209,6 +218,60 @@ 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 3baae80..1415193 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,6 +37,8 @@ private slots: void on_toolButton_clicked(); + void on_actionSave_triggered(); + void on_actionopenFile_triggered(); void on_actionEditCopy_triggered(); diff --git a/mainwindow.ui b/mainwindow.ui index d5270c3..bc8e24e 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -62,9 +62,6 @@ Path information - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - @@ -82,10 +79,7 @@ - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised + QFrame::NoFrame @@ -322,9 +316,6 @@ Step information - - Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop - @@ -342,10 +333,7 @@ - QFrame::Shape::StyledPanel - - - QFrame::Shadow::Raised + QFrame::NoFrame @@ -492,7 +480,7 @@ 0 0 800 - 23 + 21 @@ -561,7 +549,7 @@ New File - QAction::MenuRole::NoRole + QAction::NoRole @@ -573,7 +561,7 @@ Save - QAction::MenuRole::NoRole + QAction::NoRole @@ -585,7 +573,7 @@ Save as - QAction::MenuRole::NoRole + QAction::NoRole @@ -597,7 +585,7 @@ Print - QAction::MenuRole::NoRole + QAction::NoRole @@ -609,7 +597,7 @@ Copy - QAction::MenuRole::NoRole + QAction::NoRole @@ -621,7 +609,7 @@ Paste - QAction::MenuRole::NoRole + QAction::NoRole @@ -633,7 +621,7 @@ Cut - QAction::MenuRole::NoRole + QAction::NoRole @@ -645,7 +633,7 @@ Undo - QAction::MenuRole::NoRole + QAction::NoRole @@ -657,7 +645,7 @@ Redo - QAction::MenuRole::NoRole + QAction::NoRole @@ -669,7 +657,7 @@ Open file - QAction::MenuRole::NoRole + QAction::NoRole diff --git a/step.cpp b/step.cpp index fd7813c..33f9a2e 100644 --- a/step.cpp +++ b/step.cpp @@ -100,3 +100,25 @@ void Step::setLongitude(int degree, float minute, QChar EW) if (EW.toUpper() == 'W') longitude = -longitude; } + +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 3f711c1..05bf5b0 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; void setTitle(const QString &newTitle);