Merge branch 'feature/saveAs' into 'main'
add of saveAsFile function See merge request p2406187/sae201!22
This commit is contained in:
commit
2b07de57d0
@ -586,3 +586,53 @@ void MainWindow::loadAndExportPaths(QStringList fichiers) {
|
||||
exportHTMLMap(exportIndex++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::saveAsFile(){
|
||||
QString fileName = QFileDialog::getSaveFileName(this, "Save as");
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
||||
return;
|
||||
}
|
||||
setWindowTitle(fileName);
|
||||
currentFile = fileName;
|
||||
QJsonObject json;
|
||||
json["name"] = ui->titleEdit->text();
|
||||
json["city"] =ui->locEdit->text();
|
||||
json["departement"] = ui->depSpin->text();
|
||||
json["difficulty"] = ui->diffSpin->value();
|
||||
json["duration"] = ui->durationSpin->value();
|
||||
json["length"] = ui->lengthSpin->value();
|
||||
json["image"] = ui->imagePath->text();
|
||||
|
||||
QJsonArray steps;
|
||||
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.getTexte().size(); i++){
|
||||
QJsonObject dialogueObject;
|
||||
dialogueObject["personnage"] = step.getPersonnage()[i];
|
||||
dialogueObject["texte"] = step.getTexte()[i];
|
||||
dialogues.append(dialogueObject);
|
||||
}
|
||||
stepObject["dialogue"] = dialogues;
|
||||
steps.append(stepObject);
|
||||
}
|
||||
json["steps"] = steps;
|
||||
QJsonDocument doc(json);
|
||||
file.write(doc.toJson());
|
||||
file.close();
|
||||
}
|
||||
void MainWindow::on_actionSave_as_triggered()
|
||||
{
|
||||
this->saveAsFile();
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ public:
|
||||
void setPath(const QList<Path *> &newPath);
|
||||
Path *getCurrentPath() const;
|
||||
void setCurrentPath(Path *newCurrentPath);
|
||||
void saveAsFile();
|
||||
|
||||
int getIndexPath() const;
|
||||
void setIndexPath(int newIndexPath);
|
||||
@ -64,6 +65,8 @@ private slots:
|
||||
|
||||
void on_validateBtn_clicked();
|
||||
|
||||
void on_actionSave_as_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QString currentFile;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user