src/EditProfileWater.cpp

Fri, 20 May 2022 20:43:33 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 20 May 2022 20:43:33 +0200
changeset 225
448e4187cada
parent 90
2396457a8167
child 353
324a7268796b
permissions
-rw-r--r--

Implemented the tasting tab. On the generic tab, show the ingredients check or the read only prompt on the same place depending on the product stage. Fixed the yeasts ingredients in stock check. Reordered the tab order of all edit fields. It looks like this module is ready and needs testing.

48
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * EditProfileWater.cpp is part of bmsapp.
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "EditProfileWater.h"
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "../ui/ui_EditProfileWater.h"
90
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 60
diff changeset
19 #include "MainWindow.h"
48
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 EditProfileWater::EditProfileWater(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProfileWater)
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 QSqlQuery query;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "EditProfileWater record:" << id;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 ui->setupUi(this);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 this->recno = id;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 WindowTitle();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 if (id >= 0) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 query.prepare("SELECT * FROM profile_water WHERE record = :recno");
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 query.bindValue(":recno", id);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 query.exec();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 query.next();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 ui->nameEdit->setText(query.value(1).toString());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 ui->caEdit->setValue(query.value(2).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 ui->hcoEdit->setValue(query.value(3).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 ui->so4Edit->setValue(query.value(4).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 ui->clEdit->setValue(query.value(5).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 ui->naEdit->setValue(query.value(6).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 ui->mgEdit->setValue(query.value(7).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 ui->phEdit->setValue(query.value(8).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 ui->notesEdit->setPlainText(query.value(9).toString());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 ui->alkalinityEdit->setValue(query.value(10).toDouble());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 /* Set some defaults */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 ui->phEdit->setValue(7.0);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 WaterSet();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditProfileWater::is_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 connect(ui->caEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::water_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 connect(ui->hcoEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::hco_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 connect(ui->so4Edit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::water_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 connect(ui->clEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::water_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 connect(ui->naEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::water_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 connect(ui->mgEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::water_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 connect(ui->phEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::water_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 connect(ui->alkalinityEdit, &QDoubleSpinBox::textChanged, this, &EditProfileWater::alkalinity_changed);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 ui->saveButton->setEnabled(false);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 ui->deleteButton->setEnabled((id >= 0) ? true:false);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 EditProfileWater::~EditProfileWater()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 qDebug() << "EditProfileWater done";
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 delete ui;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 emit entry_changed();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 /*
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 * Window header, mark any change with '**'
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 void EditProfileWater::WindowTitle()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 QString txt;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 if (this->recno < 0) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 txt = QString(tr("BMSapp - Add new brewing water"));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 txt = QString(tr("BMSapp - Edit brewing water %1").arg(this->recno));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 if (this->textIsChanged) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 txt.append((QString(" **")));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 setWindowTitle(txt);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 void EditProfileWater::on_saveButton_clicked()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 QSqlQuery query;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 /* If there are errors in the form, show a message and do "return;" */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 if (ui->nameEdit->text().length() < 2) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 QMessageBox::warning(this, tr("Edit Water"), tr("Name empty or too short."));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 return;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 if (this->textIsChanged) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 if (this->recno == -1) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 query.prepare("INSERT INTO profile_water SET name=:name, calcium=:ca, "
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 "bicarbonate=:hco, sulfate=:so4, chloride=:cl, sodium=:na, magnesium=:mg, ph=:ph, notes=:notes, "
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 "total_alkalinity=:alkalinity, uuid = :uuid");
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 query.prepare("UPDATE profile_water SET name=:name, calcium=:ca, "
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 "bicarbonate=:hco, sulfate=:so4, chloride=:cl, sodium=:na, magnesium=:mg, ph=:ph, notes=:notes, "
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 "total_alkalinity=:alkalinity WHERE record = :recno");
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 query.bindValue(":name", ui->nameEdit->text());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 query.bindValue(":ca", QString("%1").arg(ui->caEdit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 query.bindValue(":hco", QString("%1").arg(ui->hcoEdit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 query.bindValue(":so4", QString("%1").arg(ui->so4Edit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 query.bindValue(":cl", QString("%1").arg(ui->clEdit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 query.bindValue(":na", QString("%1").arg(ui->naEdit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 query.bindValue(":mg", QString("%1").arg(ui->mgEdit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 query.bindValue(":ph", QString("%1").arg(ui->phEdit->value(), 3, 'f', 2, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 query.bindValue(":notes", ui->notesEdit->toPlainText());
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 query.bindValue(":alkalinity", QString("%1").arg(ui->alkalinityEdit->value(), 2, 'f', 1, '0'));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 if (this->recno == -1) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 query.bindValue(":recno", this->recno);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 query.exec();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 if (query.lastError().isValid()) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 qDebug() << "EditProfileWater" << query.lastError();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 QMessageBox::warning(this, tr("Database error"),
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 tr("MySQL error: %1\n%2\n%3")
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 .arg(query.lastError().nativeErrorCode())
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 .arg(query.lastError().driverText())
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 .arg(query.lastError().databaseText()));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 qDebug() << "EditProfileWater Saved";
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 ui->saveButton->setEnabled(false);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 this->textIsChanged = false;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 WindowTitle();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 void EditProfileWater::on_deleteButton_clicked()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 QSqlQuery query;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 query.prepare("DELETE FROM profile_water WHERE record = :recno");
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 query.bindValue(":recno", this->recno);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 query.exec();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 if (query.lastError().isValid()) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 qDebug() << "EditProfileWater" << query.lastError();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 QMessageBox::warning(this, tr("Database error"),
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 tr("MySQL error: %1\n%2\n%3")
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 .arg(query.lastError().nativeErrorCode())
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 .arg(query.lastError().driverText())
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 .arg(query.lastError().databaseText()));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 qDebug() << "EditProfileWater Deleted" << this->recno;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 this->close();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 this->setResult(1);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 void EditProfileWater::WaterSet()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 double cations, anions, balance;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 cations = (ui->caEdit->value() / 20.039) + (ui->mgEdit->value() / 12.1525) + (ui->naEdit->value() / 22.989);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 anions = (ui->hcoEdit->value() / 61.016) + (ui->so4Edit->value() / 48.031) + (ui->clEdit->value() / 35.4527);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 balance = round((cations - anions) * 100) / 100;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 ui->balanceEdit->setValue(balance);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 if (balance <= 0.1 && balance >= -0.1) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 ui->balanceIcon->setPixmap(QPixmap(":icons/silk/tick.png"));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 } else if (balance <= 0.5 && balance >= -0.5) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 ui->balanceIcon->setPixmap(QPixmap(":icons/silk/thumb_down.png"));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 } else {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 ui->balanceIcon->setPixmap(QPixmap(":icons/silk/error.png"));
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 void EditProfileWater::is_changed()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 ui->saveButton->setEnabled(true);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 ui->deleteButton->setEnabled((this->recno >= 0) ? true:false);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 this->textIsChanged = true;
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 WindowTitle();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 void EditProfileWater::water_changed()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 WaterSet();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 is_changed();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 void EditProfileWater::hco_changed()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 ui->alkalinityEdit->setValue(ui->hcoEdit->value() * 50 / 61);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 water_changed();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 void EditProfileWater::alkalinity_changed()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 ui->hcoEdit->setValue(ui->alkalinityEdit->value() * 1.22);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 water_changed();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 void EditProfileWater::on_quitButton_clicked()
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 if (this->textIsChanged) {
60
0d65238ebedc Updated translations and some messages.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
226 int rc = QMessageBox::warning(this, tr("Water changed"), tr("This water profile has been modified. Save changes?"),
48
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 switch (rc) {
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 case QMessageBox::Save:
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 on_saveButton_clicked();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 break; /* Saved and then Quit */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 case QMessageBox::Discard:
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 break; /* Quit without Save */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 case QMessageBox::Cancel:
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 return; /* Return to the editor page */
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 }
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 this->close();
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 this->setResult(1);
ddd1171ecda5 Added profile water table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 }

mercurial