Sat, 14 Oct 2023 11:23:24 +0200
Load and show current calibration data.
--- 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
--- 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 <http://www.gnu.org/licenses/>. */ #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<QPushButton *>(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); +} +
--- 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 <QDialog> -#include <QDoubleSpinBox> -#include <QCheckBox> -#include <QComboBox> -#include <QRadioButton> -#include <QLineEdit> +// #include <QDoubleSpinBox> +// #include <QCheckBox> +// #include <QComboBox> +// #include <QRadioButton> +// #include <QLineEdit> #include <QDialogButtonBox> +#include <QJsonDocument> + +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
--- 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 @@ <context> <name>CalibrateiSpindel</name> <message> - <location filename="../src/CalibrateiSpindel.cpp" line="34"/> - <source>BMSapp - Calibrate iSpindel</source> + <location filename="../ui/CalibrateiSpindel.ui" line="14"/> + <source>Dialog</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="29"/> + <source>Name:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="114"/> + <source>Data:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="130"/> + <source>Add</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="147"/> + <source>Old formula:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="163"/> + <source>New formula:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="67"/> + <source>Quit</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="87"/> + <source>Save</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <source>SG</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <source>°Plato</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <source>Angle</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <location filename="../src/CalibrateiSpindel.cpp" line="138"/> + <source>Del</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="202"/> + <source>BMSapp - Calibrate iSpindel %1</source> <translation type="unfinished"></translation> </message> </context>
--- 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 @@ <context> <name>CalibrateiSpindel</name> <message> + <location filename="../ui/CalibrateiSpindel.ui" line="14"/> <source>Dialog</source> - <translation type="obsolete">Dialog</translation> + <translation type="unfinished">Dialog</translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="29"/> + <source>Name:</source> + <translation type="unfinished">Naam:</translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="114"/> + <source>Data:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="130"/> + <source>Add</source> + <translation type="unfinished">Nieuw</translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="147"/> + <source>Old formula:</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="163"/> + <source>New formula:</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Name of the fermentation profile</source> + <translation type="obsolete">Naam van het vergisting profiel</translation> + </message> + <message> + <location filename="../ui/CalibrateiSpindel.ui" line="87"/> + <source>Save</source> + <translation type="unfinished">Bewaar</translation> + </message> + <message> + <source>Steps:</source> + <translation type="obsolete">Stappen:</translation> + </message> + <message> + <source>Add step</source> + <translation type="obsolete">Nieuwe stap</translation> </message> <message> <source>Uuid:</source> @@ -96,12 +139,34 @@ <translation type="obsolete">iSpindel overzicht</translation> </message> <message> + <location filename="../ui/CalibrateiSpindel.ui" line="67"/> <source>Quit</source> - <translation type="obsolete">Terug</translation> - </message> - <message> - <location filename="../src/CalibrateiSpindel.cpp" line="34"/> - <source>BMSapp - Calibrate iSpindel</source> + <translation type="unfinished">Terug</translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <source>SG</source> + <translation type="unfinished">SG</translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <source>°Plato</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <source>Angle</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="106"/> + <location filename="../src/CalibrateiSpindel.cpp" line="138"/> + <source>Del</source> + <translation type="unfinished"></translation> + </message> + <message> + <location filename="../src/CalibrateiSpindel.cpp" line="202"/> + <source>BMSapp - Calibrate iSpindel %1</source> <translation type="unfinished"></translation> </message> </context>
--- /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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>CalibrateiSpindel</class> + <widget class="QDialog" name="CalibrateiSpindel"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1024</width> + <height>560</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QWidget" name="topWidget" native="true"> + <widget class="QLabel" name="nameLabel"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>91</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Name:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + <widget class="QLineEdit" name="nameEdit"> + <property name="geometry"> + <rect> + <x>110</x> + <y>10</y> + <width>391</width> + <height>23</height> + </rect> + </property> + <property name="maxLength"> + <number>128</number> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton" name="quitButton"> + <property name="geometry"> + <rect> + <x>110</x> + <y>510</y> + <width>80</width> + <height>23</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Quit</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:icons/silk/door_out.png</normaloff>:icons/silk/door_out.png</iconset> + </property> + </widget> + <widget class="QPushButton" name="saveButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="geometry"> + <rect> + <x>820</x> + <y>510</y> + <width>80</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Save</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:icons/silk/disk.png</normaloff>:icons/silk/disk.png</iconset> + </property> + </widget> + <widget class="QTableWidget" name="dataTable"> + <property name="geometry"> + <rect> + <x>110</x> + <y>100</y> + <width>361</width> + <height>381</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="dataLabel"> + <property name="geometry"> + <rect> + <x>10</x> + <y>100</y> + <width>91</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Data:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + <widget class="QPushButton" name="addButton"> + <property name="geometry"> + <rect> + <x>10</x> + <y>160</y> + <width>91</width> + <height>23</height> + </rect> + </property> + <property name="text"> + <string>Add</string> + </property> + <property name="icon"> + <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"> + <normaloff>:/icons/silk/add.png</normaloff>:/icons/silk/add.png</iconset> + </property> + </widget> + <widget class="QLabel" name="oldLabel"> + <property name="geometry"> + <rect> + <x>10</x> + <y>40</y> + <width>91</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>Old formula:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + <widget class="QLabel" name="newLabel"> + <property name="geometry"> + <rect> + <x>10</x> + <y>70</y> + <width>91</width> + <height>20</height> + </rect> + </property> + <property name="text"> + <string>New formula:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + <widget class="QLineEdit" name="oldEdit"> + <property name="geometry"> + <rect> + <x>110</x> + <y>40</y> + <width>541</width> + <height>23</height> + </rect> + </property> + <property name="maxLength"> + <number>128</number> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + <widget class="QLineEdit" name="newEdit"> + <property name="geometry"> + <rect> + <x>110</x> + <y>70</y> + <width>541</width> + <height>23</height> + </rect> + </property> + <property name="maxLength"> + <number>128</number> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>nameEdit</tabstop> + <tabstop>quitButton</tabstop> + <tabstop>saveButton</tabstop> + </tabstops> + <resources> + <include location="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"/> + </resources> + <connections/> +</ui>