Added mash table replace

Tue, 19 Apr 2022 22:27:18 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 19 Apr 2022 22:27:18 +0200
changeset 147
af1386a6ece7
parent 146
aad2f9f38fc5
child 148
ba25a566b100

Added mash table replace

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.h file | annotate | diff | comparison | revisions
src/EditRecipeTab6.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Tue Apr 19 21:26:56 2022 +0200
+++ b/src/EditRecipe.cpp	Tue Apr 19 22:27:18 2022 +0200
@@ -685,7 +685,7 @@
     // All signals from tab "Mash"
     ui->mashsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
     connect(ui->addMash, SIGNAL(clicked()), this, SLOT(addMashRow_clicked()));
-    //connect(ui->mash_pickEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::mash_select_changed);
+    connect(ui->mash_pickEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::mash_select_changed);
 
     // All signals from tab "Water"
     connect(ui->bs_cacl2Edit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::wb_cacl2_changed);
--- a/src/EditRecipe.h	Tue Apr 19 21:26:56 2022 +0200
+++ b/src/EditRecipe.h	Tue Apr 19 22:27:18 2022 +0200
@@ -327,6 +327,7 @@
     void step_time_changed(double val);
     void ramp_time_changed(double val);
     void infuse_changed(double val);
+    void mash_select_changed(int val);
 
     /* Modified progress bars */
     void ferment_perc_mash_valueChanged(int value);
--- a/src/EditRecipeTab6.cpp	Tue Apr 19 21:26:56 2022 +0200
+++ b/src/EditRecipeTab6.cpp	Tue Apr 19 22:27:18 2022 +0200
@@ -84,7 +84,7 @@
         item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
         ui->mashsTable->setItem(i, 5, item);
 
-	if (recipe->mashs.at(i).step_infuse_amount) {
+	if (recipe->mashs.at(i).step_infuse_amount > 0) {
 	    item = new QTableWidgetItem(QString("%1 L").arg(recipe->mashs.at(i).step_infuse_amount, 2, 'f', 1, '0'));
             item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
             ui->mashsTable->setItem(i, 6, item);
@@ -522,3 +522,70 @@
 }
 
 
+void EditRecipe::mash_select_changed(int val)
+{
+    QSqlQuery query;
+    int  i;
+
+    qDebug() << "mash_select_changed" << val;
+
+    query.prepare("SELECT name,steps FROM profile_mash ORDER BY name");
+    query.exec();
+    query.first();
+    for (i = 0; i < (val -1); i++) {
+	query.next();
+    }
+
+    QJsonParseError parseError;
+    const auto& json = query.value(1).toString();
+    if (!json.trimmed().isEmpty()) {
+	const auto& formattedJson = QString("%1").arg(json);
+	QJsonDocument newsteps = QJsonDocument::fromJson(formattedJson.toUtf8(), &parseError);
+
+	if (parseError.error != QJsonParseError::NoError) {
+	    qDebug() << "Parse error: " << parseError.errorString() << "at" << parseError.offset;
+	} else {
+	    /*
+	     * Got the json data in the steps array, replace the recipe steps.
+	     */
+	    recipe->mashs.clear();
+	    ui->mashsTable->clear();
+	    if (newsteps.isArray()) {
+		for (i = 0; i < newsteps.array().size(); i++) {
+		    QJsonObject obj = newsteps.array().at(i).toObject();
+		    Mashs m;
+		    m.step_name = obj["step_name"].toString();
+		    if (obj["step_type"].isString())
+			m.step_type = QString(obj["step_type"].toString()).toInt();
+		    else
+		        m.step_type = obj["step_type"].toInt();
+		    m.step_volume = 0;
+		    m.step_infuse_amount = 0;
+		    m.step_infuse_temp = 0;
+		    if (obj["step_temp"].isString())
+			m.step_temp = QString(obj["step_temp"].toString()).toDouble();
+		    else
+		        m.step_temp = obj["step_temp"].toDouble();
+		    if (obj["step_time"].isString())
+			m.step_time = QString(obj["step_time"].toString()).toDouble();
+		    else
+		        m.step_time = obj["step_time"].toDouble();
+		    if (obj["ramp_time"].isString())
+			m.ramp_time = QString(obj["ramp_time"].toString()).toDouble();
+		    else
+		        m.ramp_time = obj["ramp_time"].toDouble();
+		    if (obj["end_temp"].isString())
+			m.end_temp = QString(obj["end_temp"].toString()).toDouble();
+		    else
+		        m.end_temp = obj["end_temp"].toDouble();
+		    m.step_wg_ratio = 0;
+		    recipe->mashs.append(m);
+		}
+	    }
+	}
+    }
+    is_changed();
+    emit refreshAll();
+}
+
+

mercurial