of save and load a path without image

This commit is contained in:
Giovanni JOSSERAND 2025-06-20 15:38:11 +02:00
parent 8659ab81c3
commit afd9997724
3 changed files with 26 additions and 24 deletions

0
data/images/d.json Normal file
View File

View File

@ -22,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent)
, Clipboard(QGuiApplication::clipboard())
{
ui->setupUi(this);
currentPath = new Path();
connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() {
static QString previousText;
@ -95,6 +95,7 @@ void MainWindow::loadNewPath()
currentPath = p;
path.append(p);
loadPath(p);
currentFile = fileName;
int pathCount = path.length();
ui->pathNumber->setMaximum(pathCount);
@ -116,6 +117,7 @@ void MainWindow::loadPath(Path* p) {
ui->depSpin->setValue(p->getDepartement());
loadImage(p->getImage());
ui->dialogEdit->clear();
if(!steps.isEmpty()) {
@ -162,36 +164,35 @@ void MainWindow::exportHTMLMap()
}
void MainWindow::loadImage(QString fileName) {
QString ext[] = {"png", "jpeg", "jpg"};
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, "Warning", "Cannot open file: " +
QMessageBox::warning(this, "Warning", "Cannot open image: " +
file.errorString());
return;
}
QString text = file.fileName();
bool acceptedExt = false;
for(QString e : ext) {
if(text.endsWith(e)) acceptedExt = true;
}else{
QString text = file.fileName();
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();
}
@ -259,7 +260,6 @@ void MainWindow::saveFile(){
steps.append(stepObject);
}
json["steps"] = steps;
QJsonDocument doc(json);
file.write(doc.toJson());

View File

@ -50,6 +50,8 @@ QList<Step> Path::getStep() const
return step;
}
Path::Path(){}
Path::Path(QFile *file){
if (!file->open(QIODevice::ReadOnly)) {
qWarning() << "Could not open file:" << file->errorString();