@@ -461,15 +461,17 @@ void MainWindow::fill_db_patterns(tinyxml2::XMLElement *body)
461461 QString img_64 {pattern->FirstChildElement (" img" )->GetText ()};
462462 QString img_type {pattern->FirstChildElement (" img_type" )->GetText ()};
463463
464- QString path_to_image {QDir::currentPath () + " /images/" + name + " ." + img_type};
464+
465+ QSqlQuery id_query (" SELECT id FROM Pattern ORDER BY id DESC" );
466+ id_query.next ();
467+ QString id{QString::number (id_query.value (0 ).toInt () + 1 )};
468+
469+ QString path_to_image {QDir::currentPath () + " /images/" + id + " ." + img_type};
465470 this ->save_img_to_file (path_to_image, img_64);
466471
467472 QSqlQuery insert (" INSERT INTO Pattern (name, description, code, path_to_image)"
468473 " VALUES ('" + name + " ', '" + description + " ', '" + code + " ', '" + path_to_image + " ')" );
469474
470-
471-
472-
473475 pattern = pattern->NextSiblingElement (" pattern" );
474476 }
475477}
@@ -632,6 +634,19 @@ void MainWindow::on_more_btn_clicked(QString name)
632634
633635 this ->pattern_pic = QPixmap ();
634636 this ->pattern_pic .load (data.path_to_image );
637+ int width{this ->pattern_pic .width ()};
638+ if (width > 512 )
639+ {
640+ double ratio {width / 512.0 };
641+
642+ this ->pattern_pic = this ->pattern_pic .scaled (512 , int (this ->pattern_pic .height () / ratio), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
643+ }
644+ else
645+ {
646+ double ratio {512.0 / width};
647+
648+ this ->pattern_pic = this ->pattern_pic .scaled (512 , int (this ->pattern_pic .height () * ratio), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
649+ }
635650
636651 this ->ui ->img_more ->setPixmap (this ->pattern_pic );
637652}
0 commit comments