2
* RecipeFormatter.cpp is part of Brewtarget, and is Copyright Philip G. Lee
3
* (rocketman768@gmail.com), 2009.
5
* Brewtarget is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Brewtarget is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "RecipeFormatter.h"
21
#include "fermentable.h"
27
#include "brewtarget.h"
30
RecipeFormatter::RecipeFormatter()
36
void RecipeFormatter::setRecipe(Recipe* recipe)
41
QString RecipeFormatter::getTextFormat()
49
Style* style = rec->getStyle();
50
Mash* mash = rec->getMash();
53
ret += rec->getName().c_str();
54
if( style != 0 && style->getName() != "" )
55
ret += (" - " + style->getName()).c_str();
58
ret += getTextSeparator();
60
ret += "Batch Size: " + Brewtarget::displayAmount(rec->getBatchSize_l(), Units::liters) + "\n";
61
ret += "Boil Size: " + Brewtarget::displayAmount(rec->getBoilSize_l(), Units::liters) + "\n";
62
ret += "Boil Time: " + Brewtarget::displayAmount(rec->getBoilTime_min(), Units::minutes) + "\n";
63
ret += "Efficiency: " + QString("%1\%").arg(rec->getEfficiency_pct(), 0, 'f', 0) + "\n";
64
ret += "OG: " + QString("%1").arg( rec->getOg(), 0, 'f', 3 ) + "\n";
65
ret += "FG: " + QString("%1").arg( rec->getFg(), 0, 'f', 3 ) + "\n";
66
ret += "ABV: " + QString("%1\%").arg( rec->getABV_pct(), 0, 'f', 0 ) + "\n";
67
ret += "Bitterness: " + QString("%1 IBUs").arg( rec->getIBU(), 0, 'f', 1 ) + "\n";
68
ret += "Color: " + QString("%1 SRM").arg( rec->getColor_srm(), 0, 'f', 0 ) + "\n";
70
if( rec->getNumFermentables() > 0 )
73
ret += "Fermentables\n";
74
ret += getTextSeparator();
76
ret += "Name\t\tType\t\tAmount\t\tMashed\t\tYield\t\tColor\n";
78
size = rec->getNumFermentables();
79
for( i = 0; i < size; ++i )
81
Fermentable* ferm = rec->getFermentable(i);
82
ret += (ferm->getName() + "\t\t").c_str();
83
ret += (ferm->getType() + "\t\t").c_str();
84
ret += Brewtarget::displayAmount(ferm->getAmount_kg(), Units::kilograms) + "\t\t";
85
ret += ferm->getIsMashed() ? "Yes\t\t" : "No\t\t";
86
ret += QString("%1\%").arg(ferm->getYield_pct(), 0, 'f', 0) + "\t\t";
87
ret += QString("%1 L").arg(ferm->getColor_srm(), 0, 'f', 0) + "\n";
91
if( rec->getNumHops() > 0 )
95
ret += getTextSeparator();
97
ret += "Name\t\tAlpha\t\tAmount\t\tUse\t\tTime\t\tIBU\n";
99
size = rec->getNumHops();
100
for( i = 0; i < size; ++i )
102
Hop* hop = rec->getHop(i);
103
ret += (hop->getName() + "\t\t").c_str();
104
ret += QString("%1").arg(hop->getAlpha_pct(), 0, 'f', 1) + "\t\t";
105
ret += Brewtarget::displayAmount(hop->getAmount_kg(), Units::kilograms) + "\t\t";
106
ret += (hop->getUse() + "\t\t").c_str();
107
ret += Brewtarget::displayAmount(hop->getTime_min(), Units::minutes) + "\t\t";
108
ret += QString("%1").arg( rec->getIBUFromHop(i), 0, 'f', 1 ) + "\n";
112
if( rec->getNumMiscs() > 0 )
116
ret += getTextSeparator();
118
ret += "Name\t\tType\t\tUse\t\tAmount\t\tTime\n";
120
size = rec->getNumMiscs();
121
for( i = 0; i < size; ++i )
123
Misc* misc = rec->getMisc(i);
124
ret += (misc->getName() + "\t\t").c_str();
125
ret += (misc->getType() + "\t\t").c_str();
126
ret += (misc->getUse() + "\t\t").c_str();
127
ret += Brewtarget::displayAmount(misc->getTime(), Units::minutes) + "\n";
131
if( rec->getNumYeasts() > 0 )
135
ret += getTextSeparator();
137
ret += "Name\t\tType\t\tForm\t\tAmount\t\tStage\n";
139
size = rec->getNumYeasts();
140
for( i = 0; i < size; ++i )
142
Yeast* y = rec->getYeast(i);
143
ret += (y->getName() + "\t\t").c_str();
144
ret += (y->getType() + "\t\t").c_str();
145
ret += (y->getForm() + "\t\t").c_str();
146
ret += Brewtarget::displayAmount( y->getAmount(), y->getAmountIsWeight() ? (Unit*)Units::kilograms : (Unit*)Units::liters ) + "\t\t";
147
ret += (y->getAddToSecondary() ? "Secondary\n" : "Primary\n");
151
if( mash && mash->getNumMashSteps() > 0 )
155
ret += getTextSeparator();
157
ret += "Name\t\tType\t\tAmount\t\tTarget\t\tTime\n";
159
size = mash->getNumMashSteps();
160
for( i = 0; i < size; ++i )
162
MashStep* s = mash->getMashStep(i);
163
ret += (s->getName() + "\t\t").c_str();
164
ret += (s->getType() + "\t\t").c_str();
165
if( s->getType() == "Infusion" )
166
ret += Brewtarget::displayAmount( s->getInfuseAmount_l(), Units::liters ) + "\t\t";
167
else if( s->getType() == "Decoction" )
168
ret += Brewtarget::displayAmount( s->getDecoctionAmount_l(), Units::liters ) + "\t\t";
171
ret += Brewtarget::displayAmount( s->getStepTemp_c(), Units::celsius ) + "\t\t";
172
ret += Brewtarget::displayAmount( s->getStepTime_min(), Units::minutes ) + "\n";
177
QString RecipeFormatter::getTextSeparator()
179
if( textSeparator != 0 )
180
return *textSeparator;
183
textSeparator = new QString();
184
for( i = 0; i < 80; ++i )
185
textSeparator->append('=');
187
textSeparator->append('\n');
188
return *textSeparator;
191
QString RecipeFormatter::getHTMLFormat()
196
QString RecipeFormatter::getBBCodeFormat()
201
void RecipeFormatter::toTextClipboard()
203
QApplication::clipboard()->setText(getTextFormat());
b'\\ No newline at end of file'