# HG changeset patch # User Michiel Broek # Date 1697275404 -7200 # Node ID 7ae4d022cf8f827ca29cb004e1af6ff221712039 # Parent ea7cf64c9a6c547e836421fdc79491dd6aea37e7 Load and show current calibration data. diff -r ea7cf64c9a6c -r 7ae4d022cf8f CMakeLists.txt --- a/CMakeLists.txt Fri Oct 13 15:36:15 2023 +0200 +++ b/CMakeLists.txt Sat Oct 14 11:23:24 2023 +0200 @@ -344,6 +344,7 @@ ${UIDIR}/DetailFermenter.ui ${UIDIR}/DetailCO2meter.ui ${UIDIR}/DetailiSpindel.ui + ${UIDIR}/CalibrateiSpindel.ui ${UIDIR}/ImportXML.ui ${UIDIR}/ImportBrew.ui ${UIDIR}/MainWindow.ui diff -r ea7cf64c9a6c -r 7ae4d022cf8f src/CalibrateiSpindel.cpp --- a/src/CalibrateiSpindel.cpp Fri Oct 13 15:36:15 2023 +0200 +++ b/src/CalibrateiSpindel.cpp Sat Oct 14 11:23:24 2023 +0200 @@ -15,6 +15,7 @@ * along with this program. If not, see . */ #include "CalibrateiSpindel.h" +#include "../ui/ui_CalibrateiSpindel.h" #include "global.h" #include "Utils.h" #include "MainWindow.h" @@ -29,31 +30,10 @@ qDebug() << "CalibrateiSpindel record:" << id; #endif - gridLayout = new QGridLayout(this); - gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - tableCalData = new QTableWidget(this); - tableCalData->setObjectName(QString::fromUtf8("tableCalData")); - tableCalData->setEnabled(true); - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - tableCalData->setSizePolicy(sizePolicy); - tableCalData->setMinimumSize(QSize(1024, 0)); - gridLayout->addWidget(tableCalData, 0, 0, 1, 1); - -// ui->setupUi(this); -// this->recno = id; -// setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); -// setWindowTitle(tr("BMSapp - Calibrate iSpindel")); - -// connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); -// emit refreshTable(); -} - - -void CalibrateiSpindel::refreshTable() -{ - QSqlQuery query; + ui->setupUi(this); + this->recno = id; + setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); + WindowTitle(); query.prepare("SELECT node,alias,calibrate FROM mon_ispindels WHERE record = :recno"); query.bindValue(":recno", this->recno); @@ -62,17 +42,115 @@ _node = query.value("node").toString(); _alias = query.value("alias").toString(); - _data_old = query.value("calibrate").toString(); - _data_new = query.value("calibrate").toString(); + ui->nameEdit->setText(_node+"/"+_alias); + + QJsonParseError parseError; + const auto& json = query.value("calibrate").toString(); + + if (!json.trimmed().isEmpty()) { + const auto& formattedJson = QString("%1").arg(json); + QJsonDocument jsonResponse = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError); + if (parseError.error != QJsonParseError::NoError) { + qWarning() << "Parse error: " << parseError.errorString() << "at" << parseError.offset ; + } else { + + QJsonObject jsonObj = jsonResponse.object(); +// qDebug() << "polyData: " << jsonObj["polyData"].toArray(); + QJsonArray polyData = jsonObj.value("polyData").toArray(); +// qDebug() << polyData; + for (int i = 0; i < polyData.size(); i++) { + Old[i] = New[i] = polyData.at(i).toDouble(); + qDebug() << i << New[i]; + } + _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'); + ui->oldEdit->setText(_data_old); + + qDebug() << "calData: " << jsonObj["calData"].toArray(); + QJsonArray calData = jsonObj.value("calData").toArray(); + qDebug() << calData; + totaldata = 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); + totaldata++; + } + + } + } } + connect(ui->dataTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int))); +// connect(parent, SIGNAL(updateiSpindel(QString)), this, SLOT(refreshiSpindel(QString))); + emit refreshTable(); +} + + +void CalibrateiSpindel::refreshTable() +{ + QString w; + QWidget* pWidget; + QHBoxLayout* pLayout; + double d; + + qDebug() << "refreshTable" << totaldata; + + /* + * During filling the table turn off the cellChanged signal because every cell that is filled + * triggers the cellChanged signal. The QTableWidget has no better signal to use. + */ + this->ignoreChanges = true; + + const QStringList labels({tr("SG"), tr("°Plato"), tr("Angle"), tr("Del")}); + ui->dataTable->setColumnCount(4); + ui->dataTable->setColumnWidth(0, 100); /* SG */ + ui->dataTable->setColumnWidth(1, 100); /* °Plato */ + ui->dataTable->setColumnWidth(2, 100); /* Tilt angle */ + ui->dataTable->setColumnWidth(3, 55); /* Del button */ + ui->dataTable->setHorizontalHeaderLabels(labels); + ui->dataTable->verticalHeader()->hide(); + ui->dataTable->setRowCount(totaldata); + + for (int i = 0; i < totaldata; i++) { + qDebug() << i << nCal[i].sg << nCal[i].plato << nCal[i].angle; + + w = QString("%1").arg(nCal[i].sg, 1, 'f', 4, '0'); + QTableWidgetItem *item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); + 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); + 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); + ui->dataTable->setItem(i, 2, item); + + /* Add the Delete row button */ + pWidget = new QWidget(); + QPushButton* btn_del = new QPushButton(); + btn_del->setObjectName(QString("%1").arg(i)); /* Send row with the button */ + btn_del->setText(tr("Del")); + connect(btn_del, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked())); + pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(btn_del); + pLayout->setContentsMargins(5, 0, 5, 0); + pWidget->setLayout(pLayout); + ui->dataTable->setCellWidget(i, 3, pWidget); + } + + this->ignoreChanges = false; } CalibrateiSpindel::~CalibrateiSpindel() { -// delete ui; + delete ui; } @@ -83,3 +161,49 @@ } +void CalibrateiSpindel::on_saveButton_clicked() +{ +} + + +void CalibrateiSpindel::on_deleteRow_clicked() +{ + QPushButton *pb = qobject_cast(QObject::sender()); + int row = pb->objectName().toInt(); + qDebug() << "Delete row" << row; +} + + +void CalibrateiSpindel::on_addButton_clicked() +{ + qDebug() << "Add row" << totaldata; +} + + +void CalibrateiSpindel::cell_Changed(int nRow, int nCol) +{ + QString w; + + if (this->ignoreChanges) + return; + + qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was changed."; + +} + + +/* + * Window header, mark any change with '**' + */ +void CalibrateiSpindel::WindowTitle() +{ + QString txt; + + txt = QString(tr("BMSapp - Calibrate iSpindel %1").arg(this->recno)); + + if (this->textIsChanged) { + txt.append((QString(" **"))); + } + setWindowTitle(txt); +} + diff -r ea7cf64c9a6c -r 7ae4d022cf8f src/CalibrateiSpindel.h --- a/src/CalibrateiSpindel.h Fri Oct 13 15:36:15 2023 +0200 +++ b/src/CalibrateiSpindel.h Sat Oct 14 11:23:24 2023 +0200 @@ -2,12 +2,19 @@ #define _CALIBRATEISPINDEL_H #include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include #include +#include + +struct Calibrate { + double sg; + double plato; + double angle; +}; namespace Ui { @@ -18,18 +25,32 @@ { Q_OBJECT +signals: + void entry_changed(); + public: explicit CalibrateiSpindel(int id, QWidget *parent = 0); ~CalibrateiSpindel(); private slots: void on_quitButton_clicked(); + void on_saveButton_clicked(); void refreshTable(void); + void on_addButton_clicked(); + void on_deleteRow_clicked(); + void cell_Changed(int nRow, int nCol); private: Ui::CalibrateiSpindel *ui; QString _node, _alias, _data_old, _data_new; - int recno; + int recno, totaldata; + QJsonDocument data; + bool ignoreChanges = false; + bool textIsChanged = false; + double Old[4], New[4]; + Calibrate oCal[12], nCal[12]; + + void WindowTitle(); }; #endif diff -r ea7cf64c9a6c -r 7ae4d022cf8f translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Fri Oct 13 15:36:15 2023 +0200 +++ b/translations/bmsapp_en.ts Sat Oct 14 11:23:24 2023 +0200 @@ -50,8 +50,69 @@ CalibrateiSpindel - - BMSapp - Calibrate iSpindel + + Dialog + + + + + Name: + + + + + Data: + + + + + Add + + + + + Old formula: + + + + + New formula: + + + + + Quit + + + + + Save + + + + + SG + + + + + °Plato + + + + + Angle + + + + + + Del + + + + + BMSapp - Calibrate iSpindel %1 diff -r ea7cf64c9a6c -r 7ae4d022cf8f translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Fri Oct 13 15:36:15 2023 +0200 +++ b/translations/bmsapp_nl.ts Sat Oct 14 11:23:24 2023 +0200 @@ -80,8 +80,51 @@ CalibrateiSpindel + Dialog - Dialog + Dialog + + + + Name: + Naam: + + + + Data: + + + + + Add + Nieuw + + + + Old formula: + + + + + New formula: + + + + Name of the fermentation profile + Naam van het vergisting profiel + + + + Save + Bewaar + + + Steps: + Stappen: + + + Add step + Nieuwe stap Uuid: @@ -96,12 +139,34 @@ iSpindel overzicht + Quit - Terug - - - - BMSapp - Calibrate iSpindel + Terug + + + + SG + SG + + + + °Plato + + + + + Angle + + + + + + Del + + + + + BMSapp - Calibrate iSpindel %1 diff -r ea7cf64c9a6c -r 7ae4d022cf8f ui/CalibrateiSpindel.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/CalibrateiSpindel.ui Sat Oct 14 11:23:24 2023 +0200 @@ -0,0 +1,214 @@ + + + CalibrateiSpindel + + + + 0 + 0 + 1024 + 560 + + + + Dialog + + + + + + + + 10 + 10 + 91 + 20 + + + + Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 10 + 391 + 23 + + + + 128 + + + true + + + + + + 110 + 510 + 80 + 23 + + + + + 0 + 0 + + + + Quit + + + + :icons/silk/door_out.png:icons/silk/door_out.png + + + + + false + + + + 820 + 510 + 80 + 23 + + + + Save + + + + :icons/silk/disk.png:icons/silk/disk.png + + + + + + 110 + 100 + 361 + 381 + + + + + + + 10 + 100 + 91 + 20 + + + + Data: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 10 + 160 + 91 + 23 + + + + Add + + + + :/icons/silk/add.png:/icons/silk/add.png + + + + + + 10 + 40 + 91 + 20 + + + + Old formula: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 10 + 70 + 91 + 20 + + + + New formula: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 40 + 541 + 23 + + + + 128 + + + true + + + + + + 110 + 70 + 541 + 23 + + + + 128 + + + true + + + + + + + + nameEdit + quitButton + saveButton + + + + + +