Merge branch 'feature/openFile' into 'main'
Feature/open file See merge request p2406187/sae201!8
This commit is contained in:
commit
29054c76a2
@ -1,5 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include "path.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@ -56,13 +57,10 @@ void MainWindow::exportHTMLMap()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_clicked()
|
void MainWindow::loadImage(QString fileName) {
|
||||||
{
|
|
||||||
|
|
||||||
QString ext[] = {"png", "jpeg", "jpg"};
|
QString ext[] = {"png", "jpeg", "jpg"};
|
||||||
|
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
|
|
||||||
if (fileName.isEmpty()) return;
|
|
||||||
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 file: " +
|
||||||
@ -91,7 +89,13 @@ void MainWindow::on_pushButton_clicked()
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_clicked()
|
||||||
|
{
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
|
||||||
|
if (fileName.isEmpty()) return;
|
||||||
|
this->loadImage(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,6 +110,25 @@ void MainWindow::on_actionOpen_triggered()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
Path* p = new Path(&file);
|
||||||
|
currentPath = p;
|
||||||
|
path.append(p);
|
||||||
|
|
||||||
|
ui->titleEdit->setText(p->getName());
|
||||||
|
ui->locEdit->setText(p->getCity());
|
||||||
|
ui->diffSpin->setValue(p->getDifficulty());
|
||||||
|
ui->lengthSpin->setValue(p->getLength());
|
||||||
|
ui->durationSpin->setValue(p->getDuration());
|
||||||
|
ui->imagePath->setText(p->getImage());
|
||||||
|
|
||||||
|
loadImage(p->getImage());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_toolButton_clicked()
|
||||||
|
{
|
||||||
|
QString fileName = ui->imagePath->text();
|
||||||
|
if(fileName.isEmpty()) return;
|
||||||
|
loadImage(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,11 +31,14 @@ private slots:
|
|||||||
|
|
||||||
void on_actionOpen_triggered();
|
void on_actionOpen_triggered();
|
||||||
|
|
||||||
|
void on_toolButton_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QString currentFile;
|
QString currentFile;
|
||||||
bool textChanged;
|
bool textChanged;
|
||||||
QList<Path*> path;
|
QList<Path*> path;
|
||||||
Path* currentPath;
|
Path* currentPath;
|
||||||
|
void loadImage(QString fileName);
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@ -67,7 +67,7 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLineEdit" name="lineEdit">
|
<widget class="QLineEdit" name="titleEdit">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>60</x>
|
<x>60</x>
|
||||||
@ -101,7 +101,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEdit_2"/>
|
<widget class="QLineEdit" name="locEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="spinBox_2"/>
|
<widget class="QSpinBox" name="spinBox_2"/>
|
||||||
@ -148,7 +148,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSpinBox" name="spinBox_3">
|
<widget class="QSpinBox" name="diffSpin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string>/5</string>
|
<string>/5</string>
|
||||||
</property>
|
</property>
|
||||||
@ -171,7 +171,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="doubleSpinBox">
|
<widget class="QDoubleSpinBox" name="durationSpin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string>h</string>
|
<string>h</string>
|
||||||
</property>
|
</property>
|
||||||
@ -197,7 +197,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_2">
|
<widget class="QDoubleSpinBox" name="lengthSpin">
|
||||||
<property name="suffix">
|
<property name="suffix">
|
||||||
<string>Km</string>
|
<string>Km</string>
|
||||||
</property>
|
</property>
|
||||||
@ -243,6 +243,16 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="imagePath"/>
|
<widget class="QLineEdit" name="imagePath"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="toolButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="QIcon::ThemeIcon::ListAdd"/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
42
path.cpp
42
path.cpp
@ -10,6 +10,46 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QString Path::getCity() const
|
||||||
|
{
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Path::getDepartement() const
|
||||||
|
{
|
||||||
|
return departement;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Path::getName() const
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Path::getDifficulty() const
|
||||||
|
{
|
||||||
|
return difficulty;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Path::getDuration() const
|
||||||
|
{
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Path::getLength() const
|
||||||
|
{
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Path::getImage() const
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Step> Path::getStep() const
|
||||||
|
{
|
||||||
|
return step;
|
||||||
|
}
|
||||||
|
|
||||||
Path::Path(QFile *file){
|
Path::Path(QFile *file){
|
||||||
if (!file->open(QIODevice::ReadOnly)) {
|
if (!file->open(QIODevice::ReadOnly)) {
|
||||||
qWarning() << "Could not open file:" << file->errorString();
|
qWarning() << "Could not open file:" << file->errorString();
|
||||||
@ -35,7 +75,7 @@ Path::Path(QFile *file){
|
|||||||
QJsonArray stepsArray = json["steps"].toArray();
|
QJsonArray stepsArray = json["steps"].toArray();
|
||||||
for (const QJsonValue &stepValue : stepsArray) {
|
for (const QJsonValue &stepValue : stepsArray) {
|
||||||
QJsonObject stepObj = stepValue.toObject();
|
QJsonObject stepObj = stepValue.toObject();
|
||||||
step.append(Step(stepObj));
|
//step.append(Step(stepObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
8
path.h
8
path.h
@ -21,6 +21,14 @@ public:
|
|||||||
Path();
|
Path();
|
||||||
Path(QFile *file);
|
Path(QFile *file);
|
||||||
void addStep(int indice=-1);
|
void addStep(int indice=-1);
|
||||||
|
QString getCity() const;
|
||||||
|
int getDepartement() const;
|
||||||
|
QString getName() const;
|
||||||
|
unsigned int getDifficulty() const;
|
||||||
|
float getDuration() const;
|
||||||
|
float getLength() const;
|
||||||
|
QString getImage() const;
|
||||||
|
QList<Step> getStep() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PATH_H
|
#endif // PATH_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user