# HG changeset patch # User Michiel Broek # Date 1646513376 -3600 # Node ID 4024b389f6893bf0b54496b241ed1c5ab2260502 # Parent 5a9a159c2d34e2567647694ba272d73ebafd9533 Added miscs XML export diff -r 5a9a159c2d34 -r 4024b389f689 src/InventoryMiscs.cpp --- a/src/InventoryMiscs.cpp Sat Mar 05 21:15:59 2022 +0100 +++ b/src/InventoryMiscs.cpp Sat Mar 05 21:49:36 2022 +0100 @@ -147,6 +147,64 @@ } +void InventoryMiscs::on_exportButton_clicked() +{ + qDebug() << Q_FUNC_INFO; + + QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name"); + const QStringList types({ "Spice", "Herb", "Flavor", "Fining", "Water agent", "Other", "Other" }); + /* 'Spice', 'Herb', 'Flavor', 'Fining', 'Water agent', 'Yeast nutrient', 'Other' */ + /* We use more misc types then beerxml knows about, so we send known names */ + /* instead of what we internally use. */ + const QStringList uses({ "Secondary", "Mash", "Boil", "Primary", "Secondary", "Bottling" }); + /* 'Starter', 'Mash', 'Boil', 'Primary', 'Secondary', 'Bottling' */ + /* Stupid beerxml leaves us no other choice then to map a starter ingredient to secondary */ + + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/miscs.xml", tr("Files (*.xml)")); + if (fileName == 0) { + QMessageBox::warning(this, tr("Save File"), tr("No XML file selected.")); + return; + } + + QFile file(fileName); + file.open(QIODevice::WriteOnly); + + QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); + xmlWriter->writeStartDocument(); + xmlWriter->setAutoFormatting(true); + xmlWriter->setAutoFormattingIndent(1); + xmlWriter->writeStartElement("MISCS"); + + query.first(); + for (int i = 0 ; i < query.size() ; i++ ) { + xmlWriter->writeStartElement("MISC"); + xmlWriter->writeTextElement("VERSION", "1"); + xmlWriter->writeTextElement("NAME", query.value(1).toString()); + xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]); + xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", query.value(5).toInt() ? "TRUE":"FALSE"); + xmlWriter->writeTextElement("USE", uses[query.value(3).toInt()]); + if (query.value(4).toDouble() > 0) + xmlWriter->writeTextElement("TIME", QString::number(query.value(4).toDouble(), 'f', 3)); + if (query.value(10).toDouble() > 0) + xmlWriter->writeTextElement("COST", QString::number(query.value(10).toDouble(), 'f', 5)); + xmlWriter->writeTextElement("ALWAYS_ON_STOCK", query.value(8).toInt() ? "TRUE":"FALSE"); + if (query.value(7).toString().length()) + xmlWriter->writeTextElement("NOTES", query.value(7).toString()); + if (query.value(6).toString().length()) + xmlWriter->writeTextElement("USE_FOR", query.value(6).toString()); + + xmlWriter->writeEndElement(); + query.next(); + } + + xmlWriter->writeEndElement(); + xmlWriter->writeEndDocument(); + QMessageBox::information(this, tr("Save File"), tr("XML export ready")); + + file.close(); +} + + void InventoryMiscs::on_quitButton_clicked() { emit firstWindow(); diff -r 5a9a159c2d34 -r 4024b389f689 src/InventoryMiscs.h --- a/src/InventoryMiscs.h Sat Mar 05 21:15:59 2022 +0100 +++ b/src/InventoryMiscs.h Sat Mar 05 21:49:36 2022 +0100 @@ -22,6 +22,7 @@ void on_quitButton_clicked(); void on_insertButton_clicked(); void on_editButton_clicked(); + void on_exportButton_clicked(); void refreshTable(void); private: