~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to src/RecipeFormatter.cpp

  • Committer: Philip Greggory Lee
  • Date: 2009-08-23 16:53:43 UTC
  • Revision ID: git-v1:f8d1a25135bd92f06c46c562293800e4faa42c61
Made a src/ and ui/ directory and moved everything.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* RecipeFormatter.cpp is part of Brewtarget, and is Copyright Philip G. Lee
 
3
* (rocketman768@gmail.com), 2009.
 
4
*
 
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.
 
9
 
 
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.
 
14
 
 
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/>.
 
17
*/
 
18
 
 
19
#include "RecipeFormatter.h"
 
20
#include "style.h"
 
21
#include "fermentable.h"
 
22
#include "hop.h"
 
23
#include "misc.h"
 
24
#include "yeast.h"
 
25
#include "mash.h"
 
26
#include "unit.h"
 
27
#include "brewtarget.h"
 
28
#include <QClipboard>
 
29
 
 
30
RecipeFormatter::RecipeFormatter()
 
31
{
 
32
   textSeparator = 0;
 
33
   rec = 0;
 
34
}
 
35
 
 
36
void RecipeFormatter::setRecipe(Recipe* recipe)
 
37
{
 
38
   rec = recipe;
 
39
}
 
40
 
 
41
QString RecipeFormatter::getTextFormat()
 
42
{
 
43
   QString ret = "";
 
44
   if( rec == 0 )
 
45
      return ret;
 
46
   
 
47
   unsigned int i, size;
 
48
   
 
49
   Style* style = rec->getStyle();
 
50
   Mash* mash = rec->getMash();
 
51
   
 
52
   // Vital statistics.
 
53
   ret += rec->getName().c_str();
 
54
   if( style != 0 && style->getName() != "" )
 
55
      ret += (" - " + style->getName()).c_str();
 
56
   ret += "\n";
 
57
   
 
58
   ret += getTextSeparator();
 
59
   
 
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";
 
69
   
 
70
   if( rec->getNumFermentables() > 0 )
 
71
   {
 
72
      ret += "\n";
 
73
      ret += "Fermentables\n";
 
74
      ret += getTextSeparator();
 
75
      
 
76
      ret += "Name\t\tType\t\tAmount\t\tMashed\t\tYield\t\tColor\n";
 
77
      
 
78
      size = rec->getNumFermentables();
 
79
      for( i = 0; i < size; ++i )
 
80
      {
 
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";
 
88
      }
 
89
   }
 
90
   
 
91
   if( rec->getNumHops() > 0 )
 
92
   {
 
93
      ret += "\n";
 
94
      ret += "Hops\n";
 
95
      ret += getTextSeparator();
 
96
      
 
97
      ret += "Name\t\tAlpha\t\tAmount\t\tUse\t\tTime\t\tIBU\n";
 
98
      
 
99
      size = rec->getNumHops();
 
100
      for( i = 0; i < size; ++i )
 
101
      {
 
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";
 
109
      }
 
110
   }
 
111
   
 
112
   if( rec->getNumMiscs() > 0 )
 
113
   {
 
114
      ret += "\n";
 
115
      ret += "Misc\n";
 
116
      ret += getTextSeparator();
 
117
      
 
118
      ret += "Name\t\tType\t\tUse\t\tAmount\t\tTime\n";
 
119
      
 
120
      size = rec->getNumMiscs();
 
121
      for( i = 0; i < size; ++i )
 
122
      {
 
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";
 
128
      }
 
129
   }
 
130
   
 
131
   if( rec->getNumYeasts() > 0 )
 
132
   {
 
133
      ret += "\n";
 
134
      ret += "Yeast\n";
 
135
      ret += getTextSeparator();
 
136
      
 
137
      ret += "Name\t\tType\t\tForm\t\tAmount\t\tStage\n";
 
138
      
 
139
      size = rec->getNumYeasts();
 
140
      for( i = 0; i < size; ++i )
 
141
      {
 
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");
 
148
      }
 
149
   }
 
150
   
 
151
   if( mash && mash->getNumMashSteps() > 0 )
 
152
   {
 
153
      ret += "\n";
 
154
      ret += "Mash\n";
 
155
      ret += getTextSeparator();
 
156
      
 
157
      ret += "Name\t\tType\t\tAmount\t\tTarget\t\tTime\n";
 
158
      
 
159
      size = mash->getNumMashSteps();
 
160
      for( i = 0; i < size; ++i )
 
161
      {
 
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";
 
169
         else
 
170
            ret += "\t\t";
 
171
         ret += Brewtarget::displayAmount( s->getStepTemp_c(), Units::celsius ) + "\t\t";
 
172
         ret += Brewtarget::displayAmount( s->getStepTime_min(), Units::minutes ) + "\n";
 
173
      }
 
174
   }
 
175
}
 
176
 
 
177
QString RecipeFormatter::getTextSeparator()
 
178
{
 
179
   if( textSeparator != 0 )
 
180
      return *textSeparator;
 
181
   
 
182
   int i;
 
183
   textSeparator = new QString();
 
184
   for( i = 0; i < 80; ++i )
 
185
      textSeparator->append('=');
 
186
   
 
187
   textSeparator->append('\n');
 
188
   return *textSeparator;
 
189
}
 
190
 
 
191
QString RecipeFormatter::getHTMLFormat()
 
192
{
 
193
   return "";
 
194
}
 
195
 
 
196
QString RecipeFormatter::getBBCodeFormat()
 
197
{
 
198
   return "";
 
199
}
 
200
 
 
201
void RecipeFormatter::toTextClipboard()
 
202
{
 
203
   QApplication::clipboard()->setText(getTextFormat());
 
204
}
 
 
b'\\ No newline at end of file'