Code cleanup after last changes.

Wed, 06 Apr 2022 22:47:37 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 Apr 2022 22:47:37 +0200
changeset 114
b027aa2a01d4
parent 113
30a34d639e90
child 115
9c90a00fd9dd

Code cleanup after last changes.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Wed Apr 06 21:57:02 2022 +0200
+++ b/src/EditRecipe.cpp	Wed Apr 06 22:47:37 2022 +0200
@@ -729,7 +729,9 @@
 	    addedmass += recipe->fermentables.at(i).f_amount;
 	    vol += (x * sugardensity + (1 - x) * 1) * recipe->fermentables.at(i).f_amount;
 	}
-	if (recipe->fermentables.at(i).f_added == 0 && (recipe->fermentables.at(i).f_type == 0 || recipe->fermentables.at(i).f_type == 4) && recipe->fermentables.at(i).f_color < 50) {
+	if (recipe->fermentables.at(i).f_added == 0 &&
+	    (recipe->fermentables.at(i).f_type == 0 || recipe->fermentables.at(i).f_type == 4) &&
+	    recipe->fermentables.at(i).f_color < 50) {
 	    lintner += recipe->fermentables.at(i).f_diastatic_power * recipe->fermentables.at(i).f_amount;
 	}
 	if (recipe->fermentables.at(i).f_added < 4) {
@@ -894,6 +896,10 @@
 	QMessageBox::warning(this, tr("Edit Recipe"), tr("Name empty or too short."));
 	return;
     }
+    if (ui->st_nameEdit->text().length() < 2) {
+        QMessageBox::warning(this, tr("Edit Recipe"), tr("No beerstyle selected."));
+        return;
+    }
 
     if (this->textIsChanged) {
     	if (this->recno == -1) {
@@ -915,39 +921,40 @@
 		"boil_time=:boil_time, efficiency=:efficiency "
                 " WHERE record = :recno");
     	}
-	query.bindValue(":locked", ui->lockedEdit->isChecked() ? 1:0);
-	query.bindValue(":st_name", ui->st_nameEdit->text());
-	query.bindValue(":st_letter", ui->st_groupEdit->text());
-	query.bindValue(":st_guide", ui->st_guideEdit->text());
-	query.bindValue(":st_category", ui->st_catEdit->text());
-	query.bindValue(":st_catnr", recipe->st_type);
-	query.bindValue(":st_og_min", QString("%1").arg(ui->est_ogShow->minval(), 4, 'f', 3, '0'));
-	query.bindValue(":st_og_max", QString("%1").arg(ui->est_ogShow->maxval(), 4, 'f', 3, '0'));
-	query.bindValue(":st_fg_min", QString("%1").arg(ui->est_fgShow->minval(), 4, 'f', 3, '0'));
-        query.bindValue(":st_fg_max", QString("%1").arg(ui->est_fgShow->maxval(), 4, 'f', 3, '0'));
-	query.bindValue(":st_ibu_min", QString("%1").arg(ui->est_ibuShow->minval(), 4, 'f', 3, '0'));
-        query.bindValue(":st_ibu_max", QString("%1").arg(ui->est_ibuShow->maxval(), 4, 'f', 3, '0'));
-	query.bindValue(":st_color_min", QString("%1").arg(ui->est_colorShow->minval(), 4, 'f', 3, '0'));
-        query.bindValue(":st_color_max", QString("%1").arg(ui->est_colorShow->maxval(), 4, 'f', 3, '0'));
-	query.bindValue(":st_carb_min", QString("%1").arg(ui->est_carbShow->minval(), 4, 'f', 3, '0'));
-        query.bindValue(":st_carb_max", QString("%1").arg(ui->est_carbShow->maxval(), 4, 'f', 3, '0'));
-	query.bindValue(":st_abv_min", QString("%1").arg(ui->est_abvShow->minval(), 4, 'f', 3, '0'));
-        query.bindValue(":st_abv_max", QString("%1").arg(ui->est_abvShow->maxval(), 4, 'f', 3, '0'));
-	query.bindValue(":name", ui->nameEdit->text());
-	query.bindValue(":notes", ui->notesEdit->toPlainText());
-	query.bindValue(":type", ui->typeEdit->currentIndex());
-	query.bindValue(":batch_size", QString("%1").arg(ui->batch_sizeEdit->value(), 2, 'f', 1, '0'));
-	query.bindValue(":boil_size", QString("%1").arg(ui->boil_sizeEdit->value(), 2, 'f', 1, '0'));
-	query.bindValue(":boil_time", QString("%1").arg(ui->boil_timeEdit->value(), 2, 'f', 1, '0'));
-	query.bindValue(":efficiency", QString("%1").arg(ui->efficiencyEdit->value(), 2, 'f', 1, '0'));
-	query.bindValue(":est_og", QString("%1").arg(ui->est_ogEdit->value(), 4, 'f', 3, '0'));
-	query.bindValue(":est_fg", QString("%1").arg(ui->est_fgEdit->value(), 4, 'f', 3, '0'));
-	query.bindValue(":est_abv", QString("%1").arg(ui->est_abvEdit->value(), 2, 'f', 1, '0'));
-	query.bindValue(":est_color", QString("%1").arg(ui->est_colorEdit->value(), 1, 'f', 0, '0'));
-	query.bindValue(":color_method", ui->color_methodEdit->currentIndex());
-	query.bindValue(":est_ibu", QString("%1").arg(ui->est_ibuEdit->value(), 1, 'f', 0, '0'));
-	query.bindValue(":ibu_method", ui->ibu_methodEdit->currentIndex());
-	query.bindValue(":est_carb", QString("%1").arg(ui->est_carbEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":locked", recipe->locked ? 1:0);
+	query.bindValue(":st_name", recipe->st_name);
+	query.bindValue(":st_letter", recipe->st_letter);
+	query.bindValue(":st_guide", recipe->st_guide);
+	query.bindValue(":st_category", recipe->st_category);
+	query.bindValue(":st_catnr", recipe->st_category_number);
+	query.bindValue(":st_type", recipe->st_type);
+	query.bindValue(":st_og_min", round(recipe->st_og_min * 1000) / 1000);
+	query.bindValue(":st_og_max", round(recipe->st_og_max * 1000) / 1000);
+	query.bindValue(":st_fg_min", round(recipe->st_fg_min * 1000) / 1000);
+        query.bindValue(":st_fg_max", round(recipe->st_fg_max * 1000) / 1000);
+	query.bindValue(":st_ibu_min", round(recipe->st_ibu_min * 10) / 10);
+        query.bindValue(":st_ibu_max", round(recipe->st_ibu_max * 10) / 10);
+	query.bindValue(":st_color_min", round(recipe->st_color_min * 10) / 10);
+        query.bindValue(":st_color_max", round(recipe->st_color_max * 10) / 10);
+	query.bindValue(":st_carb_min", round(recipe->st_carb_min * 10) / 10);
+        query.bindValue(":st_carb_max", round(recipe->st_carb_max * 10) / 10);
+	query.bindValue(":st_abv_min", round(recipe->st_abv_min * 10) / 10);
+        query.bindValue(":st_abv_max", round(recipe->st_abv_max * 10) / 10);
+	query.bindValue(":name", recipe->name);
+	query.bindValue(":notes", recipe->notes);
+	query.bindValue(":type", recipe->type);
+	query.bindValue(":batch_size", round(recipe->batch_size * 10) / 10);
+	query.bindValue(":boil_size", round(recipe->boil_size * 10) / 10);
+	query.bindValue(":boil_time", round(recipe->boil_time * 10) / 10);
+	query.bindValue(":efficiency", round(recipe->efficiency * 10) / 10);
+	query.bindValue(":est_og", round(recipe->est_og * 1000) / 1000);
+	query.bindValue(":est_fg", round(recipe->est_fg * 1000) / 1000);
+	query.bindValue(":est_abv", round(recipe->est_abv * 10) / 10);
+	query.bindValue(":est_color", round(recipe->est_color * 10) / 10);
+	query.bindValue(":color_method", recipe->color_method);
+	query.bindValue(":est_ibu", round(recipe->est_ibu * 10) / 10);
+	query.bindValue(":ibu_method", recipe->ibu_method);
+	query.bindValue(":est_carb", round(recipe->est_carb * 10) / 10);
 
 	if (this->recno == -1) {
 	    query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
@@ -1315,13 +1322,9 @@
 	// recalculate percentages
     } else {
 	qDebug() << "accepted";
-	// fermentrow to final
-
-	//fermentable_Json(); segfault !
     }
 
     // disconnect
-    // return
     emit refreshAll();
 }
 

mercurial