src/EditProfileMash.cpp

changeset 51
355100088e1f
parent 50
571a13a4860b
child 55
2d8dbbc1ffab
equal deleted inserted replaced
50:571a13a4860b 51:355100088e1f
52 this->steps = QJsonDocument::fromJson(formattedJson.toUtf8()); 52 this->steps = QJsonDocument::fromJson(formattedJson.toUtf8());
53 } 53 }
54 54
55 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditProfileMash::is_changed); 55 connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditProfileMash::is_changed);
56 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); 56 connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
57 connect(ui->stepsTable, SIGNAL(cellPressed(int, int)), this, SLOT(cell_Changed(int, int))); 57 connect(ui->stepsTable, SIGNAL(cellChanged(int, int)), this, SLOT(cell_Changed(int, int)));
58 58
59 ui->saveButton->setEnabled(false); 59 ui->saveButton->setEnabled(false);
60 ui->deleteButton->setEnabled((id >= 0) ? true:false); 60 ui->deleteButton->setEnabled((id >= 0) ? true:false);
61 61
62 emit refreshTable(); 62 emit refreshTable();
69 { 69 {
70 QString w; 70 QString w;
71 QWidget* pWidget; 71 QWidget* pWidget;
72 QHBoxLayout* pLayout; 72 QHBoxLayout* pLayout;
73 double d; 73 double d;
74 int total; 74 int total = 0;
75 75
76 qDebug() << "Steps reload"; 76 qDebug() << "refreshTable" << this->steps << this->steps.isArray() << this->steps.array().size() ;
77 /* During filling the table turn off the cellChanged signal because every cell that is filled
78 * triggers the cellChanged signal. The QTableWidget has no better signal to use. */
79 this->ignoreChanges = true;
77 80
78 const QStringList labels({tr("Step name"), tr("Type"), tr("Start °C"), tr("End °C"), tr("Rest time"), tr("Ramp time"), tr("Button")}); 81 const QStringList labels({tr("Step name"), tr("Type"), tr("Start °C"), tr("End °C"), tr("Rest time"), tr("Ramp time"), tr("Button")});
79 ui->stepsTable->setColumnCount(7); 82 ui->stepsTable->setColumnCount(7);
80 ui->stepsTable->setColumnWidth(0, 250); /* Step name */ 83 ui->stepsTable->setColumnWidth(0, 250); /* Step name */
81 ui->stepsTable->setColumnWidth(1, 150); /* Step type */ 84 ui->stepsTable->setColumnWidth(1, 150); /* Step type */
84 ui->stepsTable->setColumnWidth(4, 75); /* Step time */ 87 ui->stepsTable->setColumnWidth(4, 75); /* Step time */
85 ui->stepsTable->setColumnWidth(5, 75); /* Ramp time */ 88 ui->stepsTable->setColumnWidth(5, 75); /* Ramp time */
86 ui->stepsTable->setColumnWidth(6, 80); /* Button */ 89 ui->stepsTable->setColumnWidth(6, 80); /* Button */
87 ui->stepsTable->setHorizontalHeaderLabels(labels); 90 ui->stepsTable->setHorizontalHeaderLabels(labels);
88 ui->stepsTable->verticalHeader()->hide(); 91 ui->stepsTable->verticalHeader()->hide();
89
90 qDebug() << " ** " << this->steps << this->steps.isArray() << this->steps.array().size() ;
91
92 total = 0;
93 ui->stepsTable->setRowCount(this->steps.array().size()); 92 ui->stepsTable->setRowCount(this->steps.array().size());
94 93
95 if (this->steps.isArray()) { 94 if (this->steps.isArray()) {
96 for (int i = 0; i < this->steps.array().size(); i++) { 95 for (int i = 0; i < this->steps.array().size(); i++) {
97 QJsonObject obj = this->steps.array().at(i).toObject(); 96 QJsonObject obj = this->steps.array().at(i).toObject();
98 qDebug() << i << obj;
99 97
100 ui->stepsTable->setItem(i, 0, new QTableWidgetItem(obj["step_name"].toString())); 98 ui->stepsTable->setItem(i, 0, new QTableWidgetItem(obj["step_name"].toString()));
101 99
100 /* Adding step_type 0, 1 or 2 as combobox. */
102 QComboBox* myComboBox = new QComboBox(); 101 QComboBox* myComboBox = new QComboBox();
103 myComboBox->addItem(tr("Infusion")); 102 myComboBox->addItem(tr("Infusion"));
104 myComboBox->addItem(tr("Temperature")); 103 myComboBox->addItem(tr("Temperature"));
105 myComboBox->addItem(tr("Decoction")); 104 myComboBox->addItem(tr("Decoction"));
106 ui->stepsTable->setCellWidget(i, 1, myComboBox); 105 ui->stepsTable->setCellWidget(i, 1, myComboBox);
107 if (obj["step_type"].isString()) 106 if (obj["step_type"].isString())
108 d = QString(obj["step_type"].toString()).toDouble(); 107 d = QString(obj["step_type"].toString()).toDouble();
109 else 108 else
110 d = obj["step_type"].toDouble(); 109 d = obj["step_type"].toDouble();
111 myComboBox->setCurrentIndex((int)d); 110 myComboBox->setCurrentIndex((int)d);
112 111 connect<void(QComboBox::*)(int)>(myComboBox, &QComboBox::currentIndexChanged, this, &EditProfileMash::combo_Changed);
112
113 /* Numbers can be double quoted or not, the old application could do this wrong. */
113 if (obj["step_temp"].isString()) 114 if (obj["step_temp"].isString())
114 d = QString(obj["step_temp"].toString()).toDouble(); 115 d = QString(obj["step_temp"].toString()).toDouble();
115 else 116 else
116 d = obj["step_temp"].toDouble(); 117 d = obj["step_temp"].toDouble();
117 w = QString("%1").arg(d, 2, 'f', 1, '0'); 118 w = QString("%1").arg(d, 2, 'f', 1, '0');
163 } 164 }
164 } 165 }
165 166
166 /* Show the calculated total mash time. */ 167 /* Show the calculated total mash time. */
167 ui->totalEdit->setText(QString("%1:%2").arg(total / 60).arg(total % 60, 2, 'f', 0, '0')); 168 ui->totalEdit->setText(QString("%1:%2").arg(total / 60).arg(total % 60, 2, 'f', 0, '0'));
169 this->ignoreChanges = false;
168 } 170 }
169 171
170 172
171 EditProfileMash::~EditProfileMash() 173 EditProfileMash::~EditProfileMash()
172 { 174 {
308 } 310 }
309 311
310 312
311 void EditProfileMash::cell_Changed(int nRow, int nCol) 313 void EditProfileMash::cell_Changed(int nRow, int nCol)
312 { 314 {
315 if (this->ignoreChanges)
316 return;
317
313 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked."; 318 qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked.";
314 319
315 make_Json(); 320 make_Json();
316 //ui->stepsTable->sortItems(2, Qt::AscendingOrder); // Sort on temp 321 //ui->stepsTable->sortItems(2, Qt::AscendingOrder); // Sort on temp
322 }
323
324
325 void EditProfileMash::combo_Changed()
326 {
327 qDebug() << "combo_Changed" << Q_FUNC_INFO;
328 make_Json();
317 } 329 }
318 330
319 331
320 void EditProfileMash::on_addButton_clicked() 332 void EditProfileMash::on_addButton_clicked()
321 { 333 {

mercurial