src/EditRecipe.cpp

changeset 113
30a34d639e90
parent 112
9e0dfa78f349
child 114
b027aa2a01d4
equal deleted inserted replaced
112:9e0dfa78f349 113:30a34d639e90
194 } 194 }
195 195
196 const auto& h_json = query.value(85).toString(); 196 const auto& h_json = query.value(85).toString();
197 if (!h_json.trimmed().isEmpty()) { 197 if (!h_json.trimmed().isEmpty()) {
198 const auto& formattedJson = QString("%1").arg(h_json); 198 const auto& formattedJson = QString("%1").arg(h_json);
199 this->hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); 199 QJsonDocument hops = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
200 if (parseError.error != QJsonParseError::NoError) 200 if (parseError.error != QJsonParseError::NoError) {
201 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; 201 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
202 } else if (hops.isArray()) {
203 for (int i = 0; i < hops.array().size(); i++) {
204 QJsonObject obj = hops.array().at(i).toObject();
205 qDebug() << i << obj;
206 Hops h;
207 h.h_name = obj["h_name"].toString();
208 h.h_origin = obj["h_origin"].toString();
209 h.h_amount = obj["h_amount"].toDouble();
210 h.h_cost = obj["h_cost"].toDouble();
211 h.h_type = obj["h_type"].toInt();
212 h.h_form = obj["h_form"].toInt();
213 h.h_useat = obj["h_useat"].toInt();
214 h.h_time = obj["h_time"].toInt();
215 h.h_alpha = obj["h_alpha"].toDouble();
216 h.h_beta = obj["h_beta"].toDouble();
217 h.h_hsi = obj["h_hsi"].toDouble();
218 h.h_humulene = obj["h_humulene"].toDouble();
219 h.h_caryophyllene = obj["h_caryophyllene"].toDouble();
220 h.h_cohumulone = obj["h_cohumulone"].toDouble();
221 h.h_myrcene = obj["h_myrcene"].toDouble();
222 h.h_total_oil = obj["h_total_oil"].toDouble();
223 recipe->hops.append(h);
224 }
225 qDebug() << "hops" << recipe->hops.size();
226 }
202 } else { 227 } else {
203 qDebug() << "empty hops"; 228 qDebug() << "empty hops";
204 } 229 }
205 230
206 const auto& m_json = query.value(86).toString(); 231 const auto& m_json = query.value(86).toString();
369 recipe->wb_total_alkalinity = 0; 394 recipe->wb_total_alkalinity = 0;
370 recipe->wb_ph = 7; 395 recipe->wb_ph = 7;
371 recipe->wa_acid_name = 0; 396 recipe->wa_acid_name = 0;
372 recipe->wa_acid_perc = 80; 397 recipe->wa_acid_perc = 80;
373 recipe->wa_base_name = 0; 398 recipe->wa_base_name = 0;
374
375 const auto& formattedJson = QString("[]");
376 this->hops = QJsonDocument::fromJson(formattedJson.toUtf8());
377 } 399 }
378 400
379 ui->lockedEdit->setChecked(recipe->locked); 401 ui->lockedEdit->setChecked(recipe->locked);
380 ui->st_nameEdit->setText(recipe->st_name); 402 ui->st_nameEdit->setText(recipe->st_name);
381 ui->st_groupEdit->setText(recipe->st_letter); 403 ui->st_groupEdit->setText(recipe->st_letter);

mercurial