src/ImportXML.cpp

changeset 389
a98d45793808
parent 338
473479de8c5b
child 458
ac216a75ca9b
equal deleted inserted replaced
388:5eea69925634 389:a98d45793808
505 * Hop 505 * Hop
506 */ 506 */
507 total++; 507 total++;
508 Hops *h = new Hops(); 508 Hops *h = new Hops();
509 h->notes = h->origin = h->substitutes = ""; 509 h->notes = h->origin = h->substitutes = "";
510 h->bu_factor = 1.0;
511 h->utilisation = my_ut_pellet;
510 512
511 while (xml->readNext()) { 513 while (xml->readNext()) {
512 if (xml->atEnd()) 514 if (xml->atEnd())
513 break; 515 break;
514 if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "HOP")) { 516 if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "HOP")) {
515 query.prepare("INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, " 517 query.prepare("INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, "
516 "humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, " 518 "humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, "
517 "hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, " 519 "hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, "
518 "total_oil=:oil, uuid = :uuid"); 520 "total_oil=:oil, utilisation=:utilisation, bu_factor=:bu_factor, uuid = :uuid");
519 query.bindValue(":name", h->name); 521 query.bindValue(":name", h->name);
520 query.bindValue(":alpha", QString("%1").arg(h->alpha, 2, 'f', 1, '0')); 522 query.bindValue(":alpha", QString("%1").arg(h->alpha, 2, 'f', 1, '0'));
521 query.bindValue(":beta", QString("%1").arg(h->beta, 2, 'f', 1, '0')); 523 query.bindValue(":beta", QString("%1").arg(h->beta, 2, 'f', 1, '0'));
522 query.bindValue(":humulene", QString("%1").arg(h->humulene, 2, 'f', 1, '0')); 524 query.bindValue(":humulene", QString("%1").arg(h->humulene, 2, 'f', 1, '0'));
523 query.bindValue(":cary", QString("%1").arg(h->caryophyllene, 2, 'f', 1, '0')); 525 query.bindValue(":cary", QString("%1").arg(h->caryophyllene, 2, 'f', 1, '0'));
528 query.bindValue(":form", h->form); 530 query.bindValue(":form", h->form);
529 query.bindValue(":notes", h->notes); 531 query.bindValue(":notes", h->notes);
530 query.bindValue(":origin", h->origin); 532 query.bindValue(":origin", h->origin);
531 query.bindValue(":substitutes", h->substitutes); 533 query.bindValue(":substitutes", h->substitutes);
532 query.bindValue(":oil", QString("%1").arg(h->total_oil, 2, 'f', 1, '0')); 534 query.bindValue(":oil", QString("%1").arg(h->total_oil, 2, 'f', 1, '0'));
535 query.bindValue(":utilisation", QString("%1").arg(h->utilisation, 2, 'f', 1, '0'));
536 query.bindValue(":bu_factor", QString("%1").arg(h->bu_factor, 2, 'f', 1, '0'));
533 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); 537 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
534 query.exec(); 538 query.exec();
535 if (query.lastError().isValid()) { 539 if (query.lastError().isValid()) {
536 qWarning() << query.lastError(); 540 qWarning() << query.lastError();
537 errors++; 541 errors++;
548 h->name = xml->readElementText(); 552 h->name = xml->readElementText();
549 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ORIGIN")) { 553 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ORIGIN")) {
550 h->origin = xml->readElementText(); 554 h->origin = xml->readElementText();
551 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) { 555 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) {
552 h->notes = xml->readElementText(); 556 h->notes = xml->readElementText();
553 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FORM")) { 557 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) &&
554 QString temp = xml->readElementText(); 558 ((xml->name() == "FORM") || (xml->name() == "BMS_FORM"))) {
555 if (temp == "Plug") 559 QString temp = xml->readElementText();
556 h->form = 1; 560 if (temp == "Plug")
561 h->form = HOP_FORMS_PLUG;
557 else if (temp == "Leaf") 562 else if (temp == "Leaf")
558 h->form = 2; 563 h->form = HOP_FORMS_LEAF;
559 else if (temp == "Leaf wet") 564 else if (temp == "Leaf wet")
560 h->form = 3; 565 h->form = HOP_FORMS_LEAF_WET;
561 else if (temp == "Cryo") 566 else if (temp == "Cryo")
562 h->form = 4; 567 h->form = HOP_FORMS_CRYO;
563 else 568 else if (temp == "CO2 extract")
564 h->form = 0; 569 h->form = HOP_FORMS_CO2EXTRACT;
570 else if (temp == "Iso extract")
571 h->form = HOP_FORMS_ISOEXTRACT;
572 else
573 h->form = HOP_FORMS_PELLET;
565 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) { 574 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) {
566 h->alpha = xml->readElementText().toDouble(); 575 h->alpha = xml->readElementText().toDouble();
567 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) { 576 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) {
568 QString temp = xml->readElementText(); 577 QString temp = xml->readElementText();
569 if (temp == "Aroma") 578 if (temp == "Aroma")
570 h->type = 1; 579 h->type = HOP_TYPE_AROMA;
571 else if (temp == "Both") 580 else if (temp == "Both")
572 h->type = 2; 581 h->type = HOP_TYPE_BOTH;
573 else 582 else
574 h->type = 0; 583 h->type = HOP_TYPE_BITTERING;
575 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) { 584 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) {
576 QString temp = xml->readElementText(); 585 QString temp = xml->readElementText();
577 if (temp == "First wort") 586 if (temp == "First wort")
578 h->useat = 1; 587 h->useat = HOP_USEAT_FWH;
579 else if (temp == "Boil") 588 else if (temp == "Boil")
580 h->useat = 2; 589 h->useat = HOP_USEAT_BOIL;
581 else if (temp == "Aroma") 590 else if (temp == "Aroma")
582 h->useat = 3; 591 h->useat = HOP_USEAT_AROMA;
583 else if (temp == "Whirlpool") 592 else if (temp == "Whirlpool")
584 h->useat = 4; 593 h->useat = HOP_USEAT_WHIRLPOOL;
585 else if (temp == "Dry hop") 594 else if (temp == "Dry hop")
586 h->useat = 5; 595 h->useat = HOP_USEAT_DRY_HOP;
596 else if (temp == "Bottling")
597 h->useat = HOP_USEAT_BOTTLING;
587 else 598 else
588 h->useat = 0; 599 h->useat = 0;
589 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) { 600 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) {
590 h->beta = xml->readElementText().toDouble(); 601 h->beta = xml->readElementText().toDouble();
591 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HSI")) { 602 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HSI")) {
601 h->cohumulone = xml->readElementText().toDouble(); 612 h->cohumulone = xml->readElementText().toDouble();
602 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MYRCENE")) { 613 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MYRCENE")) {
603 h->myrcene = xml->readElementText().toDouble(); 614 h->myrcene = xml->readElementText().toDouble();
604 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) { 615 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) {
605 h->total_oil = xml->readElementText().toDouble(); 616 h->total_oil = xml->readElementText().toDouble();
617 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UTILISATION")) {
618 h->utilisation = xml->readElementText().toDouble();
619 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UT_FACTOR")) {
620 h->bu_factor = xml->readElementText().toDouble();
606 } else { 621 } else {
607 if (xml->tokenType() == QXmlStreamReader::StartElement) 622 if (xml->tokenType() == QXmlStreamReader::StartElement)
608 qDebug() << "2 " << xml->tokenType() << xml->name(); 623 qDebug() << "2 " << xml->tokenType() << xml->name();
609 } 624 }
610 } 625 }
1148 if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HOP")) { 1163 if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HOP")) {
1149 /* 1164 /*
1150 * Process hop 1165 * Process hop
1151 */ 1166 */
1152 Hops *newh = new Hops(); 1167 Hops *newh = new Hops();
1168 newh->utilisation = my_ut_pellet;
1169 newh->bu_factor = 1.0;
1153 while (xml->readNext()) { 1170 while (xml->readNext()) {
1154 if (xml->atEnd()) 1171 if (xml->atEnd())
1155 break; 1172 break;
1156 if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "HOP")) { 1173 if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "HOP")) {
1157 r->hops.append(*newh); 1174 r->hops.append(*newh);
1166 newh->notes = xml->readElementText(); 1183 newh->notes = xml->readElementText();
1167 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TIME")) { 1184 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TIME")) {
1168 newh->time = xml->readElementText().toDouble(); 1185 newh->time = xml->readElementText().toDouble();
1169 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "AMOUNT")) { 1186 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "AMOUNT")) {
1170 newh->amount = xml->readElementText().toDouble(); 1187 newh->amount = xml->readElementText().toDouble();
1171 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FORM")) { 1188 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) &&
1189 ((xml->name() == "FORM") || (xml->name() == "BMS_FORM"))) {
1172 QString temp = xml->readElementText(); 1190 QString temp = xml->readElementText();
1173 if (temp == "Plug") 1191 if (temp == "Plug")
1174 newh->form = 1; 1192 newh->form = HOP_FORMS_PLUG;
1175 else if (temp == "Leaf") 1193 else if (temp == "Leaf")
1176 newh->form = 2; 1194 newh->form = HOP_FORMS_LEAF;
1177 else if (temp == "Leaf wet") 1195 else if (temp == "Leaf wet")
1178 newh->form = 3; 1196 newh->form = HOP_FORMS_LEAF_WET;
1179 else if (temp == "Cryo") 1197 else if (temp == "Cryo")
1180 newh->form = 4; 1198 newh->form = HOP_FORMS_CRYO;
1199 else if (temp == "CO2 extract")
1200 newh->form = HOP_FORMS_CO2EXTRACT;
1201 else if (temp == "Iso extract")
1202 newh->form = HOP_FORMS_ISOEXTRACT;
1181 else 1203 else
1182 newh->form = 0; 1204 newh->form = HOP_FORMS_PELLET;
1183 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) { 1205 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) {
1184 newh->alpha = xml->readElementText().toDouble(); 1206 newh->alpha = xml->readElementText().toDouble();
1185 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) { 1207 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) {
1186 QString temp = xml->readElementText(); 1208 QString temp = xml->readElementText();
1187 if (temp == "Aroma") 1209 if (temp == "Aroma")
1188 newh->type = 1; 1210 newh->type = HOP_TYPE_AROMA;
1189 else if (temp == "Both") 1211 else if (temp == "Both")
1190 newh->type = 2; 1212 newh->type = HOP_TYPE_BOTH;
1191 else 1213 else
1192 newh->type = 0; 1214 newh->type = HOP_TYPE_BITTERING;
1193 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) { 1215 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) {
1194 QString temp = xml->readElementText(); 1216 QString temp = xml->readElementText();
1195 if (temp == "First wort") 1217 if (temp == "First wort")
1196 newh->useat = 1; 1218 newh->useat = HOP_USEAT_FWH;
1197 else if (temp == "Boil") 1219 else if (temp == "Boil")
1198 newh->useat = 2; 1220 newh->useat = HOP_USEAT_BOIL;
1199 else if (temp == "Aroma") 1221 else if (temp == "Aroma")
1200 newh->useat = 3; 1222 newh->useat = HOP_USEAT_AROMA;
1201 else if (temp == "Whirlpool") 1223 else if (temp == "Whirlpool")
1202 newh->useat = 4; 1224 newh->useat = HOP_USEAT_WHIRLPOOL;
1203 else if (temp == "Dry hop") 1225 else if (temp == "Dry hop")
1204 newh->useat = 5; 1226 newh->useat = HOP_USEAT_DRY_HOP;
1227 else if (temp == "Bottling")
1228 newh->useat = HOP_USEAT_BOTTLING;
1205 else 1229 else
1206 newh->useat = 0; 1230 newh->useat = HOP_USEAT_MASH;
1207 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) { 1231 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) {
1208 newh->beta = xml->readElementText().toDouble(); 1232 newh->beta = xml->readElementText().toDouble();
1209 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HSI")) { 1233 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HSI")) {
1210 newh->hsi = xml->readElementText().toDouble(); 1234 newh->hsi = xml->readElementText().toDouble();
1211 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "SUBSTITUTES")) { 1235 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "SUBSTITUTES")) {
1219 newh->cohumulone = xml->readElementText().toDouble(); 1243 newh->cohumulone = xml->readElementText().toDouble();
1220 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MYRCENE")) { 1244 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "MYRCENE")) {
1221 newh->myrcene = xml->readElementText().toDouble(); 1245 newh->myrcene = xml->readElementText().toDouble();
1222 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) { 1246 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) {
1223 newh->total_oil = xml->readElementText().toDouble(); 1247 newh->total_oil = xml->readElementText().toDouble();
1248 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UTILISATION")) {
1249 newh->utilisation = xml->readElementText().toDouble();
1250 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UT_FACTOR")) {
1251 newh->bu_factor = xml->readElementText().toDouble();
1224 } 1252 }
1225 } 1253 }
1226 } 1254 }
1227 } 1255 }
1228 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FERMENTABLES")) { 1256 } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FERMENTABLES")) {

mercurial