129 lines
2.1 KiB
C++
129 lines
2.1 KiB
C++
#include "path.h"
|
|
#include "step.h"
|
|
#include <QFile>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QDebug>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
QString Path::getCity() const
|
|
{
|
|
return city;
|
|
}
|
|
|
|
int Path::getDepartement() const
|
|
{
|
|
return departement;
|
|
}
|
|
|
|
QString Path::getName() const
|
|
{
|
|
return name;
|
|
}
|
|
|
|
unsigned int Path::getDifficulty() const
|
|
{
|
|
return difficulty;
|
|
}
|
|
|
|
float Path::getDuration() const
|
|
{
|
|
return duration;
|
|
}
|
|
|
|
float Path::getLength() const
|
|
{
|
|
return length;
|
|
}
|
|
|
|
QString Path::getImage() const
|
|
{
|
|
return image;
|
|
}
|
|
|
|
QList<Step>& Path::getStep()
|
|
{
|
|
return step;
|
|
}
|
|
|
|
void Path::setCity(const QString &newCity)
|
|
{
|
|
city = newCity;
|
|
}
|
|
|
|
void Path::setDepartement(int newDepartement)
|
|
{
|
|
departement = newDepartement;
|
|
}
|
|
|
|
void Path::setName(const QString &newName)
|
|
{
|
|
name = newName;
|
|
}
|
|
|
|
void Path::setDifficulty(unsigned int newDifficulty)
|
|
{
|
|
difficulty = newDifficulty;
|
|
}
|
|
|
|
void Path::setDuration(float newDuration)
|
|
{
|
|
duration = newDuration;
|
|
}
|
|
|
|
void Path::setLength(float newLength)
|
|
{
|
|
length = newLength;
|
|
}
|
|
|
|
void Path::setImage(const QString &newImage)
|
|
{
|
|
image = newImage;
|
|
}
|
|
|
|
Path::Path(){}
|
|
|
|
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){
|
|
if(indice==-1){
|
|
step.append(Step());
|
|
}else{
|
|
step.insert(indice, Step());
|
|
}
|
|
|
|
}
|