~scottydelicious666/brewtarget/brewtarget

« back to all changes in this revision

Viewing changes to MashEditor.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
 
 * MashEditor.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 "MashEditor.h"
20
 
#include <QWidget>
21
 
#include "mash.h"
22
 
#include "brewtarget.h"
23
 
#include "unit.h"
24
 
#include "equipment.h"
25
 
 
26
 
MashEditor::MashEditor(QWidget* parent) : QDialog(parent)
27
 
{
28
 
   setupUi(this);
29
 
   rec = 0;
30
 
 
31
 
   connect(pushButton_fromEquipment, SIGNAL(clicked()), this, SLOT(fromEquipment()) );
32
 
   connect(this, SIGNAL(accepted()), this, SLOT(saveAndClose()) );
33
 
   connect(this, SIGNAL(rejected()), this, SLOT(closeEditor()) );
34
 
}
35
 
 
36
 
void MashEditor::showEditor()
37
 
{
38
 
   showChanges();
39
 
   setVisible(true);
40
 
}
41
 
 
42
 
void MashEditor::closeEditor()
43
 
{
44
 
   setVisible(false);
45
 
}
46
 
 
47
 
void MashEditor::saveAndClose()
48
 
{
49
 
   Mash* mash;
50
 
 
51
 
   // Create a new mash if the recipe has none.
52
 
   if( rec == 0 )
53
 
      return;
54
 
   else if( rec->getMash() == 0 )
55
 
   {
56
 
      mash = new Mash();
57
 
      rec->setMash(mash);
58
 
   }
59
 
   else
60
 
   {
61
 
      mash = rec->getMash();
62
 
   }
63
 
   
64
 
   mash->disableNotification(); // If we don't do this, the notification will propagate to a showChanges() and we'll lose any info we want saved.
65
 
   mash->setEquipAdjust( true ); // BeerXML won't like me, but it's just stupid not to adjust for the equipment when you're able.
66
 
 
67
 
   mash->setName( lineEdit_name->text().toStdString() );
68
 
   mash->setGrainTemp_c(Unit::qstringToSI(lineEdit_grainTemp->text()));
69
 
   mash->setSpargeTemp_c(Unit::qstringToSI(lineEdit_spargeTemp->text()));
70
 
   mash->setPh(Unit::qstringToSI(lineEdit_spargePh->text()));
71
 
   mash->setTunTemp_c(Unit::qstringToSI(lineEdit_tunTemp->text()));
72
 
   mash->setTunWeight_kg(Unit::qstringToSI(lineEdit_tunMass->text()));
73
 
   mash->setTunSpecificHeat_calGC(Unit::qstringToSI(lineEdit_tunSpHeat->text()) );
74
 
 
75
 
   mash->setNotes( textEdit_notes->toPlainText().toStdString() );
76
 
   
77
 
   mash->reenableNotification();
78
 
   mash->forceNotify();
79
 
}
80
 
 
81
 
void MashEditor::fromEquipment()
82
 
{
83
 
   if( rec == 0 || rec->getEquipment() == 0 )
84
 
   {
85
 
      return;
86
 
   }
87
 
 
88
 
   Equipment* equip = rec->getEquipment();
89
 
 
90
 
   lineEdit_tunMass->setText(Brewtarget::displayAmount(equip->getTunWeight_kg(), Units::kilograms));
91
 
   lineEdit_tunSpHeat->setText(Brewtarget::displayAmount(equip->getTunSpecificHeat_calGC()));
92
 
}
93
 
 
94
 
void MashEditor::setRecipe(Recipe* recipe)
95
 
{
96
 
   rec = recipe;
97
 
   showChanges();
98
 
}
99
 
 
100
 
void MashEditor::showChanges()
101
 
{
102
 
   if( rec == 0 || rec->getMash() == 0 )
103
 
   {
104
 
      clear();
105
 
      return;
106
 
   }
107
 
 
108
 
   Mash* mash = rec->getMash();
109
 
   
110
 
   lineEdit_name->setText(mash->getName().c_str());
111
 
   lineEdit_grainTemp->setText(Brewtarget::displayAmount(mash->getGrainTemp_c(), Units::celsius));
112
 
   lineEdit_spargeTemp->setText(Brewtarget::displayAmount(mash->getSpargeTemp_c(), Units::celsius));
113
 
   lineEdit_spargePh->setText(Brewtarget::displayAmount(mash->getPh()));
114
 
   lineEdit_tunTemp->setText(Brewtarget::displayAmount(mash->getTunTemp_c(), Units::celsius));
115
 
   lineEdit_tunMass->setText(Brewtarget::displayAmount(mash->getTunWeight_kg(), Units::kilograms));
116
 
   lineEdit_tunSpHeat->setText(Brewtarget::displayAmount(mash->getTunSpecificHeat_calGC()));
117
 
 
118
 
   textEdit_notes->setPlainText(mash->getNotes().c_str());
119
 
}
120
 
 
121
 
void MashEditor::clear()
122
 
{
123
 
   lineEdit_name->setText("");
124
 
   lineEdit_grainTemp->setText("");
125
 
   lineEdit_spargeTemp->setText("");
126
 
   lineEdit_spargePh->setText("");
127
 
   lineEdit_tunTemp->setText("");
128
 
   lineEdit_tunMass->setText("");
129
 
   lineEdit_tunSpHeat->setText("");
130
 
 
131
 
   textEdit_notes->setPlainText("");
132
 
}
 
 
b'\\ No newline at end of file'