src/EditProfileFerment.cpp

Tue, 31 Jan 2023 16:24:11 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 31 Jan 2023 16:24:11 +0100
changeset 482
e13763ec829f
parent 385
09af9f46518f
permissions
-rw-r--r--

Expanded Yeast edit popup with a Yeast Pack dropdown list. Prepared database product read and write with values for yeast package. They will be stored as json object in the yeast records.

57
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * EditProfileFerment.cpp is part of bmsapp.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "EditProfileFerment.h"
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "../ui/ui_EditProfileFerment.h"
90
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
19 #include "MainWindow.h"
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 57
diff changeset
20 #include "Utils.h"
57
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 EditProfileFerment::EditProfileFerment(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProfileFerment)
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 QSqlQuery query;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 qDebug() << "EditProfileFerment record:" << id;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 ui->setupUi(this);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 this->recno = id;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 ui->sensorEdit->addItem(tr("Beer"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 ui->sensorEdit->addItem(tr("Fridge"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 if (id >= 0) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 query.prepare("SELECT * FROM profile_fermentation WHERE record = :recno");
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 query.bindValue(":recno", id);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 query.exec();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 query.next();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 ui->nameEdit->setText(query.value(2).toString());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 ui->temploEdit->setValue(query.value(3).toDouble());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 ui->temphiEdit->setValue(query.value(4).toDouble());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 ui->sensorEdit->setCurrentIndex(query.value(5).toInt());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 QJsonParseError parseError;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 const auto& json = query.value(8).toString();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 if (!json.trimmed().isEmpty()) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 const auto& formattedJson = QString("%1").arg(json);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 this->steps = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 if (parseError.error != QJsonParseError::NoError)
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 /* Set some defaults */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 const auto& formattedJson = QString("[]");
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 this->steps = QJsonDocument::fromJson(formattedJson.toUtf8());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditProfileFerment::is_changed);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 connect(ui->temploEdit, &QDoubleSpinBox::textChanged, this, &EditProfileFerment::templo_changed);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 connect(ui->temphiEdit, &QDoubleSpinBox::textChanged, this, &EditProfileFerment::temphi_changed);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 connect(ui->sensorEdit, &QComboBox::currentTextChanged, this, &EditProfileFerment::is_changed);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 connect(ui->stepsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 ui->saveButton->setEnabled(false);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 ui->deleteButton->setEnabled((id >= 0) ? true:false);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 emit refreshTable();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 WindowTitle();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 void EditProfileFerment::refreshTable()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 QString w;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 QWidget* pWidget;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 QHBoxLayout* pLayout;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 double d;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 // qDebug() << "refreshTable" << this->steps << this->steps.isArray() << this->steps.array().size() ;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 /*
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 * During filling the table turn off the cellChanged signal because every cell that is filled
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 * triggers the cellChanged signal. The QTableWidget has no better signal to use.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 this->ignoreChanges = true;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 const QStringList labels({tr("Step name"), tr("Start °C"), tr("End °C"), tr("Sensor"), tr("Ramp time"), tr("Rest time"), tr("Button")});
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 ui->stepsTable->setColumnCount(7);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 ui->stepsTable->setColumnWidth(0, 248); /* Step name */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 ui->stepsTable->setColumnWidth(1, 75); /* Start temp */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 ui->stepsTable->setColumnWidth(2, 75); /* End temp */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 ui->stepsTable->setColumnWidth(3, 120); /* Sensor */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 ui->stepsTable->setColumnWidth(4, 85); /* Ramp time */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 ui->stepsTable->setColumnWidth(5, 85); /* Rest time */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 ui->stepsTable->setColumnWidth(6, 80); /* Button */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 ui->stepsTable->setHorizontalHeaderLabels(labels);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 ui->stepsTable->verticalHeader()->hide();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 ui->stepsTable->setRowCount(this->steps.array().size());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 totalsteps = 0;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 duration = 0;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 if (this->steps.isArray()) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 totalsteps = this->steps.array().size();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 for (int i = 0; i < this->steps.array().size(); i++) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 QJsonObject obj = this->steps.array().at(i).toObject();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 ui->stepsTable->setItem(i, 0, new QTableWidgetItem(obj["name"].toString()));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 /* Numbers can be double quoted or not, the old application could do this wrong. */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 if (obj["target_lo"].isString())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 d = QString(obj["target_lo"].toString()).toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 else
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 d = obj["target_lo"].toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 w = QString("%1").arg(d, 2, 'f', 1, '0');
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 QTableWidgetItem *item = new QTableWidgetItem(w);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 ui->stepsTable->setItem(i, 1, item);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 if (obj["target_hi"].isString())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 d = QString(obj["target_hi"].toString()).toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 else
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 d = obj["target_hi"].toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 w = QString("%1").arg(d, 2, 'f', 1, '0');
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 item = new QTableWidgetItem(w);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 ui->stepsTable->setItem(i, 2, item);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 /* Adding fridgemode 0, 1 as combobox. */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 QComboBox* myComboBox = new QComboBox();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 myComboBox->addItem(tr("Beer"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 myComboBox->addItem(tr("Fridge"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 ui->stepsTable->setCellWidget(i, 3, myComboBox);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 if (obj["fridgemode"].isString()) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 d = QString(obj["fridgemode"].toString()).toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 d = obj["fridgemode"].toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 myComboBox->setCurrentIndex((int)d);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 connect<void(QComboBox::*)(int)>(myComboBox, &QComboBox::currentIndexChanged, this, &EditProfileFerment::combo_Changed);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 if (obj["steptime"].isString())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 d = QString(obj["steptime"].toString()).toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 else
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 d = obj["steptime"].toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 w = QString("%1").arg(d, 1, 'f', 0, '0');
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 item = new QTableWidgetItem(w);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 ui->stepsTable->setItem(i, 4, item);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 duration += (int)d;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 if (obj["resttime"].isString())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 d = QString(obj["resttime"].toString()).toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 else
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 d = obj["resttime"].toDouble();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 w = QString("%1").arg(d, 1, 'f', 0, '0');
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 item = new QTableWidgetItem(w);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 ui->stepsTable->setItem(i, 5, item);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 duration += (int)d;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 /* Add the Delete row button */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 pWidget = new QWidget();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 QPushButton* btn_edit = new QPushButton();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 btn_edit->setText(tr("Delete"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked()));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 pLayout = new QHBoxLayout(pWidget);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 pLayout->addWidget(btn_edit);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 pLayout->setContentsMargins(5, 0, 5, 0);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 pWidget->setLayout(pLayout);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 ui->stepsTable->setCellWidget(i, 6, pWidget);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 /* Show the calculated total fermentation time. */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 ui->totalEdit->setText(Utils::hours_to_string(duration));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 this->ignoreChanges = false;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 EditProfileFerment::~EditProfileFerment()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 delete ui;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 emit entry_changed();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 /*
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 * Window header, mark any change with '**'
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 void EditProfileFerment::WindowTitle()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 QString txt;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 if (this->recno < 0) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 txt = QString(tr("BMSapp - Add new fermentation profile"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 txt = QString(tr("BMSapp - Edit fermentation profile %1").arg(this->recno));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 if (this->textIsChanged) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 txt.append((QString(" **")));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 setWindowTitle(txt);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 void EditProfileFerment::on_saveButton_clicked()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 QSqlQuery query;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 /* If there are errors in the form, show a message and do "return;" */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 if (ui->nameEdit->text().length() < 2) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 QMessageBox::warning(this, tr("Edit Ferment"), tr("Name empty or too short."));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 return;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 if (this->textIsChanged) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 if (this->recno == -1) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 query.prepare("INSERT INTO profile_fermentation SET name=:name, inittemp_lo=:templo, "
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 "inittemp_hi=:temphi, fridgemode=:fridgemode, totalsteps=:totalsteps, duration=:duration, "
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 "steps=:steps, uuid = :uuid");
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 query.prepare("UPDATE profile_fermentation SET name=:name, inittemp_lo=:templo, "
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 "inittemp_hi=:temphi, fridgemode=:fridgemode, totalsteps=:totalsteps, duration=:duration, "
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 "steps=:steps WHERE record = :recno");
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 query.bindValue(":name", ui->nameEdit->text());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 query.bindValue(":templo", QString("%1").arg(ui->temploEdit->value(), 2, 'f', 1, '0'));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 query.bindValue(":temphi", QString("%1").arg(ui->temphiEdit->value(), 2, 'f', 1, '0'));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 query.bindValue(":fridgemode", ui->sensorEdit->currentIndex());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 query.bindValue(":totalsteps", QString("%1").arg(totalsteps));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 query.bindValue(":duration", QString("%1").arg(duration));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 query.bindValue(":steps", this->steps.toJson(QJsonDocument::Compact));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 if (this->recno == -1) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 query.bindValue(":recno", this->recno);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 query.exec();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 if (query.lastError().isValid()) {
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
249 qWarning() << "EditProfileFerment" << query.lastError();
57
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 QMessageBox::warning(this, tr("Database error"),
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 tr("MySQL error: %1\n%2\n%3")
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 .arg(query.lastError().nativeErrorCode())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 .arg(query.lastError().driverText())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 .arg(query.lastError().databaseText()));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 qDebug() << "EditProfileFerment Saved";
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 ui->saveButton->setEnabled(false);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 this->textIsChanged = false;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 WindowTitle();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
266 void EditProfileFerment::on_cloneButton_clicked()
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
267 {
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
268 QSqlQuery query;
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
269
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
270 query.prepare("INSERT INTO profile_fermentation SET name=:name, inittemp_lo=:templo, "
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
271 "inittemp_hi=:temphi, fridgemode=:fridgemode, totalsteps=:totalsteps, duration=:duration, "
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
272 "steps=:steps, uuid = :uuid");
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
273
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
274 query.bindValue(":name", ui->nameEdit->text() + " [copy]");
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
275 query.bindValue(":templo", QString("%1").arg(ui->temploEdit->value(), 2, 'f', 1, '0'));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
276 query.bindValue(":temphi", QString("%1").arg(ui->temphiEdit->value(), 2, 'f', 1, '0'));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
277 query.bindValue(":fridgemode", ui->sensorEdit->currentIndex());
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
278 query.bindValue(":totalsteps", QString("%1").arg(totalsteps));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
279 query.bindValue(":duration", QString("%1").arg(duration));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
280 query.bindValue(":steps", this->steps.toJson(QJsonDocument::Compact));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
281 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
282
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
283 query.exec();
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
284 if (query.lastError().isValid()) {
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
285 qWarning() << "EditProfileFerment" << query.lastError();
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
286 QMessageBox::warning(this, tr("Database error"),
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
287 tr("MySQL error: %1\n%2\n%3")
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
288 .arg(query.lastError().nativeErrorCode())
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
289 .arg(query.lastError().driverText())
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
290 .arg(query.lastError().databaseText()));
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
291 } else {
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
292 qDebug() << "EditProfileFerment Saved";
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
293 }
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
294 }
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
295
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
296
57
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 void EditProfileFerment::on_deleteButton_clicked()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 QSqlQuery query;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
301 int rc = QMessageBox::warning(this, tr("Delete fermentation profile"), tr("Delete %1").arg(ui->nameEdit->text()),
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
302 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
303 if (rc == QMessageBox::No)
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
304 return;
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
305
57
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 query.prepare("DELETE FROM profile_fermentation WHERE record = :recno");
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 query.bindValue(":recno", this->recno);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 query.exec();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 if (query.lastError().isValid()) {
385
09af9f46518f All profile and inventory editors now log warnings if something went wrong. Also added a Clone button. Delete now asks for confirmation.
Michiel Broek <mbroek@mbse.eu>
parents: 90
diff changeset
310 qWarning() << "EditProfileFerment" << query.lastError();
57
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 QMessageBox::warning(this, tr("Database error"),
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 tr("MySQL error: %1\n%2\n%3")
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 .arg(query.lastError().nativeErrorCode())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 .arg(query.lastError().driverText())
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 .arg(query.lastError().databaseText()));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 } else {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 qDebug() << "EditProfileFerment Deleted" << this->recno;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 this->close();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 this->setResult(1);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 void EditProfileFerment::is_changed()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 ui->saveButton->setEnabled(true);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 ui->deleteButton->setEnabled((this->recno >= 0) ? true:false);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 this->textIsChanged = true;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 WindowTitle();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 /*
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 * Rebuild the json string from the table contents.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 void EditProfileFerment::make_Json()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 QTableWidgetItem *item;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 QJsonArray array;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 for (int i = 0; i < ui->stepsTable->rowCount(); i++) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 QJsonObject obj;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 item = ui->stepsTable->item(i, 0);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 obj.insert("name", item->text());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 item = ui->stepsTable->item(i, 1);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 obj.insert("target_lo", item->text().toDouble());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 item = ui->stepsTable->item(i, 2);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 obj.insert("target_hi", item->text().toDouble());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 QWidget *widget = ui->stepsTable->cellWidget(i, 3);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 obj.insert("fridgemode", static_cast<QComboBox*>(widget)->currentIndex() );
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 item = ui->stepsTable->item(i, 4);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 obj.insert("steptime", item->text().toInt());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355 item = ui->stepsTable->item(i, 5);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 obj.insert("resttime", item->text().toInt());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 // qDebug() << "make_Json" << i << obj;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 array.append(obj); /* Append this object */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 // qDebug() << array;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 /* Copy to the global array and refresh */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 this->steps.setArray(array);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 is_changed();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 emit refreshTable();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 void EditProfileFerment::cell_Changed(int nRow, int nCol)
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371 QString w;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373 if (this->ignoreChanges)
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 return;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was changed.";
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 /*
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 * Check the temperature ranges. Make sure that the high temperature is at least
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 * 0.1 degree higher then the low temperature.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 if (nCol == 1) { // Low temperature was changed
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 if (ui->stepsTable->item(nRow, 1)->text().toDouble() > (ui->stepsTable->item(nRow, 2)->text().toDouble() - 0.1)) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 w = QString("%1").arg(ui->stepsTable->item(nRow, 1)->text().toDouble() + 0.1, 2, 'f', 1, '0');
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 ui->stepsTable->setItem(nRow, 2, new QTableWidgetItem(w));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 } else if (nCol == 2) { // High temperature was changed
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 if (ui->stepsTable->item(nRow, 2)->text().toDouble() < (ui->stepsTable->item(nRow, 1)->text().toDouble() + 0.1)) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 w = QString("%1").arg(ui->stepsTable->item(nRow, 2)->text().toDouble() - 0.1, 2, 'f', 1, '0');
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 ui->stepsTable->setItem(nRow, 1, new QTableWidgetItem(w));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 make_Json();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 void EditProfileFerment::combo_Changed()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 make_Json();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 void EditProfileFerment::templo_changed()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 if (ui->temploEdit->value() > (ui->temphiEdit->value() - 0.1))
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 ui->temphiEdit->setValue(ui->temploEdit->value() + 0.1);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 is_changed();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 void EditProfileFerment::temphi_changed()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 if (ui->temphiEdit->value() < (ui->temploEdit->value() + 0.1))
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 ui->temploEdit->setValue(ui->temphiEdit->value() - 0.1);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 is_changed();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 /*
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 * Add new row and initialize all fields.
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 void EditProfileFerment::on_addButton_clicked()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 QWidget* pWidget;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 QHBoxLayout* pLayout;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 qDebug() << "Add row" << totalsteps;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 this->ignoreChanges = true;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 ui->stepsTable->insertRow(totalsteps);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430 ui->stepsTable->setItem(totalsteps, 0, new QTableWidgetItem(QString("new row %1").arg(totalsteps)));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 ui->stepsTable->setItem(totalsteps, 1, new QTableWidgetItem(QString("19.8")));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432 ui->stepsTable->setItem(totalsteps, 2, new QTableWidgetItem(QString("20.0")));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 QComboBox* myComboBox = new QComboBox();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 myComboBox->addItem(tr("Beer"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 myComboBox->addItem(tr("Fridge"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 myComboBox->setCurrentIndex(0);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 ui->stepsTable->setCellWidget(totalsteps, 3, myComboBox);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438 ui->stepsTable->setItem(totalsteps, 4, new QTableWidgetItem(QString("0")));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 ui->stepsTable->setItem(totalsteps, 5, new QTableWidgetItem(QString("0")));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 pWidget = new QWidget();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442 QPushButton* btn_edit = new QPushButton();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 btn_edit->setObjectName(QString("%1").arg(totalsteps)); /* Send row with the button */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 btn_edit->setText(tr("Delete"));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked()));
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446 pLayout = new QHBoxLayout(pWidget);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 pLayout->addWidget(btn_edit);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 pLayout->setContentsMargins(5, 0, 5, 0);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 pWidget->setLayout(pLayout);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450 ui->stepsTable->setCellWidget(totalsteps, 6, pWidget);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452 this->ignoreChanges = false;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 make_Json();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457 void EditProfileFerment::on_deleteRow_clicked()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 int row = pb->objectName().toInt();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 qDebug() << "Delete row" << row;
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 ui->stepsTable->removeRow(row);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463 make_Json();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467 void EditProfileFerment::on_quitButton_clicked()
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
469 if (this->textIsChanged) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 int rc = QMessageBox::warning(this, tr("Fermentation changed"), tr("This fermentation profile has been modified. Save changes?"),
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 switch (rc) {
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 case QMessageBox::Save:
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 on_saveButton_clicked();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 break; /* Saved and then Quit */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 case QMessageBox::Discard:
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 break; /* Quit without Save */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 case QMessageBox::Cancel:
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 return; /* Return to the editor page */
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 }
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 this->close();
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 this->setResult(1);
75d11cc05ce4 Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 }

mercurial