src/EditProfileMash.cpp

changeset 50
571a13a4860b
parent 49
29cf6e350063
child 51
355100088e1f
equal deleted inserted replaced
49:29cf6e350063 50:571a13a4860b
271 this->textIsChanged = true; 271 this->textIsChanged = true;
272 WindowTitle(); 272 WindowTitle();
273 } 273 }
274 274
275 275
276 /*
277 * Rebuild the json string from the table contents.
278 */
279 void EditProfileMash::make_Json()
280 {
281 QTableWidgetItem *item;
282 QJsonArray array;
283
284 for (int i = 0; i < ui->stepsTable->rowCount(); i++) {
285
286 QJsonObject obj;
287 item = ui->stepsTable->item(i, 0);
288 obj.insert("step_name", item->text());
289 QWidget *widget = ui->stepsTable->cellWidget(i, 1);
290 obj.insert("step_type", static_cast<QComboBox*>(widget)->currentIndex() );
291 item = ui->stepsTable->item(i, 2);
292 obj.insert("step_temp", item->text().toDouble());
293 item = ui->stepsTable->item(i, 3);
294 obj.insert("end_temp", item->text().toDouble());
295 item = ui->stepsTable->item(i, 4);
296 obj.insert("step_time", item->text().toInt());
297 item = ui->stepsTable->item(i, 5);
298 obj.insert("ramp_time", item->text().toInt());
299 qDebug() << "make_Json" << i << obj;
300 array.append(obj); /* Append this object */
301 }
302
303 qDebug() << array;
304 /* Copy to the global array and refresh */
305 this->steps.setArray(array);
306 is_changed();
307 emit refreshTable();
308 }
309
310
276 void EditProfileMash::cell_Changed(int nRow, int nCol) 311 void EditProfileMash::cell_Changed(int nRow, int nCol)
277 { 312 {
278 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked."; 313 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked.";
279 314
315 make_Json();
280 //ui->stepsTable->sortItems(2, Qt::AscendingOrder); // Sort on temp 316 //ui->stepsTable->sortItems(2, Qt::AscendingOrder); // Sort on temp
281 } 317 }
282 318
283 319
284 void EditProfileMash::on_addButton_clicked() 320 void EditProfileMash::on_addButton_clicked()
285 { 321 {
286 qDebug() << "Add cell"; 322 qDebug() << "Add row";
323
324 make_Json();
287 } 325 }
288 326
289 327
290 void EditProfileMash::on_deleteRow_clicked() 328 void EditProfileMash::on_deleteRow_clicked()
291 { 329 {
292 qDebug() << "Delete row"; 330 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
331 int row = pb->objectName().toInt();
332 //qDebug() << Q_FUNC_INFO << row;
333 qDebug() << "Delete row" << row;
334 ui->stepsTable->removeRow(row);
335 make_Json();
293 } 336 }
294 337
295 338
296 void EditProfileMash::on_quitButton_clicked() 339 void EditProfileMash::on_quitButton_clicked()
297 { 340 {

mercurial