# HG changeset patch # User Michiel Broek # Date 1697449160 -7200 # Node ID c6fa5be476349845300d1b1f44aa3d8ae709f9b7 # Parent 080524ab2fe813c395f5ab8804a1e24197c5f3ac Added error checks on calibration data diff -r 080524ab2fe8 -r c6fa5be47634 src/CalibrateiSpindel.cpp --- a/src/CalibrateiSpindel.cpp Sun Oct 15 17:37:08 2023 +0200 +++ b/src/CalibrateiSpindel.cpp Mon Oct 16 11:39:20 2023 +0200 @@ -110,6 +110,7 @@ QWidget* pWidget; QHBoxLayout* pLayout; double d, x[12], y[12]; + bool gerror, aerror; qDebug() << "refreshTable" << oldtotal << newtotal; @@ -136,6 +137,7 @@ std::sort(nCal.begin() , nCal.end(), [=]( const Calibrate& test1 , const Calibrate& test2 )->bool { return test2.angle < test1.angle; }); + this->dataHasErrors = false; for (int i = 0; i < newtotal; i++) { qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; @@ -143,19 +145,41 @@ y[i] = nCal[i].plato; x[i] = nCal[i].angle; + gerror = aerror = false; + if ((nCal[i].angle < 10) || (nCal[i].angle > 80)) + aerror = true; + if (i == 0) { + if (nCal[0].plato <= nCal[1].plato) + gerror = true; + } else if (i == (newtotal -1)) { + if (nCal[i].plato != 0) + gerror = true; + } else { + if ((nCal[i].plato <= nCal[i + 1].plato) || (nCal[i].plato >= nCal[i - 1].plato)) + gerror = true; + } + if (gerror || aerror) + this->dataHasErrors = true; + w = QString("%1").arg(nCal[i].sg, 1, 'f', 4, '0'); QTableWidgetItem *item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + if (gerror) + item->setForeground(QBrush(QColor(Qt::red))); ui->dataTable->setItem(i, 0, item); w = QString("%1").arg(nCal[i].plato, 1, 'f', 3, '0'); item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + if (gerror) + item->setForeground(QBrush(QColor(Qt::red))); ui->dataTable->setItem(i, 1, item); w = QString("%1").arg(nCal[i].angle, 1, 'f', 5, '0'); item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + if (aerror) + item->setForeground(QBrush(QColor(Qt::red))); ui->dataTable->setItem(i, 2, item); /* Add the Delete row button */ @@ -182,7 +206,6 @@ 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(); @@ -242,7 +265,12 @@ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); switch (rc) { case QMessageBox::Save: - on_saveButton_clicked(); + if (this->dataHasErrors) { + QMessageBox::warning(this, tr("iSpindel calibrate"), tr("Data is changed but has errors, not saving.")); + return; /* Return to the editor page */ + } else { + SaveData(); + } break; /* Saved and then Quit */ case QMessageBox::Discard: break; /* Quit without Save */ @@ -256,7 +284,7 @@ } -void CalibrateiSpindel::on_saveButton_clicked() +void CalibrateiSpindel::SaveData() { QSqlQuery query; diff -r 080524ab2fe8 -r c6fa5be47634 src/CalibrateiSpindel.h --- a/src/CalibrateiSpindel.h Sun Oct 15 17:37:08 2023 +0200 +++ b/src/CalibrateiSpindel.h Mon Oct 16 11:39:20 2023 +0200 @@ -28,7 +28,6 @@ private slots: void on_quitButton_clicked(); - void on_saveButton_clicked(); void refreshTable(void); void on_addButton_clicked(); void on_deleteRow_clicked(); @@ -44,12 +43,13 @@ QJsonDocument data; bool ignoreChanges = false; bool textIsChanged = false; + bool dataHasErrors = false; double Old[4], New[4]; QList oCal; QList nCal; - bool sort_test(const Calibrate &D1, const Calibrate &D2); void WindowTitle(); + void SaveData(); }; #endif diff -r 080524ab2fe8 -r c6fa5be47634 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Sun Oct 15 17:37:08 2023 +0200 +++ b/translations/bmsapp_en.ts Mon Oct 16 11:39:20 2023 +0200 @@ -60,22 +60,22 @@ - + Data: - + Add - + Old formula: - + New formula: @@ -85,99 +85,100 @@ - - Save - - - - + SG - + °Plato - - + + Angle - - + + Del - + Old - + New - + Calibration plot - + iSpindel calibrate changed - + The calibration data has been modified. Save changes? - + + Data is changed but has errors, not saving. + + + + 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 080524ab2fe8 -r c6fa5be47634 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Sun Oct 15 17:37:08 2023 +0200 +++ b/translations/bmsapp_nl.ts Mon Oct 16 11:39:20 2023 +0200 @@ -90,22 +90,22 @@ Naam: - + Data: - + Add Nieuw - + Old formula: - + New formula: @@ -114,9 +114,8 @@ Naam van het vergisting profiel - Save - Bewaar + Bewaar Steps: @@ -144,59 +143,64 @@ Terug - + SG SG - + °Plato - - + + Angle - - + + Del - + Old - + New Nieuw - + Calibration plot - + iSpindel calibrate changed - + The calibration data has been modified. Save changes? - + + Data is changed but has errors, not saving. + + + + Database error Database fout - + MySQL error: %1 %2 %3 @@ -205,35 +209,36 @@ %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 080524ab2fe8 -r c6fa5be47634 ui/CalibrateiSpindel.ui --- a/ui/CalibrateiSpindel.ui Sun Oct 15 17:37:08 2023 +0200 +++ b/ui/CalibrateiSpindel.ui Mon Oct 16 11:39:20 2023 +0200 @@ -51,7 +51,7 @@ - 110 + 462 510 80 23 @@ -71,26 +71,6 @@ :icons/silk/door_out.png:icons/silk/door_out.png - - - false - - - - 820 - 510 - 80 - 23 - - - - Save - - - - :icons/silk/disk.png:icons/silk/disk.png - - @@ -225,7 +205,6 @@ nameEdit quitButton - saveButton