diff -r 29cf6e350063 -r 571a13a4860b src/EditProfileMash.cpp --- 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(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(QObject::sender()); + int row = pb->objectName().toInt(); + //qDebug() << Q_FUNC_INFO << row; + qDebug() << "Delete row" << row; + ui->stepsTable->removeRow(row); + make_Json(); }