Merge branch 'main' into 'feature/Terraventura'
# Conflicts: # sae201.pro
This commit is contained in:
commit
d9ccb54768
5
main.cpp
5
main.cpp
@ -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
44
path.cpp
Normal 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
5
path.h
@ -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
|
||||
|
||||
@ -11,11 +11,13 @@ CONFIG += c++17
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
path.cpp
|
||||
step.cpp \
|
||||
path.cpp \
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
path.h
|
||||
step.h \
|
||||
path.h \
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
35
step.cpp
Normal file
35
step.cpp
Normal 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
22
step.h
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user