| 1 | /*************************************************************************** |
| 2 | hop.cpp |
| 3 | ------------------- |
| 4 | A hop class |
| 5 | ------------------- |
| 6 | Copyright 1999-2008, David Johnson |
| 7 | Please see the header file for copyright and license information |
| 8 | ***************************************************************************/ |
| 9 | |
| 10 | #include <QStringList> |
| 11 | #include "resource.h" |
| 12 | #include "hop.h" |
| 13 | |
| 14 | const QByteArray Hop::PELLET_STRING = QT_TRANSLATE_NOOP("Hop", "Pellet"); |
| 15 | const QByteArray Hop::PLUG_STRING = QT_TRANSLATE_NOOP("Hop", "Plug"); |
| 16 | const QByteArray Hop::WHOLE_STRING = QT_TRANSLATE_NOOP("Hop", "Whole"); |
| 17 | |
| 18 | ////////////////////////////////////////////////////////////////////////////// |
| 19 | // Hop() |
| 20 | // ----- |
| 21 | // constructor |
| 22 | |
| 23 | Hop::Hop() |
| 24 | : name_(QObject::tr("Generic")), weight_(), type_(PELLET_STRING), |
| 25 | alpha_(10.0), time_(0) |
| 26 | { ; } |
| 27 | |
| 28 | Hop::Hop(const QString &name, const Weight &weight, const QString &typ, |
| 29 | const double &alpha, const unsigned &time) |
| 30 | : name_(name), weight_(weight), type_(typ), alpha_(alpha), time_(time) |
| 31 | |
| 32 | { |
| 33 | recalc(); |
| 34 | } |
| 35 | |
| 36 | Hop::~Hop() { ; } |
| 37 | |
| 38 | ////////////////////////////////////////////////////////////////////////////// |
| 39 | // Hop(const Hop &) |
| 40 | // ---------------- |
| 41 | // Copy constructor |
| 42 | |
| 43 | Hop::Hop(const Hop &h) |
| 44 | : name_(h.name_), weight_(h.weight_), type_(h.type_), alpha_(h.alpha_), |
| 45 | time_(h.time_), hbu_(h.hbu_) |
| 46 | { ; } |
| 47 | |
| 48 | ////////////////////////////////////////////////////////////////////////////// |
| 49 | // operator=() |
| 50 | // ----------- |
| 51 | // Assignment operator |
| 52 | |
| 53 | Hop Hop::operator=(const Hop &h) |
| 54 | { |
| 55 | if (this != &h) { |
| 56 | name_ = h.name_; |
| 57 | weight_ = h.weight_; |
| 58 | type_ = h.type_; |
| 59 | alpha_ = h.alpha_; |
| 60 | time_ = h.time_; |
| 61 | hbu_ = h.hbu_; |
| 62 | } |
| 63 | return *this; |
| 64 | } |
| 65 | |
| 66 | ////////////////////////////////////////////////////////////////////////////// |
| 67 | // operator==() |
| 68 | // ------------ |
| 69 | // Equivalence operator |
| 70 | |
| 71 | bool Hop::operator==(const Hop &h) const |
| 72 | { |
| 73 | return (name_ == h.name_) |
| 74 | && (weight_ == h.weight_) |
| 75 | && (type_ == h.type_) |
| 76 | && (alpha_ == h.alpha_) |
| 77 | && (time_ == h.time_); |
| 78 | } |
| 79 | |
| 80 | ////////////////////////////////////////////////////////////////////////////// |
| 81 | // typeStringList() |
| 82 | // ---------------- |
| 83 | // Return string list of available hop types |
| 84 | |
| 85 | QStringList Hop::typeStringList() |
| 86 | { |
| 87 | return (QStringList() << PELLET_STRING << PLUG_STRING << WHOLE_STRING); |
| 88 | } |
| 89 | |
| 90 | //////////////////////////////////////////////////////////3///////////////////// |
| 91 | // recalc() |
| 92 | // -------- |
| 93 | // Recalculate internal values |
| 94 | |
| 95 | void Hop::recalc() |
| 96 | { |
| 97 | hbu_ = 0.75 * alpha_ * weight_.amount(Weight::ounce); |
| 98 | } |