src/EditProductExport.cpp

changeset 268
72e8ade9aff2
parent 267
8af232524e64
child 269
f92db2eabd0d
--- a/src/EditProductExport.cpp	Tue Jun 07 20:57:42 2022 +0200
+++ b/src/EditProductExport.cpp	Wed Jun 08 15:20:38 2022 +0200
@@ -584,14 +584,44 @@
 
     qDebug() << "split_show" << product->splits.size();
     const QSignalBlocker blocker1(splitTable);
-    split_delButton->setEnabled(product->splits.size() > 0);
+
+    if (product->divide_type == 0) {
+        split_addButton->setEnabled(false);
+        split_addButton->setToolTip("");
+    } else {
+        split_addButton->setEnabled(true);
+        split_addButton->setToolTip(tr("Add a splitted batch"));
+    }
+
+    if (product->splits.size() == 0) {
+	splitatEdit->setEnabled(true);
+	splitatEdit->setToolTip(tr("Choose split moment in the brew process"));
+	split_delButton->setEnabled(false);
+	split_delButton->setToolTip(tr(""));
+    } else {
+	splitatEdit->setEnabled(false);
+	splitatEdit->setToolTip("");
+	split_delButton->setEnabled(true);
+	split_delButton->setToolTip(tr("Delete the last splitted batch"));
+    }
 
     for (int i = 0; i < product->splits.size(); i++) {
 
 	qDebug() << i << product->splits.at(i).code << product->splits.at(i).name << QString::number(product->splits.at(i).size);
-    	splitTable->setItem(i, 0, new QTableWidgetItem(product->splits.at(i).code));
-	splitTable->setItem(i, 1, new QTableWidgetItem(product->splits.at(i).name));
-	splitTable->setItem(i, 2, new QTableWidgetItem(QString::number(product->splits.at(i).size, 'f', 1)));
+
+	QTableWidgetItem *item = new QTableWidgetItem(product->splits.at(i).code);
+	item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+	item->setToolTip(tr("The read-only `product code` of the batch"));
+    	splitTable->setItem(i, 0, item);
+
+	item = new QTableWidgetItem(product->splits.at(i).name);
+	item->setToolTip(tr("Batch name, click to change the name"));
+	splitTable->setItem(i, 1, item);
+
+	item = new QTableWidgetItem(QString::number(product->splits.at(i).size, 'f', 2));
+	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+	item->setToolTip(tr("Batch size, click to change the volume"));
+	splitTable->setItem(i, 2, item);
 	left -= product->splits.at(i).size;
     }
 
@@ -649,15 +679,38 @@
 		break;
     }
     product->divide_type = val;
-    split_addButton->setEnabled(product->divide_type != 0);
     split_show();
 }
 
 
 void EditProduct::split_table_changed(int nRow, int nCol)
 {
+    QTableWidgetItem *item;
+
     qDebug() << "split_table_changed" << nRow << nCol;
 
+    if (nCol == 1) {
+	/* Split name is changed. */
+	item = splitTable->item(nRow, nCol);
+	product->splits[nRow].name = item->text();
+    }
+    if (nCol == 2) {
+	item = splitTable->item(nRow, nCol);
+	double vol = item->text().toDouble();
+	double room = vol_availEdit->value();
+
+	for (int i = 0; i < product->splits.size(); i++) {
+	    if (i != nRow)
+		room -= product->splits.at(i).size;
+	}
+	qDebug() << vol << room;
+	if (vol > (room - 1)) {
+	    product->splits[nRow].size = room - 1;
+	} else {
+	    product->splits[nRow].size = round(vol * 100.0) / 100.0;
+	}
+    }
+
     split_show();
 }
 
@@ -673,15 +726,18 @@
 
     QDialog* dialog = new QDialog(this);
     dialog->setWindowTitle(tr("Split product"));
-
+    dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
     dialog->setObjectName(QString::fromUtf8("SplitDialog"));
     dialog->resize(1024, 560);
+
     QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
     buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
     buttonBox->setGeometry(QRect(30, 510, 961, 32));
     buttonBox->setOrientation(Qt::Horizontal);
     buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
     buttonBox->setCenterButtons(true);
+    //buttonBox->button(QDialogButtonBox::Ok)->setDefault(false);
+    //buttonBox->button(QDialogButtonBox::Cancel)->setDefault(false);
     QLabel *topLabel = new QLabel(dialog);
     topLabel->setObjectName(QString::fromUtf8("topLabel"));
     topLabel->setGeometry(QRect(30, 20, 961, 31));
@@ -737,12 +793,6 @@
     splitatLabel->setGeometry(QRect(660, 110, 141, 20));
     splitatLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
     splitatLabel->setText(tr("Split at moment:"));
-    QLabel *vol_leftLabel = new QLabel(dialog);
-    vol_leftLabel->setObjectName(QString::fromUtf8("vol_leftLabel"));
-    vol_leftLabel->setGeometry(QRect(660, 140, 141, 20));
-    vol_leftLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
-    vol_leftLabel->setText(tr("Volume remaining:"));
-
     splitatEdit = new QComboBox(dialog);
     splitatEdit->setObjectName(QString::fromUtf8("splitatEdit"));
     splitatEdit->setGeometry(QRect(810, 110, 181, 23));
@@ -769,6 +819,11 @@
 	splitatEdit->setItemData(6, false, Qt::UserRole -1);
     }
 
+    QLabel *vol_leftLabel = new QLabel(dialog);
+    vol_leftLabel->setObjectName(QString::fromUtf8("vol_leftLabel"));
+    vol_leftLabel->setGeometry(QRect(660, 140, 141, 20));
+    vol_leftLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
+    vol_leftLabel->setText(tr("Volume remaining:"));
     vol_leftEdit = new QDoubleSpinBox(dialog);
     vol_leftEdit->setObjectName(QString::fromUtf8("vol_leftEdit"));
     vol_leftEdit->setGeometry(QRect(810, 140, 111, 24));
@@ -805,7 +860,6 @@
     icon.addFile(QString::fromUtf8("../resources/icons/silk/add.png"), QSize(), QIcon::Normal, QIcon::Off);
     split_addButton->setIcon(icon);
     split_addButton->setText(tr("Add"));
-    split_addButton->setEnabled(product->divide_type != 0);
 
     split_delButton = new QPushButton(dialog);
     split_delButton->setObjectName(QString::fromUtf8("delButton"));
@@ -814,8 +868,8 @@
     icon2.addFile(QString::fromUtf8("../resources/icons/silk/delete.png"), QSize(), QIcon::Normal, QIcon::Off);
     split_delButton->setIcon(icon2);
     split_delButton->setText(tr("Delete"));
-    split_delButton->setEnabled(false);
 
+    split_show();
     QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
     QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
     connect(split_addButton, SIGNAL(clicked()), this, SLOT(split_add_clicked()));

mercurial