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(); |
60 |
61 |
61 QJsonParseError parseError; |
62 QJsonParseError parseError; |
62 const auto& json = query.value("calibrate").toString(); |
63 const auto& json = query.value("calibrate").toString(); |
63 |
64 |
64 if (!json.trimmed().isEmpty()) { |
65 if (!json.trimmed().isEmpty()) { |
81 QJsonArray calData = jsonObj.value("calData").toArray(); |
82 QJsonArray calData = jsonObj.value("calData").toArray(); |
82 qDebug() << calData; |
83 qDebug() << calData; |
83 oldtotal = 0; |
84 oldtotal = 0; |
84 for (int i = 0; i < calData.size(); i++) { |
85 for (int i = 0; i < calData.size(); i++) { |
85 QJsonObject calObj = calData.at(i).toObject(); |
86 QJsonObject calObj = calData.at(i).toObject(); |
86 oCal[i].plato = nCal[i].plato = calObj["plato"].toDouble(); |
87 Calibrate c; |
87 oCal[i].angle = nCal[i].angle = calObj["angle"].toDouble(); |
88 c.plato = calObj["plato"].toDouble(); |
88 oCal[i].sg = nCal[i].sg = Utils::plato_to_sg(oCal[i].plato); |
89 c.angle = calObj["angle"].toDouble(); |
|
90 c.sg = Utils::plato_to_sg(c.plato); |
|
91 nCal.append(c); |
|
92 oCal.append(c); |
89 oldtotal++; |
93 oldtotal++; |
90 } |
94 } |
91 newtotal = oldtotal; |
95 newtotal = oldtotal; |
92 } |
96 } |
93 } |
97 } |
126 ui->dataTable->setRowCount(newtotal); |
130 ui->dataTable->setRowCount(newtotal); |
127 |
131 |
128 for (int i = 0; i < 12; i++) { |
132 for (int i = 0; i < 12; i++) { |
129 x[i] = y[i] = 0; |
133 x[i] = y[i] = 0; |
130 } |
134 } |
|
135 |
|
136 std::sort(nCal.begin() , nCal.end(), [=]( const Calibrate& test1 , const Calibrate& test2 )->bool { |
|
137 return test2.angle < test1.angle; |
|
138 }); |
131 |
139 |
132 for (int i = 0; i < newtotal; i++) { |
140 for (int i = 0; i < newtotal; i++) { |
133 qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; |
141 qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; |
134 |
142 |
135 y[i] = nCal[i].plato; |
143 y[i] = nCal[i].plato; |
172 * Check the new formula against the old formula. |
180 * Check the new formula against the old formula. |
173 */ |
181 */ |
174 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; |
182 this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; |
175 qDebug() << "changed" << this->textIsChanged << _data_old.compare(_data_new); |
183 qDebug() << "changed" << this->textIsChanged << _data_old.compare(_data_new); |
176 CalibrateiSpindel::WindowTitle(); |
184 CalibrateiSpindel::WindowTitle(); |
|
185 ui->saveButton->setEnabled(this->textIsChanged); |
177 |
186 |
178 new_plot = new QLineSeries(); |
187 new_plot = new QLineSeries(); |
179 old_plot = new QLineSeries(); |
188 old_plot = new QLineSeries(); |
180 |
189 |
181 for (int i = 0; i < oldtotal; i++) { |
190 for (int i = 0; i < oldtotal; i++) { |
226 } |
235 } |
227 |
236 |
228 |
237 |
229 void CalibrateiSpindel::on_quitButton_clicked() |
238 void CalibrateiSpindel::on_quitButton_clicked() |
230 { |
239 { |
|
240 if (this->textIsChanged) { |
|
241 int rc = QMessageBox::warning(this, tr("iSpindel calibrate changed"), tr("The calibration data has been modified. Save changes?"), |
|
242 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); |
|
243 switch (rc) { |
|
244 case QMessageBox::Save: |
|
245 on_saveButton_clicked(); |
|
246 break; /* Saved and then Quit */ |
|
247 case QMessageBox::Discard: |
|
248 break; /* Quit without Save */ |
|
249 case QMessageBox::Cancel: |
|
250 return; /* Return to the editor page */ |
|
251 } |
|
252 } |
|
253 |
231 this->close(); |
254 this->close(); |
232 this->setResult(1); |
255 this->setResult(1); |
233 } |
256 } |
234 |
257 |
235 |
258 |
236 void CalibrateiSpindel::on_saveButton_clicked() |
259 void CalibrateiSpindel::on_saveButton_clicked() |
237 { |
260 { |
|
261 QSqlQuery query; |
|
262 |
|
263 if (this->textIsChanged) { |
|
264 /* |
|
265 * Build json data |
|
266 */ |
|
267 QJsonObject calObj; |
|
268 QJsonArray coeff, poly; |
|
269 |
|
270 for (int i = 0; i < 4; i++) { |
|
271 coeff.append(New[i]); |
|
272 } |
|
273 calObj.insert("polyData", coeff); |
|
274 for (int i = 0; i < newtotal; i++) { |
|
275 QJsonObject obj; |
|
276 obj.insert("plato", nCal[i].plato); |
|
277 obj.insert("angle", nCal[i].angle); |
|
278 poly.append(obj); |
|
279 } |
|
280 calObj.insert("calData", poly); |
|
281 |
|
282 query.prepare("UPDATE mon_ispindels SET calibrate=:calibrate WHERE record = :recno"); |
|
283 query.bindValue(":calibrate", QJsonDocument(calObj).toJson(QJsonDocument::Compact) ); |
|
284 query.bindValue(":recno", this->recno); |
|
285 query.exec(); |
|
286 if (query.lastError().isValid()) { |
|
287 qWarning() << "CalibrateiSpindel" << query.lastError(); |
|
288 QMessageBox::warning(this, tr("Database error"), |
|
289 tr("MySQL error: %1\n%2\n%3") |
|
290 .arg(query.lastError().nativeErrorCode()) |
|
291 .arg(query.lastError().driverText()) |
|
292 .arg(query.lastError().databaseText())); |
|
293 } else { |
|
294 qDebug() << "CalibrateiSpindel Saved"; |
|
295 } |
|
296 } |
238 } |
297 } |
239 |
298 |
240 |
299 |
241 void CalibrateiSpindel::on_deleteRow_clicked() |
300 void CalibrateiSpindel::on_deleteRow_clicked() |
242 { |
301 { |