Finished delete fermentable row.

Fri, 08 Apr 2022 19:44:14 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 08 Apr 2022 19:44:14 +0200
changeset 119
68853aee2ef9
parent 118
c57771e40ca8
child 120
0ab611547a57

Finished delete fermentable row.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Fri Apr 08 17:34:27 2022 +0200
+++ b/src/EditRecipe.cpp	Fri Apr 08 19:44:14 2022 +0200
@@ -1340,15 +1340,29 @@
 {
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
-    qDebug() << "Delete fermentable row" << row;
+    qDebug() << "Delete fermentable row" << row << recipe->fermentables.size();
 
     int rc = QMessageBox::warning(this, tr("Delete fermentable"), tr("Delete %1").arg(recipe->fermentables.at(row).f_name),
 		    QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
     if (rc == QMessageBox::No)
 	return;
 
-    ui->fermentablesTable->removeRow(row);
-//    recalculate percentages
+    this->ignoreChanges = true;
+    recipe->fermentables.removeAt(row);
+
+    /*
+     * Recalculate the percentages on the rows left.
+     */
+    double total = 0;
+    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;
+    for (int i = 0; i < recipe->fermentables.size(); i++)
+        if (recipe->fermentables.at(i).f_added < 4)
+            recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100;
+
+    this->ignoreChanges = false;
+    emit refreshAll();
 }
 
 

mercurial