File: recipe.h

package info (click to toggle)
qbrew 0.4.1-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 1,724 kB
  • ctags: 1,355
  • sloc: cpp: 7,503; sh: 414; makefile: 18
file content (233 lines) | stat: -rw-r--r-- 6,727 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/***************************************************************************
  recipe.h
  -------------------
  Recipe (document) class
  -------------------
  Copyright 2001-2008, David Johnson
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ***************************************************************************/

#ifndef RECIPE_H
#define RECIPE_H

#include <QObject>
#include <QString>

#include "quantity.h"
#include "grain.h"
#include "hop.h"
#include "misc.h"
#include "style.h"

class TextPrinter;

class Recipe : public QObject {
    Q_OBJECT
public:
    // TODO: make sure am comparing lowercase
    // recipe strings
    static const QByteArray EXTRACT_STRING;
    static const QByteArray PARTIAL_STRING;
    static const QByteArray ALLGRAIN_STRING;

    // default constructor
    Recipe(QObject *parent=0);
    Recipe(const Recipe &recipe);
    Recipe operator=(const Recipe &recipe);
    virtual ~Recipe();

    // start a new recipe
    void newRecipe();
    // load a recipe
    bool loadRecipe(const QString &filename);
    // save the current recipe
    bool saveRecipe(const QString &filename);
    // preview the recipe
    void previewRecipe(TextPrinter *textprinter);
    // print the recipe
    void printRecipe(TextPrinter *textprinter);
    // is the file in native format?
    bool nativeFormat(const QString &filename);
    // is the file in BeerXml format?
    bool beerXmlFormat(const QString &filename);

    // import a recipe from another BeerXML format
    bool importBeerXml(const QString &filename);
    // export the recipe as html
    bool exportHtml(const QString &filename);
    // export the recipe to BeerXML format
    bool exportBeerXML(const QString &filename);
    // export the recipe as pdf
    bool exportPdf(TextPrinter *textprinter, const QString &filename);
    // export the recipe as html
    bool exportText(const QString &filename);

    // get and set
    const QString& title() const;
    void setTitle(const QString &t);
    const QString& brewer() const;
    void setBrewer(const QString &b);
    const Volume &size() const;
    void setSize(const Volume &s);
    const Style &style() const;
    void setStyle(const Style &s);
    void setStyle(const QString &s);
    const QString& recipeNotes() const;
    void setRecipeNotes(const QString &n);
    const QString& batchNotes() const;
    void setBatchNotes(const QString &n);

    // add an ingredient to the recipe
    void addGrain(const Grain &g);
    void addHop(const Hop &h);
    void addMisc(const Misc &m);

    // return pointer to ingredient lists
    GrainList *grains();
    HopList *hops();
    MiscList *miscs();

    // return original gravity
    double OG();
    // return bitterness
    int IBU();
    // return color
    int SRM();
    // return estimated final gravity
    double FGEstimate();
    // return method of recipe
    QString method();

    // return alcohol %v
    double ABV();
    static double ABV(double og, double fg);
    // return alcohol %w
    double ABW();
    static double ABW(double og, double fg);
    // convert Specific Gravity to Plato
    static double SgToP(double sg);
    // convert grain extract to yield
    static double extractToYield(double extract);
    static double yieldToExtract(double yield);

    // is the recipe modified?
    bool modified() const;

public slots:
    // recalculate the recipe values
    void recalc();
    // set recipe as modified
    void setModified(bool m);

signals:
    // send that the recipe has been loaded or created
    void recipeChanged();
    // send that the recipe has been modified
    void recipeModified();

private:
    // calculations
    double calcOG();
    int calcSRM();
    int calcIBU();
    int calcRagerIBU();
    int calcTinsethIBU();

    const QString recipeHTML();
    const QString recipeText();

private:
    bool modified_;

    QString title_;
    QString brewer_;

    Volume size_;
    Style style_;

    GrainList grains_;
    HopList hops_;
    MiscList miscs_;

    QString recipenotes_;
    QString batchnotes_;

    double og_;
    int ibu_;
    int srm_;
};

// Inlined Methods //////////////////////////////////////////////////////////

inline const QString &Recipe::title() const
    { return title_; }

inline void Recipe::setTitle(const QString &t)
{ title_ = t; setModified(true); }

inline const QString &Recipe::brewer() const
    { return brewer_; }

inline void Recipe::setBrewer(const QString &b)
    { brewer_ = b; setModified(true); }

inline const Volume &Recipe::size() const
    { return size_; }

inline void Recipe::setSize(const Volume &s)
    { size_ = s; recalc(); setModified(true); }

inline const Style &Recipe::style() const
    { return style_; }

inline void Recipe::setStyle(const Style &s)
    { style_ = s; setModified(true); }

inline const QString& Recipe::recipeNotes() const
    { return recipenotes_; }

inline void Recipe::setRecipeNotes(const QString &n)
    { recipenotes_ = n; setModified(true); }

inline const QString& Recipe::batchNotes() const
    { return batchnotes_; }

inline void Recipe::setBatchNotes(const QString &n)
    { batchnotes_ = n; setModified(true); }

inline GrainList *Recipe::grains() { return &grains_; }

inline HopList *Recipe::hops() { return &hops_; }

inline MiscList *Recipe::miscs() { return &miscs_; }

inline double Recipe::OG() { return og_; }

inline int Recipe::IBU() { return ibu_; }

inline int Recipe::SRM() { return srm_; }

#endif // RECIPE_H