1338 |
1338 |
1339 void EditRecipe::on_deleteFermentRow_clicked() |
1339 void EditRecipe::on_deleteFermentRow_clicked() |
1340 { |
1340 { |
1341 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
1341 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
1342 int row = pb->objectName().toInt(); |
1342 int row = pb->objectName().toInt(); |
1343 qDebug() << "Delete fermentable row" << row; |
1343 qDebug() << "Delete fermentable row" << row << recipe->fermentables.size(); |
1344 |
1344 |
1345 int rc = QMessageBox::warning(this, tr("Delete fermentable"), tr("Delete %1").arg(recipe->fermentables.at(row).f_name), |
1345 int rc = QMessageBox::warning(this, tr("Delete fermentable"), tr("Delete %1").arg(recipe->fermentables.at(row).f_name), |
1346 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
1346 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
1347 if (rc == QMessageBox::No) |
1347 if (rc == QMessageBox::No) |
1348 return; |
1348 return; |
1349 |
1349 |
1350 ui->fermentablesTable->removeRow(row); |
1350 this->ignoreChanges = true; |
1351 // recalculate percentages |
1351 recipe->fermentables.removeAt(row); |
|
1352 |
|
1353 /* |
|
1354 * Recalculate the percentages on the rows left. |
|
1355 */ |
|
1356 double total = 0; |
|
1357 for (int i = 0; i < recipe->fermentables.size(); i++) |
|
1358 if (recipe->fermentables.at(i).f_added < 4) // Only before bottle/kegging |
|
1359 total += recipe->fermentables.at(i).f_amount; |
|
1360 for (int i = 0; i < recipe->fermentables.size(); i++) |
|
1361 if (recipe->fermentables.at(i).f_added < 4) |
|
1362 recipe->fermentables[i].f_percentage = recipe->fermentables.at(i).f_amount / total * 100; |
|
1363 |
|
1364 this->ignoreChanges = false; |
|
1365 emit refreshAll(); |
1352 } |
1366 } |
1353 |
1367 |
1354 |
1368 |
1355 void EditRecipe::ferment_amount_changed(double val) |
1369 void EditRecipe::ferment_amount_changed(double val) |
1356 { |
1370 { |