diff -r c5f6f3f1b714 -r b21da6f583be src/EditProductTab13.cpp --- a/src/EditProductTab13.cpp Fri Jan 20 16:44:08 2023 +0100 +++ b/src/EditProductTab13.cpp Sat Jan 21 14:27:10 2023 +0100 @@ -26,6 +26,13 @@ /* * Clean old picture areas. */ + if (product->images_count < 0 && product->images_list.size()) { + qDebug() << " clean images_list"; + ui->filmStrip->clear(); + product->images_list.clear(); + product->images_count = -1; + product->images_current = -1; + } /* * Load images data for this product uuid. @@ -47,7 +54,8 @@ while (query.next()) { Images i; - qDebug() << product->images_count << query.value("pic_data").toByteArray().size(); + i.record = query.value("record").toInt(); + i.uuid = query.value("uuid").toString(); i.pic_type = query.value("pic_type").toInt(); i.pic_data = query.value("pic_data").toByteArray(); i.pic_comment = query.value("pic_comment").toString(); @@ -79,27 +87,20 @@ */ void EditProduct::images_Thumbnails() { - QList items = ui->filmStrip->selectedItems(); - foreach(QListWidgetItem * item, items) { - delete ui->filmStrip->takeItem(ui->filmStrip->row(item)); - } + ui->filmStrip->clear(); for (int i = 0; i < product->images_list.size(); i++) { QListWidgetItem* newItem = new QListWidgetItem(); QString text = QCoreApplication::translate("PicType", g_prod_pic_types[product->images_list.at(i).pic_type]); - if (product->images_list.at(i).filename != "") - text.append("\n" + product->images_list.at(i).filename); - if (product->images_list.at(i).pic_comment != "") - text.append("\n" + product->images_list.at(i).pic_comment); - // product->images_list.at(i).timestamp newItem->setText(text); newItem->setBackground(QColor(0x45,0x53,0x64)); QPixmap outPixmap = QPixmap(); outPixmap.loadFromData(product->images_list.at(i).pic_data); qDebug() << " " << outPixmap.width() << "x" << outPixmap.height() << "size" << outPixmap.size() << product->images_list.at(i).filename; - if (outPixmap.width() > 320 || outPixmap.height() > 240) - newItem->setIcon(QIcon(outPixmap.scaled(320, 240, Qt::KeepAspectRatio, Qt::SmoothTransformation))); + qDebug() << " " << ui->filmStrip->iconSize(); + if (outPixmap.width() > 240 || outPixmap.height() > 180) + newItem->setIcon(QIcon(outPixmap.scaled(240, 180, Qt::KeepAspectRatio, Qt::SmoothTransformation))); else newItem->setIcon(QIcon(outPixmap)); @@ -117,6 +118,28 @@ ui->downloadImage->setEnabled((product->images_count > 0) ? true:false); ui->printImage->setEnabled((product->images_count > 0) ? true:false); ui->delImage->setEnabled((product->images_count > 0) ? true:false); + + 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(); + 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; + 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 + ui->currentImage->setPixmap(outPixmap); + + ui->image_filenameEdit->setText(product->images_list.at(id).filename); + ui->image_timestampEdit->setText(product->images_list.at(id).timestamp.toString(Qt::RFC2822Date)); + ui->image_commentEdit->setText(product->images_list.at(id).pic_comment); + ui->image_typeEdit->setCurrentIndex(product->images_list.at(id).pic_type); } @@ -194,7 +217,7 @@ typeEdit->setObjectName(QString::fromUtf8("typeEdit")); typeEdit->setGeometry(QRect(160, 360, 161, 23)); for (int i = 0; i < 7; i++) - typeEdit->addItem(g_prod_pic_types[i]); + typeEdit->addItem(QCoreApplication::translate("PicType", g_prod_pic_types[i])); typeEdit->setCurrentIndex(0); QLabel *commentLabel = new QLabel(dialog); @@ -235,15 +258,36 @@ .arg(query.lastError().nativeErrorCode()).arg(query.lastError().driverText()).arg(query.lastError().databaseText())); } else { qDebug() << "new image Saved"; + product->images_count = -1; // Force reload data + images_Init(); } - - //emit refreshAll(); } void EditProduct::delImage_clicked() { - qDebug() << "delImage_clicked()" << product->images_current << ui->filmStrip->currentRow(); + qDebug() << "delImage_clicked()" << ui->filmStrip->currentRow(); + + int rc = QMessageBox::warning(this, tr("Delete image"), tr("Delete %1").arg(product->images_list.at(ui->filmStrip->currentRow()).filename), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (rc == QMessageBox::No) + return; + + qDebug() << " delete record" << product->images_list.at(ui->filmStrip->currentRow()).record; + + QSqlQuery query; + query.prepare("DELETE FROM products_pics WHERE record=:record"); + query.bindValue(":record", product->images_list.at(ui->filmStrip->currentRow()).record); + query.exec(); + + if (query.lastError().isValid()) { + qWarning() << "delImage_clicked()" << query.lastError(); + 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())); + } + + product->images_count = -1; // Force reload data + images_Init(); } @@ -287,8 +331,13 @@ } -void EditProduct::selectImage_clicked(int val) +void EditProduct::selectImage_clicked(QListWidgetItem *val) { - qDebug() << "selectImage_clicked()" << val << product->images_current << ui->filmStrip->currentRow(); + qDebug() << "selectImage_clicked()" << ui->filmStrip->currentRow(); + + if (product->images_count > 0) { + product->images_current = ui->filmStrip->currentRow(); + images_Main(product->images_current); + } }