diff -r 9c90a00fd9dd -r 6f415bf6340a src/EditRecipe.cpp --- a/src/EditRecipe.cpp Thu Apr 07 19:07:28 2022 +0200 +++ b/src/EditRecipe.cpp Thu Apr 07 20:20:42 2022 +0200 @@ -1049,7 +1049,7 @@ obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil); obj.insert("f_added", recipe->fermentables.at(i).f_added); obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100); - obj.insert("f_amount", round(recipe->fermentables.at(i).f_added * 10000) / 10000); + obj.insert("f_amount", round(recipe->fermentables.at(i).f_amount * 10000) / 10000); obj.insert("f_coarse_fine_diff", round(recipe->fermentables.at(i).f_coarse_fine_diff * 10) / 10); obj.insert("f_color", round(recipe->fermentables.at(i).f_color * 10) / 10); obj.insert("f_cost", round(recipe->fermentables.at(i).f_cost * 1000) / 1000); @@ -1070,8 +1070,10 @@ // qDebug() << "fermentable_Json" << i << obj; array.append(obj); /* Append this object */ } -// qDebug() << array; - query.bindValue(":json_fermentables", array); + QJsonDocument doc; + doc.setArray(array); + qDebug() << doc.toJson(QJsonDocument::Compact); + query.bindValue(":json_fermentables", doc.toJson(QJsonDocument::Compact)); } if (recipe->hops.size() == 0) { @@ -1096,11 +1098,12 @@ obj.insert("h_cohumulone", round(recipe->hops.at(i).h_cohumulone * 100) / 100); obj.insert("h_myrcene", round(recipe->hops.at(i).h_myrcene * 100) / 100); obj.insert("h_total_oil", round(recipe->hops.at(i).h_total_oil * 100) / 100); - qDebug() << "hops_Json" << i << obj; +// qDebug() << "hops_Json" << i << obj; array.append(obj); /* Append this object */ } -// qDebug() << array; - query.bindValue(":json_hops", array); + QJsonDocument doc; + doc.setArray(array); + query.bindValue(":json_hops", doc.toJson(QJsonDocument::Compact)); } if (recipe->miscs.size() == 0) { @@ -1116,11 +1119,13 @@ obj.insert("m_time", recipe->miscs.at(i).m_time); obj.insert("m_amount_is_weight", recipe->miscs.at(i).m_amount_is_weight); obj.insert("m_cost", recipe->miscs.at(i).m_cost); - qDebug() << "miscs_Json" << i << obj; +// qDebug() << "miscs_Json" << i << obj; array.append(obj); /* Append this object */ } -// qDebug() << array; - query.bindValue(":json_miscs", array); + QJsonDocument doc; + doc.setArray(array); +// qDebug() << doc.toJson(QJsonDocument::Compact); + query.bindValue(":json_miscs", doc.toJson(QJsonDocument::Compact)); } if (recipe->yeasts.size() == 0) { @@ -1155,11 +1160,13 @@ obj.insert("y_gr_hl_hi", recipe->yeasts.at(i).y_gr_hl_hi); obj.insert("y_sg_hi", round(recipe->yeasts.at(i).y_sg_hi * 1000) / 1000); obj.insert("y_cost", recipe->yeasts.at(i).y_cost); - qDebug() << "yeasts_Json" << i << obj; +// qDebug() << "yeasts_Json" << i << obj; array.append(obj); /* Append this object */ } -// qDebug() << array; - query.bindValue(":json_yeasts", array); + QJsonDocument doc; + doc.setArray(array); +// qDebug() << doc.toJson(QJsonDocument::Compact); + query.bindValue(":json_yeasts", doc.toJson(QJsonDocument::Compact)); } if (recipe->mashs.size() == 0) { @@ -1178,11 +1185,13 @@ obj.insert("ramp_time", round(recipe->mashs.at(i).ramp_time * 100) / 100); obj.insert("end_temp", round(recipe->mashs.at(i).end_temp * 100) / 100); obj.insert("step_wg_ratio", round(recipe->mashs.at(i).step_wg_ratio * 100) / 100); - qDebug() << "mashs_Json" << i << obj; +// qDebug() << "mashs_Json" << i << obj; array.append(obj); /* Append this object */ } -// qDebug() << array; - query.bindValue(":json_mashs", array); + QJsonDocument doc; + doc.setArray(array); +// qDebug() << doc.toJson(QJsonDocument::Compact); + query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact)); } if (this->recno == -1) { @@ -1319,49 +1328,6 @@ } -/* TODO: move this code to MySQL save */ -void EditRecipe::fermentable_Json() -{ - QTableWidgetItem *item; - QJsonArray array; - - qDebug() << "fermentable_Json()"; - - for (int i = 0; i < recipe->fermentables.size(); i++) { - - QJsonObject obj; - obj.insert("f_acid_to_ph_57", recipe->fermentables.at(i).f_acid_to_ph_57); - obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil); - obj.insert("f_added", recipe->fermentables.at(i).f_added); - obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100); - obj.insert("f_amount", recipe->fermentables.at(i).f_added); - obj.insert("f_coarse_fine_diff", recipe->fermentables.at(i).f_coarse_fine_diff); - obj.insert("f_color", recipe->fermentables.at(i).f_color); - obj.insert("f_cost", recipe->fermentables.at(i).f_cost); - obj.insert("f_di_ph", recipe->fermentables.at(i).f_di_ph); - obj.insert("f_diastatic_power", recipe->fermentables.at(i).f_diastatic_power); - obj.insert("f_dissolved_protein", recipe->fermentables.at(i).f_dissolved_protein); - obj.insert("f_graintype", recipe->fermentables.at(i).f_graintype); - obj.insert("f_max_in_batch", recipe->fermentables.at(i).f_max_in_batch); - obj.insert("f_moisture", recipe->fermentables.at(i).f_moisture); - obj.insert("f_name", recipe->fermentables.at(i).f_name); - obj.insert("f_origin", recipe->fermentables.at(i).f_origin); - obj.insert("f_percentage", recipe->fermentables.at(i).f_percentage); - obj.insert("f_protein", recipe->fermentables.at(i).f_protein); - obj.insert("f_recommend_mash", recipe->fermentables.at(i).f_recommend_mash); - obj.insert("f_supplier", recipe->fermentables.at(i).f_supplier); - obj.insert("f_type", recipe->fermentables.at(i).f_type); - obj.insert("f_yield", recipe->fermentables.at(i).f_yield); - qDebug() << "fermentable_Json" << i << obj; - array.append(obj); /* Append this object */ - } - - qDebug() << array; - /* Copy to the global array and refresh */ -// this->fermentables.setArray(array); -} - - void EditRecipe::on_deleteFermentRow_clicked() { QPushButton *pb = qobject_cast(QObject::sender()); @@ -1375,7 +1341,6 @@ ui->fermentablesTable->removeRow(row); // recalculate percentages -// fermentable_Json(); } @@ -1411,6 +1376,7 @@ this->pctEdit->setValue(perc); } this->ignoreChanges = false; + is_changed(); } void EditRecipe::ferment_pct_changed(double val)