src/CalibrateiSpindel.cpp

Sat, 08 Jun 2024 15:54:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 08 Jun 2024 15:54:30 +0200
changeset 527
84091b9cb800
parent 512
1dfae8de6ca9
permissions
-rw-r--r--

Version 0.4.6a1. Added HLT equipment volume and deadspace settings. In EditProduct the target water selection is now sticky. Changed the water treatment tab. Added a row wich displays the salt adjustments. This can be selected between actual and target values. The treated water show can select between mash or sparge water. The total line will become the final water in the boil kettle. Database update function is expanded with the new settings. Added a popup message warning that the database is upgraded and user action is required for the equipment profiles.

503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * CalibrateiSpindel.cpp is part of bmsapp.
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "CalibrateiSpindel.h"
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
18 #include "../ui/ui_CalibrateiSpindel.h"
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "global.h"
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include "Utils.h"
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
21 #include "polyfit.h"
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 #include "MainWindow.h"
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
509
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
24 /*
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
25 * The following MySQL query produces a table with historic real results:
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
26 *
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
27 * SELECT pr.code,
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
28 * pr.og,
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
29 * (SELECT angle FROM log_ispindel WHERE code=pr.code ORDER BY datetime LIMIT 1) as og_angle,
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
30 * pr.fg,
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
31 * (SELECT angle FROM log_ispindel WHERE code=pr.code ORDER BY datetime DESC LIMIT 1) as fg_angle
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
32 * FROM products AS pr
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
33 * WHERE pr.stage=11 AND pr.log_ispindel=1
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
34 * ORDER BY pr.fg DESC
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
35 * ;
af4a8649245e Added MySQL query example in the source.
Michiel Broek <mbroek@mbse.eu>
parents: 507
diff changeset
36 */
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 CalibrateiSpindel::CalibrateiSpindel(int id, QWidget *parent) : QDialog(parent), ui(new Ui::CalibrateiSpindel)
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 {
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 QSqlQuery query;
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 #ifdef DEBUG_MONITOR
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 qDebug() << "CalibrateiSpindel record:" << id;
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 #endif
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
47 ui->setupUi(this);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
48 this->recno = id;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
49 setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
50 WindowTitle();
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 query.prepare("SELECT node,alias,calibrate FROM mon_ispindels WHERE record = :recno");
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 query.bindValue(":recno", this->recno);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 query.exec();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 if (query.next()) {
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 _node = query.value("node").toString();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 _alias = query.value("alias").toString();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
59 ui->nameEdit->setText(_node+"/"+_alias);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
60
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
61 QJsonParseError parseError;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
62 const auto& json = query.value("calibrate").toString();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
63
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
64 if (!json.trimmed().isEmpty()) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
65 const auto& formattedJson = QString("%1").arg(json);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
66 QJsonDocument jsonResponse = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
67 if (parseError.error != QJsonParseError::NoError) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
68 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
69 } else {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
70
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
71 QJsonObject jsonObj = jsonResponse.object();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
72 QJsonArray polyData = jsonObj.value("polyData").toArray();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
73 for (int i = 0; i < polyData.size(); i++) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
74 Old[i] = New[i] = polyData.at(i).toDouble();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
75 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
76 _data_old = QString("(%1 * x^3) + (%2 * x^2) + (%3 * x) + %4").arg(Old[0], 0, 'f', 9, '0').arg(Old[1], 0, 'f', 9, '0').arg(Old[2], 0, 'f', 9, '0').arg(Old[3], 0, 'f', 9, '0');
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
77 ui->oldEdit->setText(_data_old);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
78
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
79 QJsonArray calData = jsonObj.value("calData").toArray();
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
80 oldtotal = 0;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
81 for (int i = 0; i < calData.size(); i++) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
82 QJsonObject calObj = calData.at(i).toObject();
510
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
83 Calibrate c;
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
84 c.plato = calObj["plato"].toDouble();
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
85 c.angle = calObj["angle"].toDouble();
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
86 c.sg = Utils::plato_to_sg(c.plato);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
87 nCal.append(c);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
88 oCal.append(c);
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
89 oldtotal++;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
90 }
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
91 newtotal = oldtotal;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
92 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
93 }
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
97 connect(ui->dataTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
98 emit refreshTable();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
99 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
100
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
101
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
102 void CalibrateiSpindel::refreshTable()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
103 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
104 QString w;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
105 QWidget* pWidget;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
106 QHBoxLayout* pLayout;
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
107 double d, x[12], y[12];
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
108 bool gerror, aerror;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
109
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
110 qDebug() << "refreshTable" << oldtotal << newtotal;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
111
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
112 /*
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
113 * During filling the table turn off the cellChanged signal because every cell that is filled
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
114 * triggers the cellChanged signal. The QTableWidget has no better signal to use.
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
115 */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
116 this->ignoreChanges = true;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
117
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
118 const QStringList labels({tr("SG"), tr("°Plato"), tr("Angle"), tr("Del")});
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
119 ui->dataTable->setColumnCount(4);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
120 ui->dataTable->setColumnWidth(0, 100); /* SG */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
121 ui->dataTable->setColumnWidth(1, 100); /* °Plato */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
122 ui->dataTable->setColumnWidth(2, 100); /* Tilt angle */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
123 ui->dataTable->setColumnWidth(3, 55); /* Del button */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
124 ui->dataTable->setHorizontalHeaderLabels(labels);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
125 ui->dataTable->verticalHeader()->hide();
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
126 ui->dataTable->setRowCount(newtotal);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
127
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
128 for (int i = 0; i < 12; i++) {
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
129 x[i] = y[i] = 0;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
130 }
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
131
510
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
132 std::sort(nCal.begin() , nCal.end(), [=]( const Calibrate& test1 , const Calibrate& test2 )->bool {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
133 return test2.angle < test1.angle;
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
134 });
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
135 this->dataHasErrors = false;
510
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
136
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
137 for (int i = 0; i < newtotal; i++) {
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
138
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
139 y[i] = nCal[i].plato;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
140 x[i] = nCal[i].angle;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
141
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
142 gerror = aerror = false;
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
143 if ((nCal[i].angle < 10) || (nCal[i].angle > 80))
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
144 aerror = true;
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
145 if (i == 0) {
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
146 if (nCal[0].plato <= nCal[1].plato)
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
147 gerror = true;
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
148 } else if (i == (newtotal -1)) {
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
149 if (nCal[i].plato != 0)
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
150 gerror = true;
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
151 } else {
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
152 if ((nCal[i].plato <= nCal[i + 1].plato) || (nCal[i].plato >= nCal[i - 1].plato))
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
153 gerror = true;
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
154 }
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
155 if (gerror || aerror)
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
156 this->dataHasErrors = true;
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
157
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
158 w = QString("%1").arg(nCal[i].sg, 1, 'f', 4, '0');
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
159 QTableWidgetItem *item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
160 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
161 if (gerror)
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
162 item->setForeground(QBrush(QColor(Qt::red)));
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
163 ui->dataTable->setItem(i, 0, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
164
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
165 w = QString("%1").arg(nCal[i].plato, 1, 'f', 3, '0');
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
166 item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
167 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
168 if (gerror)
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
169 item->setForeground(QBrush(QColor(Qt::red)));
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
170 ui->dataTable->setItem(i, 1, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
171
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
172 w = QString("%1").arg(nCal[i].angle, 1, 'f', 5, '0');
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
173 item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
174 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
175 if (aerror)
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
176 item->setForeground(QBrush(QColor(Qt::red)));
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
177 ui->dataTable->setItem(i, 2, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
178
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
179 /* Add the Delete row button */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
180 pWidget = new QWidget();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
181 QPushButton* btn_del = new QPushButton();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
182 btn_del->setObjectName(QString("%1").arg(i)); /* Send row with the button */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
183 btn_del->setText(tr("Del"));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
184 connect(btn_del, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked()));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
185 pLayout = new QHBoxLayout(pWidget);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
186 pLayout->addWidget(btn_del);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
187 pLayout->setContentsMargins(5, 0, 5, 0);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
188 pWidget->setLayout(pLayout);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
189 ui->dataTable->setCellWidget(i, 3, pWidget);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
190 }
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
191 int rc = Polyfit::polyfit(newtotal, x, y, 4, New);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
192
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
193 _data_new = QString("(%1 * x^3) + (%2 * x^2) + (%3 * x) + %4").arg(New[0], 0, 'f', 9, '0').arg(New[1], 0, 'f', 9, '0').arg(New[2], 0, 'f', 9, '0').arg(New[3], 0, 'f', 9, '0');
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
194 ui->newEdit->setText(_data_new);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
195
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
196 /*
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
197 * Check the new formula against the old formula.
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
198 */
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
199 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
200 CalibrateiSpindel::WindowTitle();
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
201
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
202 new_plot = new QLineSeries();
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
203 old_plot = new QLineSeries();
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
204
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
205 for (int i = 0; i < oldtotal; i++) {
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
206 old_plot->append(oCal[i].angle, oCal[i].plato);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
207 }
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
208 for (int i = 0; i < newtotal; i++) {
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
209 new_plot->append(nCal[i].angle, nCal[i].plato);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
210 }
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
211
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
212 old_plot->setName(tr("Old"));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
213 new_plot->setName(tr("New"));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
214
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
215 chart = new QChart();
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
216 chart->setTitle(tr("Calibration plot"));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
217 chart->addSeries(old_plot);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
218 chart->addSeries(new_plot);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
219
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
220 QValueAxis *axisX = new QValueAxis;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
221 axisX->setRange(10, 80);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
222 axisX->setTickCount(8);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
223 axisX->setLabelFormat("%.0f");
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
224 axisX->setTitleText(tr("Angle"));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
225 axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
226 chart->addAxis(axisX, Qt::AlignBottom);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
227 old_plot->attachAxis(axisX);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
228 new_plot->attachAxis(axisX);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
229
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
230 QValueAxis *axisY = new QValueAxis;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
231 axisY->setRange(0, 20);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
232 axisY->setTickCount(11);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
233 axisY->setLabelFormat("%.1f");
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
234 axisY->setTitleText("Plato");
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
235 axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
236 chart->addAxis(axisY, Qt::AlignLeft);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
237 old_plot->attachAxis(axisY);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
238 new_plot->attachAxis(axisY);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
239
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
240 ui->chartView->setRenderHint(QPainter::Antialiasing);
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
241 ui->chartView->setChart(chart);
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
242
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
243 this->ignoreChanges = false;
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 CalibrateiSpindel::~CalibrateiSpindel()
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 {
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
249 delete ui;
512
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
250 emit entry_changed();
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 void CalibrateiSpindel::on_quitButton_clicked()
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 {
510
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
256 if (this->textIsChanged) {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
257 int rc = QMessageBox::warning(this, tr("iSpindel calibrate changed"), tr("The calibration data has been modified. Save changes?"),
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
258 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
259 switch (rc) {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
260 case QMessageBox::Save:
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
261 if (this->dataHasErrors) {
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
262 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("Data is changed but has errors, not saving."));
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
263 return; /* Return to the editor page */
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
264 } else {
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
265 SaveData();
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
266 }
510
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
267 break; /* Saved and then Quit */
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
268 case QMessageBox::Discard:
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
269 break; /* Quit without Save */
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
270 case QMessageBox::Cancel:
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
271 return; /* Return to the editor page */
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
272 }
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
273 }
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
274
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 this->close();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 this->setResult(1);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279
511
c6fa5be47634 Added error checks on calibration data
Michiel Broek <mbroek@mbse.eu>
parents: 510
diff changeset
280 void CalibrateiSpindel::SaveData()
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
281 {
510
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
282 QSqlQuery query;
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
283
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
284 if (this->textIsChanged) {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
285 /*
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
286 * Build json data
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
287 */
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
288 QJsonObject calObj;
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
289 QJsonArray coeff, poly;
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
290
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
291 for (int i = 0; i < 4; i++) {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
292 coeff.append(New[i]);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
293 }
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
294 calObj.insert("polyData", coeff);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
295 for (int i = 0; i < newtotal; i++) {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
296 QJsonObject obj;
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
297 obj.insert("plato", nCal[i].plato);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
298 obj.insert("angle", nCal[i].angle);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
299 poly.append(obj);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
300 }
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
301 calObj.insert("calData", poly);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
302
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
303 query.prepare("UPDATE mon_ispindels SET calibrate=:calibrate WHERE record = :recno");
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
304 query.bindValue(":calibrate", QJsonDocument(calObj).toJson(QJsonDocument::Compact) );
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
305 query.bindValue(":recno", this->recno);
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
306 query.exec();
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
307 if (query.lastError().isValid()) {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
308 qWarning() << "CalibrateiSpindel" << query.lastError();
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
309 QMessageBox::warning(this, tr("Database error"),
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
310 tr("MySQL error: %1\n%2\n%3")
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
311 .arg(query.lastError().nativeErrorCode())
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
312 .arg(query.lastError().driverText())
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
313 .arg(query.lastError().databaseText()));
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
314 } else {
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
315 qDebug() << "CalibrateiSpindel Saved";
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
316 }
080524ab2fe8 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.
Michiel Broek <mbroek@mbse.eu>
parents: 509
diff changeset
317 }
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
318 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
319
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
320
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
321 void CalibrateiSpindel::on_deleteRow_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
322 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
323 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
324 int row = pb->objectName().toInt();
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
325 qDebug() << "Delete row" << row << newtotal;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
326
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
327 if (newtotal < 4) {
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
328 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("You cannot delete too many rows."));
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
329 return;
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
330 }
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
331
512
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
332 nCal.removeAt(row);
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
333 newtotal--;
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
334 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
335 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
336
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
337
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
338 void CalibrateiSpindel::on_addButton_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
339 {
506
ea07f6c97a69 Added Simple polynomial fitting functions written by Henry M. Forson. Added a graph that displays the old and new iSpindel calibration curve. Implemented delete row from the data.
Michiel Broek <mbroek@mbse.eu>
parents: 505
diff changeset
340 qDebug() << "Add row" << newtotal;
512
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
341 this->ignoreChanges = true;
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
342
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
343 Calibrate c;
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
344 c.plato = 10.0;
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
345 c.angle = 50.0;
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
346 c.sg = Utils::plato_to_sg(10.0);
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
347 nCal.append(c);
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
348 newtotal++;
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
349
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
350 this->ignoreChanges = false;
1dfae8de6ca9 Removed several development debug messages. Implemented delete and add data row.
Michiel Broek <mbroek@mbse.eu>
parents: 511
diff changeset
351 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
352 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
353
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
354
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
355 void CalibrateiSpindel::cell_Changed(int nRow, int nCol)
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
356 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
357 QString w;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
358
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
359 if (this->ignoreChanges)
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
360 return;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
361
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
362 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was changed.";
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
363
507
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
364 if (nCol == 0) { // SG changed
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
365 double d = ui->dataTable->item(nRow, 0)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
366 if (d < 1.000 || d > 1.100) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
367 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("The SG must be between 1.000 and 1.100."));
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
368 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
369 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
370 nCal[nRow].sg = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
371 nCal[nRow].plato = Utils::sg_to_plato(d);
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
372 } else if (nCol == 1) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
373 double d = ui->dataTable->item(nRow, 1)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
374 if (d < 0 || d > 25) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
375 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("Plato must be between 0 and 25."));
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
376 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
377 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
378 nCal[nRow].plato = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
379 nCal[nRow].sg = Utils::plato_to_sg(d);
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
380 } else if (nCol == 2) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
381 double d = ui->dataTable->item(nRow, 2)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
382 if (d < 10 || d > 80) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
383 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("The tilt angles must be between 10 and 80."));
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
384 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
385 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
386 nCal[nRow].angle = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
387 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
388
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
389 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
390 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
391
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
392
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
393 /*
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
394 * Window header, mark any change with '**'
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
395 */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
396 void CalibrateiSpindel::WindowTitle()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
397 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
398 QString txt;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
399
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
400 txt = QString(tr("BMSapp - Calibrate iSpindel %1").arg(this->recno));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
401
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
402 if (this->textIsChanged) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
403 txt.append((QString(" **")));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
404 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
405 setWindowTitle(txt);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
406 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
407

mercurial