Sat, 05 Mar 2022 16:19:52 +0100
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
--- a/src/EditFermentable.cpp Sat Mar 05 10:37:09 2022 +0100 +++ b/src/EditFermentable.cpp Sat Mar 05 16:19:52 2022 +0100 @@ -63,7 +63,7 @@ ui->typeEdit->setCurrentIndex(query.value(2).toInt()); ui->graintypeEdit->setCurrentIndex(query.value(20).toInt()); ui->maxinbatchEdit->setValue(query.value(14).toDouble()); - ui->mashEdit->setChecked(query.value(16).toInt() ? true:false); + ui->mashEdit->setChecked(query.value(15).toInt() ? true:false); ui->addafterEdit->setChecked(query.value(5).toInt() ? true:false); ui->addedEdit->setCurrentIndex(query.value(17).toInt()); ui->alwaysEdit->setChecked(query.value(5).toInt() ? true:false);
--- a/src/InventoryFermentables.cpp Sat Mar 05 10:37:09 2022 +0100 +++ b/src/InventoryFermentables.cpp Sat Mar 05 16:19:52 2022 +0100 @@ -142,6 +142,72 @@ } +void InventoryFermentables::on_exportButton_clicked() +{ + qDebug() << Q_FUNC_INFO; + + QSqlQuery query("SELECT * FROM inventory_fermentables ORDER BY supplier,name"); + const QStringList types({"Grain", "Sugar", "Extract", "Dry extract", "Adjunct"}); + const QStringList graintypes({"Base", "Roast", "Crystal", "Kilned", "Sour Malt", "Special", "No malt"}); + const QStringList added({"Mash", "Boil", "Fermentation", "Lagering", "Bottle"}); + + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", 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->writeStartElement("FERMENTABLES"); + + query.first(); + for (int i = 0 ; i < query.size() ; i++ ) { + xmlWriter->writeStartElement("FERMENTABLE"); + xmlWriter->writeTextElement("VERSION", "1"); + xmlWriter->writeTextElement("NAME", query.value(1).toString()); + xmlWriter->writeTextElement("NOTES", query.value(8).toString()); + xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]); + xmlWriter->writeTextElement("YIELD", QString::number(query.value(3).toDouble(), 'f', 5)); + xmlWriter->writeTextElement("COLOR", QString::number(Utils::ebc_to_srm(query.value(4).toDouble()), 'f', 3) ); + xmlWriter->writeTextElement("ADD_AFTER_BOIL", query.value(5).toInt() ? "TRUE":"FALSE"); + xmlWriter->writeTextElement("ORIGIN", query.value(6).toString()); + xmlWriter->writeTextElement("SUPPLIER", query.value(7).toString()); + if (query.value(9).toDouble() > 0) + xmlWriter->writeTextElement("COARSE_FINE_DIFF", QString::number(query.value(9).toDouble(), 'f', 4)); + if (query.value(10).toDouble() > 0) + xmlWriter->writeTextElement("MOISTURE", QString::number(query.value(10).toDouble(), 'f', 4)); + if (query.value(11).toDouble() > 0) + xmlWriter->writeTextElement("DIASTATIC_POWER", QString::number(query.value(11).toDouble(), 'f', 4)); + if (query.value(12).toDouble() > 0) + xmlWriter->writeTextElement("PROTEIN", QString::number(query.value(12).toDouble(), 'f', 4)); + if (query.value(14).toDouble() > 0) + xmlWriter->writeTextElement("MAX_IN_BATCH", QString::number(query.value(14).toDouble(), 'f', 3)); + xmlWriter->writeTextElement("RECOMMEND_MASH", query.value(15).toInt() ? "TRUE":"FALSE"); + xmlWriter->writeTextElement("DISPLAY_COLOR", QString("%1 EBC").arg(query.value(4).toDouble(), 1, 'f', 0)); + xmlWriter->writeTextElement("GRAINTYPE", graintypes[query.value(20).toInt()]); + xmlWriter->writeTextElement("ADDED", added[query.value(17).toInt()]); + if (query.value(18).toDouble() > 0) + xmlWriter->writeTextElement("DI_pH", QString::number(query.value(18).toDouble(), 'f', 5)); + if (query.value(19).toDouble() > 0) + xmlWriter->writeTextElement("ACID_TO_pH_5.7", QString::number(query.value(19).toDouble(), 'f', 5)); + + xmlWriter->writeEndElement(); + query.next(); + } + + xmlWriter->writeEndElement(); + xmlWriter->writeEndDocument(); + QMessageBox::warning(this, tr("Save File"), tr("XML export ready")); + + file.close(); +} + + void InventoryFermentables::on_quitButton_clicked() { emit firstWindow();
--- a/src/InventoryFermentables.h Sat Mar 05 10:37:09 2022 +0100 +++ b/src/InventoryFermentables.h Sat Mar 05 16:19:52 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:
--- a/src/Utils.cpp Sat Mar 05 10:37:09 2022 +0100 +++ b/src/Utils.cpp Sat Mar 05 16:19:52 2022 +0100 @@ -16,6 +16,7 @@ */ #include "Utils.h" +#include <QDebug> #include <math.h> @@ -33,3 +34,24 @@ return round(((kolbach + 16) / 3.5) * 1000.0) / 1000.0; } + +double Utils::ebc_to_srm(double ebc) +{ + double srm = -1.32303E-12 * 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 srm; +} + + +double Utils::srm_to_ebc(double srm) +{ + // Formule van Adrie Otten. brouwhulp. + 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 ebc; +} + + +
--- a/src/Utils.h Sat Mar 05 10:37:09 2022 +0100 +++ b/src/Utils.h Sat Mar 05 16:19:52 2022 +0100 @@ -10,8 +10,9 @@ namespace Utils { double lintner_to_kolbach(double lintner); - double kolbach_to_lintner(double kolbach); + double ebc_to_srm(double ebc); + double srm_to_ebc(double srm); } #endif
--- a/src/bmsapp.h Sat Mar 05 10:37:09 2022 +0100 +++ b/src/bmsapp.h Sat Mar 05 16:19:52 2022 +0100 @@ -21,7 +21,6 @@ #include <QPlainTextEdit> #include <QMessageBox> #include <QLabel> - #include <QImage> #include <QImageReader> #include <QImageWriter> @@ -29,6 +28,9 @@ #include <QGraphicsView> #include <QFileDialog> +#include <QXmlStreamReader> +#include <QXmlStreamWriter> + #include "Utils.h" #include "database/database.h"
--- a/translations/bmsapp_en.ts Sat Mar 05 10:37:09 2022 +0100 +++ b/translations/bmsapp_en.ts Sat Mar 05 16:19:52 2022 +0100 @@ -1889,12 +1889,12 @@ <translation type="unfinished"></translation> </message> <message> - <location filename="../ui/InventoryFermentables.ui" line="105"/> + <location filename="../ui/InventoryFermentables.ui" line="109"/> <source>Import</source> <translation type="unfinished"></translation> </message> <message> - <location filename="../ui/InventoryFermentables.ui" line="124"/> + <location filename="../ui/InventoryFermentables.ui" line="132"/> <source>New</source> <translation type="unfinished"></translation> </message> @@ -2000,6 +2000,28 @@ <source>No malt</source> <translation type="unfinished"></translation> </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="154"/> + <location filename="../src/InventoryFermentables.cpp" line="156"/> + <location filename="../src/InventoryFermentables.cpp" line="205"/> + <source>Save File</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="154"/> + <source>Files (*.xml)</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="156"/> + <source>No XML file selected.</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="205"/> + <source>XML export ready</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>InventoryHops</name>
--- a/translations/bmsapp_nl.ts Sat Mar 05 10:37:09 2022 +0100 +++ b/translations/bmsapp_nl.ts Sat Mar 05 16:19:52 2022 +0100 @@ -1923,12 +1923,12 @@ <translation>Exporteer</translation> </message> <message> - <location filename="../ui/InventoryFermentables.ui" line="105"/> + <location filename="../ui/InventoryFermentables.ui" line="109"/> <source>Import</source> <translation>Importeer</translation> </message> <message> - <location filename="../ui/InventoryFermentables.ui" line="124"/> + <location filename="../ui/InventoryFermentables.ui" line="132"/> <source>New</source> <translation>Nieuw</translation> </message> @@ -2034,6 +2034,28 @@ <source>No malt</source> <translation>Geen mout</translation> </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="154"/> + <location filename="../src/InventoryFermentables.cpp" line="156"/> + <location filename="../src/InventoryFermentables.cpp" line="205"/> + <source>Save File</source> + <translation>Bestand opslaan</translation> + </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="154"/> + <source>Files (*.xml)</source> + <translation>Files (*.xml)</translation> + </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="156"/> + <source>No XML file selected.</source> + <translation>Geen XML bestand gekozen.</translation> + </message> + <message> + <location filename="../src/InventoryFermentables.cpp" line="205"/> + <source>XML export ready</source> + <translation>XML uitvoer gereed</translation> + </message> </context> <context> <name>InventoryHops</name>
--- a/ui/InventoryFermentables.ui Sat Mar 05 10:37:09 2022 +0100 +++ b/ui/InventoryFermentables.ui Sat Mar 05 16:19:52 2022 +0100 @@ -63,7 +63,7 @@ <string>Quit</string> </property> <property name="icon"> - <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <iconset> <normaloff>:icons/silk/door_out.png</normaloff>:icons/silk/door_out.png</iconset> </property> </widget> @@ -85,6 +85,10 @@ <property name="text"> <string>Export</string> </property> + <property name="icon"> + <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <normaloff>:/icons/silk/database_save.png</normaloff>:/icons/silk/database_save.png</iconset> + </property> </widget> </item> <item> @@ -104,6 +108,10 @@ <property name="text"> <string>Import</string> </property> + <property name="icon"> + <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <normaloff>:/icons/silk/database_add.png</normaloff>:/icons/silk/database_add.png</iconset> + </property> </widget> </item> <item> @@ -124,7 +132,7 @@ <string>New</string> </property> <property name="icon"> - <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <iconset> <normaloff>:icons/silk/table_row_insert.png</normaloff>:icons/silk/table_row_insert.png</iconset> </property> </widget>