src/CalibrateiSpindel.cpp

Sun, 15 Oct 2023 17:37:08 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 15 Oct 2023 17:37:08 +0200
changeset 510
080524ab2fe8
parent 509
af4a8649245e
child 511
c6fa5be47634
permissions
-rw-r--r--

Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog.

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);
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
60 qDebug() << query.value("calibrate").toString();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
61
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
62 QJsonParseError parseError;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
63 const auto& json = query.value("calibrate").toString();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
64
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
65 if (!json.trimmed().isEmpty()) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
66 const auto& formattedJson = QString("%1").arg(json);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
67 QJsonDocument jsonResponse = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
68 if (parseError.error != QJsonParseError::NoError) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
69 qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
70 } else {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
71
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
72 QJsonObject jsonObj = jsonResponse.object();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
73 QJsonArray polyData = jsonObj.value("polyData").toArray();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
74 for (int i = 0; i < polyData.size(); i++) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
75 Old[i] = New[i] = polyData.at(i).toDouble();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
76 qDebug() << i << New[i];
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
77 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
78 _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
79 ui->oldEdit->setText(_data_old);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
80
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
81 qDebug() << "calData: " << jsonObj["calData"].toArray();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
82 QJsonArray calData = jsonObj.value("calData").toArray();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
83 qDebug() << calData;
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
84 oldtotal = 0;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
85 for (int i = 0; i < calData.size(); i++) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 oldtotal++;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
94 }
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
95 newtotal = oldtotal;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
96 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
97 }
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
101 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
102 // connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString)));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
103 emit refreshTable();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
104 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
105
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
106
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
107 void CalibrateiSpindel::refreshTable()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
108 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
109 QString w;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
110 QWidget* pWidget;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
111 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
112 double d, x[12], y[12];
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
113
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
114 qDebug() << "refreshTable" << oldtotal << newtotal;
505
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 /*
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
117 * 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
118 * 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
119 */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
120 this->ignoreChanges = true;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
121
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
122 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
123 ui->dataTable->setColumnCount(4);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
124 ui->dataTable->setColumnWidth(0, 100); /* SG */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
125 ui->dataTable->setColumnWidth(1, 100); /* °Plato */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
126 ui->dataTable->setColumnWidth(2, 100); /* Tilt angle */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
127 ui->dataTable->setColumnWidth(3, 55); /* Del button */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
128 ui->dataTable->setHorizontalHeaderLabels(labels);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
129 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
130 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
131
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
132 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
133 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
134 }
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
135
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 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
137 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
138 });
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
139
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
140 for (int i = 0; i < newtotal; i++) {
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
141 qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
142
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
143 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
144 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
145
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
146 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
147 QTableWidgetItem *item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
148 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
149 ui->dataTable->setItem(i, 0, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
150
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
151 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
152 item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
153 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
154 ui->dataTable->setItem(i, 1, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
155
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
156 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
157 item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
158 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
159 ui->dataTable->setItem(i, 2, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
160
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
161 /* Add the Delete row button */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
162 pWidget = new QWidget();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
163 QPushButton* btn_del = new QPushButton();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
164 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
165 btn_del->setText(tr("Del"));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
166 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
167 pLayout = new QHBoxLayout(pWidget);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
168 pLayout->addWidget(btn_del);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
169 pLayout->setContentsMargins(5, 0, 5, 0);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
170 pWidget->setLayout(pLayout);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
171 ui->dataTable->setCellWidget(i, 3, pWidget);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
172 }
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
173 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
174 qDebug() << "poly:" << rc << New[0] << New[1] << New[2] << New[3];
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
175
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
176 _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
177 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
178
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
179 /*
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
180 * 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
181 */
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
182 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
183 qDebug() << "changed" << this->textIsChanged << _data_old.compare(_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
184 CalibrateiSpindel::WindowTitle();
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
185 ui->saveButton->setEnabled(this->textIsChanged);
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
186
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
187 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
188 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
189
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
190 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
191 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
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 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
194 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
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 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
198 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
199
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 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
201 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
202 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
203 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
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 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
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 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224
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 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
226 ui->chartView->setChart(chart);
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
227
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
228 this->ignoreChanges = false;
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 CalibrateiSpindel::~CalibrateiSpindel()
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 {
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
234 delete ui;
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 void CalibrateiSpindel::on_quitButton_clicked()
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 {
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
240 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
241 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
242 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
243 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
244 case 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
245 on_saveButton_clicked();
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
246 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
247 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
248 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
249 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
250 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
251 }
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
252 }
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
253
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 this->close();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 this->setResult(1);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
259 void CalibrateiSpindel::on_saveButton_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
260 {
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
261 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
262
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
263 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
264 /*
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
265 * 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
266 */
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 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
268 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
269
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 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
271 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
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 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
274 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
275 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
276 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
277 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
278 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
279 }
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
280 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
281
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 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
283 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
284 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
285 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
286 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
287 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
288 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
289 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
290 .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
291 .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
292 .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
293 } 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
294 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
295 }
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 }
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
297 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
298
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
299
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
300 void CalibrateiSpindel::on_deleteRow_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
301 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
302 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
303 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
304 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
305
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
306 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
307 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
308 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
309 }
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
310
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
311 if (row == (newtotal - 1)) {
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
312 qDebug() << "Delete last row";
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
313 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
314 } else {
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
315 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
316 for (int i = row; 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
317 nCal[i].sg = nCal[i+1].sg;
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
318 nCal[i].plato = nCal[i+1].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
319 nCal[i].angle = nCal[i+1].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
320 qDebug() << i << " < " << i+1;
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
321 }
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
322 }
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
323
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
324 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
325 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
326
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
327
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
328 void CalibrateiSpindel::on_addButton_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
329 {
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
330 qDebug() << "Add row" << newtotal;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
331 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
332
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
333
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
334 void CalibrateiSpindel::cell_Changed(int nRow, int nCol)
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 QString w;
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 if (this->ignoreChanges)
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
339 return;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
340
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
341 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
342
507
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
343 if (nCol == 0) { // SG changed
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
344 double d = ui->dataTable->item(nRow, 0)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
345 if (d < 1.000 || d > 1.100) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
346 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
347 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
348 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
349 nCal[nRow].sg = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
350 nCal[nRow].plato = Utils::sg_to_plato(d);
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
351 qDebug() << "sg" << nCal[nRow].sg << "plato" << nCal[nRow].plato;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
352 } else if (nCol == 1) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
353 double d = ui->dataTable->item(nRow, 1)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
354 if (d < 0 || d > 25) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
355 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
356 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
357 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
358 nCal[nRow].plato = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
359 nCal[nRow].sg = Utils::plato_to_sg(d);
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
360 qDebug() << "sg" << nCal[nRow].sg << "plato" << nCal[nRow].plato;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
361 } else if (nCol == 2) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
362 double d = ui->dataTable->item(nRow, 2)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
363 if (d < 10 || d > 80) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
364 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
365 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
366 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
367 nCal[nRow].angle = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
368 }
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 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
371 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
372
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
373
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
374 /*
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
375 * Window header, mark any change with '**'
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
376 */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
377 void CalibrateiSpindel::WindowTitle()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
378 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
379 QString txt;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
380
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
381 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
382
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
383 if (this->textIsChanged) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
384 txt.append((QString(" **")));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
385 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
386 setWindowTitle(txt);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
387 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
388

mercurial