diff --git a/main.cpp b/main.cpp index fd3e533..2c8cdf2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,16 @@ #include "mainwindow.h" +#include "path.h" + #include +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); + + return a.exec(); } diff --git a/path.cpp b/path.cpp new file mode 100644 index 0000000..4f4fd97 --- /dev/null +++ b/path.cpp @@ -0,0 +1,44 @@ +#include "path.h" +#include "step.h" +#include +#include +#include +#include +#include + +#include + + + +Path::Path(QFile *file){ + if (!file->open(QIODevice::ReadOnly)) { + qWarning() << "Could not open file:" << file->errorString(); + return; + } + QByteArray data = file->readAll(); + file->close(); + QJsonDocument doc = QJsonDocument::fromJson(data); + if (doc.isNull()) { + qWarning() << "Failed to create JSON document"; + return; + } + QJsonObject json = doc.object(); + + name = json["name"].toString(); + city = json["city"].toString(); + departement = json["departement"].toInt(); + difficulty = json["difficulty"].toInt(); + duration = json["duration"].toDouble(); + length = json["length"].toDouble(); + image = json["image"].toString(); + + QJsonArray stepsArray = json["steps"].toArray(); + for (const QJsonValue &stepValue : stepsArray) { + QJsonObject stepObj = stepValue.toObject(); + step.append(Step(stepObj)); + } + +} + + +void Path::addStep(int indice){step.insert(indice, Step());} diff --git a/path.h b/path.h index 52ec154..025aafa 100644 --- a/path.h +++ b/path.h @@ -2,6 +2,9 @@ #define PATH_H #include +#include +#include "step.h" + class Path { @@ -17,7 +20,7 @@ private: public: Path(); Path(QFile *file); - void addStep(); + void addStep(int indice); }; #endif // PATH_H diff --git a/sae201.pro b/sae201.pro index b915c09..2019663 100644 --- a/sae201.pro +++ b/sae201.pro @@ -10,10 +10,14 @@ CONFIG += c++17 SOURCES += \ main.cpp \ - mainwindow.cpp + mainwindow.cpp \ + step.cpp \ + path.cpp \ HEADERS += \ - mainwindow.h + mainwindow.h \ + step.h \ + path.h \ FORMS += \ mainwindow.ui diff --git a/step.cpp b/step.cpp new file mode 100644 index 0000000..17f2edc --- /dev/null +++ b/step.cpp @@ -0,0 +1,35 @@ +#include "step.h" + +Step::Step() { + latitude = 0.0; + longitude = 0.0; + response = 0; +} + +Step::Step(QTextStream &in) +{ + int stepNumber; + in >> stepNumber; + in.readLine(); + title = in.readLine(); + QChar latDir, lonDir; + int latDeg, lonDeg; + float latMin, lonMin; + in >> latDir >> latDeg >> latMin >> lonDir >> lonDeg >> lonMin; + setLatitude(latDeg, latMin, latDir); + setLongitude(lonDeg, lonMin, lonDir); + in >> response; + in.readLine(); +} +void Step::setLatitude(int degree, float minute, QChar NS) +{ + latitude = degree + minute / 60.0; + if (NS.toUpper() == 'S') + latitude = -latitude; +} +void Step::setLongitude(int degree, float minute, QChar EW) +{ + longitude = degree + minute / 60.0; + if (EW.toUpper() == 'W') + longitude = -longitude; +} diff --git a/step.h b/step.h new file mode 100644 index 0000000..eb46bbc --- /dev/null +++ b/step.h @@ -0,0 +1,22 @@ +#ifndef STEP_H +#define STEP_H +#include +#include +class Step +{ + +private: + QString title; + float latitude; + float longitude; + QString text; + int response; + +public: + Step(); + Step(QTextStream &in); + void setLatitude(int degree,float minute,QChar NS); + void setLongitude(int degree,float minute,QChar EW); +}; + +#endif // STEP_H