end of addStep and constructor per parameter
This commit is contained in:
parent
7722dde604
commit
f6d2929140
43
path.cpp
43
path.cpp
@ -1,13 +1,44 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "step.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Path::Path(QFile *file){
|
Path::Path(QFile *file){
|
||||||
QTextStream in(&file);
|
if (!file->open(QIODevice::ReadOnly)) {
|
||||||
QString text = in.readAll();
|
qWarning() << "Could not open file:" << file->errorString();
|
||||||
ui->textEdit->setText(text);
|
return;
|
||||||
file.close();
|
}
|
||||||
}
|
QByteArray data = file->readAll();
|
||||||
void Path::addStep(){
|
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
|
#define PATH_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QFile>
|
||||||
|
#include "step.h"
|
||||||
|
|
||||||
|
|
||||||
class Path
|
class Path
|
||||||
{
|
{
|
||||||
@ -17,7 +20,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
Path();
|
Path();
|
||||||
Path(QFile *file);
|
Path(QFile *file);
|
||||||
void addStep();
|
void addStep(int indice);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PATH_H
|
#endif // PATH_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user