Merge branch 'main' into 'feature/validateBtn'
# Conflicts: # mainwindow.h # mainwindow.ui # path.cpp
This commit is contained in:
commit
3e9e248f04
0
data/images/d.json
Normal file
0
data/images/d.json
Normal file
109
mainwindow.cpp
109
mainwindow.cpp
@ -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)
|
||||||
@ -15,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, Clipboard(QGuiApplication::clipboard())
|
, Clipboard(QGuiApplication::clipboard())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
currentPath = new Path();
|
||||||
|
|
||||||
connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() {
|
connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||||
static QString previousText;
|
static QString previousText;
|
||||||
@ -88,6 +95,7 @@ void MainWindow::loadNewPath()
|
|||||||
currentPath = p;
|
currentPath = p;
|
||||||
path.append(p);
|
path.append(p);
|
||||||
loadPath(p);
|
loadPath(p);
|
||||||
|
currentFile = fileName;
|
||||||
|
|
||||||
int pathCount = path.length();
|
int pathCount = path.length();
|
||||||
ui->pathNumber->setMaximum(pathCount);
|
ui->pathNumber->setMaximum(pathCount);
|
||||||
@ -106,8 +114,10 @@ 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();
|
||||||
|
|
||||||
if(!steps.isEmpty()) {
|
if(!steps.isEmpty()) {
|
||||||
@ -155,36 +165,35 @@ void MainWindow::exportHTMLMap()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadImage(QString fileName) {
|
void MainWindow::loadImage(QString fileName) {
|
||||||
|
|
||||||
QString ext[] = {"png", "jpeg", "jpg"};
|
QString ext[] = {"png", "jpeg", "jpg"};
|
||||||
|
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
||||||
QMessageBox::warning(this, "Warning", "Cannot open file: " +
|
QMessageBox::warning(this, "Warning", "Cannot open image: " +
|
||||||
file.errorString());
|
file.errorString());
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString text = file.fileName();
|
|
||||||
|
|
||||||
bool acceptedExt = false;
|
}else{
|
||||||
for(QString e : ext) {
|
QString text = file.fileName();
|
||||||
if(text.endsWith(e)) acceptedExt = true;
|
bool acceptedExt = false;
|
||||||
|
for(QString e : ext) {
|
||||||
|
if(text.endsWith(e)) acceptedExt = true;
|
||||||
|
}
|
||||||
|
if(!acceptedExt) {
|
||||||
|
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ui->imagePath->setText(text);
|
||||||
|
|
||||||
|
|
||||||
|
QPixmap px(fileName);
|
||||||
|
|
||||||
|
ui->imageLbl->setPixmap(px);
|
||||||
|
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!acceptedExt) {
|
|
||||||
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ui->imagePath->setText(text);
|
|
||||||
|
|
||||||
|
|
||||||
QPixmap px(fileName);
|
|
||||||
|
|
||||||
ui->imageLbl->setPixmap(px);
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +218,60 @@ 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,6 +37,8 @@ private slots:
|
|||||||
|
|
||||||
void on_toolButton_clicked();
|
void on_toolButton_clicked();
|
||||||
|
|
||||||
|
void on_actionSave_triggered();
|
||||||
|
|
||||||
void on_actionopenFile_triggered();
|
void on_actionopenFile_triggered();
|
||||||
|
|
||||||
void on_actionEditCopy_triggered();
|
void on_actionEditCopy_triggered();
|
||||||
|
|||||||
@ -62,9 +62,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>
|
||||||
@ -82,10 +79,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>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
||||||
<item>
|
<item>
|
||||||
@ -322,9 +316,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>
|
||||||
@ -342,10 +333,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>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
@ -492,7 +480,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">
|
||||||
@ -561,7 +549,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">
|
||||||
@ -573,7 +561,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">
|
||||||
@ -585,7 +573,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">
|
||||||
@ -597,7 +585,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">
|
||||||
@ -609,7 +597,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">
|
||||||
@ -621,7 +609,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">
|
||||||
@ -633,7 +621,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">
|
||||||
@ -645,7 +633,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">
|
||||||
@ -657,7 +645,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">
|
||||||
@ -669,7 +657,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>
|
||||||
|
|||||||
22
step.cpp
22
step.cpp
@ -100,3 +100,25 @@ void Step::setLongitude(int degree, float minute, QChar EW)
|
|||||||
if (EW.toUpper() == 'W')
|
if (EW.toUpper() == 'W')
|
||||||
longitude = -longitude;
|
longitude = -longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
void setTitle(const QString &newTitle);
|
void setTitle(const QString &newTitle);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user