Thu, 21 Apr 2022 17:22:01 +0200
New recipe, calculate the boil_size. Lot's of ignoreChanges removeals and where needed QSignalBlocker is used. Bottle priming calculation added. In fermentables editor block and release to100 settings only in mash to fermentation steps, bottle and kegging are ignored. Update the IBU slider after hop changes. Set the mash name when another mash profile is selected. Don't backup initial infuse amount if there was no mash table. A small cosmetic layout change on the mash tab.
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 | qDebug() << "EditProfileFerment done"; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
191 | delete ui; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
192 | emit entry_changed(); |
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 | /* |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
197 | * Window header, mark any change with '**' |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
198 | */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
199 | void EditProfileFerment::WindowTitle() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
200 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
201 | QString txt; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
202 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
203 | if (this->recno < 0) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
204 | txt = QString(tr("BMSapp - Add new fermentation profile")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
205 | } else { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
206 | 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
|
207 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
208 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
209 | if (this->textIsChanged) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
210 | txt.append((QString(" **"))); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
211 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
212 | setWindowTitle(txt); |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
216 | void EditProfileFerment::on_saveButton_clicked() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
217 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
218 | QSqlQuery query; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
219 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
220 | /* 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
|
221 | if (ui->nameEdit->text().length() < 2) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
222 | 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
|
223 | return; |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
226 | if (this->textIsChanged) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
227 | if (this->recno == -1) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
228 | 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
|
229 | "inittemp_hi=:temphi, fridgemode=:fridgemode, totalsteps=:totalsteps, duration=:duration, " |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
230 | "steps=:steps, uuid = :uuid"); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
231 | } else { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
232 | 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
|
233 | "inittemp_hi=:temphi, fridgemode=:fridgemode, totalsteps=:totalsteps, duration=:duration, " |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
234 | "steps=:steps WHERE record = :recno"); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
235 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
236 | query.bindValue(":name", ui->nameEdit->text()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
237 | 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
|
238 | 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
|
239 | query.bindValue(":fridgemode", ui->sensorEdit->currentIndex()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
240 | query.bindValue(":totalsteps", QString("%1").arg(totalsteps)); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
241 | query.bindValue(":duration", QString("%1").arg(duration)); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
242 | query.bindValue(":steps", this->steps.toJson(QJsonDocument::Compact)); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
243 | if (this->recno == -1) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
244 | query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
245 | } else { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
246 | query.bindValue(":recno", this->recno); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
247 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
248 | query.exec(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
249 | if (query.lastError().isValid()) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
250 | qDebug() << "EditProfileFerment" << query.lastError(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
251 | QMessageBox::warning(this, tr("Database error"), |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
252 | tr("MySQL error: %1\n%2\n%3") |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
253 | .arg(query.lastError().nativeErrorCode()) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
254 | .arg(query.lastError().driverText()) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
255 | .arg(query.lastError().databaseText())); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
256 | } else { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
257 | qDebug() << "EditProfileFerment Saved"; |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
261 | ui->saveButton->setEnabled(false); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
262 | this->textIsChanged = false; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
263 | WindowTitle(); |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
266 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
267 | void EditProfileFerment::on_deleteButton_clicked() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
268 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
269 | QSqlQuery query; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
270 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
271 | query.prepare("DELETE FROM profile_fermentation WHERE record = :recno"); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
272 | query.bindValue(":recno", this->recno); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
273 | query.exec(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
274 | if (query.lastError().isValid()) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
275 | qDebug() << "EditProfileFerment" << query.lastError(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
276 | QMessageBox::warning(this, tr("Database error"), |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
277 | tr("MySQL error: %1\n%2\n%3") |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
278 | .arg(query.lastError().nativeErrorCode()) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
279 | .arg(query.lastError().driverText()) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
280 | .arg(query.lastError().databaseText())); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
281 | } else { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
282 | qDebug() << "EditProfileFerment Deleted" << this->recno; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
283 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
284 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
285 | this->close(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
286 | this->setResult(1); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
287 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
288 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
289 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
290 | void EditProfileFerment::is_changed() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
291 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
292 | ui->saveButton->setEnabled(true); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
293 | ui->deleteButton->setEnabled((this->recno >= 0) ? true:false); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
294 | this->textIsChanged = true; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
295 | WindowTitle(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
296 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
297 | |
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 | /* |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
300 | * Rebuild the json string from the table contents. |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
301 | */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
302 | void EditProfileFerment::make_Json() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
303 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
304 | QTableWidgetItem *item; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
305 | QJsonArray array; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
306 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
307 | for (int i = 0; i < ui->stepsTable->rowCount(); i++) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
308 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
309 | QJsonObject obj; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
310 | item = ui->stepsTable->item(i, 0); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
311 | obj.insert("name", item->text()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
312 | item = ui->stepsTable->item(i, 1); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
313 | obj.insert("target_lo", item->text().toDouble()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
314 | item = ui->stepsTable->item(i, 2); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
315 | obj.insert("target_hi", item->text().toDouble()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
316 | QWidget *widget = ui->stepsTable->cellWidget(i, 3); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
317 | obj.insert("fridgemode", static_cast<QComboBox*>(widget)->currentIndex() ); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
318 | item = ui->stepsTable->item(i, 4); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
319 | obj.insert("steptime", item->text().toInt()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
320 | item = ui->stepsTable->item(i, 5); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
321 | obj.insert("resttime", item->text().toInt()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
322 | // qDebug() << "make_Json" << i << obj; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
323 | array.append(obj); /* Append this object */ |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
326 | // qDebug() << array; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
327 | /* Copy to the global array and refresh */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
328 | this->steps.setArray(array); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
329 | is_changed(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
330 | emit refreshTable(); |
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 | void EditProfileFerment::cell_Changed(int nRow, int nCol) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
335 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
336 | QString w; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
337 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
338 | if (this->ignoreChanges) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
339 | return; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
340 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
341 | 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
|
342 | |
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 | * 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
|
345 | * 0.1 degree higher then the low temperature. |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
346 | */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
347 | if (nCol == 1) { // Low temperature was changed |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
348 | 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
|
349 | 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
|
350 | ui->stepsTable->setItem(nRow, 2, new QTableWidgetItem(w)); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
351 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
352 | } else if (nCol == 2) { // High temperature was changed |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
353 | 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
|
354 | 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
|
355 | ui->stepsTable->setItem(nRow, 1, new QTableWidgetItem(w)); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
356 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
357 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
358 | make_Json(); |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
362 | void EditProfileFerment::combo_Changed() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
363 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
364 | make_Json(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
365 | } |
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 | void EditProfileFerment::templo_changed() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
369 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
370 | if (ui->temploEdit->value() > (ui->temphiEdit->value() - 0.1)) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
371 | ui->temphiEdit->setValue(ui->temploEdit->value() + 0.1); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
372 | is_changed(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
373 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
374 | |
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 | void EditProfileFerment::temphi_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 | if (ui->temphiEdit->value() < (ui->temploEdit->value() + 0.1)) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
379 | ui->temploEdit->setValue(ui->temphiEdit->value() - 0.1); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
380 | is_changed(); |
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 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
383 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
384 | /* |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
385 | * Add new row and initialize all fields. |
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 | void EditProfileFerment::on_addButton_clicked() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
388 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
389 | QWidget* pWidget; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
390 | QHBoxLayout* pLayout; |
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 | qDebug() << "Add row" << totalsteps; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
393 | this->ignoreChanges = true; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
394 | ui->stepsTable->insertRow(totalsteps); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
395 | 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
|
396 | 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
|
397 | 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
|
398 | QComboBox* myComboBox = new QComboBox(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
399 | myComboBox->addItem(tr("Beer")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
400 | myComboBox->addItem(tr("Fridge")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
401 | myComboBox->setCurrentIndex(0); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
402 | ui->stepsTable->setCellWidget(totalsteps, 3, myComboBox); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
403 | ui->stepsTable->setItem(totalsteps, 4, new QTableWidgetItem(QString("0"))); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
404 | ui->stepsTable->setItem(totalsteps, 5, new QTableWidgetItem(QString("0"))); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
405 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
406 | pWidget = new QWidget(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
407 | QPushButton* btn_edit = new QPushButton(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
408 | 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
|
409 | btn_edit->setText(tr("Delete")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
410 | 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
|
411 | pLayout = new QHBoxLayout(pWidget); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
412 | pLayout->addWidget(btn_edit); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
413 | pLayout->setContentsMargins(5, 0, 5, 0); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
414 | pWidget->setLayout(pLayout); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
415 | ui->stepsTable->setCellWidget(totalsteps, 6, pWidget); |
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 | this->ignoreChanges = false; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
418 | make_Json(); |
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 | |
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_deleteRow_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 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
425 | int row = pb->objectName().toInt(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
426 | qDebug() << "Delete row" << row; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
427 | ui->stepsTable->removeRow(row); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
428 | make_Json(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
429 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
430 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
431 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
432 | void EditProfileFerment::on_quitButton_clicked() |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
433 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
434 | if (this->textIsChanged) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
435 | 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
|
436 | QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
437 | switch (rc) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
438 | case QMessageBox::Save: |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
439 | on_saveButton_clicked(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
440 | break; /* Saved and then Quit */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
441 | case QMessageBox::Discard: |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
442 | break; /* Quit without Save */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
443 | case QMessageBox::Cancel: |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
444 | return; /* Return to the editor page */ |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
445 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
446 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
447 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
448 | this->close(); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
449 | this->setResult(1); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
450 | } |