Fermentable row editor added the adjust_to_total_100 setting.

Fri, 08 Apr 2022 22:46:57 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 08 Apr 2022 22:46:57 +0200
changeset 122
a614932fd908
parent 121
2f9711ce5ad4
child 123
41563800aa92

Fermentable row editor added the adjust_to_total_100 setting.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Fri Apr 08 20:44:04 2022 +0200
+++ b/src/EditRecipe.cpp	Fri Apr 08 22:46:57 2022 +0200
@@ -1523,7 +1523,59 @@
 
 void EditRecipe::ferment_to100_changed(bool val)
 {
-    qDebug() << "ferment_to100_changed()" << recipe->fermentables_row << val;
+    QWidget* pWidget;
+    QHBoxLayout* pLayout;
+    QLabel *label;
+
+    qDebug() << "ferment_to100_changed()" << recipe->fermentables_row << val << recipe->fermentables_use100;
+
+    /*
+     * Three scenario's.
+     * 1. There is no fermentable selected yet, just mark it.
+     * 2. There is current one is selected, deselect it.
+     * 3. There is another one selected, deselect and select this one.
+     */
+    if (! recipe->fermentables_use100 && val) {
+	/* Scenario 1. */
+        recipe->fermentables_use100 = true;
+        recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = true;
+	pctEdit->setReadOnly(false);
+	amountEdit->setReadOnly(true);
+    } else if (recipe->fermentables_use100 && recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 && ! val) {
+	/* Scenario 2. */
+	recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = false;
+	recipe->fermentables_use100 = false;
+	pctEdit->setReadOnly(true);
+	amountEdit->setReadOnly(false);
+    } else if (recipe->fermentables_use100 && ! recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 && val) {
+	/* Scenario 3. */
+	for (int i = 0; i < recipe->fermentables.size(); i++) {
+	    recipe->fermentables[i].f_adjust_to_total_100 = false;
+	}
+	recipe->fermentables[recipe->fermentables_row].f_adjust_to_total_100 = true;
+    } else {
+	qDebug() << "bug";
+	return;
+    }
+
+    this->ignoreChanges = true;
+    for (int i = 0; i < recipe->fermentables.size(); i++) {
+	if (recipe->fermentables.at(i).f_adjust_to_total_100) {
+	    pWidget = new QWidget();
+	    label = new QLabel;
+	    label->setPixmap(QPixmap(":icons/silk/tick.png"));
+	    pLayout = new QHBoxLayout(pWidget);
+	    pLayout->addWidget(label);
+	    pLayout->setAlignment(Qt::AlignCenter);
+	    pLayout->setContentsMargins(0, 0, 0, 0);
+	    pWidget->setLayout(pLayout);
+	    ui->fermentablesTable->setCellWidget(i, 9, pWidget);
+        } else {
+	    ui->fermentablesTable->removeCellWidget(i, 9);
+        }
+    }
+    this->ignoreChanges = false;
+    is_changed();
 }
 
 void EditRecipe::ferment_select_changed(int val)
@@ -1798,7 +1850,10 @@
 	for (int i = 0; i < recipe->fermentables.size(); i++)
 	    if (recipe->fermentables.at(i).f_added < 4)             // Only before bottle/kegging
 		total += recipe->fermentables.at(i).f_amount;
+	recipe->fermentables_use100 = false;
 	for (int i = 0; i < recipe->fermentables.size(); i++) {
+	    if (recipe->fermentables.at(i).f_adjust_to_total_100)
+	    	recipe->fermentables_use100 = true;
 	    if (recipe->fermentables.at(i).f_added < 4) {
 		recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100;
 	    }

mercurial