Merge branch 'feature/save' into 'main'
Feature/save See merge request p2406187/sae201!14
This commit is contained in:
commit
3616867793
@ -8,6 +8,13 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
@ -106,6 +113,7 @@ void MainWindow::loadPath(Path* p) {
|
|||||||
ui->lengthSpin->setValue(p->getLength());
|
ui->lengthSpin->setValue(p->getLength());
|
||||||
ui->durationSpin->setValue(p->getDuration());
|
ui->durationSpin->setValue(p->getDuration());
|
||||||
ui->imagePath->setText(p->getImage());
|
ui->imagePath->setText(p->getImage());
|
||||||
|
ui->depSpin->setValue(p->getDepartement());
|
||||||
loadImage(p->getImage());
|
loadImage(p->getImage());
|
||||||
|
|
||||||
ui->dialogEdit->clear();
|
ui->dialogEdit->clear();
|
||||||
@ -208,6 +216,61 @@ void MainWindow::on_toolButton_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::saveFile(){
|
||||||
|
QString fileName;
|
||||||
|
if (currentFile.isEmpty()) {
|
||||||
|
fileName = QFileDialog::getSaveFileName(this, "Save");
|
||||||
|
currentFile = fileName;
|
||||||
|
} else {
|
||||||
|
fileName = currentFile;
|
||||||
|
}
|
||||||
|
QFile file(fileName);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
|
||||||
|
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setWindowTitle(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_triggered()
|
||||||
|
{
|
||||||
|
this->saveFile();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionopenFile_triggered()
|
void MainWindow::on_actionopenFile_triggered()
|
||||||
{
|
{
|
||||||
this->loadNewPath();
|
this->loadNewPath();
|
||||||
|
|||||||
@ -28,6 +28,7 @@ public:
|
|||||||
void addNewPath();
|
void addNewPath();
|
||||||
void addNewStep();
|
void addNewStep();
|
||||||
void exportHTMLMap();
|
void exportHTMLMap();
|
||||||
|
void saveFile();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_clicked();
|
void on_pushButton_clicked();
|
||||||
@ -36,8 +37,9 @@ private slots:
|
|||||||
|
|
||||||
void on_toolButton_clicked();
|
void on_toolButton_clicked();
|
||||||
|
|
||||||
void on_actionopenFile_triggered();
|
void on_actionSave_triggered();
|
||||||
|
|
||||||
|
void on_actionopenFile_triggered();
|
||||||
|
|
||||||
void on_actionEditCopy_triggered();
|
void on_actionEditCopy_triggered();
|
||||||
|
|
||||||
|
|||||||
@ -50,9 +50,6 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Path information</string>
|
<string>Path information</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -64,10 +61,7 @@
|
|||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::Shape::StyledPanel</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Shadow::Raised</enum>
|
|
||||||
</property>
|
</property>
|
||||||
<widget class="QSpinBox" name="pathNumber">
|
<widget class="QSpinBox" name="pathNumber">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -122,7 +116,11 @@
|
|||||||
<widget class="QLineEdit" name="locEdit"/>
|
<widget class="QLineEdit" name="locEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="spinBox_2"/>
|
<widget class="QSpinBox" name="depSpin">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -297,9 +295,6 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Step information</string>
|
<string>Step information</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -311,10 +306,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::Shape::StyledPanel</enum>
|
<enum>QFrame::NoFrame</enum>
|
||||||
</property>
|
|
||||||
<property name="frameShadow">
|
|
||||||
<enum>QFrame::Shadow::Raised</enum>
|
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="steptitleFrame" native="true">
|
<widget class="QWidget" name="steptitleFrame" native="true">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -455,7 +447,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>23</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
@ -531,7 +523,7 @@
|
|||||||
<string>New File</string>
|
<string>New File</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSaveFile">
|
<action name="actionSaveFile">
|
||||||
@ -543,7 +535,7 @@
|
|||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSaveAsFile">
|
<action name="actionSaveAsFile">
|
||||||
@ -555,7 +547,7 @@
|
|||||||
<string>Save as</string>
|
<string>Save as</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionPrintFile">
|
<action name="actionPrintFile">
|
||||||
@ -567,7 +559,7 @@
|
|||||||
<string>Print</string>
|
<string>Print</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditCopy">
|
<action name="actionEditCopy">
|
||||||
@ -579,7 +571,7 @@
|
|||||||
<string>Copy</string>
|
<string>Copy</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditPaste">
|
<action name="actionEditPaste">
|
||||||
@ -591,7 +583,7 @@
|
|||||||
<string>Paste</string>
|
<string>Paste</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditCut">
|
<action name="actionEditCut">
|
||||||
@ -603,7 +595,7 @@
|
|||||||
<string>Cut</string>
|
<string>Cut</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditUndo">
|
<action name="actionEditUndo">
|
||||||
@ -615,7 +607,7 @@
|
|||||||
<string>Undo</string>
|
<string>Undo</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionEditRedo">
|
<action name="actionEditRedo">
|
||||||
@ -627,7 +619,7 @@
|
|||||||
<string>Redo</string>
|
<string>Redo</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionopenFile">
|
<action name="actionopenFile">
|
||||||
@ -639,7 +631,7 @@
|
|||||||
<string>Open file</string>
|
<string>Open file</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="menuRole">
|
<property name="menuRole">
|
||||||
<enum>QAction::MenuRole::NoRole</enum>
|
<enum>QAction::NoRole</enum>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
30
step.cpp
30
step.cpp
@ -90,3 +90,33 @@ void Step::setLongitude(int degree, float minute, QChar EW)
|
|||||||
if (EW.toUpper() == 'W')
|
if (EW.toUpper() == 'W')
|
||||||
longitude = -longitude;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
1
step.h
1
step.h
@ -26,6 +26,7 @@ public:
|
|||||||
float getLatitude() const;
|
float getLatitude() const;
|
||||||
float getLongitude() const;
|
float getLongitude() const;
|
||||||
int getResponse() const;
|
int getResponse() const;
|
||||||
|
QString toGPSFormat();
|
||||||
QList<QString> getPersonnage() const;
|
QList<QString> getPersonnage() const;
|
||||||
QList<QString> getTexte() const;
|
QList<QString> getTexte() const;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user