src/CalibrateiSpindel.cpp

Sun, 15 Oct 2023 13:30:24 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 15 Oct 2023 13:30:24 +0200
changeset 509
af4a8649245e
parent 507
fa07b6c6238a
child 510
080524ab2fe8
permissions
-rw-r--r--

Added MySQL query example in the source.

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 qDebug() << i << New[i];
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
76 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
77 _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
78 ui->oldEdit->setText(_data_old);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
79
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
80 qDebug() << "calData: " << jsonObj["calData"].toArray();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
81 QJsonArray calData = jsonObj.value("calData").toArray();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
82 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
83 oldtotal = 0;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
84 for (int i = 0; i < calData.size(); i++) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
85 QJsonObject calObj = calData.at(i).toObject();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
86 oCal[i].plato = nCal[i].plato = calObj["plato"].toDouble();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
87 oCal[i].angle = nCal[i].angle = calObj["angle"].toDouble();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
88 oCal[i].sg = nCal[i].sg = Utils::plato_to_sg(oCal[i].plato);
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 // 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
99 emit refreshTable();
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
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
103 void CalibrateiSpindel::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 QString w;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
106 QWidget* pWidget;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
107 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
108 double d, x[12], y[12];
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
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
132 for (int i = 0; i < newtotal; i++) {
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
133 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
134
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
135 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
136 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
137
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
138 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
139 QTableWidgetItem *item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
140 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
141 ui->dataTable->setItem(i, 0, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
142
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
143 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
144 item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
145 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
146 ui->dataTable->setItem(i, 1, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
147
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
148 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
149 item = new QTableWidgetItem(w);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
150 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
151 ui->dataTable->setItem(i, 2, item);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
152
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
153 /* Add the Delete row button */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
154 pWidget = new QWidget();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
155 QPushButton* btn_del = new QPushButton();
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
156 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
157 btn_del->setText(tr("Del"));
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
158 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
159 pLayout = new QHBoxLayout(pWidget);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
160 pLayout->addWidget(btn_del);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
161 pLayout->setContentsMargins(5, 0, 5, 0);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
162 pWidget->setLayout(pLayout);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
163 ui->dataTable->setCellWidget(i, 3, pWidget);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
164 }
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
165 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
166 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
167
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
168 _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
169 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
170
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
171 /*
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
172 * 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
173 */
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 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
175 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
176 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
177
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 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
179 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
180
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 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
182 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
183 }
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 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
185 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
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
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->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
189 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
190
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 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
192 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
193 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
194 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
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 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205
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 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215
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 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
217 ui->chartView->setChart(chart);
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
218
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
219 this->ignoreChanges = false;
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 CalibrateiSpindel::~CalibrateiSpindel()
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 {
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
225 delete ui;
503
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 void CalibrateiSpindel::on_quitButton_clicked()
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 this->close();
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 this->setResult(1);
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 }
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234
61c114afb0ee Basic setup for iSpindel calibration.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
236 void CalibrateiSpindel::on_saveButton_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
237 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
238 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
239
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
240
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
241 void CalibrateiSpindel::on_deleteRow_clicked()
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 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
244 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
245 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
246
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
247 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
248 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
249 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
250 }
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
251
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
252 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
253 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
254 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
255 } 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
256 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
257 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
258 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
259 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
260 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
261 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
262 }
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
263 }
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
264
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
265 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
266 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
267
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
268
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
269 void CalibrateiSpindel::on_addButton_clicked()
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
270 {
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
271 qDebug() << "Add row" << newtotal;
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
272 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
273
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
274
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
275 void CalibrateiSpindel::cell_Changed(int nRow, int nCol)
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
276 {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
277 QString w;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
278
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
279 if (this->ignoreChanges)
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
280 return;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
281
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
282 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
283
507
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
284 if (nCol == 0) { // SG changed
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
285 double d = ui->dataTable->item(nRow, 0)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
286 if (d < 1.000 || d > 1.100) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
287 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
288 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
289 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
290 nCal[nRow].sg = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
291 nCal[nRow].plato = Utils::sg_to_plato(d);
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
292 qDebug() << "sg" << nCal[nRow].sg << "plato" << nCal[nRow].plato;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
293 } else if (nCol == 1) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
294 double d = ui->dataTable->item(nRow, 1)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
295 if (d < 0 || d > 25) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
296 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
297 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
298 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
299 nCal[nRow].plato = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
300 nCal[nRow].sg = Utils::plato_to_sg(d);
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
301 qDebug() << "sg" << nCal[nRow].sg << "plato" << nCal[nRow].plato;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
302 } else if (nCol == 2) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
303 double d = ui->dataTable->item(nRow, 2)->text().toDouble();
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
304 if (d < 10 || d > 80) {
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
305 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
306 return;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
307 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
308 nCal[nRow].angle = d;
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
309 }
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
310
fa07b6c6238a Added the cell edit function.
Michiel Broek <mbroek@mbse.eu>
parents: 506
diff changeset
311 emit refreshTable();
505
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
312 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
313
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
314
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
315 /*
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
316 * Window header, mark any change with '**'
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
317 */
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
318 void CalibrateiSpindel::WindowTitle()
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 QString txt;
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
321
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
322 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
323
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
324 if (this->textIsChanged) {
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
325 txt.append((QString(" **")));
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 setWindowTitle(txt);
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
328 }
7ae4d022cf8f Load and show current calibration data.
Michiel Broek <mbroek@mbse.eu>
parents: 504
diff changeset
329

mercurial