When editing mash step cells the table is updated. The combobox changes are finally working too.

Tue, 08 Mar 2022 16:15:31 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 08 Mar 2022 16:15:31 +0100
changeset 51
355100088e1f
parent 50
571a13a4860b
child 52
ff7b3a41c9b5

When editing mash step cells the table is updated. The combobox changes are finally working too.

src/EditProfileMash.cpp file | annotate | diff | comparison | revisions
src/EditProfileMash.h file | annotate | diff | comparison | revisions
--- a/src/EditProfileMash.cpp	Mon Mar 07 21:50:09 2022 +0100
+++ b/src/EditProfileMash.cpp	Tue Mar 08 16:15:31 2022 +0100
@@ -54,7 +54,7 @@
 
     connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditProfileMash::is_changed);
     connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
-    connect(ui->stepsTable, SIGNAL(cellPressed(int, int)), this, SLOT(cell_Changed(int, int)));
+    connect(ui->stepsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
 
     ui->saveButton->setEnabled(false);
     ui->deleteButton->setEnabled((id >= 0) ? true:false);
@@ -71,9 +71,12 @@
     QWidget* pWidget;
     QHBoxLayout* pLayout;
     double  d;
-    int	total;
+    int	total = 0;
 
-    qDebug() << "Steps reload";
+    qDebug() << "refreshTable" << this->steps << this->steps.isArray() << this->steps.array().size() ;
+    /* 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("Step name"), tr("Type"), tr("Start °C"), tr("End °C"), tr("Rest time"), tr("Ramp time"), tr("Button")});
     ui->stepsTable->setColumnCount(7);
@@ -86,19 +89,15 @@
     ui->stepsTable->setColumnWidth(6,  80);	/* Button	*/
     ui->stepsTable->setHorizontalHeaderLabels(labels);
     ui->stepsTable->verticalHeader()->hide();
-
-    qDebug() << " ** " << this->steps << this->steps.isArray() << this->steps.array().size() ;
-
-    total = 0;
     ui->stepsTable->setRowCount(this->steps.array().size());
 
     if (this->steps.isArray()) {
 	for (int i = 0; i < this->steps.array().size(); i++) {
 	    QJsonObject obj = this->steps.array().at(i).toObject();
-	    qDebug() << i << obj;
 
 	    ui->stepsTable->setItem(i, 0, new QTableWidgetItem(obj["step_name"].toString()));
 
+	    /* Adding step_type 0, 1 or 2 as combobox. */
 	    QComboBox* myComboBox = new QComboBox();
 	    myComboBox->addItem(tr("Infusion"));
 	    myComboBox->addItem(tr("Temperature"));
@@ -109,7 +108,9 @@
 	    else
 		d = obj["step_type"].toDouble();
 	    myComboBox->setCurrentIndex((int)d);
+	    connect<void(QComboBox::*)(int)>(myComboBox, &QComboBox::currentIndexChanged, this, &EditProfileMash::combo_Changed);
 
+	    /* Numbers can be double quoted or not, the old application could do this wrong. */
 	    if (obj["step_temp"].isString())
 		d = QString(obj["step_temp"].toString()).toDouble();
 	    else
@@ -165,6 +166,7 @@
 
     /* Show the calculated total mash time. */
     ui->totalEdit->setText(QString("%1:%2").arg(total / 60).arg(total % 60, 2, 'f', 0, '0'));
+    this->ignoreChanges = false;
 }
 
 
@@ -310,6 +312,9 @@
 
 void EditProfileMash::cell_Changed(int nRow, int nCol)
 {
+    if (this->ignoreChanges)
+	return;
+
     qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked.";
 
     make_Json();
@@ -317,6 +322,13 @@
 }
 
 
+void EditProfileMash::combo_Changed()
+{
+    qDebug() << "combo_Changed" << Q_FUNC_INFO;
+    make_Json();
+}
+
+
 void EditProfileMash::on_addButton_clicked()
 {
     qDebug() << "Add row";
--- a/src/EditProfileMash.h	Mon Mar 07 21:50:09 2022 +0100
+++ b/src/EditProfileMash.h	Tue Mar 08 16:15:31 2022 +0100
@@ -27,6 +27,7 @@
     void make_Json();
     void refreshTable(void);
     void cell_Changed(int nRow, int nCol);
+    void combo_Changed();
     void on_addButton_clicked();
     void on_deleteRow_clicked();
 
@@ -34,6 +35,7 @@
     Ui::EditProfileMash *ui;
     int recno;
     bool textIsChanged = false;
+    bool ignoreChanges = false;
     QJsonDocument steps;
 
     void WindowTitle();

mercurial