Merge branch 'fix/save' into 'main'
of save and load a path without image See merge request p2406187/sae201!15
This commit is contained in:
commit
7bfa00db0a
0
data/images/d.json
Normal file
0
data/images/d.json
Normal file
@ -22,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;
|
||||||
@ -95,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);
|
||||||
@ -116,6 +117,7 @@ void MainWindow::loadPath(Path* p) {
|
|||||||
ui->depSpin->setValue(p->getDepartement());
|
ui->depSpin->setValue(p->getDepartement());
|
||||||
loadImage(p->getImage());
|
loadImage(p->getImage());
|
||||||
|
|
||||||
|
|
||||||
ui->dialogEdit->clear();
|
ui->dialogEdit->clear();
|
||||||
|
|
||||||
if(!steps.isEmpty()) {
|
if(!steps.isEmpty()) {
|
||||||
@ -162,22 +164,19 @@ 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();
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
QString text = file.fileName();
|
||||||
bool acceptedExt = false;
|
bool acceptedExt = false;
|
||||||
for(QString e : ext) {
|
for(QString e : ext) {
|
||||||
if(text.endsWith(e)) acceptedExt = true;
|
if(text.endsWith(e)) acceptedExt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!acceptedExt) {
|
if(!acceptedExt) {
|
||||||
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
||||||
return;
|
return;
|
||||||
@ -192,6 +191,8 @@ void MainWindow::loadImage(QString fileName) {
|
|||||||
ui->imageLbl->setPixmap(px);
|
ui->imageLbl->setPixmap(px);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +260,6 @@ void MainWindow::saveFile(){
|
|||||||
steps.append(stepObject);
|
steps.append(stepObject);
|
||||||
}
|
}
|
||||||
json["steps"] = steps;
|
json["steps"] = steps;
|
||||||
|
|
||||||
QJsonDocument doc(json);
|
QJsonDocument doc(json);
|
||||||
file.write(doc.toJson());
|
file.write(doc.toJson());
|
||||||
|
|
||||||
|
|||||||
2
path.cpp
2
path.cpp
@ -50,6 +50,8 @@ QList<Step> Path::getStep() const
|
|||||||
return step;
|
return step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path::Path(){}
|
||||||
|
|
||||||
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();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user