| 1 | /*************************************************************************** |
| 2 | recipe.cpp |
| 3 | ------------------- |
| 4 | Recipe (document) class |
| 5 | ------------------- |
| 6 | Copyright 2001-2008, David Johnson |
| 7 | Please see the header file for copyright and license information |
| 8 | ***************************************************************************/ |
| 9 | |
| 10 | #include <cmath> |
| 11 | |
| 12 | #include <QApplication> |
| 13 | #include <QFile> |
| 14 | #include <QMessageBox> |
| 15 | #include <QTextDocument> |
| 16 | #include <QTextStream> |
| 17 | |
| 18 | #include "beerxmlreader.h"cxx . . $ `<file>/src/beerxmlreader.h`/ |
| 19 | #include "data.h"cxx . . $ `<file>/src/data.h`/ |
| 20 | #include "recipereader.h"cxx . . $ `<file>/src/recipereader.h`/ |
| 21 | #include "resource.h"cxx . . $ `<file>/src/resource.h`/ |
| 22 | #include "textprinter.h"cxx . . $ `<file>/src/textprinter.h`/ |
| 23 | |
| 24 | #include "recipe.h"cxx . . $ `<file>/src/recipe.h`/ |
| 25 | |
| 26 | using namespace Resource; |
| 27 | |
| 28 | const QByteArraycxx . . $ QByteArray# Recipecxx . . $ Recipe#::EXTRACT_STRINGcxx . . $ Recipe#EXTRACT_STRING. = QT_TRANSLATE_NOOPcxx . . $ `<external>/15045578679651060896/qglobal.h:1182:9`!("recipe", "Extract"); |
| 29 | const QByteArraycxx . . $ QByteArray# Recipecxx . . $ Recipe#::PARTIAL_STRINGcxx . . $ Recipe#PARTIAL_STRING. = QT_TRANSLATE_NOOPcxx . . $ `<external>/15045578679651060896/qglobal.h:1182:9`!("recipe", "Partial Mash"); |
| 30 | const QByteArraycxx . . $ QByteArray# Recipecxx . . $ Recipe#::ALLGRAIN_STRINGcxx . . $ Recipe#ALLGRAIN_STRING. = QT_TRANSLATE_NOOPcxx . . $ `<external>/15045578679651060896/qglobal.h:1182:9`!("recipe", "All Grain"); |
| 31 | |
| 32 | ////////////////////////////////////////////////////////////////////////////// |
| 33 | // Construction, destruction // |
| 34 | ////////////////////////////////////////////////////////////////////////////// |
| 35 | |
| 36 | ////////////////////////////////////////////////////////////////////////////// |
| 37 | // Recipe() |
| 38 | // -------- |
| 39 | // Default constructor |
| 40 | |
| 41 | Recipecxx . . $ Recipe#::Recipecxx . . $ Recipe#Recipe(749de1b6ae65bddd).(QObjectcxx . . $ QObject# *parent) |
| 42 | : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent), modified_cxx . . $ Recipe#modified_.(false), title_cxx . . $ Recipe#title_.(), brewer_cxx . . $ Recipe#brewer_.(), |
| 43 | size_cxx . . $ Recipe#size_.(5.0, Volumecxx . . $ Volume#::galloncxx . . $ Volume#gallon.), style_cxx . . $ Recipe#style_.(), grains_cxx . . $ Recipe#grains_.(), hops_cxx . . $ Recipe#hops_.(), miscs_cxx . . $ Recipe#miscs_.(), |
| 44 | recipenotes_cxx . . $ Recipe#recipenotes_.(), batchnotes_cxx . . $ Recipe#batchnotes_.(), og_cxx . . $ Recipe#og_.(0.0), ibu_cxx . . $ Recipe#ibu_.(0), srm_cxx . . $ Recipe#srm_.(0) |
| 45 | { ; } |
| 46 | |
| 47 | ////////////////////////////////////////////////////////////////////////////// |
| 48 | // Recipe() |
| 49 | // -------- |
| 50 | // Copy constructor |
| 51 | |
| 52 | Recipecxx . . $ Recipe#::Recipecxx . . $ Recipe#Recipe(894f235acc26e914).(const Recipecxx . . $ Recipe# &r) |
| 53 | : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(0), modified_cxx . . $ Recipe#modified_.(r.modified_cxx . . $ Recipe#modified_.), title_cxx . . $ Recipe#title_.(r.title_cxx . . $ Recipe#title_.), brewer_cxx . . $ Recipe#brewer_.(r.brewer_cxx . . $ Recipe#brewer_.), |
| 54 | size_cxx . . $ Recipe#size_.(r.size_cxx . . $ Recipe#size_.), style_cxx . . $ Recipe#style_.(r.style_cxx . . $ Recipe#style_.), grains_cxx . . $ Recipe#grains_.(r.grains_cxx . . $ Recipe#grains_.), hops_cxx . . $ Recipe#hops_.(r.hops_cxx . . $ Recipe#hops_.), |
| 55 | miscs_cxx . . $ Recipe#miscs_.(r.miscs_cxx . . $ Recipe#miscs_.), recipenotes_cxx . . $ Recipe#recipenotes_.(r.recipenotes_cxx . . $ Recipe#recipenotes_.), |
| 56 | batchnotes_cxx . . $ Recipe#batchnotes_.(r.batchnotes_cxx . . $ Recipe#batchnotes_.), og_cxx . . $ Recipe#og_.(r.og_cxx . . $ Recipe#og_.), ibu_cxx . . $ Recipe#ibu_.(r.ibu_cxx . . $ Recipe#ibu_.), srm_cxx . . $ Recipe#srm_.(r.srm_cxx . . $ Recipe#srm_.) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | ////////////////////////////////////////////////////////////////////////////// |
| 61 | // operator=() |
| 62 | // ----------- |
| 63 | // Assignment operator |
| 64 | Recipecxx . . $ Recipe# Recipecxx . . $ Recipe#::operatorcxx . . $ Recipe#`operator=`(1061f923ca6c467f).=(const Recipecxx . . $ Recipe# &r) |
| 65 | { |
| 66 | if (this != &r) { |
| 67 | modified_cxx . . $ Recipe#modified_. = r.modified_cxx . . $ Recipe#modified_.; |
| 68 | title_cxx . . $ Recipe#title_. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). r.title_cxx . . $ Recipe#title_.; |
| 69 | brewer_cxx . . $ Recipe#brewer_. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). r.brewer_cxx . . $ Recipe#brewer_.; |
| 70 | size_cxx . . $ Recipe#size_. =cxx . . $ Volume#`operator=`(dbe4f9802804587b). r.size_cxx . . $ Recipe#size_.; |
| 71 | style_cxx . . $ Recipe#style_. =cxx . . $ Style#`operator=`(73c14b8dd1039aa8). r.style_cxx . . $ Recipe#style_.; |
| 72 | grains_cxx . . $ Recipe#grains_. =cxx . . $ QList#`operator=`(296c5e09a09ca26f). r.grains_cxx . . $ Recipe#grains_.; |
| 73 | hops_cxx . . $ Recipe#hops_. =cxx . . $ QList#`operator=`(296c5e09a09ca26f). r.hops_cxx . . $ Recipe#hops_.; |
| 74 | miscs_cxx . . $ Recipe#miscs_. =cxx . . $ QList#`operator=`(296c5e09a09ca26f). r.miscs_cxx . . $ Recipe#miscs_.; |
| 75 | recipenotes_cxx . . $ Recipe#recipenotes_. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). r.recipenotes_cxx . . $ Recipe#recipenotes_.; |
| 76 | batchnotes_cxx . . $ Recipe#batchnotes_. =cxx . . $ QString#`operator=`(b79fde0b0ce9b948). r.batchnotes_cxx . . $ Recipe#batchnotes_.; |
| 77 | og_cxx . . $ Recipe#og_. = r.og_cxx . . $ Recipe#og_.; |
| 78 | ibu_cxx . . $ Recipe#ibu_. = r.ibu_cxx . . $ Recipe#ibu_.; |
| 79 | srm_cxx . . $ Recipe#srm_. = r.srm_cxx . . $ Recipe#srm_.; |
| 80 | } |
| 81 | return *cxx . . $ Recipe#Recipe(894f235acc26e914).this; |
| 82 | } |
| 83 | |
| 84 | Recipecxx . . $ Recipe#::~cxx . . $ Recipe#`~Recipe`(ced63f7c635d850d).Recipecxx . . $ Recipe#() |
| 85 | { ; } |
| 86 | |
| 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | // Serialization // |
| 89 | ////////////////////////////////////////////////////////////////////////////// |
| 90 | |
| 91 | ////////////////////////////////////////////////////////////////////////////// |
| 92 | // newRecipe() |
| 93 | // ------------- |
| 94 | // Clears recipe (new document) |
| 95 | |
| 96 | void Recipecxx . . $ Recipe#::newRecipecxx . . $ Recipe#newRecipe(49f6e7a06ebc5aa8).() |
| 97 | { |
| 98 | title_cxx . . $ Recipe#title_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 99 | brewer_cxx . . $ Recipe#brewer_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 100 | size_cxx . . $ Recipe#size_. =cxx . . $ Volume#`operator=`(dbe4f9802804587b). Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultSizecxx . . $ Data#defaultSize(72d6f2be71f69f8b).(); |
| 101 | style_cxx . . $ Recipe#style_. =cxx . . $ Style#`operator=`(73c14b8dd1039aa8). Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultStylecxx . . $ Data#defaultStyle(c446394d65978504).(); |
| 102 | grains_cxx . . $ Recipe#grains_..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 103 | hops_cxx . . $ Recipe#hops_..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 104 | miscs_cxx . . $ Recipe#miscs_..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 105 | recipenotes_cxx . . $ Recipe#recipenotes_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 106 | batchnotes_cxx . . $ Recipe#batchnotes_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 107 | |
| 108 | og_cxx . . $ Recipe#og_. = 0.0; |
| 109 | ibu_cxx . . $ Recipe#ibu_. = 0; |
| 110 | srm_cxx . . $ Recipe#srm_. = 0; |
| 111 | |
| 112 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(false); // new documents are not in a modified state |
| 113 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! recipeChangedcxx . . $ Recipe#recipeChanged(49f6e7a06ebc5aa8).(); |
| 114 | } |
| 115 | |
| 116 | ///////////////////////////////////////////////////////////////////////////// |
| 117 | // nativeFormat() |
| 118 | // ------------- |
| 119 | // Is the recipe in native format? |
| 120 | |
| 121 | bool Recipecxx . . $ Recipe#::nativeFormatcxx . . $ Recipe#nativeFormat(e1defb592416720d).(const QStringcxx . . $ QString# &filename) |
| 122 | { |
| 123 | QFilecxx . . $ QFile# datafilecxx . . $ QFile#QFile(3520e46b33348bf6).(filename); |
| 124 | if (!datafile.opencxx . . $ QFile#open(dca164408be960c8).(QFilecxx . . $ QFile#::ReadOnlycxx . . $ QIODevice#ReadOnly. |cxx . . $ `operator|`(c9e45f682471e48d). QFilecxx . . $ QFile#::Textcxx . . $ QIODevice#Text.)) { |
| 125 | // error opening file |
| 126 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Error: Cannot open" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). filename; |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | RecipeReadercxx . . $ RecipeReader# readercxx . . $ RecipeReader#RecipeReader(bebe8f2dee7f9e86).(&datafile); |
| 131 | return reader.isRecipeFormatcxx . . $ RecipeReader#isRecipeFormat(c9857a73d68e59ba).(); |
| 132 | } |
| 133 | |
| 134 | ///////////////////////////////////////////////////////////////////////////// |
| 135 | // beerXmlFormat() |
| 136 | // --------------- |
| 137 | // Is the recipe in BeerXML format? |
| 138 | |
| 139 | bool Recipecxx . . $ Recipe#::beerXmlFormatcxx . . $ Recipe#beerXmlFormat(e1defb592416720d).(const QStringcxx . . $ QString# &filename) |
| 140 | { |
| 141 | QFilecxx . . $ QFile# datafilecxx . . $ QFile#QFile(3520e46b33348bf6).(filename); |
| 142 | if (!datafile.opencxx . . $ QFile#open(dca164408be960c8).(QFilecxx . . $ QFile#::ReadOnlycxx . . $ QIODevice#ReadOnly. |cxx . . $ `operator|`(c9e45f682471e48d). QFilecxx . . $ QFile#::Textcxx . . $ QIODevice#Text.)) { |
| 143 | // error opening file |
| 144 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Error: Cannot open" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). filename; |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | BeerXmlReadercxx . . $ BeerXmlReader# readercxx . . $ BeerXmlReader#BeerXmlReader(bebe8f2dee7f9e86).(&datafile); |
| 149 | return reader.isBeerXmlFormatcxx . . $ BeerXmlReader#isBeerXmlFormat(c9857a73d68e59ba).(); |
| 150 | } |
| 151 | |
| 152 | ////////////////////////////////////////////////////////////////////////////// |
| 153 | // loadRecipe() |
| 154 | // -------------- |
| 155 | // Load a recipe. Assumes file has been checked with nativeFormat() |
| 156 | |
| 157 | bool Recipecxx . . $ Recipe#::loadRecipecxx . . $ Recipe#loadRecipe(e1defb592416720d).(const QStringcxx . . $ QString# &filename) |
| 158 | { |
| 159 | // open file |
| 160 | QFilecxx . . $ QFile# datafilecxx . . $ QFile#QFile(3520e46b33348bf6).(filename); |
| 161 | if (!datafile.opencxx . . $ QFile#open(dca164408be960c8).(QFilecxx . . $ QFile#::ReadOnlycxx . . $ QIODevice#ReadOnly. |cxx . . $ `operator|`(c9e45f682471e48d). QFilecxx . . $ QFile#::Textcxx . . $ QIODevice#Text.)) { |
| 162 | // error opening file |
| 163 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Error: Cannot open" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). filename; |
| 164 | QMessageBoxcxx . . $ QMessageBox#::warningcxx . . $ QMessageBox#warning(a9e3742e6f7b4147).(0, TITLEcxx . . $ QString#QString(45672f3c6961a244)., |
| 165 | trcxx . . $ Recipe#tr(75d9f1c324b4579d).("Cannot read file %1:\n%2") |
| 166 | .argcxx . . $ QString#arg(bc823072288cbbb5).(filename) |
| 167 | .argcxx . . $ QString#arg(bc823072288cbbb5).(datafile.errorStringcxx . . $ QIODevice#errorString(6ef7b6c27b00b43d).())); |
| 168 | datafile.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).(); |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | QApplicationcxx . . $ QApplication#::setOverrideCursorcxx . . $ QGuiApplication#setOverrideCursor(abdcfda6ee8376ea).(Qtcxx . . $ QCursor#QCursor(1a9232e7b845eb22).::WaitCursorcxx . . $ Qt/WaitCursor.); |
| 173 | title_cxx . . $ Recipe#title_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 174 | brewer_cxx . . $ Recipe#brewer_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 175 | size_cxx . . $ Recipe#size_. =cxx . . $ Volume#`operator=`(dbe4f9802804587b). Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultSizecxx . . $ Data#defaultSize(72d6f2be71f69f8b).(); |
| 176 | style_cxx . . $ Recipe#style_. =cxx . . $ Style#`operator=`(73c14b8dd1039aa8). Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->defaultStylecxx . . $ Data#defaultStyle(c446394d65978504).(); |
| 177 | grains_cxx . . $ Recipe#grains_..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 178 | hops_cxx . . $ Recipe#hops_..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 179 | miscs_cxx . . $ Recipe#miscs_..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).(); |
| 180 | recipenotes_cxx . . $ Recipe#recipenotes_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 181 | batchnotes_cxx . . $ Recipe#batchnotes_..clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 182 | |
| 183 | // parse file |
| 184 | RecipeReadercxx . . $ RecipeReader# readercxx . . $ RecipeReader#RecipeReader(bebe8f2dee7f9e86).(&datafile); |
| 185 | bool status = reader.readRecipecxx . . $ RecipeReader#readRecipe(b1877db5cb6732a7).(this); |
| 186 | datafile.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).(); |
| 187 | |
| 188 | if (!status) { |
| 189 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Error: Problem reading file" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). filename; |
| 190 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). reader.errorStringcxx . . $ QXmlStreamReader#errorString(6ef7b6c27b00b43d).(); |
| 191 | QMessageBoxcxx . . $ QMessageBox#::warningcxx . . $ QMessageBox#warning(a9e3742e6f7b4147).(0, TITLEcxx . . $ QString#QString(45672f3c6961a244)., |
| 192 | trcxx . . $ Recipe#tr(75d9f1c324b4579d).("Error reading file %1").argcxx . . $ QString#arg(bc823072288cbbb5).(filename)); |
| 193 | QApplicationcxx . . $ QApplication#::restoreOverrideCursorcxx . . $ QGuiApplication#restoreOverrideCursor(49f6e7a06ebc5aa8).(); |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | // calculate the numbers |
| 198 | recalccxx . . $ Recipe#recalc(49f6e7a06ebc5aa8).(); |
| 199 | |
| 200 | // just loaded recipes are not modified |
| 201 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(false); |
| 202 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! recipeChangedcxx . . $ Recipe#recipeChanged(49f6e7a06ebc5aa8).(); |
| 203 | |
| 204 | QApplicationcxx . . $ QApplication#::restoreOverrideCursorcxx . . $ QGuiApplication#restoreOverrideCursor(49f6e7a06ebc5aa8).(); |
| 205 | return true; |
| 206 | } |
| 207 | |
| 208 | ////////////////////////////////////////////////////////////////////////////// |
| 209 | // saveRecipe() |
| 210 | // --------------- |
| 211 | // Save a recipe |
| 212 | |
| 213 | bool Recipecxx . . $ Recipe#::saveRecipecxx . . $ Recipe#saveRecipe(e1defb592416720d).(const QStringcxx . . $ QString# &filename) |
| 214 | { |
| 215 | // open file |
| 216 | QFilecxx . . $ QFile# datafilecxx . . $ QFile#QFile(3520e46b33348bf6).(filename); |
| 217 | if (!datafile.opencxx . . $ QFile#open(dca164408be960c8).(QFilecxx . . $ QFile#::WriteOnlycxx . . $ QIODevice#WriteOnly. |cxx . . $ `operator|`(c9e45f682471e48d). QFilecxx . . $ QFile#::Textcxx . . $ QIODevice#Text.)) { |
| 218 | // error opening file |
| 219 | qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Error: Cannot open file" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). filename; |
| 220 | QMessageBoxcxx . . $ QMessageBox#::warningcxx . . $ QMessageBox#warning(a9e3742e6f7b4147).(0, TITLEcxx . . $ QString#QString(45672f3c6961a244)., |
| 221 | trcxx . . $ Recipe#tr(75d9f1c324b4579d).("Cannot write file %1:\n%2") |
| 222 | .argcxx . . $ QString#arg(bc823072288cbbb5).(filename) |
| 223 | .argcxx . . $ QString#arg(bc823072288cbbb5).(datafile.errorStringcxx . . $ QIODevice#errorString(6ef7b6c27b00b43d).())); |
| 224 | datafile.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).(); |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | QApplicationcxx . . $ QApplication#::setOverrideCursorcxx . . $ QGuiApplication#setOverrideCursor(abdcfda6ee8376ea).(Qtcxx . . $ QCursor#QCursor(1a9232e7b845eb22).::WaitCursorcxx . . $ Qt/WaitCursor.); |
| 229 | |
| 230 | // write out xml |
| 231 | RecipeWritercxx . . $ RecipeWriter# writercxx . . $ RecipeWriter#RecipeWriter(bebe8f2dee7f9e86).(&datafile); |
| 232 | writer.writeRecipecxx . . $ RecipeWriter#writeRecipe(b1877db5cb6732a7).(this); |
| 233 | datafile.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).(); |
| 234 | |
| 235 | // recipe is saved, so set flags accordingly |
| 236 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(false); |
| 237 | QApplicationcxx . . $ QApplication#::restoreOverrideCursorcxx . . $ QGuiApplication#restoreOverrideCursor(49f6e7a06ebc5aa8).(); |
| 238 | return true; |
| 239 | } |
| 240 | |
| 241 | ////////////////////////////////////////////////////////////////////////////// |
| 242 | // previewRecipe() |
| 243 | // --------------- |
| 244 | // Preview the recipe (assumes textprinter has been setup) |
| 245 | |
| 246 | void Recipecxx . . $ Recipe#::previewRecipecxx . . $ Recipe#previewRecipe(79329d6b37ebd6ba).(TextPrintercxx . . $ TextPrinter# *textprinter) |
| 247 | { |
| 248 | if (!textprinter) return; |
| 249 | QTextDocumentcxx . . $ QTextDocument# documentcxx . . $ QTextDocument#QTextDocument(749de1b6ae65bddd).; |
| 250 | document.setHtmlcxx . . $ QTextDocument#setHtml(3520e46b33348bf6).(recipeHTMLcxx . . $ Recipe#recipeHTML(ea4b39313763ec41).()); |
| 251 | textprinter->previewcxx . . $ TextPrinter#preview(cbbf3cfeb0227921).(&document); |
| 252 | } |
| 253 | |
| 254 | void previewRecipecxx . . $ previewRecipe(c5af57f4faf13681).(TextPrintercxx . . $ TextPrinter# *textprinter, QWidgetcxx . . $ QWidget# *wparent); |
| 255 | ////////////////////////////////////////////////////////////////////////////// |
| 256 | // printRecipe() |
| 257 | // --------------- |
| 258 | // Print the recipe (assumes textprinter has been setup) |
| 259 | |
| 260 | void Recipecxx . . $ Recipe#::printRecipecxx . . $ Recipe#printRecipe(79329d6b37ebd6ba).(TextPrintercxx . . $ TextPrinter# *textprinter) |
| 261 | { |
| 262 | if (!textprinter) return; |
| 263 | QTextDocumentcxx . . $ QTextDocument# documentcxx . . $ QTextDocument#QTextDocument(749de1b6ae65bddd).; |
| 264 | document.setHtmlcxx . . $ QTextDocument#setHtml(3520e46b33348bf6).(recipeHTMLcxx . . $ Recipe#recipeHTML(ea4b39313763ec41).()); |
| 265 | textprinter->printcxx . . $ TextPrinter#print(cbbf3cfeb0227921).(&document); |
| 266 | } |
| 267 | |
| 268 | ////////////////////////////////////////////////////////////////////////////// |
| 269 | // Miscellaneous // |
| 270 | ////////////////////////////////////////////////////////////////////////////// |
| 271 | |
| 272 | ///////////////////////////////////////////////////////////////////////////// |
| 273 | // setStyle() |
| 274 | // ---------- |
| 275 | // Set style from string |
| 276 | |
| 277 | void Recipecxx . . $ Recipe#::setStylecxx . . $ Recipe#setStyle(3520e46b33348bf6).(const QStringcxx . . $ QString# &s) |
| 278 | { |
| 279 | if (Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->hasStylecxx . . $ Data#hasStyle(e1defb592416720d).(s)) |
| 280 | style_cxx . . $ Recipe#style_. =cxx . . $ Style#`operator=`(73c14b8dd1039aa8). Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->stylecxx . . $ Data#style(d153d65730aa8714).(s); |
| 281 | else |
| 282 | style_cxx . . $ Recipe#style_. =cxx . . $ Style#`operator=`(73c14b8dd1039aa8). Stylecxx . . $ Style#Style(49f6e7a06ebc5aa8).(); |
| 283 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(true); |
| 284 | } |
| 285 | |
| 286 | ////////////////////////////////////////////////////////////////////////////// |
| 287 | // addGrain() |
| 288 | // ---------- |
| 289 | // Add a grain ingredient to the recipe |
| 290 | |
| 291 | void Recipecxx . . $ Recipe#::addGraincxx . . $ Recipe#addGrain(a6c84258c6f1c14e).(const Graincxx . . $ Grain# &g) |
| 292 | { |
| 293 | grains_cxx . . $ Recipe#grains_..appendcxx . . $ QList#append(77d9f17553126ecb).(g); |
| 294 | recalccxx . . $ Recipe#recalc(49f6e7a06ebc5aa8).(); |
| 295 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(true); |
| 296 | } |
| 297 | |
| 298 | ////////////////////////////////////////////////////////////////////////////// |
| 299 | // addHop() |
| 300 | // ---------- |
| 301 | // Add a hop ingredient to the recipe |
| 302 | |
| 303 | void Recipecxx . . $ Recipe#::addHopcxx . . $ Recipe#addHop(1ff9fed636ba4a7f).(const Hopcxx . . $ Hop# &h) |
| 304 | { |
| 305 | hops_cxx . . $ Recipe#hops_..appendcxx . . $ QList#append(77d9f17553126ecb).(h); |
| 306 | recalccxx . . $ Recipe#recalc(49f6e7a06ebc5aa8).(); |
| 307 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(true); |
| 308 | } |
| 309 | |
| 310 | ////////////////////////////////////////////////////////////////////////////// |
| 311 | // addMisc() |
| 312 | // ---------- |
| 313 | // Add a misc ingredient to the recipe |
| 314 | |
| 315 | void Recipecxx . . $ Recipe#::addMisccxx . . $ Recipe#addMisc(9f5928fef634771).(const Misccxx . . $ Misc# &m) |
| 316 | { |
| 317 | miscs_cxx . . $ Recipe#miscs_..appendcxx . . $ QList#append(77d9f17553126ecb).(m); |
| 318 | recalccxx . . $ Recipe#recalc(49f6e7a06ebc5aa8).(); |
| 319 | setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(true); |
| 320 | } |
| 321 | |
| 322 | ////////////////////////////////////////////////////////////////////////////// |
| 323 | // recipeType() |
| 324 | // ------------ |
| 325 | // Return type of recipe |
| 326 | |
| 327 | QStringcxx . . $ QString# Recipecxx . . $ Recipe#::methodcxx . . $ Recipe#method(4365c3963150523e).() |
| 328 | { |
| 329 | int extract = 0; |
| 330 | int mash = 0; |
| 331 | |
| 332 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(Grain grain, grains_) { |
| 333 | if (grain.usecxx . . $ Grain#use(a2fb7a6ce195d51).().toLowercxx . . $ QString#toLower(dca2c5857e9adf82).() ==cxx . . $ QString#`operator==`(4b967917d5ca120d). Graincxx . . $ Grain#::MASHED_STRINGcxx . . $ Grain#MASHED_STRING..toLowercxx . . $ QByteArray#toLower(ef52b713090bc85a).()) mash++; |
| 334 | else if (grain.usecxx . . $ Grain#use(a2fb7a6ce195d51).().toLowercxx . . $ QString#toLower(dca2c5857e9adf82).() ==cxx . . $ QString#`operator==`(4b967917d5ca120d). Graincxx . . $ Grain#::EXTRACT_STRINGcxx . . $ Grain#EXTRACT_STRING..toLowercxx . . $ QByteArray#toLower(ef52b713090bc85a).()) extract++; |
| 335 | } |
| 336 | |
| 337 | if (mash > 0) { |
| 338 | if (extract > 0) return PARTIAL_STRINGcxx . . $ QString#QString(45672f3c6961a244).; |
| 339 | else return ALLGRAIN_STRINGcxx . . $ QString#QString(45672f3c6961a244).; |
| 340 | } |
| 341 | return EXTRACT_STRINGcxx . . $ QString#QString(45672f3c6961a244).; |
| 342 | } |
| 343 | |
| 344 | ////////////////////////////////////////////////////////////////////////////// |
| 345 | // Calculations // |
| 346 | ////////////////////////////////////////////////////////////////////////////// |
| 347 | |
| 348 | ////////////////////////////////////////////////////////////////////////////// |
| 349 | // recalc() |
| 350 | // ------- |
| 351 | // Recalculate recipe values |
| 352 | |
| 353 | void Recipecxx . . $ Recipe#::recalccxx . . $ Recipe#recalc(49f6e7a06ebc5aa8).() |
| 354 | { |
| 355 | og_cxx . . $ Recipe#og_. = calcOGcxx . . $ Recipe#calcOG(31fa7155c10fdd13).(); |
| 356 | ibu_cxx . . $ Recipe#ibu_. = calcIBUcxx . . $ Recipe#calcIBU(b126dc7c1de90089).(); |
| 357 | srm_cxx . . $ Recipe#srm_. = calcSRMcxx . . $ Recipe#calcSRM(b126dc7c1de90089).(); |
| 358 | } |
| 359 | |
| 360 | ////////////////////////////////////////////////////////////////////////////// |
| 361 | // calcOG() |
| 362 | // -------- |
| 363 | // Calculate the original gravity |
| 364 | |
| 365 | double Recipecxx . . $ Recipe#::calcOGcxx . . $ Recipe#calcOG(31fa7155c10fdd13).() |
| 366 | { |
| 367 | double yield; |
| 368 | double est = 0.0; |
| 369 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(Grain grain, grains_) { |
| 370 | yield = grain.yieldcxx . . $ Grain#yield(21b6c25e127938e2).(); |
| 371 | if (grain.usecxx . . $ Grain#use(a2fb7a6ce195d51).().toLowercxx . . $ QString#toLower(dca2c5857e9adf82).() ==cxx . . $ QString#`operator==`(4b967917d5ca120d). Graincxx . . $ Grain#::MASHED_STRINGcxx . . $ Grain#MASHED_STRING..toLowercxx . . $ QByteArray#toLower(ef52b713090bc85a).()) { |
| 372 | // adjust for mash efficiency |
| 373 | yield *= Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->efficiencycxx . . $ Data#efficiency(31fa7155c10fdd13).(); |
| 374 | } else if (grain.usecxx . . $ Grain#use(a2fb7a6ce195d51).().toLowercxx . . $ QString#toLower(dca2c5857e9adf82).() ==cxx . . $ QString#`operator==`(4b967917d5ca120d). Graincxx . . $ Grain#::STEEPED_STRINGcxx . . $ Grain#STEEPED_STRING..toLowercxx . . $ QByteArray#toLower(ef52b713090bc85a).()) { |
| 375 | // steeped grains don't yield nearly as much as mashed grains |
| 376 | yield *= Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->steepYieldcxx . . $ Data#steepYield(31fa7155c10fdd13).(); |
| 377 | } |
| 378 | est += yield; |
| 379 | } |
| 380 | if (size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(21b6c25e127938e2).()) { |
| 381 | est /= size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(4f9526ff0a26ae42).(Volumecxx . . $ Volume#::galloncxx . . $ Volume#gallon.); |
| 382 | } else { |
| 383 | est = 0.0; |
| 384 | } |
| 385 | return est + 1.0; |
| 386 | } |
| 387 | |
| 388 | ////////////////////////////////////////////////////////////////////////////// |
| 389 | // calcIBU() |
| 390 | // --------- |
| 391 | // Calculate the bitterness |
| 392 | |
| 393 | int Recipecxx . . $ Recipe#::calcIBUcxx . . $ Recipe#calcIBU(b126dc7c1de90089).() |
| 394 | { |
| 395 | // switch between two possible calculations |
| 396 | if (Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->tinsethcxx . . $ Data#tinseth(c9857a73d68e59ba).()) |
| 397 | return calcTinsethIBUcxx . . $ Recipe#calcTinsethIBU(b126dc7c1de90089).(); |
| 398 | else |
| 399 | return calcRagerIBUcxx . . $ Recipe#calcRagerIBU(b126dc7c1de90089).(); |
| 400 | } |
| 401 | |
| 402 | ////////////////////////////////////////////////////////////////////////////// |
| 403 | // calcRagerIBU() |
| 404 | // -------------- |
| 405 | // Calculate the bitterness based on Rager's method (table method) |
| 406 | |
| 407 | int Recipecxx . . $ Recipe#::calcRagerIBUcxx . . $ Recipe#calcRagerIBU(b126dc7c1de90089).() |
| 408 | { |
| 409 | // TODO: update this (and other) hop calculations |
| 410 | double bitterness = 0.0; |
| 411 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(Hop hop, hops_) { |
| 412 | bitterness += hop.HBUcxx . . $ Hop#HBU(31fa7155c10fdd13).() * Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->utilizationcxx . . $ Data#utilization(15aa3a26f3ee3975).(hop.timecxx . . $ Hop#time(ddd8539a2fcdd4ce).()); |
| 413 | // TODO: we should also correct for hop type |
| 414 | } |
| 415 | if (size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(21b6c25e127938e2).()) { |
| 416 | bitterness /= size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(4f9526ff0a26ae42).(Volumecxx . . $ Volume#::galloncxx . . $ Volume#gallon.); |
| 417 | } else { |
| 418 | bitterness = 0.0; |
| 419 | } |
| 420 | // correct for boil gravity |
| 421 | if (og_cxx . . $ Recipe#og_. > 1.050) bitterness /= 1.0 + ((og_cxx . . $ Recipe#og_. - 1.050) / 0.2); |
| 422 | return qRoundcxx . . $ qRound(620b9ac44d2573a6).(bitterness); |
| 423 | } |
| 424 | |
| 425 | ////////////////////////////////////////////////////////////////////////////// |
| 426 | // calcTinsethIBU() |
| 427 | // ---------------- |
| 428 | // Calculate the bitterness based on Tinseth's method (formula method) |
| 429 | // The formula used is: |
| 430 | // (1.65*0.000125^(gravity-1))*(1-EXP(-0.04*time))*alpha*mass*1000 |
| 431 | // --------------------------------------------------------------- |
| 432 | // (volume*4.15) |
| 433 | |
| 434 | // TODO: recheck this formula |
| 435 | |
| 436 | int Recipecxx . . $ Recipe#::calcTinsethIBUcxx . . $ Recipe#calcTinsethIBU(b126dc7c1de90089).() |
| 437 | { |
| 438 | const double GPO = 28.3495; // grams per ounce |
| 439 | const double LPG = 3.785; // liters per gallon |
| 440 | |
| 441 | const double COEFF1 = 1.65; |
| 442 | const double COEFF2 = 0.000125; |
| 443 | const double COEFF3 = 0.04; |
| 444 | const double COEFF4 = 4.15; |
| 445 | |
| 446 | double ibu; |
| 447 | double bitterness = 0.0; |
| 448 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(Hop hop, hops_) { |
| 449 | ibu = (COEFF1 * pow(COEFF2, (og_cxx . . $ Recipe#og_. - 1.0))) * |
| 450 | (1.0 - exp(-COEFF3 * hop.timecxx . . $ Hop#time(ddd8539a2fcdd4ce).())) * |
| 451 | (hop.alphacxx . . $ Hop#alpha(21b6c25e127938e2).()) * hop.weightcxx . . $ Hop#weight(e805bc742de5fe4b).().amountcxx . . $ Quantity#amount(4f9526ff0a26ae42).(Weightcxx . . $ Weight#::ouncecxx . . $ Weight#ounce.) * 1000.0; |
| 452 | if (size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(21b6c25e127938e2).()) { |
| 453 | ibu /= (size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(4f9526ff0a26ae42).(Volumecxx . . $ Volume#::galloncxx . . $ Volume#gallon.) * COEFF4); |
| 454 | } else { |
| 455 | ibu = 0.0; |
| 456 | } |
| 457 | bitterness += ibu; |
| 458 | } |
| 459 | bitterness *= (GPO / LPG) / 100.0; |
| 460 | return qRoundcxx . . $ qRound(620b9ac44d2573a6).(bitterness); |
| 461 | } |
| 462 | |
| 463 | ////////////////////////////////////////////////////////////////////////////// |
| 464 | // calcSRM() |
| 465 | // --------- |
| 466 | // Calculate the color |
| 467 | |
| 468 | int Recipecxx . . $ Recipe#::calcSRMcxx . . $ Recipe#calcSRM(b126dc7c1de90089).() |
| 469 | { |
| 470 | double srm = 0.0; |
| 471 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(Grain grain, grains_) { |
| 472 | srm += grain.HCUcxx . . $ Grain#HCU(21b6c25e127938e2).(); |
| 473 | } |
| 474 | if (size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(21b6c25e127938e2).()) { |
| 475 | srm /= size_cxx . . $ Recipe#size_..amountcxx . . $ Quantity#amount(4f9526ff0a26ae42).(Volumecxx . . $ Volume#::galloncxx . . $ Volume#gallon.); |
| 476 | } else { |
| 477 | srm = 0.0; |
| 478 | } |
| 479 | |
| 480 | // switch between two possible calculations |
| 481 | if (Datacxx . . $ Data#::instancecxx . . $ Data#instance(ddf71f0b6dfdf13b).()->moreycxx . . $ Data#morey(c9857a73d68e59ba).()) { |
| 482 | // power model (morey) [courtesy Rob Hudson <[email protected]>] |
| 483 | srm = (pow(srm, 0.6859)) * 1.4922; |
| 484 | if (srm > 50) srm = 50; |
| 485 | } else { |
| 486 | // linear model (daniels) |
| 487 | if (srm > 8.0) { |
| 488 | srm *= 0.2; |
| 489 | srm += 8.4; |
| 490 | } |
| 491 | } |
| 492 | return qRoundcxx . . $ qRound(620b9ac44d2573a6).(srm); |
| 493 | } |
| 494 | |
| 495 | // TODO: following formulas need to use constants |
| 496 | |
| 497 | ////////////////////////////////////////////////////////////////////////////// |
| 498 | // FGEstimate() |
| 499 | // ------------ |
| 500 | // Return estimated final gravity |
| 501 | |
| 502 | double Recipecxx . . $ Recipe#::FGEstimatecxx . . $ Recipe#FGEstimate(31fa7155c10fdd13).() |
| 503 | { |
| 504 | if (og_cxx . . $ Recipe#og_. <= 0.0) return 0.0; |
| 505 | return (((og_cxx . . $ Recipe#og_. - 1.0) * 0.25) + 1.0); |
| 506 | } |
| 507 | |
| 508 | ////////////////////////////////////////////////////////////////////////////// |
| 509 | // ABV() |
| 510 | // ----- |
| 511 | // Calculate alcohol by volume |
| 512 | |
| 513 | double Recipecxx . . $ Recipe#::ABVcxx . . $ Recipe#ABV(31fa7155c10fdd13).() // recipe version |
| 514 | { |
| 515 | return (ABVcxx . . $ Recipe#ABV(d8e7e0733fa41c87).(og_cxx . . $ Recipe#og_., FGEstimatecxx . . $ Recipe#FGEstimate(31fa7155c10fdd13).())); |
| 516 | } |
| 517 | |
| 518 | double Recipecxx . . $ Recipe#::ABVcxx . . $ Recipe#ABV(d8e7e0733fa41c87).(double og, double fg) // static version |
| 519 | { |
| 520 | return (og - fg) * 1.29; |
| 521 | } |
| 522 | |
| 523 | ////////////////////////////////////////////////////////////////////////////// |
| 524 | // ABW() |
| 525 | // ----- |
| 526 | // Calculate alcohol by weight |
| 527 | // NOTE: Calculations were taken from http://hbd.org/ensmingr/ |
| 528 | |
| 529 | double Recipecxx . . $ Recipe#::ABWcxx . . $ Recipe#ABW(31fa7155c10fdd13).() // recipe version |
| 530 | { |
| 531 | return (ABWcxx . . $ Recipe#ABW(d8e7e0733fa41c87).(og_cxx . . $ Recipe#og_., FGEstimatecxx . . $ Recipe#FGEstimate(31fa7155c10fdd13).())); |
| 532 | } |
| 533 | |
| 534 | double Recipecxx . . $ Recipe#::ABWcxx . . $ Recipe#ABW(d8e7e0733fa41c87).(double og, double fg) // static version |
| 535 | { |
| 536 | return (ABVcxx . . $ Recipe#ABV(d8e7e0733fa41c87).(og, fg) * 0.785); |
| 537 | } |
| 538 | |
| 539 | ////////////////////////////////////////////////////////////////////////////// |
| 540 | // SgToP() |
| 541 | // ------- |
| 542 | // Convert specific gravity to degrees plato |
| 543 | |
| 544 | double Recipecxx . . $ Recipe#::SgToPcxx . . $ Recipe#SgToP(447c67c6676f75c3).(double sg) |
| 545 | { |
| 546 | return ((-463.37) + (668.72*sg) - (205.35 * sg * sg)); |
| 547 | } |
| 548 | |
| 549 | ////////////////////////////////////////////////////////////////////////////// |
| 550 | // extractToYield() |
| 551 | // ---------------- |
| 552 | // Convert extract potential to percent yield |
| 553 | |
| 554 | // TODO: need to double check this, as well as terms |
| 555 | double Recipecxx . . $ Recipe#::extractToYieldcxx . . $ Recipe#extractToYield(447c67c6676f75c3).(double extract) |
| 556 | { |
| 557 | const double SUCROSE = 46.21415; |
| 558 | return (((extract-1.0)*1000.0) / SUCROSE); |
| 559 | } |
| 560 | |
| 561 | ////////////////////////////////////////////////////////////////////////////// |
| 562 | // yieldToExtract() |
| 563 | // ---------------- |
| 564 | // Convert percent yield to extract potential |
| 565 | |
| 566 | double Recipecxx . . $ Recipe#::yieldToExtractcxx . . $ Recipe#yieldToExtract(447c67c6676f75c3).(double yield) |
| 567 | { |
| 568 | const double SUCROSE = 46.21415; |
| 569 | return ((yield*SUCROSE)/1000.0)+1.0; |
| 570 | } |
| 571 | |
| 572 | ////////////////////////////////////////////////////////////////////////////// |
| 573 | // Miscellaneous // |
| 574 | ////////////////////////////////////////////////////////////////////////////// |
| 575 | |
| 576 | void Recipecxx . . $ Recipe#::setModifiedcxx . . $ Recipe#setModified(b45ddcbc8423892c).(bool mod) |
| 577 | { |
| 578 | modified_cxx . . $ Recipe#modified_. = mod; |
| 579 | if (mod) emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! recipeModifiedcxx . . $ Recipe#recipeModified(49f6e7a06ebc5aa8).(); |
| 580 | } |
| 581 | |
| 582 | bool Recipecxx . . $ Recipe#::modifiedcxx . . $ Recipe#modified(50ce9a9e25b4a850).() const |
| 583 | { |
| 584 | return modified_cxx . . $ Recipe#modified_.; |
| 585 | } |