# HG changeset patch # User Michiel Broek # Date 1655115987 -7200 # Node ID af3dac6ff6c3d9ca96d54b4a43edf8e9d012be63 # Parent efc213beb6052d30dfa3997df8dd4886f182002a Fixed init of import record. Added miscs import diff -r efc213beb605 -r af3dac6ff6c3 src/ImportXML.cpp --- a/src/ImportXML.cpp Mon Jun 13 10:54:23 2022 +0200 +++ b/src/ImportXML.cpp Mon Jun 13 12:26:27 2022 +0200 @@ -91,9 +91,8 @@ * Equipment */ total++; - Equipment *eq = new Equipment; + Equipment *eq = new Equipment(); eq->notes = ""; - eq->top_up_kettle = eq->top_up_water = 0; while (xml->readNext()) { if (xml->atEnd()) @@ -226,10 +225,9 @@ /* * Style */ - Style *st = new Style; + Style *st = new Style(); st->notes = st->category = st->style_letter = st->profile = st->ingredients = st->examples = ""; st->style_guide = "BKG 2019"; - st->category_number = 0; total++; while (xml->readNext()) { @@ -361,14 +359,12 @@ * Fermentable */ total++; - Fermentables *f = new Fermentables; + Fermentables *f = new Fermentables(); f->f_supplier = f->f_origin = f->f_notes = ""; f->f_yield = 80; f->f_max_in_batch = 100; f->f_recommend_mash = true; - f->f_protein = f->f_dissolved_protein = f->f_coarse_fine_diff = f->f_moisture = f->f_diastatic_power = 0; f->f_di_ph = 5.7; - f->f_acid_to_ph_57 = 0; while (xml->readNext()) { if (xml->atEnd()) @@ -508,10 +504,8 @@ * Hop */ total++; - Hops *h = new Hops; - h->h_inventory = h->h_cost = 0; + Hops *h = new Hops(); h->h_notes = h->h_origin = h->h_substitutes = ""; - h->h_beta = h->h_hsi = h->h_humulene = h->h_caryophyllene = h->h_cohumulone = h->h_myrcene = h->h_total_oil = 0; while (xml->readNext()) { if (xml->atEnd()) @@ -631,24 +625,80 @@ * Misc */ total++; + Miscs *m = new Miscs(); + m->name = m->use_for = m->notes = ""; while (xml->readNext()) { if (xml->atEnd()) break; if ((xml->tokenType() == QXmlStreamReader::EndElement) && (xml->name() == "MISC")) { -// query.exec(sql); + query.prepare("INSERT INTO inventory_miscs SET name=:name, type=:type, use_use=:use, " + "time=:time, amount_is_weight=:isweight, use_for=:usefor, notes=:notes, " + "uuid = :uuid"); + query.bindValue(":name", m->name); + query.bindValue(":type", m->type); + query.bindValue(":use", m->use_use); + query.bindValue(":time", QString("%1").arg(m->time, 1, 'f', 0, '0')); + query.bindValue(":isweight", m->amount_is_weight ? 1:0); + query.bindValue(":usefor", m->use_for); + query.bindValue(":notes", m->notes); + query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); + query.exec(); if (query.lastError().isValid()) { -// qWarning() << sql << query.lastError(); + qWarning() << query.lastError(); errors++; } ui->progressBar->setValue(round(100 * xml->characterOffset() / fsize)); break; } if ((xml->tokenType() == QXmlStreamReader::StartElement) && ( - (xml->name() == "VERSION") + (xml->name() == "VERSION") || (xml->name() == "DISPLAY_AMOUNT") || + (xml->name() == "AMOUNT") || (xml->name() == "ALWAYS_ON_STOCK") || + (xml->name() == "COST") || (xml->name() == "DISPLAY_COST") || + (xml->name() == "INVENTORY") || (xml->name() == "DISPLAY_TIME") || + (xml->name() == "FREE_FIELD") || (xml->name() == "FREE_FIELD_NAME") )) { // Ignore. } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NAME")) { + m->name = xml->readElementText(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) { + m->notes = xml->readElementText(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE_FOR")) { + m->use_for = xml->readElementText(); + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) { + QString temp = xml->readElementText(); + if (temp == "Herb") + m->type = 1; + else if (temp == "Flavor") + m->type = 2; + else if (temp == "Fining") + m->type = 3; + else if (temp == "Water agent") + m->type = 4; + else if (temp == "Yeast nutrient") + m->type = 5; + else if (temp == "Other") + m->type = 6; + else + m->type = 0; + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) { + QString temp = xml->readElementText(); + if (temp == "Mash") + m->use_use = 1; + else if (temp == "Boil") + m->use_use = 2; + else if (temp == "Primary") + m->use_use = 3; + else if (temp == "Secondary") + m->use_use = 4; + else if (temp == "Bottling") + m->use_use = 5; + else + m->use_use = 0; + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "AMOUNT_IS_WEIGHT")) { + m->amount_is_weight = (xml->readElementText() == "TRUE") ? true:false; + } else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TIME")) { + m->time = xml->readElementText().toDouble(); } else { if (xml->tokenType() == QXmlStreamReader::StartElement) qDebug() << "2 " << xml->tokenType() << xml->name(); diff -r efc213beb605 -r af3dac6ff6c3 src/Utils.cpp --- a/src/Utils.cpp Mon Jun 13 10:54:23 2022 +0200 +++ b/src/Utils.cpp Mon Jun 13 12:26:27 2022 +0200 @@ -51,7 +51,7 @@ { double srm = -0.00000000000132303 * pow(ebc, 4) - 0.00000000291515 * pow(ebc, 3) + 0.00000818515 * pow(ebc, 2) + 0.372038 * ebc + 0.596351; if (ebc < 0 || srm < 0) - qDebug() << "ebc_to_srm(" << ebc << ") =" << srm; + return 0; return srm; } @@ -60,7 +60,7 @@ { double ebc = round( 0.000000000176506 * pow(srm, 4) + 0.000000154529 * pow(srm, 3) - 0.000159428 * pow(srm, 2) + 2.68837 * srm - 1.6004 ); if ((ebc < 0) || (srm < 0)) - qDebug() << "srm_to_ebc(" << srm << ") =" << ebc; + return 0; return ebc; }