103 } else { |
101 } else { |
104 pWidget = new QWidget(); |
102 pWidget = new QWidget(); |
105 QPushButton* btn_dele = new QPushButton(); |
103 QPushButton* btn_dele = new QPushButton(); |
106 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
104 btn_dele->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
107 btn_dele->setText(tr("Delete")); |
105 btn_dele->setText(tr("Delete")); |
108 connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteFermentRow_clicked())); |
106 connect(btn_dele, SIGNAL(clicked()), this, SLOT(on_deleteMiscRow_clicked())); |
109 pLayout = new QHBoxLayout(pWidget); |
107 pLayout = new QHBoxLayout(pWidget); |
110 pLayout->addWidget(btn_dele); |
108 pLayout->addWidget(btn_dele); |
111 pLayout->setContentsMargins(5, 0, 5, 0); |
109 pLayout->setContentsMargins(5, 0, 5, 0); |
112 pWidget->setLayout(pLayout); |
110 pWidget->setLayout(pLayout); |
113 ui->miscsTable->setCellWidget(i, 5, pWidget); |
111 ui->miscsTable->setCellWidget(i, 5, pWidget); |
114 |
112 |
115 pWidget = new QWidget(); |
113 pWidget = new QWidget(); |
116 QPushButton* btn_edit = new QPushButton(); |
114 QPushButton* btn_edit = new QPushButton(); |
117 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
115 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */ |
118 btn_edit->setText(tr("Edit")); |
116 btn_edit->setText(tr("Edit")); |
119 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editFermentRow_clicked())); |
117 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editMiscRow_clicked())); |
120 pLayout = new QHBoxLayout(pWidget); |
118 pLayout = new QHBoxLayout(pWidget); |
121 pLayout->addWidget(btn_edit); |
119 pLayout->addWidget(btn_edit); |
122 pLayout->setContentsMargins(5, 0, 5, 0); |
120 pLayout->setContentsMargins(5, 0, 5, 0); |
123 pWidget->setLayout(pLayout); |
121 pWidget->setLayout(pLayout); |
124 ui->miscsTable->setCellWidget(i, 6, pWidget); |
122 ui->miscsTable->setCellWidget(i, 6, pWidget); |
167 ui->mw_acidpercEdit->setValue(my_acids.at(3).AcidPrc); |
165 ui->mw_acidpercEdit->setValue(my_acids.at(3).AcidPrc); |
168 ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
166 ui->mw_acidvolEdit->setValue(recipe->miscs.at(i).m_amount * 1000.0); |
169 } |
167 } |
170 } |
168 } |
171 } |
169 } |
172 } |
170 this->ignoreChanges = false; |
173 |
171 } |
174 |
172 |
|
173 |
|
174 void EditRecipe::on_addMiscRow_clicked() |
|
175 { |
|
176 Miscs newm; |
|
177 |
|
178 qDebug() << "Add misc row"; |
|
179 |
|
180 for (int i = 0; i < recipe->miscs.size(); i++) { |
|
181 if (recipe->miscs.at(i).m_amount == 0) |
|
182 return; // Add only one at a time. |
|
183 } |
|
184 |
|
185 newm.m_name = "Select one"; |
|
186 |
|
187 |
|
188 recipe->miscs.append(newm); |
|
189 emit refreshAll(); |
|
190 } |
|
191 |
|
192 |
|
193 void EditRecipe::on_deleteMiscRow_clicked() |
|
194 { |
|
195 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
196 int row = pb->objectName().toInt(); |
|
197 qDebug() << "Delete misc row" << row << recipe->miscs.size(); |
|
198 |
|
199 if (recipe->miscs.size() < 1) |
|
200 return; |
|
201 |
|
202 int rc = QMessageBox::warning(this, tr("Delete misc"), tr("Delete %1").arg(recipe->miscs.at(row).m_name), |
|
203 QMessageBox::Yes | QMessageBox::No, QMessageBox::No); |
|
204 if (rc == QMessageBox::No) |
|
205 return; |
|
206 |
|
207 this->ignoreChanges = true; |
|
208 recipe->miscs.removeAt(row); |
|
209 this->ignoreChanges = false; |
|
210 is_changed(); |
|
211 emit refreshAll(); |
|
212 } |
|
213 |
|
214 |
|
215 void EditRecipe::misc_amount_changed(double val) |
|
216 { |
|
217 |
|
218 } |
|
219 |
|
220 |
|
221 void EditRecipe::misc_time_changed(int val) |
|
222 { |
|
223 |
|
224 } |
|
225 |
|
226 |
|
227 void EditRecipe::misc_select_changed(int val) |
|
228 { |
|
229 QSqlQuery query; |
|
230 bool instock = hinstockEdit->isChecked(); |
|
231 QString w; |
|
232 QTableWidgetItem *item; |
|
233 |
|
234 if (val < 1) |
|
235 return; |
|
236 |
|
237 qDebug() << "misc_select_changed()" << recipe->fermentables_row << val << instock; |
|
238 |
|
239 } |
|
240 |
|
241 |
|
242 void EditRecipe::misc_instock_changed(bool val) |
|
243 { |
|
244 |
|
245 } |
|
246 |
|
247 |
|
248 void EditRecipe::misc_useat_changed(int val) |
|
249 { |
|
250 |
|
251 } |
|
252 |
|
253 |
|
254 void EditRecipe::on_editMiscRow_clicked() |
|
255 { |
|
256 QSqlQuery query; |
|
257 |
|
258 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
259 recipe->miscs_row = pb->objectName().toInt(); |
|
260 qDebug() << "Edit misc row" << recipe->miscs_row; |
|
261 Miscs backup = recipe->miscs.at(recipe->miscs_row); |
|
262 |
|
263 QDialog* dialog = new QDialog(this); |
|
264 dialog->resize(738, 230); |
|
265 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); |
|
266 buttonBox->setObjectName(QString::fromUtf8("buttonBox")); |
|
267 buttonBox->setGeometry(QRect(30, 180, 671, 32)); |
|
268 buttonBox->setLayoutDirection(Qt::LeftToRight); |
|
269 buttonBox->setOrientation(Qt::Horizontal); |
|
270 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); |
|
271 buttonBox->setCenterButtons(true); |
|
272 |
|
273 QLabel *nameLabel = new QLabel(dialog); |
|
274 nameLabel->setObjectName(QString::fromUtf8("nameLabel")); |
|
275 nameLabel->setText(tr("Current ingredient:")); |
|
276 nameLabel->setGeometry(QRect(10, 10, 141, 20)); |
|
277 nameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
278 |
|
279 QLabel *amountLabel = new QLabel(dialog); |
|
280 amountLabel->setObjectName(QString::fromUtf8("amountLabel")); |
|
281 if (recipe->miscs.at(recipe->miscs_row).m_amount_is_weight) |
|
282 amountLabel->setText(tr("Amount in gr:")); |
|
283 else |
|
284 amountLabel->setText(tr("Amount in ml:")); |
|
285 amountLabel->setGeometry(QRect(10, 70, 141, 20)); |
|
286 amountLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
287 |
|
288 mtimeLabel = new QLabel(dialog); |
|
289 mtimeLabel->setObjectName(QString::fromUtf8("mtimeLabel")); |
|
290 if (recipe->miscs.at(recipe->miscs_row).m_use_use == 3 || recipe->miscs.at(recipe->miscs_row).m_use_use == 4) // Fermentation stages |
|
291 mtimeLabel->setText(tr("Time in days:")); |
|
292 else if (recipe->miscs.at(recipe->miscs_row).m_use_use == 2) // Boil |
|
293 mtimeLabel->setText(tr("Time in minutes:")); |
|
294 else |
|
295 mtimeLabel->setText(""); |
|
296 mtimeLabel->setGeometry(QRect(10, 100, 141, 20)); |
|
297 mtimeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
298 |
|
299 QLabel *selectLabel = new QLabel(dialog); |
|
300 selectLabel->setObjectName(QString::fromUtf8("selectLabel")); |
|
301 selectLabel->setText(tr("Select ingredient:")); |
|
302 selectLabel->setGeometry(QRect(10, 40, 141, 20)); |
|
303 selectLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
304 QLabel *instockLabel = new QLabel(dialog); |
|
305 instockLabel->setObjectName(QString::fromUtf8("instockLabel")); |
|
306 instockLabel->setText(tr("In stock:")); |
|
307 instockLabel->setGeometry(QRect(525, 40, 121, 20)); |
|
308 instockLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
309 |
|
310 mselectEdit = new QComboBox(dialog); |
|
311 mselectEdit->setObjectName(QString::fromUtf8("selectEdit")); |
|
312 mselectEdit->setGeometry(QRect(160, 40, 371, 23)); |
|
313 |
|
314 mnameEdit = new QLineEdit(dialog); |
|
315 mnameEdit->setObjectName(QString::fromUtf8("mnameEdit")); |
|
316 mnameEdit->setText(recipe->miscs.at(recipe->miscs_row).m_name); |
|
317 mnameEdit->setGeometry(QRect(160, 10, 511, 23)); |
|
318 mnameEdit->setReadOnly(true); |
|
319 |
|
320 mamountEdit = new QDoubleSpinBox(dialog); |
|
321 mamountEdit->setObjectName(QString::fromUtf8("mamountEdit")); |
|
322 mamountEdit->setGeometry(QRect(160, 70, 121, 24)); |
|
323 mamountEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
324 mamountEdit->setAccelerated(true); |
|
325 mamountEdit->setDecimals(1); |
|
326 mamountEdit->setMaximum(1000000.0); |
|
327 mamountEdit->setSingleStep(0.5); |
|
328 mamountEdit->setValue(recipe->miscs.at(recipe->miscs_row).m_amount * 1000.0); |
|
329 |
|
330 mtimeEdit = new QSpinBox(dialog); |
|
331 mtimeEdit->setObjectName(QString::fromUtf8("mtimeEdit")); |
|
332 mtimeEdit->setGeometry(QRect(160, 100, 121, 24)); |
|
333 mtimeEdit->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
|
334 mtimeEdit->setAccelerated(true); |
|
335 mtimeEdit->setMaximum(10000.0); |
|
336 if (recipe->miscs.at(recipe->miscs_row).m_use_use == 3 || recipe->miscs.at(recipe->miscs_row).m_use_use == 4) { // Fermentation stages |
|
337 mtimeEdit->setValue(recipe->miscs.at(recipe->miscs_row).m_time / 1440); |
|
338 mtimeEdit->setReadOnly(false); |
|
339 } else if (recipe->miscs.at(recipe->miscs_row).m_use_use == 2) { // Boil |
|
340 mtimeEdit->setValue(recipe->miscs.at(recipe->miscs_row).m_time); |
|
341 mtimeEdit->setReadOnly(false); |
|
342 } else { |
|
343 mtimeEdit->setReadOnly(true); |
|
344 } |
|
345 |
|
346 useatEdit = new QComboBox(dialog); |
|
347 useatEdit->setObjectName(QString::fromUtf8("useatEdit")); |
|
348 useatEdit->setGeometry(QRect(160, 130, 161, 23)); |
|
349 useatEdit->addItem(tr("Starter")); |
|
350 useatEdit->addItem(tr("Mash")); |
|
351 useatEdit->addItem(tr("Boil")); |
|
352 useatEdit->addItem(tr("Primary")); |
|
353 useatEdit->addItem(tr("Secondary")); |
|
354 useatEdit->addItem(tr("Bottling")); |
|
355 useatEdit->setCurrentIndex(recipe->miscs.at(recipe->miscs_row).m_use_use); |
|
356 |
|
357 minstockEdit = new QCheckBox(dialog); |
|
358 minstockEdit->setObjectName(QString::fromUtf8("minstockEdit")); |
|
359 minstockEdit->setGeometry(QRect(655, 40, 85, 21)); |
|
360 minstockEdit->setChecked(true); |
|
361 |
|
362 misc_instock_changed(true); |
|
363 |
|
364 connect(mselectEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::misc_select_changed); |
|
365 connect(mamountEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::misc_amount_changed); |
|
366 connect(mtimeEdit, QOverload<int>::of(&QSpinBox::valueChanged), this, &EditRecipe::misc_time_changed); |
|
367 connect(useatEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::misc_useat_changed); |
|
368 connect(minstockEdit, &QCheckBox::stateChanged, this, &EditRecipe::misc_instock_changed); |
|
369 connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject())); |
|
370 connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept())); |
|
371 |
|
372 dialog->setModal(true); |
|
373 dialog->exec(); |
|
374 if (dialog->result() == QDialog::Rejected) { |
|
375 qDebug() << "reject and rollback"; |
|
376 recipe->miscs[recipe->miscs_row] = backup; |
|
377 } else { |
|
378 /* Clear time if misc is not used for boil or fermentation. */ |
|
379 if (! (recipe->miscs.at(recipe->miscs_row).m_use_use == 2 || |
|
380 recipe->miscs.at(recipe->miscs_row).m_use_use == 3 || |
|
381 recipe->miscs.at(recipe->miscs_row).m_use_use == 4)) { |
|
382 if (recipe->miscs.at(recipe->miscs_row).m_time) { |
|
383 recipe->miscs[recipe->miscs_row].m_time = 0; |
|
384 is_changed(); |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 disconnect(mselectEdit, nullptr, nullptr, nullptr); |
|
390 disconnect(mamountEdit, nullptr, nullptr, nullptr); |
|
391 disconnect(mtimeEdit, nullptr, nullptr, nullptr); |
|
392 disconnect(useatEdit, nullptr, nullptr, nullptr); |
|
393 disconnect(minstockEdit, nullptr, nullptr, nullptr); |
|
394 disconnect(buttonBox, nullptr, nullptr, nullptr); |
|
395 |
|
396 emit refreshAll(); |
|
397 } |
|
398 |