src/EditProfileMash.cpp

Tue, 05 Jul 2022 14:31:39 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 05 Jul 2022 14:31:39 +0200
changeset 336
e97f9e87d94b
parent 90
2396457a8167
child 385
09af9f46518f
permissions
-rw-r--r--

IBU method names are now global.

49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * EditProfileMash.cpp is part of bmsapp.
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "EditProfileMash.h"
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "../ui/ui_EditProfileMash.h"
90
2396457a8167 Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
19 #include "MainWindow.h"
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 EditProfileMash::EditProfileMash(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProfileMash)
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 QSqlQuery query;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "EditProfileMash record:" << id;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 ui->setupUi(this);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 this->recno = id;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 if (id >= 0) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 query.prepare("SELECT * FROM profile_mash WHERE record = :recno");
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 query.bindValue(":recno", id);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 query.exec();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 query.next();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36 ui->nameEdit->setText(query.value(1).toString());
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 ui->notesEdit->setPlainText(query.value(2).toString());
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 QJsonParseError parseError;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 const auto& json = query.value(3).toString();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 if (!json.trimmed().isEmpty()) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 const auto& formattedJson = QString("%1").arg(json);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 this->steps = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 if (parseError.error != QJsonParseError::NoError)
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 } else {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 /* Set some defaults */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 const auto& formattedJson = QString("[]");
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 this->steps = QJsonDocument::fromJson(formattedJson.toUtf8());
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditProfileMash::is_changed);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
57 connect(ui->stepsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 ui->saveButton->setEnabled(false);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 ui->deleteButton->setEnabled((id >= 0) ? true:false);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 emit refreshTable();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 WindowTitle();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 void EditProfileMash::refreshTable()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 QString w;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 QWidget* pWidget;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 QHBoxLayout* pLayout;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 double d;
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
74 int total = 0;
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
76 // qDebug() << "refreshTable" << this->steps << this->steps.isArray() << this->steps.array().size() ;
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
77 /* During filling the table turn off the cellChanged signal because every cell that is filled
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
78 * triggers the cellChanged signal. The QTableWidget has no better signal to use. */
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
79 this->ignoreChanges = true;
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 const QStringList labels({tr("Step name"), tr("Type"), tr("Start °C"), tr("End °C"), tr("Rest time"), tr("Ramp time"), tr("Button")});
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 ui->stepsTable->setColumnCount(7);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 ui->stepsTable->setColumnWidth(0, 250); /* Step name */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 ui->stepsTable->setColumnWidth(1, 150); /* Step type */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 ui->stepsTable->setColumnWidth(2, 75); /* Start temp */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 ui->stepsTable->setColumnWidth(3, 75); /* End temp */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 ui->stepsTable->setColumnWidth(4, 75); /* Step time */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 ui->stepsTable->setColumnWidth(5, 75); /* Ramp time */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 ui->stepsTable->setColumnWidth(6, 80); /* Button */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 ui->stepsTable->setHorizontalHeaderLabels(labels);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 ui->stepsTable->verticalHeader()->hide();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 ui->stepsTable->setRowCount(this->steps.array().size());
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 if (this->steps.isArray()) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 for (int i = 0; i < this->steps.array().size(); i++) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 QJsonObject obj = this->steps.array().at(i).toObject();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 ui->stepsTable->setItem(i, 0, new QTableWidgetItem(obj["step_name"].toString()));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
100 /* Adding step_type 0, 1 or 2 as combobox. */
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 QComboBox* myComboBox = new QComboBox();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 myComboBox->addItem(tr("Infusion"));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 myComboBox->addItem(tr("Temperature"));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 myComboBox->addItem(tr("Decoction"));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 ui->stepsTable->setCellWidget(i, 1, myComboBox);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 if (obj["step_type"].isString())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 d = QString(obj["step_type"].toString()).toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 else
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 d = obj["step_type"].toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 myComboBox->setCurrentIndex((int)d);
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
111 connect<void(QComboBox::*)(int)>(myComboBox, &QComboBox::currentIndexChanged, this, &EditProfileMash::combo_Changed);
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
113 /* Numbers can be double quoted or not, the old application could do this wrong. */
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 if (obj["step_temp"].isString())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 d = QString(obj["step_temp"].toString()).toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 else
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 d = obj["step_temp"].toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 w = QString("%1").arg(d, 2, 'f', 1, '0');
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 QTableWidgetItem *item = new QTableWidgetItem(w);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 ui->stepsTable->setItem(i, 2, item);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 if (obj["end_temp"].isString())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 d = QString(obj["end_temp"].toString()).toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 else
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 d = obj["end_temp"].toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 w = QString("%1").arg(d, 2, 'f', 1, '0');
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 item = new QTableWidgetItem(w);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 ui->stepsTable->setItem(i, 3, item);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 if (obj["step_time"].isString())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 d = QString(obj["step_time"].toString()).toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 else
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 d = obj["step_time"].toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 w = QString("%1").arg(d, 1, 'f', 0, '0');
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 item = new QTableWidgetItem(w);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 ui->stepsTable->setItem(i, 4, item);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 total += (int)d;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 if (obj["ramp_time"].isString())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 d = QString(obj["ramp_time"].toString()).toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 else
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 d = obj["ramp_time"].toDouble();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 w = QString("%1").arg(d, 1, 'f', 0, '0');
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 item = new QTableWidgetItem(w);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 ui->stepsTable->setItem(i, 5, item);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 if (i > 0)
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 total += (int)d;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 /* Add the Delete row button */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 pWidget = new QWidget();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 QPushButton* btn_edit = new QPushButton();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 btn_edit->setObjectName(QString("%1").arg(i)); /* Send row with the button */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 btn_edit->setText(tr("Delete"));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked()));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 pLayout = new QHBoxLayout(pWidget);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 pLayout->addWidget(btn_edit);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 pLayout->setContentsMargins(5, 0, 5, 0);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 pWidget->setLayout(pLayout);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 ui->stepsTable->setCellWidget(i, 6, pWidget);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 /* Show the calculated total mash time. */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 ui->totalEdit->setText(QString("%1:%2").arg(total / 60).arg(total % 60, 2, 'f', 0, '0'));
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
169 this->ignoreChanges = false;
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 EditProfileMash::~EditProfileMash()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 qDebug() << "EditProfileMash done";
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 delete ui;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 emit entry_changed();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 /*
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 * Window header, mark any change with '**'
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 void EditProfileMash::WindowTitle()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 QString txt;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 if (this->recno < 0) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 txt = QString(tr("BMSapp - Add new mash profile"));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 } else {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 txt = QString(tr("BMSapp - Edit mash profile %1").arg(this->recno));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 if (this->textIsChanged) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 txt.append((QString(" **")));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 setWindowTitle(txt);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 void EditProfileMash::on_saveButton_clicked()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 QSqlQuery query;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 /* If there are errors in the form, show a message and do "return;" */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 if (ui->nameEdit->text().length() < 2) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 QMessageBox::warning(this, tr("Edit Mash"), tr("Name empty or too short."));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 return;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 if (this->textIsChanged) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 if (this->recno == -1) {
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
213 query.prepare("INSERT INTO profile_mash SET name=:name, notes=:notes, steps=:steps, uuid=:uuid");
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 } else {
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
215 query.prepare("UPDATE profile_mash SET name=:name, notes=:notes, steps=:steps WHERE record=:recno");
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 query.bindValue(":name", ui->nameEdit->text());
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 query.bindValue(":notes", ui->notesEdit->toPlainText());
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
219 query.bindValue(":steps", this->steps.toJson(QJsonDocument::Compact));
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 if (this->recno == -1) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 } else {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 query.bindValue(":recno", this->recno);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 query.exec();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 if (query.lastError().isValid()) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 qDebug() << "EditProfileMash" << query.lastError();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 QMessageBox::warning(this, tr("Database error"),
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 tr("MySQL error: %1\n%2\n%3")
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 .arg(query.lastError().nativeErrorCode())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 .arg(query.lastError().driverText())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 .arg(query.lastError().databaseText()));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 } else {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 qDebug() << "EditProfileMash Saved";
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 ui->saveButton->setEnabled(false);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 this->textIsChanged = false;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 WindowTitle();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 void EditProfileMash::on_deleteButton_clicked()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 QSqlQuery query;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
249 query.prepare("DELETE FROM profile_mash WHERE record = :recno");
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 query.bindValue(":recno", this->recno);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 query.exec();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 if (query.lastError().isValid()) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 qDebug() << "EditProfileMash" << query.lastError();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 QMessageBox::warning(this, tr("Database error"),
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 tr("MySQL error: %1\n%2\n%3")
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 .arg(query.lastError().nativeErrorCode())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 .arg(query.lastError().driverText())
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 .arg(query.lastError().databaseText()));
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 } else {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 qDebug() << "EditProfileMash Deleted" << this->recno;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 this->close();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 this->setResult(1);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 void EditProfileMash::is_changed()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 ui->saveButton->setEnabled(true);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 ui->deleteButton->setEnabled((this->recno >= 0) ? true:false);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 this->textIsChanged = true;
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 WindowTitle();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
277 /*
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
278 * Rebuild the json string from the table contents.
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
279 */
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
280 void EditProfileMash::make_Json()
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
281 {
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
282 QTableWidgetItem *item;
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
283 QJsonArray array;
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
284
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
285 ui->stepsTable->sortItems(2, Qt::AscendingOrder); // Sort on temperature.
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
286
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
287 for (int i = 0; i < ui->stepsTable->rowCount(); i++) {
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
288
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
289 QJsonObject obj;
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
290 item = ui->stepsTable->item(i, 0);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
291 obj.insert("step_name", item->text());
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
292 QWidget *widget = ui->stepsTable->cellWidget(i, 1);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
293 obj.insert("step_type", static_cast<QComboBox*>(widget)->currentIndex() );
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
294 item = ui->stepsTable->item(i, 2);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
295 obj.insert("step_temp", item->text().toDouble());
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
296 item = ui->stepsTable->item(i, 3);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
297 obj.insert("end_temp", item->text().toDouble());
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
298 item = ui->stepsTable->item(i, 4);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
299 obj.insert("step_time", item->text().toInt());
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
300 item = ui->stepsTable->item(i, 5);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
301 obj.insert("ramp_time", item->text().toInt());
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
302 // qDebug() << "make_Json" << i << obj;
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
303 array.append(obj); /* Append this object */
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
304 }
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
305
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
306 // qDebug() << array;
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
307 /* Copy to the global array and refresh */
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
308 this->steps.setArray(array);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
309 is_changed();
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
310 emit refreshTable();
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
311 }
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
312
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
313
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 void EditProfileMash::cell_Changed(int nRow, int nCol)
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 {
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
316 if (this->ignoreChanges)
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
317 return;
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
318
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
319 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was changed.";
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
321 // TODO: some checks and auto fixes.
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
322 make_Json();
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325
51
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
326 void EditProfileMash::combo_Changed()
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
327 {
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
328 make_Json();
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
329 }
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
330
355100088e1f When editing mash step cells the table is updated. The combobox changes are finally working too.
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
331
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 void EditProfileMash::on_addButton_clicked()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 {
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
334 int total = ui->stepsTable->rowCount();
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
335 QWidget* pWidget;
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
336 QHBoxLayout* pLayout;
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
337
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
338 qDebug() << "Add row" << total;
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
339 this->ignoreChanges = true;
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
340
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
341 ui->stepsTable->insertRow(total);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
342 ui->stepsTable->setItem(total, 0, new QTableWidgetItem(QString("new row %1").arg(total)));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
343 QComboBox* myComboBox = new QComboBox();
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
344 myComboBox->addItem(tr("Infusion"));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
345 myComboBox->addItem(tr("Temperature"));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
346 myComboBox->addItem(tr("Decoction"));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
347 myComboBox->setCurrentIndex(0);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
348 ui->stepsTable->setCellWidget(total, 1, myComboBox);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
349 ui->stepsTable->setItem(total, 2, new QTableWidgetItem(QString("65.0")));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
350 ui->stepsTable->setItem(total, 3, new QTableWidgetItem(QString("65.0")));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
351 ui->stepsTable->setItem(total, 4, new QTableWidgetItem(QString("20")));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
352 ui->stepsTable->setItem(total, 5, new QTableWidgetItem(QString("10")));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
353 pWidget = new QWidget();
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
354 QPushButton* btn_edit = new QPushButton();
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
355 btn_edit->setObjectName(QString("%1").arg(total)); /* Send row with the button */
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
356 btn_edit->setText(tr("Delete"));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
357 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked()));
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
358 pLayout = new QHBoxLayout(pWidget);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
359 pLayout->addWidget(btn_edit);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
360 pLayout->setContentsMargins(5, 0, 5, 0);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
361 pWidget->setLayout(pLayout);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
362 ui->stepsTable->setCellWidget(total, 6, pWidget);
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
363
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
364 this->ignoreChanges = false;
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
365 make_Json();
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 void EditProfileMash::on_deleteRow_clicked()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370 {
50
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
371 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
372 int row = pb->objectName().toInt();
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
373 qDebug() << "Delete row" << row;
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
374 ui->stepsTable->removeRow(row);
571a13a4860b Show changes in the steps table. Delete row implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 49
diff changeset
375 make_Json();
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 void EditProfileMash::on_quitButton_clicked()
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 if (this->textIsChanged) {
58
27eaf3a22c1a Finished the profile mash editor.
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
382 int rc = QMessageBox::warning(this, tr("Mash changed"), tr("This mash profile has been modified. Save changes?"),
49
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 switch (rc) {
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 case QMessageBox::Save:
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 on_saveButton_clicked();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 break; /* Saved and then Quit */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 case QMessageBox::Discard:
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 break; /* Quit without Save */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 case QMessageBox::Cancel:
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 return; /* Return to the editor page */
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 }
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 this->close();
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 this->setResult(1);
29cf6e350063 Added Mash profiles table and the first part of the Mash profile editor. Edit and write must be written.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 }

mercurial