--- 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();