15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ |
16 */ |
17 #include "EditRecipe.h" |
17 #include "EditRecipe.h" |
18 #include "../ui/ui_EditRecipe.h" |
18 #include "../ui/ui_EditRecipe.h" |
19 #include "MainWindow.h" |
19 #include "MainWindow.h" |
|
20 #include "Utils.h" |
20 |
21 |
21 |
22 |
22 EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe) |
23 EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe) |
23 { |
24 { |
24 QSqlQuery query; |
25 QSqlQuery query; |
63 ui->typeEdit->setCurrentIndex(query.value(23).toInt()); |
64 ui->typeEdit->setCurrentIndex(query.value(23).toInt()); |
64 ui->batch_sizeEdit->setValue(query.value(24).toDouble()); |
65 ui->batch_sizeEdit->setValue(query.value(24).toDouble()); |
65 ui->boil_sizeEdit->setValue(query.value(25).toDouble()); |
66 ui->boil_sizeEdit->setValue(query.value(25).toDouble()); |
66 ui->boil_timeEdit->setValue(query.value(26).toInt()); |
67 ui->boil_timeEdit->setValue(query.value(26).toInt()); |
67 ui->efficiencyEdit->setValue(query.value(27).toDouble()); |
68 ui->efficiencyEdit->setValue(query.value(27).toDouble()); |
68 // 28 est_og |
69 |
69 // 29 est_fg |
70 ui->est_ogEdit->setValue(query.value(28).toDouble()); |
70 // 30 est_abv |
71 ui->est_ogShow->setRange(query.value(9).toDouble(), query.value(10).toDouble()); |
71 // 31 est_color |
72 ui->est_ogShow->setPrecision(3); |
72 // 32 color_method |
73 ui->est_ogShow->setTickMarks(0.010, 2); |
|
74 ui->est_ogShow->setBackgroundBrush(QColor(121,201,121)); |
|
75 ui->est_ogShow->setPreferredRangeBrush(QColor(0,127,0)); |
|
76 ui->est_ogShow->setMarkerTextIsValue(true); |
|
77 ui->est_ogShow->setValue(query.value(28).toDouble()); |
|
78 |
|
79 ui->est_fgEdit->setValue(query.value(29).toDouble()); |
|
80 ui->est_fgShow->setRange(query.value(11).toDouble(), query.value(12).toDouble()); |
|
81 ui->est_fgShow->setPrecision(3); |
|
82 ui->est_fgShow->setTickMarks(0.010, 2); |
|
83 ui->est_fgShow->setBackgroundBrush(QColor(121,201,121)); |
|
84 ui->est_fgShow->setPreferredRangeBrush(QColor(0,127,0)); |
|
85 ui->est_fgShow->setMarkerTextIsValue(true); |
|
86 ui->est_fgShow->setValue(query.value(29).toDouble()); |
|
87 |
|
88 ui->est_abvEdit->setValue(query.value(30).toDouble()); |
|
89 ui->est_abvShow->setRange(query.value(19).toDouble(), query.value(20).toDouble()); |
|
90 ui->est_abvShow->setPrecision(1); |
|
91 ui->est_abvShow->setTickMarks(1.0, 2); |
|
92 ui->est_abvShow->setBackgroundBrush(QColor(121,201,121)); |
|
93 ui->est_abvShow->setPreferredRangeBrush(QColor(0,127,0)); |
|
94 ui->est_abvShow->setMarkerTextIsValue(true); |
|
95 ui->est_abvShow->setValue(query.value(30).toDouble()); |
|
96 |
|
97 ui->est_colorEdit->setValue(query.value(31).toDouble()); |
|
98 QColor color = Utils::ebc_to_color(query.value(31).toInt()); |
|
99 ui->est_colorShow->setColor(color); |
|
100 |
|
101 color_methodEdit->addItem("Morey"); |
|
102 color_methodEdit->addItem("Mosher"); |
|
103 color_methodEdit->addItem("Daniels"); |
|
104 color_methodEdit->addItem("Halberstadt"); |
|
105 color_methodEdit->addItem("Naudts"); |
|
106 color_methodEdit->setCurrentIndex(query.value(32).toInt()); |
|
107 |
73 // 33 est_ibu |
108 // 33 est_ibu |
74 // 34 ibu_method |
109 // 34 ibu_method |
75 // 35 est_carb |
110 // 35 est_carb |
76 // 36 sparge_temp |
111 // 36 sparge_temp |
77 // 37 sparge_ph |
112 // 37 sparge_ph |
138 connect(ui->batch_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); |
173 connect(ui->batch_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); |
139 connect(ui->boil_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); |
174 connect(ui->boil_sizeEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); |
140 connect(ui->boil_timeEdit, &QSpinBox::textChanged, this, &EditRecipe::is_changed); |
175 connect(ui->boil_timeEdit, &QSpinBox::textChanged, this, &EditRecipe::is_changed); |
141 connect(ui->efficiencyEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); |
176 connect(ui->efficiencyEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); |
142 |
177 |
|
178 connect(ui->color_methodEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed); |
|
179 |
143 ui->saveButton->setEnabled(false); |
180 ui->saveButton->setEnabled(false); |
144 ui->deleteButton->setEnabled((id >= 0) ? true:false); |
181 ui->deleteButton->setEnabled((id >= 0) ? true:false); |
145 } |
182 } |
146 |
183 |
147 |
184 |
148 EditRecipe::~EditRecipe() |
185 EditRecipe::~EditRecipe() |
149 { |
186 { |
150 qDebug() << "EditRecipe done"; |
187 qDebug() << "EditRecipe done start"; |
151 delete ui; |
188 delete ui; |
152 emit entry_changed(); |
189 emit entry_changed(); |
|
190 qDebug() << "EditRecipe done final"; |
153 } |
191 } |
154 |
192 |
155 |
193 |
156 /* |
194 /* |
157 * Window header, mark any change with '**' |
195 * Window header, mark any change with '**' |
176 void EditRecipe::on_saveButton_clicked() |
214 void EditRecipe::on_saveButton_clicked() |
177 { |
215 { |
178 QSqlQuery query; |
216 QSqlQuery query; |
179 |
217 |
180 /* If there are errors in the form, show a message and do "return;" */ |
218 /* If there are errors in the form, show a message and do "return;" */ |
181 // if (ui->nameEdit->text().length() < 2) { |
219 if (ui->nameEdit->text().length() < 2) { |
182 // QMessageBox::warning(this, tr("Edit Recipe"), tr("Name empty or too short.")); |
220 QMessageBox::warning(this, tr("Edit Recipe"), tr("Name empty or too short.")); |
183 // return; |
221 return; |
184 // } |
222 } |
185 |
223 |
186 if (this->textIsChanged) { |
224 if (this->textIsChanged) { |
187 if (this->recno == -1) { |
225 if (this->recno == -1) { |
188 query.prepare("INSERT INTO recipes SET name=:name, " |
226 query.prepare("INSERT INTO recipes SET name=:name, " |
189 "uuid = :uuid"); |
227 "uuid = :uuid"); |