src/EditRecipe.cpp

changeset 116
6f415bf6340a
parent 115
9c90a00fd9dd
child 117
84eda8ff3b60
equal deleted inserted replaced
115:9c90a00fd9dd 116:6f415bf6340a
1047 QJsonObject obj; 1047 QJsonObject obj;
1048 obj.insert("f_acid_to_ph_57", round(recipe->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000); 1048 obj.insert("f_acid_to_ph_57", round(recipe->fermentables.at(i).f_acid_to_ph_57 * 100000) / 100000);
1049 obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil); 1049 obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil);
1050 obj.insert("f_added", recipe->fermentables.at(i).f_added); 1050 obj.insert("f_added", recipe->fermentables.at(i).f_added);
1051 obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100); 1051 obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100);
1052 obj.insert("f_amount", round(recipe->fermentables.at(i).f_added * 10000) / 10000); 1052 obj.insert("f_amount", round(recipe->fermentables.at(i).f_amount * 10000) / 10000);
1053 obj.insert("f_coarse_fine_diff", round(recipe->fermentables.at(i).f_coarse_fine_diff * 10) / 10); 1053 obj.insert("f_coarse_fine_diff", round(recipe->fermentables.at(i).f_coarse_fine_diff * 10) / 10);
1054 obj.insert("f_color", round(recipe->fermentables.at(i).f_color * 10) / 10); 1054 obj.insert("f_color", round(recipe->fermentables.at(i).f_color * 10) / 10);
1055 obj.insert("f_cost", round(recipe->fermentables.at(i).f_cost * 1000) / 1000); 1055 obj.insert("f_cost", round(recipe->fermentables.at(i).f_cost * 1000) / 1000);
1056 obj.insert("f_di_ph", round(recipe->fermentables.at(i).f_di_ph * 100000) / 100000); 1056 obj.insert("f_di_ph", round(recipe->fermentables.at(i).f_di_ph * 100000) / 100000);
1057 obj.insert("f_diastatic_power", round(recipe->fermentables.at(i).f_diastatic_power * 100000) / 100000); 1057 obj.insert("f_diastatic_power", round(recipe->fermentables.at(i).f_diastatic_power * 100000) / 100000);
1068 obj.insert("f_type", recipe->fermentables.at(i).f_type); 1068 obj.insert("f_type", recipe->fermentables.at(i).f_type);
1069 obj.insert("f_yield", round(recipe->fermentables.at(i).f_yield * 10) / 10); 1069 obj.insert("f_yield", round(recipe->fermentables.at(i).f_yield * 10) / 10);
1070 // qDebug() << "fermentable_Json" << i << obj; 1070 // qDebug() << "fermentable_Json" << i << obj;
1071 array.append(obj); /* Append this object */ 1071 array.append(obj); /* Append this object */
1072 } 1072 }
1073 // qDebug() << array; 1073 QJsonDocument doc;
1074 query.bindValue(":json_fermentables", array); 1074 doc.setArray(array);
1075 qDebug() << doc.toJson(QJsonDocument::Compact);
1076 query.bindValue(":json_fermentables", doc.toJson(QJsonDocument::Compact));
1075 } 1077 }
1076 1078
1077 if (recipe->hops.size() == 0) { 1079 if (recipe->hops.size() == 0) {
1078 query.bindValue(":json_hops", "[]"); 1080 query.bindValue(":json_hops", "[]");
1079 } else { 1081 } else {
1094 obj.insert("h_humulene", round(recipe->hops.at(i).h_humulene * 100) / 100); 1096 obj.insert("h_humulene", round(recipe->hops.at(i).h_humulene * 100) / 100);
1095 obj.insert("h_caryophyllene", round(recipe->hops.at(i).h_caryophyllene * 100) / 100); 1097 obj.insert("h_caryophyllene", round(recipe->hops.at(i).h_caryophyllene * 100) / 100);
1096 obj.insert("h_cohumulone", round(recipe->hops.at(i).h_cohumulone * 100) / 100); 1098 obj.insert("h_cohumulone", round(recipe->hops.at(i).h_cohumulone * 100) / 100);
1097 obj.insert("h_myrcene", round(recipe->hops.at(i).h_myrcene * 100) / 100); 1099 obj.insert("h_myrcene", round(recipe->hops.at(i).h_myrcene * 100) / 100);
1098 obj.insert("h_total_oil", round(recipe->hops.at(i).h_total_oil * 100) / 100); 1100 obj.insert("h_total_oil", round(recipe->hops.at(i).h_total_oil * 100) / 100);
1099 qDebug() << "hops_Json" << i << obj; 1101 // qDebug() << "hops_Json" << i << obj;
1100 array.append(obj); /* Append this object */ 1102 array.append(obj); /* Append this object */
1101 } 1103 }
1102 // qDebug() << array; 1104 QJsonDocument doc;
1103 query.bindValue(":json_hops", array); 1105 doc.setArray(array);
1106 query.bindValue(":json_hops", doc.toJson(QJsonDocument::Compact));
1104 } 1107 }
1105 1108
1106 if (recipe->miscs.size() == 0) { 1109 if (recipe->miscs.size() == 0) {
1107 query.bindValue(":json_miscs", "[]"); 1110 query.bindValue(":json_miscs", "[]");
1108 } else { 1111 } else {
1114 obj.insert("m_type", recipe->miscs.at(i).m_type); 1117 obj.insert("m_type", recipe->miscs.at(i).m_type);
1115 obj.insert("m_use_use", recipe->miscs.at(i).m_use_use); 1118 obj.insert("m_use_use", recipe->miscs.at(i).m_use_use);
1116 obj.insert("m_time", recipe->miscs.at(i).m_time); 1119 obj.insert("m_time", recipe->miscs.at(i).m_time);
1117 obj.insert("m_amount_is_weight", recipe->miscs.at(i).m_amount_is_weight); 1120 obj.insert("m_amount_is_weight", recipe->miscs.at(i).m_amount_is_weight);
1118 obj.insert("m_cost", recipe->miscs.at(i).m_cost); 1121 obj.insert("m_cost", recipe->miscs.at(i).m_cost);
1119 qDebug() << "miscs_Json" << i << obj; 1122 // qDebug() << "miscs_Json" << i << obj;
1120 array.append(obj); /* Append this object */ 1123 array.append(obj); /* Append this object */
1121 } 1124 }
1122 // qDebug() << array; 1125 QJsonDocument doc;
1123 query.bindValue(":json_miscs", array); 1126 doc.setArray(array);
1127 // qDebug() << doc.toJson(QJsonDocument::Compact);
1128 query.bindValue(":json_miscs", doc.toJson(QJsonDocument::Compact));
1124 } 1129 }
1125 1130
1126 if (recipe->yeasts.size() == 0) { 1131 if (recipe->yeasts.size() == 0) {
1127 query.bindValue(":json_yeasts", "[]"); 1132 query.bindValue(":json_yeasts", "[]");
1128 } else { 1133 } else {
1153 obj.insert("y_gr_hl_lo", recipe->yeasts.at(i).y_gr_hl_lo); 1158 obj.insert("y_gr_hl_lo", recipe->yeasts.at(i).y_gr_hl_lo);
1154 obj.insert("y_sg_lo", round(recipe->yeasts.at(i).y_sg_lo * 1000) / 1000); 1159 obj.insert("y_sg_lo", round(recipe->yeasts.at(i).y_sg_lo * 1000) / 1000);
1155 obj.insert("y_gr_hl_hi", recipe->yeasts.at(i).y_gr_hl_hi); 1160 obj.insert("y_gr_hl_hi", recipe->yeasts.at(i).y_gr_hl_hi);
1156 obj.insert("y_sg_hi", round(recipe->yeasts.at(i).y_sg_hi * 1000) / 1000); 1161 obj.insert("y_sg_hi", round(recipe->yeasts.at(i).y_sg_hi * 1000) / 1000);
1157 obj.insert("y_cost", recipe->yeasts.at(i).y_cost); 1162 obj.insert("y_cost", recipe->yeasts.at(i).y_cost);
1158 qDebug() << "yeasts_Json" << i << obj; 1163 // qDebug() << "yeasts_Json" << i << obj;
1159 array.append(obj); /* Append this object */ 1164 array.append(obj); /* Append this object */
1160 } 1165 }
1161 // qDebug() << array; 1166 QJsonDocument doc;
1162 query.bindValue(":json_yeasts", array); 1167 doc.setArray(array);
1168 // qDebug() << doc.toJson(QJsonDocument::Compact);
1169 query.bindValue(":json_yeasts", doc.toJson(QJsonDocument::Compact));
1163 } 1170 }
1164 1171
1165 if (recipe->mashs.size() == 0) { 1172 if (recipe->mashs.size() == 0) {
1166 query.bindValue(":json_mashs", "[]"); 1173 query.bindValue(":json_mashs", "[]");
1167 } else { 1174 } else {
1176 obj.insert("step_temp", round(recipe->mashs.at(i).step_temp * 100) / 100); 1183 obj.insert("step_temp", round(recipe->mashs.at(i).step_temp * 100) / 100);
1177 obj.insert("step_time", round(recipe->mashs.at(i).step_time * 100) / 100); 1184 obj.insert("step_time", round(recipe->mashs.at(i).step_time * 100) / 100);
1178 obj.insert("ramp_time", round(recipe->mashs.at(i).ramp_time * 100) / 100); 1185 obj.insert("ramp_time", round(recipe->mashs.at(i).ramp_time * 100) / 100);
1179 obj.insert("end_temp", round(recipe->mashs.at(i).end_temp * 100) / 100); 1186 obj.insert("end_temp", round(recipe->mashs.at(i).end_temp * 100) / 100);
1180 obj.insert("step_wg_ratio", round(recipe->mashs.at(i).step_wg_ratio * 100) / 100); 1187 obj.insert("step_wg_ratio", round(recipe->mashs.at(i).step_wg_ratio * 100) / 100);
1181 qDebug() << "mashs_Json" << i << obj; 1188 // qDebug() << "mashs_Json" << i << obj;
1182 array.append(obj); /* Append this object */ 1189 array.append(obj); /* Append this object */
1183 } 1190 }
1184 // qDebug() << array; 1191 QJsonDocument doc;
1185 query.bindValue(":json_mashs", array); 1192 doc.setArray(array);
1193 // qDebug() << doc.toJson(QJsonDocument::Compact);
1194 query.bindValue(":json_mashs", doc.toJson(QJsonDocument::Compact));
1186 } 1195 }
1187 1196
1188 if (this->recno == -1) { 1197 if (this->recno == -1) {
1189 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); 1198 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
1190 } else { 1199 } else {
1317 calcFermentables(); 1326 calcFermentables();
1318 is_changed(); 1327 is_changed();
1319 } 1328 }
1320 1329
1321 1330
1322 /* TODO: move this code to MySQL save */
1323 void EditRecipe::fermentable_Json()
1324 {
1325 QTableWidgetItem *item;
1326 QJsonArray array;
1327
1328 qDebug() << "fermentable_Json()";
1329
1330 for (int i = 0; i < recipe->fermentables.size(); i++) {
1331
1332 QJsonObject obj;
1333 obj.insert("f_acid_to_ph_57", recipe->fermentables.at(i).f_acid_to_ph_57);
1334 obj.insert("f_add_after_boil", recipe->fermentables.at(i).f_add_after_boil);
1335 obj.insert("f_added", recipe->fermentables.at(i).f_added);
1336 obj.insert("f_adjust_to_total_100", recipe->fermentables.at(i).f_adjust_to_total_100);
1337 obj.insert("f_amount", recipe->fermentables.at(i).f_added);
1338 obj.insert("f_coarse_fine_diff", recipe->fermentables.at(i).f_coarse_fine_diff);
1339 obj.insert("f_color", recipe->fermentables.at(i).f_color);
1340 obj.insert("f_cost", recipe->fermentables.at(i).f_cost);
1341 obj.insert("f_di_ph", recipe->fermentables.at(i).f_di_ph);
1342 obj.insert("f_diastatic_power", recipe->fermentables.at(i).f_diastatic_power);
1343 obj.insert("f_dissolved_protein", recipe->fermentables.at(i).f_dissolved_protein);
1344 obj.insert("f_graintype", recipe->fermentables.at(i).f_graintype);
1345 obj.insert("f_max_in_batch", recipe->fermentables.at(i).f_max_in_batch);
1346 obj.insert("f_moisture", recipe->fermentables.at(i).f_moisture);
1347 obj.insert("f_name", recipe->fermentables.at(i).f_name);
1348 obj.insert("f_origin", recipe->fermentables.at(i).f_origin);
1349 obj.insert("f_percentage", recipe->fermentables.at(i).f_percentage);
1350 obj.insert("f_protein", recipe->fermentables.at(i).f_protein);
1351 obj.insert("f_recommend_mash", recipe->fermentables.at(i).f_recommend_mash);
1352 obj.insert("f_supplier", recipe->fermentables.at(i).f_supplier);
1353 obj.insert("f_type", recipe->fermentables.at(i).f_type);
1354 obj.insert("f_yield", recipe->fermentables.at(i).f_yield);
1355 qDebug() << "fermentable_Json" << i << obj;
1356 array.append(obj); /* Append this object */
1357 }
1358
1359 qDebug() << array;
1360 /* Copy to the global array and refresh */
1361 // this->fermentables.setArray(array);
1362 }
1363
1364
1365 void EditRecipe::on_deleteFermentRow_clicked() 1331 void EditRecipe::on_deleteFermentRow_clicked()
1366 { 1332 {
1367 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); 1333 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
1368 int row = pb->objectName().toInt(); 1334 int row = pb->objectName().toInt();
1369 qDebug() << "Delete fermentable row" << row; 1335 qDebug() << "Delete fermentable row" << row;
1373 if (rc == QMessageBox::No) 1339 if (rc == QMessageBox::No)
1374 return; 1340 return;
1375 1341
1376 ui->fermentablesTable->removeRow(row); 1342 ui->fermentablesTable->removeRow(row);
1377 // recalculate percentages 1343 // recalculate percentages
1378 // fermentable_Json();
1379 } 1344 }
1380 1345
1381 1346
1382 void EditRecipe::ferment_amount_changed(double val) 1347 void EditRecipe::ferment_amount_changed(double val)
1383 { 1348 {
1409 ui->fermentablesTable->setItem(i, 8, item); 1374 ui->fermentablesTable->setItem(i, 8, item);
1410 if (i == editrow) 1375 if (i == editrow)
1411 this->pctEdit->setValue(perc); 1376 this->pctEdit->setValue(perc);
1412 } 1377 }
1413 this->ignoreChanges = false; 1378 this->ignoreChanges = false;
1379 is_changed();
1414 } 1380 }
1415 1381
1416 void EditRecipe::ferment_pct_changed(double val) 1382 void EditRecipe::ferment_pct_changed(double val)
1417 { 1383 {
1418 if (! recipe->fermentables_use100) 1384 if (! recipe->fermentables_use100)

mercurial