55 if (query.next()) { |
55 if (query.next()) { |
56 |
56 |
57 _node = query.value("node").toString(); |
57 _node = query.value("node").toString(); |
58 _alias = query.value("alias").toString(); |
58 _alias = query.value("alias").toString(); |
59 ui->nameEdit->setText(_node+"/"+_alias); |
59 ui->nameEdit->setText(_node+"/"+_alias); |
60 qDebug() << query.value("calibrate").toString(); |
|
61 |
60 |
62 QJsonParseError parseError; |
61 QJsonParseError parseError; |
63 const auto& json = query.value("calibrate").toString(); |
62 const auto& json = query.value("calibrate").toString(); |
64 |
63 |
65 if (!json.trimmed().isEmpty()) { |
64 if (!json.trimmed().isEmpty()) { |
71 |
70 |
72 QJsonObject jsonObj = jsonResponse.object(); |
71 QJsonObject jsonObj = jsonResponse.object(); |
73 QJsonArray polyData = jsonObj.value("polyData").toArray(); |
72 QJsonArray polyData = jsonObj.value("polyData").toArray(); |
74 for (int i = 0; i < polyData.size(); i++) { |
73 for (int i = 0; i < polyData.size(); i++) { |
75 Old[i] = New[i] = polyData.at(i).toDouble(); |
74 Old[i] = New[i] = polyData.at(i).toDouble(); |
76 qDebug() << i << New[i]; |
|
77 } |
75 } |
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'); |
76 _data_old = QString("(%1 * x^3) + (%2 * x^2) + (%3 * x) + %4").arg(Old[0], 0, 'f', 9, '0').arg(Old[1], 0, 'f', 9, '0').arg(Old[2], 0, 'f', 9, '0').arg(Old[3], 0, 'f', 9, '0'); |
79 ui->oldEdit->setText(_data_old); |
77 ui->oldEdit->setText(_data_old); |
80 |
78 |
81 qDebug() << "calData: " << jsonObj["calData"].toArray(); |
|
82 QJsonArray calData = jsonObj.value("calData").toArray(); |
79 QJsonArray calData = jsonObj.value("calData").toArray(); |
83 qDebug() << calData; |
|
84 oldtotal = 0; |
80 oldtotal = 0; |
85 for (int i = 0; i < calData.size(); i++) { |
81 for (int i = 0; i < calData.size(); i++) { |
86 QJsonObject calObj = calData.at(i).toObject(); |
82 QJsonObject calObj = calData.at(i).toObject(); |
87 Calibrate c; |
83 Calibrate c; |
88 c.plato = calObj["plato"].toDouble(); |
84 c.plato = calObj["plato"].toDouble(); |
97 } |
93 } |
98 |
94 |
99 } |
95 } |
100 |
96 |
101 connect(ui->dataTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int))); |
97 connect(ui->dataTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int))); |
102 // connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); |
|
103 emit refreshTable(); |
98 emit refreshTable(); |
104 } |
99 } |
105 |
100 |
106 |
101 |
107 void CalibrateiSpindel::refreshTable() |
102 void CalibrateiSpindel::refreshTable() |
138 return test2.angle < test1.angle; |
133 return test2.angle < test1.angle; |
139 }); |
134 }); |
140 this->dataHasErrors = false; |
135 this->dataHasErrors = false; |
141 |
136 |
142 for (int i = 0; i < newtotal; i++) { |
137 for (int i = 0; i < newtotal; i++) { |
143 qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; |
|
144 |
138 |
145 y[i] = nCal[i].plato; |
139 y[i] = nCal[i].plato; |
146 x[i] = nCal[i].angle; |
140 x[i] = nCal[i].angle; |
147 |
141 |
148 gerror = aerror = false; |
142 gerror = aerror = false; |
193 pLayout->setContentsMargins(5, 0, 5, 0); |
187 pLayout->setContentsMargins(5, 0, 5, 0); |
194 pWidget->setLayout(pLayout); |
188 pWidget->setLayout(pLayout); |
195 ui->dataTable->setCellWidget(i, 3, pWidget); |
189 ui->dataTable->setCellWidget(i, 3, pWidget); |
196 } |
190 } |
197 int rc = Polyfit::polyfit(newtotal, x, y, 4, New); |
191 int rc = Polyfit::polyfit(newtotal, x, y, 4, New); |
198 qDebug() << "poly:" << rc << New[0] << New[1] << New[2] << New[3]; |
|
199 |
192 |
200 _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'); |
193 _data_new = QString("(%1 * x^3) + (%2 * x^2) + (%3 * x) + %4").arg(New[0], 0, 'f', 9, '0').arg(New[1], 0, 'f', 9, '0').arg(New[2], 0, 'f', 9, '0').arg(New[3], 0, 'f', 9, '0'); |
201 ui->newEdit->setText(_data_new); |
194 ui->newEdit->setText(_data_new); |
202 |
195 |
203 /* |
196 /* |
204 * Check the new formula against the old formula. |
197 * Check the new formula against the old formula. |
205 */ |
198 */ |
206 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; |
199 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; |
207 qDebug() << "changed" << this->textIsChanged << _data_old.compare(_data_new); |
|
208 CalibrateiSpindel::WindowTitle(); |
200 CalibrateiSpindel::WindowTitle(); |
209 |
201 |
210 new_plot = new QLineSeries(); |
202 new_plot = new QLineSeries(); |
211 old_plot = new QLineSeries(); |
203 old_plot = new QLineSeries(); |
212 |
204 |
334 if (newtotal < 4) { |
327 if (newtotal < 4) { |
335 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("You cannot delete too many rows.")); |
328 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("You cannot delete too many rows.")); |
336 return; |
329 return; |
337 } |
330 } |
338 |
331 |
339 if (row == (newtotal - 1)) { |
332 nCal.removeAt(row); |
340 qDebug() << "Delete last row"; |
333 newtotal--; |
341 newtotal--; |
|
342 } else { |
|
343 newtotal--; |
|
344 for (int i = row; i < newtotal; i++) { |
|
345 nCal[i].sg = nCal[i+1].sg; |
|
346 nCal[i].plato = nCal[i+1].plato; |
|
347 nCal[i].angle = nCal[i+1].angle; |
|
348 qDebug() << i << " < " << i+1; |
|
349 } |
|
350 } |
|
351 |
|
352 emit refreshTable(); |
334 emit refreshTable(); |
353 } |
335 } |
354 |
336 |
355 |
337 |
356 void CalibrateiSpindel::on_addButton_clicked() |
338 void CalibrateiSpindel::on_addButton_clicked() |
357 { |
339 { |
358 qDebug() << "Add row" << newtotal; |
340 qDebug() << "Add row" << newtotal; |
|
341 this->ignoreChanges = true; |
|
342 |
|
343 Calibrate c; |
|
344 c.plato = 10.0; |
|
345 c.angle = 50.0; |
|
346 c.sg = Utils::plato_to_sg(10.0); |
|
347 nCal.append(c); |
|
348 newtotal++; |
|
349 |
|
350 this->ignoreChanges = false; |
|
351 emit refreshTable(); |
359 } |
352 } |
360 |
353 |
361 |
354 |
362 void CalibrateiSpindel::cell_Changed(int nRow, int nCol) |
355 void CalibrateiSpindel::cell_Changed(int nRow, int nCol) |
363 { |
356 { |
374 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("The SG must be between 1.000 and 1.100.")); |
367 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("The SG must be between 1.000 and 1.100.")); |
375 return; |
368 return; |
376 } |
369 } |
377 nCal[nRow].sg = d; |
370 nCal[nRow].sg = d; |
378 nCal[nRow].plato = Utils::sg_to_plato(d); |
371 nCal[nRow].plato = Utils::sg_to_plato(d); |
379 qDebug() << "sg" << nCal[nRow].sg << "plato" << nCal[nRow].plato; |
|
380 } else if (nCol == 1) { |
372 } else if (nCol == 1) { |
381 double d = ui->dataTable->item(nRow, 1)->text().toDouble(); |
373 double d = ui->dataTable->item(nRow, 1)->text().toDouble(); |
382 if (d < 0 || d > 25) { |
374 if (d < 0 || d > 25) { |
383 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("Plato must be between 0 and 25.")); |
375 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("Plato must be between 0 and 25.")); |
384 return; |
376 return; |
385 } |
377 } |
386 nCal[nRow].plato = d; |
378 nCal[nRow].plato = d; |
387 nCal[nRow].sg = Utils::plato_to_sg(d); |
379 nCal[nRow].sg = Utils::plato_to_sg(d); |
388 qDebug() << "sg" << nCal[nRow].sg << "plato" << nCal[nRow].plato; |
|
389 } else if (nCol == 2) { |
380 } else if (nCol == 2) { |
390 double d = ui->dataTable->item(nRow, 2)->text().toDouble(); |
381 double d = ui->dataTable->item(nRow, 2)->text().toDouble(); |
391 if (d < 10 || d > 80) { |
382 if (d < 10 || d > 80) { |
392 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("The tilt angles must be between 10 and 80.")); |
383 QMessageBox::warning(this, tr("iSpindel calibrate"), tr("The tilt angles must be between 10 and 80.")); |
393 return; |
384 return; |