Show changes in the steps table. Delete row implemented.

Mon, 07 Mar 2022 21:50:09 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 07 Mar 2022 21:50:09 +0100
changeset 50
571a13a4860b
parent 49
29cf6e350063
child 51
355100088e1f

Show changes in the steps table. Delete row implemented.

src/EditProfileMash.cpp file | annotate | diff | comparison | revisions
src/EditProfileMash.h file | annotate | diff | comparison | revisions
--- a/src/EditProfileMash.cpp	Mon Mar 07 17:33:22 2022 +0100
+++ b/src/EditProfileMash.cpp	Mon Mar 07 21:50:09 2022 +0100
@@ -273,23 +273,66 @@
 }
 
 
+/*
+ * Rebuild the json string from the table contents.
+ */
+void EditProfileMash::make_Json()
+{
+    QTableWidgetItem *item;
+    QJsonArray array;
+
+    for (int i = 0; i < ui->stepsTable->rowCount(); i++) {
+
+	QJsonObject obj;
+	item = ui->stepsTable->item(i, 0);
+	obj.insert("step_name", item->text());
+	QWidget *widget = ui->stepsTable->cellWidget(i, 1);
+        obj.insert("step_type", static_cast<QComboBox*>(widget)->currentIndex() );
+	item = ui->stepsTable->item(i, 2);
+	obj.insert("step_temp", item->text().toDouble());
+	item = ui->stepsTable->item(i, 3);
+        obj.insert("end_temp", item->text().toDouble());
+	item = ui->stepsTable->item(i, 4);
+        obj.insert("step_time", item->text().toInt());
+	item = ui->stepsTable->item(i, 5);
+        obj.insert("ramp_time", item->text().toInt());
+	qDebug() << "make_Json" << i << obj;
+	array.append(obj);	/* Append this object */
+    }
+
+    qDebug() << array;
+    /* Copy to the global array and refresh */
+    this->steps.setArray(array);
+    is_changed();
+    emit refreshTable();
+}
+
+
 void EditProfileMash::cell_Changed(int nRow, int nCol)
 {
     qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked.";
 
+    make_Json();
     //ui->stepsTable->sortItems(2, Qt::AscendingOrder);	// Sort on temp
 }
 
 
 void EditProfileMash::on_addButton_clicked()
 {
-    qDebug() << "Add cell";
+    qDebug() << "Add row";
+
+    make_Json();
 }
 
 
 void EditProfileMash::on_deleteRow_clicked()
 {
-    qDebug() << "Delete row";
+    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
+    int row = pb->objectName().toInt();
+    //qDebug() << Q_FUNC_INFO << row;
+    qDebug() << "Delete row" << row;
+    ui->stepsTable->removeRow(row);
+    make_Json();
 }
 
 
--- a/src/EditProfileMash.h	Mon Mar 07 17:33:22 2022 +0100
+++ b/src/EditProfileMash.h	Mon Mar 07 21:50:09 2022 +0100
@@ -24,6 +24,7 @@
     void on_quitButton_clicked();
     void on_deleteButton_clicked();
     void is_changed();
+    void make_Json();
     void refreshTable(void);
     void cell_Changed(int nRow, int nCol);
     void on_addButton_clicked();

mercurial