Merge branch 'feature/Path' into 'main'

Feature/path

See merge request p2406187/sae201!3
This commit is contained in:
JOSSERAND GIOVANNI p2405212 2025-06-19 07:30:09 +00:00
commit 0be1ffc72d
6 changed files with 116 additions and 3 deletions

View File

@ -1,11 +1,16 @@
#include "mainwindow.h"
#include "path.h"
#include <QApplication>
#include <step.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

44
path.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "path.h"
#include "step.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <iostream>
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());}

5
path.h
View File

@ -2,6 +2,9 @@
#define PATH_H
#include <QMainWindow>
#include <QFile>
#include "step.h"
class Path
{
@ -17,7 +20,7 @@ private:
public:
Path();
Path(QFile *file);
void addStep();
void addStep(int indice);
};
#endif // PATH_H

View File

@ -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

35
step.cpp Normal file
View File

@ -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;
}

22
step.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef STEP_H
#define STEP_H
#include <QString>
#include <QTextStream>
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