Finished the profile mash editor.

Thu, 17 Mar 2022 11:24:05 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 17 Mar 2022 11:24:05 +0100
changeset 58
27eaf3a22c1a
parent 57
75d11cc05ce4
child 59
6190b58dcace

Finished the profile mash editor.

src/EditProfileMash.cpp file | annotate | diff | comparison | revisions
--- a/src/EditProfileMash.cpp	Wed Mar 16 21:26:31 2022 +0100
+++ b/src/EditProfileMash.cpp	Thu Mar 17 11:24:05 2022 +0100
@@ -73,7 +73,7 @@
     double  d;
     int	total = 0;
 
-    qDebug() << "refreshTable" << this->steps << this->steps.isArray() << this->steps.array().size() ;
+//    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;
@@ -210,14 +210,13 @@
 
     if (this->textIsChanged) {
     	if (this->recno == -1) {
-    	    query.prepare("INSERT INTO profile_mash SET name=:name, notes=:notes, "
-		"uuid = :uuid");
+    	    query.prepare("INSERT INTO profile_mash SET name=:name, notes=:notes, steps=:steps, uuid=:uuid");
     	} else {
-	    query.prepare("UPDATE profile_mash SET name=:name, notes=:notes "
-                "WHERE record = :recno");
+	    query.prepare("UPDATE profile_mash SET name=:name, notes=:notes, steps=:steps WHERE record=:recno");
     	}
 	query.bindValue(":name", ui->nameEdit->text());
 	query.bindValue(":notes", ui->notesEdit->toPlainText());
+	query.bindValue(":steps", this->steps.toJson(QJsonDocument::Compact));
 
 	if (this->recno == -1) {
 	    query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
@@ -247,7 +246,7 @@
 {
     QSqlQuery query;
 
-    query.prepare("DELETE FROM profile_water WHERE record = :recno");
+    query.prepare("DELETE FROM profile_mash WHERE record = :recno");
     query.bindValue(":recno", this->recno);
     query.exec();
     if (query.lastError().isValid()) {
@@ -283,6 +282,8 @@
     QTableWidgetItem *item;
     QJsonArray array;
 
+    ui->stepsTable->sortItems(2, Qt::AscendingOrder);   // Sort on temperature.
+
     for (int i = 0; i < ui->stepsTable->rowCount(); i++) {
 
 	QJsonObject obj;
@@ -298,11 +299,11 @@
         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;
+//	qDebug() << "make_Json" << i << obj;
 	array.append(obj);	/* Append this object */
     }
 
-    qDebug() << array;
+//    qDebug() << array;
     /* Copy to the global array and refresh */
     this->steps.setArray(array);
     is_changed();
@@ -315,24 +316,52 @@
     if (this->ignoreChanges)
 	return;
 
-    qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was double clicked.";
+    qDebug() << "Cell at row " + QString::number(nRow) + " column " + QString::number(nCol) + " was changed.";
 
+    // TODO: some checks and auto fixes.
     make_Json();
-    //ui->stepsTable->sortItems(2, Qt::AscendingOrder);	// Sort on temp
 }
 
 
 void EditProfileMash::combo_Changed()
 {
-    qDebug() << "combo_Changed" << Q_FUNC_INFO;
     make_Json();
 }
 
 
 void EditProfileMash::on_addButton_clicked()
 {
-    qDebug() << "Add row";
+    int total = ui->stepsTable->rowCount();
+    QWidget* pWidget;
+    QHBoxLayout* pLayout;
+
+    qDebug() << "Add row" << total;
+    this->ignoreChanges = true;
 
+    ui->stepsTable->insertRow(total);
+    ui->stepsTable->setItem(total, 0, new QTableWidgetItem(QString("new row %1").arg(total)));
+    QComboBox* myComboBox = new QComboBox();
+    myComboBox->addItem(tr("Infusion"));
+    myComboBox->addItem(tr("Temperature"));
+    myComboBox->addItem(tr("Decoction"));
+    myComboBox->setCurrentIndex(0);
+    ui->stepsTable->setCellWidget(total, 1, myComboBox);
+    ui->stepsTable->setItem(total, 2, new QTableWidgetItem(QString("65.0")));
+    ui->stepsTable->setItem(total, 3, new QTableWidgetItem(QString("65.0")));
+    ui->stepsTable->setItem(total, 4, new QTableWidgetItem(QString("20")));
+    ui->stepsTable->setItem(total, 5, new QTableWidgetItem(QString("10")));
+    pWidget = new QWidget();
+    QPushButton* btn_edit = new QPushButton();
+    btn_edit->setObjectName(QString("%1").arg(total));  /* Send row with the button */
+    btn_edit->setText(tr("Delete"));
+    connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_deleteRow_clicked()));
+    pLayout = new QHBoxLayout(pWidget);
+    pLayout->addWidget(btn_edit);
+    pLayout->setContentsMargins(5, 0, 5, 0);
+    pWidget->setLayout(pLayout);
+    ui->stepsTable->setCellWidget(total, 6, pWidget);
+
+    this->ignoreChanges = false;
     make_Json();
 }
 
@@ -341,7 +370,6 @@
 {
     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();
@@ -351,7 +379,7 @@
 void EditProfileMash::on_quitButton_clicked()
 {
     if (this->textIsChanged) {
-	int rc = QMessageBox::warning(this, tr("Mash changed"), tr("The mash profile has been modified\n Save changes?"),
+	int rc = QMessageBox::warning(this, tr("Mash changed"), tr("This mash profile has been modified. Save changes?"),
                                 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
         switch (rc) {
             case QMessageBox::Save:

mercurial