Some extra debug info en some removed for the product images. Clear picmap area if no pixmaps are left. Block pictype_changed and piccomment_changed if there are no pictures, prevents segfault.

Wed, 25 Jan 2023 13:11:51 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 25 Jan 2023 13:11:51 +0100
changeset 475
895c5ae1dab1
parent 474
18b72c518d0d
child 476
29487eac1183

Some extra debug info en some removed for the product images. Clear picmap area if no pixmaps are left. Block pictype_changed and piccomment_changed if there are no pictures, prevents segfault.

src/EditProductTab13.cpp file | annotate | diff | comparison | revisions
--- a/src/EditProductTab13.cpp	Tue Jan 24 16:08:16 2023 +0100
+++ b/src/EditProductTab13.cpp	Wed Jan 25 13:11:51 2023 +0100
@@ -19,7 +19,7 @@
 
 void EditProduct::images_Init()
 {
-    qDebug() << "images_Init()";
+    qDebug() << "images_Init() count" << product->images_count << "current" << product->images_current << "size" << product->images_list.size();
 
 	// Start spinner
 
@@ -86,6 +86,7 @@
  */
 void EditProduct::images_Thumbnails()
 {
+    qDebug() << "images_Thumbnails()" << product->images_list.size();
     ui->filmStrip->clear();
 
     for (int i = 0; i < product->images_list.size(); i++) {
@@ -119,19 +120,20 @@
     ui->delImage->setEnabled((product->images_count > 0) ? true:false);
 
     const QSignalBlocker blocker1(ui->image_typeEdit);
+    const QSignalBlocker blocker2(ui->image_commentEdit);
 
     if (product->images_count < 1) {
 	ui->image_filenameEdit->setText("");
 	ui->image_timestampEdit->setText("");
 	ui->image_commentEdit->setText("");
 	ui->image_typeEdit->setCurrentIndex(0);
-	//ui->currentImage->setPixmap();
+	ui->currentImage->clear();
 	return;
     }
 
     QPixmap outPixmap = QPixmap();
     outPixmap.loadFromData(product->images_list.at(id).pic_data);
-    qDebug() << "  " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(id).filename;
+//    qDebug() << "  " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(id).filename;
     if (outPixmap.width() > ui->currentImage->width() || outPixmap.height() > ui->currentImage->height())
 	ui->currentImage->setPixmap(outPixmap.scaled(ui->currentImage->width(), ui->currentImage->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
     else
@@ -291,6 +293,7 @@
 	QMessageBox::warning(this, tr("Database error"), tr("MySQL error: %1\n%2\n%3")
                 .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText()));
     }
+    qDebug() << "  delete record done";
 
     product->images_count = -1;		// Force reload data
     images_Init();
@@ -389,8 +392,10 @@
 
 void EditProduct::pictype_changed(int val)
 {
+    if (product->images_count < 1)
+	return;
+
     qDebug() << "pictype_changed" << val;
-
     product->images_list[ui->filmStrip->currentRow()].pic_type = val;
 
     QSqlQuery query;
@@ -411,8 +416,10 @@
 
 void EditProduct::piccomment_changed()
 {
+    if (product->images_count < 1)
+	return;
+
     qDebug() << "piccomment_changed" << ui->image_commentEdit->text();
-
     product->images_list[ui->filmStrip->currentRow()].pic_comment = ui->image_commentEdit->text();
 
     QSqlQuery query;
@@ -420,9 +427,7 @@
     query.prepare("UPDATE products_pics SET pic_comment=:pic_comment WHERE record=:record");
     query.bindValue(":pic_comment", ui->image_commentEdit->text());
     query.bindValue(":record", product->images_list.at(ui->filmStrip->currentRow()).record);
-    qDebug() << "piccomment_changed 1";
     query.exec();
-    qDebug() << "piccomment_changed 2";
 
     if (query.lastError().isValid()) {
         qWarning() << "pictype_changed()" << query.lastError();

mercurial