final save function

This commit is contained in:
Giovanni JOSSERAND 2025-06-20 14:08:36 +02:00
parent 4fe0884432
commit 9aee1f659b
3 changed files with 51 additions and 15 deletions

View File

@ -162,22 +162,25 @@ void MainWindow::saveFile(){
json["length"] = ui->lengthSpin->value();
json["image"] = ui->imagePath->text();
QJsonArray steps;
QJsonObject step1;
step1["numero"] = "3";
step1["title"] = "ok ca marche";
step1["GPS"] = "S 45 37.199 E 1 2.009";
step1["reponse"] = "34";
QJsonArray dialogues;
QJsonObject dialogue1;
dialogue1["personnage"] = "Quentin";
dialogue1["texte"] = "ok c'est cool";
dialogues.append(dialogue1);
step1["dialogue"] = dialogues;
steps.append(step1);
int cpt=0;
for(Step step: currentPath->getStep()){
cpt++;
QJsonObject stepObject;
stepObject["numero"] = cpt;
stepObject["title"] = step.getTitle();
stepObject["GPS"] = step.toGPSFormat();
stepObject["reponse"] = step.getResponse();
QJsonArray dialogues;
for(int i=0; i<step.getListeDialogue().size(); i++){
QJsonObject dialogueObject;
dialogueObject["personnage"] = step.getListePersonnage()[i];
dialogueObject["texte"] = step.getListeDialogue()[i];
dialogues.append(dialogueObject);
}
stepObject["dialogue"] = dialogues;
steps.append(stepObject);
}
json["steps"] = steps;
QJsonDocument doc(json);

View File

@ -80,3 +80,33 @@ void Step::setLongitude(int degree, float minute, QChar EW)
if (EW.toUpper() == 'W')
longitude = -longitude;
}
QList<QString> Step::getListeDialogue(){
return texte;
}
QList<QString> Step::getListePersonnage(){
return personnage;
}
QString Step::toGPSFormat(){
int latDeg = static_cast<int>(latitude);
float latMin = (latitude - latDeg) * 60.0;
QChar latDir = latitude >= 0 ? 'N' : 'S';
latDeg = abs(latDeg);
int lonDeg = static_cast<int>(longitude);
float lonMin = (longitude - lonDeg) * 60.0;
QChar lonDir = longitude >= 0 ? 'E' : 'W';
lonDeg = abs(lonDeg);
QString gpsString = QString("%1 %2 %3 %4 %5 %6")
.arg(latDir)
.arg(latDeg, 2)
.arg(latMin, 5, 'f', 3)
.arg(lonDir)
.arg(lonDeg, 2)
.arg(lonMin, 5, 'f', 3);
return gpsString;
}

3
step.h
View File

@ -26,6 +26,9 @@ public:
float getLatitude() const;
float getLongitude() const;
int getResponse() const;
QList<QString> getListeDialogue();
QList<QString> getListePersonnage();
QString toGPSFormat();
};
#endif // STEP_H