# HG changeset patch # User Michiel Broek # Date 1697384228 -7200 # Node ID 080524ab2fe813c395f5ab8804a1e24197c5f3ac # Parent af4a8649245e97ce0a53708acd71a7ce89544376 Changed xCal array to a QList. Added sort on angle. Added save data. Added quit/save dialog. diff -r af4a8649245e -r 080524ab2fe8 src/CalibrateiSpindel.cpp --- a/src/CalibrateiSpindel.cpp Sun Oct 15 13:30:24 2023 +0200 +++ b/src/CalibrateiSpindel.cpp Sun Oct 15 17:37:08 2023 +0200 @@ -57,6 +57,7 @@ _node = query.value("node").toString(); _alias = query.value("alias").toString(); ui->nameEdit->setText(_node+"/"+_alias); + qDebug() << query.value("calibrate").toString(); QJsonParseError parseError; const auto& json = query.value("calibrate").toString(); @@ -83,9 +84,12 @@ oldtotal = 0; for (int i = 0; i < calData.size(); i++) { QJsonObject calObj = calData.at(i).toObject(); - oCal[i].plato = nCal[i].plato = calObj["plato"].toDouble(); - oCal[i].angle = nCal[i].angle = calObj["angle"].toDouble(); - oCal[i].sg = nCal[i].sg = Utils::plato_to_sg(oCal[i].plato); + Calibrate c; + c.plato = calObj["plato"].toDouble(); + c.angle = calObj["angle"].toDouble(); + c.sg = Utils::plato_to_sg(c.plato); + nCal.append(c); + oCal.append(c); oldtotal++; } newtotal = oldtotal; @@ -129,6 +133,10 @@ x[i] = y[i] = 0; } + std::sort(nCal.begin() , nCal.end(), [=]( const Calibrate& test1 , const Calibrate& test2 )->bool { + return test2.angle < test1.angle; + }); + for (int i = 0; i < newtotal; i++) { qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; @@ -174,6 +182,7 @@ this->textIsChanged = (_data_old.compare(_data_new) == 0) ? false:true; qDebug() << "changed" << this->textIsChanged << _data_old.compare(_data_new); CalibrateiSpindel::WindowTitle(); + ui->saveButton->setEnabled(this->textIsChanged); new_plot = new QLineSeries(); old_plot = new QLineSeries(); @@ -228,6 +237,20 @@ void CalibrateiSpindel::on_quitButton_clicked() { + if (this->textIsChanged) { + int rc = QMessageBox::warning(this, tr("iSpindel calibrate changed"), tr("The calibration data has been modified. Save changes?"), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); + switch (rc) { + case QMessageBox::Save: + on_saveButton_clicked(); + break; /* Saved and then Quit */ + case QMessageBox::Discard: + break; /* Quit without Save */ + case QMessageBox::Cancel: + return; /* Return to the editor page */ + } + } + this->close(); this->setResult(1); } @@ -235,6 +258,42 @@ void CalibrateiSpindel::on_saveButton_clicked() { + QSqlQuery query; + + if (this->textIsChanged) { + /* + * Build json data + */ + QJsonObject calObj; + QJsonArray coeff, poly; + + for (int i = 0; i < 4; i++) { + coeff.append(New[i]); + } + calObj.insert("polyData", coeff); + for (int i = 0; i < newtotal; i++) { + QJsonObject obj; + obj.insert("plato", nCal[i].plato); + obj.insert("angle", nCal[i].angle); + poly.append(obj); + } + calObj.insert("calData", poly); + + query.prepare("UPDATE mon_ispindels SET calibrate=:calibrate WHERE record = :recno"); + query.bindValue(":calibrate", QJsonDocument(calObj).toJson(QJsonDocument::Compact) ); + query.bindValue(":recno", this->recno); + query.exec(); + if (query.lastError().isValid()) { + qWarning() << "CalibrateiSpindel" << query.lastError(); + QMessageBox::warning(this, tr("Database error"), + tr("MySQL error: %1\n%2\n%3") + .arg(query.lastError().nativeErrorCode()) + .arg(query.lastError().driverText()) + .arg(query.lastError().databaseText())); + } else { + qDebug() << "CalibrateiSpindel Saved"; + } + } } diff -r af4a8649245e -r 080524ab2fe8 src/CalibrateiSpindel.h --- a/src/CalibrateiSpindel.h Sun Oct 15 13:30:24 2023 +0200 +++ b/src/CalibrateiSpindel.h Sun Oct 15 17:37:08 2023 +0200 @@ -45,8 +45,10 @@ bool ignoreChanges = false; bool textIsChanged = false; double Old[4], New[4]; - Calibrate oCal[12], nCal[12]; + QList oCal; + QList nCal; + bool sort_test(const Calibrate &D1, const Calibrate &D2); void WindowTitle(); }; diff -r af4a8649245e -r 080524ab2fe8 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Sun Oct 15 13:30:24 2023 +0200 +++ b/translations/bmsapp_en.ts Sun Oct 15 17:37:08 2023 +0200 @@ -90,72 +90,94 @@ - + SG - + °Plato - - + + Angle - - + + Del - + Old - + New - + Calibration plot - - - - + + iSpindel calibrate changed + + + + + The calibration data has been modified. Save changes? + + + + + Database error + + + + + MySQL error: %1 +%2 +%3 + + + + + + + iSpindel calibrate - + You cannot delete too many rows. - + The SG must be between 1.000 and 1.100. - + Plato must be between 0 and 25. - + The tilt angles must be between 10 and 80. - + BMSapp - Calibrate iSpindel %1 diff -r af4a8649245e -r 080524ab2fe8 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Sun Oct 15 13:30:24 2023 +0200 +++ b/translations/bmsapp_nl.ts Sun Oct 15 17:37:08 2023 +0200 @@ -144,72 +144,96 @@ Terug - + SG SG - + °Plato - - + + Angle - - + + Del - + Old - + New Nieuw - + Calibration plot - - - - + + iSpindel calibrate changed + + + + + The calibration data has been modified. Save changes? + + + + + Database error + Database fout + + + + MySQL error: %1 +%2 +%3 + MySQL fout: %1 +%2 +%3 + + + + + + iSpindel calibrate - + You cannot delete too many rows. - + The SG must be between 1.000 and 1.100. - + Plato must be between 0 and 25. - + The tilt angles must be between 10 and 80. - + BMSapp - Calibrate iSpindel %1