Implemented recipe lock setting.

Thu, 28 Apr 2022 13:08:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 28 Apr 2022 13:08:20 +0200
changeset 171
6cd2d808d863
parent 170
d25e41da6be2
child 172
b93f5e5afc67

Implemented recipe lock setting.

src/EditRecipe.cpp file | annotate | diff | comparison | revisions
src/EditRecipe.h file | annotate | diff | comparison | revisions
src/EditRecipeTab1.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab2.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab3.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab4.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab5.cpp file | annotate | diff | comparison | revisions
src/EditRecipeTab6.cpp file | annotate | diff | comparison | revisions
--- a/src/EditRecipe.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipe.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -683,6 +683,7 @@
     connect(ui->est_ogEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::est_og_changed);
     connect(ui->color_methodEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::colormethod_changed);
     connect(ui->ibu_methodEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::ibumethod_changed);
+    connect(ui->lockedEdit, &QCheckBox::stateChanged, this, &EditRecipe::locked_changed);
 
     // All signals from tab "Fermentables"
     ui->fermentablesTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -733,8 +734,10 @@
     connect(ui->sp_acidtypeEdit, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &EditRecipe::sp_type_changed);
     connect(ui->sp_phEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditRecipe::sp_ph_changed);
 
+    setLocked(recipe->locked);
+
     ui->saveButton->setEnabled(false);
-    ui->deleteButton->setEnabled((id >= 0) ? true:false);
+    ui->deleteButton->setEnabled((id >= 0 && ! recipe->locked) ? true:false);
 
     emit refreshAll();
 }
@@ -1171,7 +1174,7 @@
 void EditRecipe::is_changed()
 {
     ui->saveButton->setEnabled(true);
-    ui->deleteButton->setEnabled((this->recno >= 0) ? true:false);
+    ui->deleteButton->setEnabled(((this->recno >= 0) ? true:false) && ! recipe->locked);
     this->textIsChanged = true;
     WindowTitle();
 }
--- a/src/EditRecipe.h	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipe.h	Thu Apr 28 13:08:20 2022 +0200
@@ -47,6 +47,7 @@
     void boil_time_changed(int val);
     void batch_size_changed(double val);
     void brew_type_changed(int val);
+    void locked_changed(bool val);
     void refreshFermentables();
     void refreshHops();
     void refreshMiscs();
@@ -140,7 +141,6 @@
     QString bar_100 = "QProgressBar::chunk {background: #80FF80;}";
     int recno;
     bool textIsChanged = false;
-//    Recipe *recipe;
     /*
      * Variables for popup ingredients editing.
      */
@@ -158,6 +158,7 @@
     static bool misc_sort_test(const Miscs &D1, const Miscs &D2);
     static bool yeast_sort_test(const Yeasts &D1, const Yeasts &D2);
     void WindowTitle();
+    void setLocked(bool val);
     void brewing_salt_sub(QString salt, double val);
     void set_brewing_salt(QString salt, double val);
     void calcFermentables();
--- a/src/EditRecipeTab1.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipeTab1.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -172,3 +172,96 @@
 }
 
 
+void EditRecipe::locked_changed(bool val)
+{
+    qDebug() << "locked_changed" << val;
+
+    recipe->locked = val;
+    setLocked(val);
+    is_changed();
+}
+
+
+void EditRecipe::setLocked(bool val)
+{
+    /* Tab 1, generic */
+    ui->typeEdit->setDisabled(val);
+    ui->color_methodEdit->setDisabled(val);
+    ui->ibu_methodEdit->setDisabled(val);
+    ui->beerstyleEdit->setDisabled(val);
+    ui->nameEdit->setReadOnly(val);
+    ui->notesEdit->setReadOnly(val);
+    ui->batch_sizeEdit->setReadOnly(val);
+    ui->batch_sizeEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->boil_sizeEdit->setReadOnly(val);
+    ui->boil_sizeEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->boil_timeEdit->setReadOnly(val);
+    ui->boil_timeEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->efficiencyEdit->setReadOnly(val);
+    ui->efficiencyEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->est_ogEdit->setReadOnly(val);
+    ui->est_ogEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+
+    /* Tab 2, fermentables */
+    ui->est_og2Edit->setReadOnly(val);
+    ui->est_og2Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->addFermentable->setEnabled(! val);
+
+    /* Tab 3, hops */
+    ui->addHop->setEnabled(! val);
+
+    /* Tab 4, miscs */
+    ui->addMisc->setEnabled(! val);
+
+    /* Tab 5, yeasts */
+    ui->addYeast->setEnabled(! val);
+
+    /* Tab 6, mash */
+    ui->addMash->setEnabled(! val);
+    ui->mash_nameEdit->setReadOnly(val);
+    ui->mash_pickEdit->setDisabled(val);
+
+    /* Tab 7, water */
+    ui->sp_sourceEdit->setDisabled(val);
+    ui->wt_sourceEdit->setDisabled(val);
+    ui->w1_nameEdit->setDisabled(val);
+    ui->w2_nameEdit->setDisabled(val);
+    ui->mw_acidPick->setDisabled(val);
+    ui->sp_acidtypeEdit->setDisabled(val);
+    ui->w2_volEdit->setReadOnly(val);
+    ui->w2_volEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->sp_phEdit->setReadOnly(val);
+    ui->sp_phEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->sp_tempEdit->setReadOnly(val);
+    ui->sp_tempEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->sp_volEdit->setReadOnly(val);
+    ui->sp_volEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_cacl2Edit->setReadOnly(val);
+    ui->bs_cacl2Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_caso4Edit->setReadOnly(val);
+    ui->bs_caso4Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_mgso4Edit->setReadOnly(val);
+    ui->bs_mgso4Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_naclEdit->setReadOnly(val);
+    ui->bs_naclEdit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_mgcl2Edit->setReadOnly(val);
+    ui->bs_mgcl2Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_nahco3Edit->setReadOnly(val);
+    ui->bs_nahco3Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    ui->bs_caco3Edit->setReadOnly(val);
+    ui->bs_caco3Edit->setButtonSymbols(val ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    if (val) {
+    	ui->mw_phEdit->setReadOnly(true);
+	ui->mw_phEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
+	ui->mw_acidvolEdit->setReadOnly(true);
+	ui->mw_acidvolEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
+    } else {
+    	ui->mw_phEdit->setReadOnly(! recipe->calc_acid);
+    	ui->mw_phEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::UpDownArrows : QAbstractSpinBox::NoButtons);
+    	ui->mw_acidvolEdit->setReadOnly(recipe->calc_acid);
+    	ui->mw_acidvolEdit->setButtonSymbols(recipe->calc_acid ? QAbstractSpinBox::NoButtons : QAbstractSpinBox::UpDownArrows);
+    }
+    ui->mw_autoEdit->setDisabled(val);
+}
+
+
--- a/src/EditRecipeTab2.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipeTab2.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -483,6 +483,9 @@
 
 void EditRecipe::deleteFermentRow_clicked()
 {
+    if (recipe->locked)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Delete fermentable row" << row << recipe->fermentables.size();
@@ -781,6 +784,9 @@
 {
     QSqlQuery query;
 
+    if (recipe->locked)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     recipe->fermentables_row = pb->objectName().toInt();
     qDebug() << "Edit fermentable row" << recipe->fermentables_row;
--- a/src/EditRecipeTab3.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipeTab3.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -241,13 +241,13 @@
 
 void EditRecipe::deleteHopRow_clicked()
 {
+    if (recipe->locked || recipe->hops.size() < 1)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Delete hop row" << row << recipe->hops.size();
 
-    if (recipe->hops.size() < 1)
-        return;
-
     int rc = QMessageBox::warning(this, tr("Delete hop"), tr("Delete %1").arg(recipe->hops.at(row).h_name),
                     QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
     if (rc == QMessageBox::No)
@@ -452,6 +452,9 @@
 {
     QSqlQuery query;
 
+    if (recipe->locked)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     recipe->hops_row = pb->objectName().toInt();
     qDebug() << "Edit hop row" << recipe->hops_row;
--- a/src/EditRecipeTab4.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipeTab4.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -280,13 +280,13 @@
 
 void EditRecipe::deleteMiscRow_clicked()
 {
+    if (recipe->locked || recipe->miscs.size() < 1)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Delete misc row" << row << recipe->miscs.size();
 
-    if (recipe->miscs.size() < 1)
-        return;
-
     int rc = QMessageBox::warning(this, tr("Delete misc"), tr("Delete %1").arg(recipe->miscs.at(row).m_name),
                     QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
     if (rc == QMessageBox::No)
@@ -487,6 +487,9 @@
 {
     QSqlQuery query;
 
+    if (recipe->locked)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     recipe->miscs_row = pb->objectName().toInt();
     qDebug() << "Edit misc row" << recipe->miscs_row;
--- a/src/EditRecipeTab5.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipeTab5.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -251,13 +251,13 @@
 
 void EditRecipe::deleteYeastRow_clicked()
 {
+    if (recipe->locked || recipe->yeasts.size() < 1)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Delete yeast row" << row << recipe->yeasts.size();
 
-    if (recipe->yeasts.size() < 1)
-        return;
-
     int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(recipe->yeasts.at(row).y_name),
                     QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
     if (rc == QMessageBox::No)
@@ -439,6 +439,9 @@
 {
     QSqlQuery query;
 
+    if (recipe->locked)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     recipe->yeasts_row = pb->objectName().toInt();
     qDebug() << "Edit yeast row" << recipe->yeasts_row;
--- a/src/EditRecipeTab6.cpp	Wed Apr 27 13:07:54 2022 +0200
+++ b/src/EditRecipeTab6.cpp	Thu Apr 28 13:08:20 2022 +0200
@@ -275,13 +275,13 @@
 
 void EditRecipe::deleteMashRow_clicked()
 {
+    if (recipe->locked || recipe->mashs.size() < 1)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Delete mash row" << row << recipe->mashs.size();
 
-    if (recipe->mashs.size() < 1)
-        return;
-
     int rc = QMessageBox::warning(this, tr("Delete mash step"), tr("Delete %1").arg(recipe->mashs.at(row).step_name),
                     QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
     if (rc == QMessageBox::No)
@@ -295,13 +295,13 @@
 
 void EditRecipe::upMashRow_clicked()
 {
+    if (recipe->locked || recipe->mashs.size() < 1)
+        return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Move up mash row" << row << recipe->mashs.size();
 
-    if (recipe->mashs.size() < 1)
-        return;
-
     Mashs temp;
     temp = recipe->mashs[row - 1];
     recipe->mashs[row - 1] = recipe->mashs[row];
@@ -313,13 +313,13 @@
 
 void EditRecipe::downMashRow_clicked()
 {
+    if (recipe->locked || recipe->mashs.size() < 1)
+        return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int row = pb->objectName().toInt();
     qDebug() << "Move down mash row" << row << recipe->mashs.size();
 
-    if (recipe->mashs.size() < 1)
-        return;
-
     Mashs temp;
     temp = recipe->mashs[row + 1];
     recipe->mashs[row + 1] = recipe->mashs[row];
@@ -430,6 +430,9 @@
 {
     QSqlQuery query;
 
+    if (recipe->locked)
+	return;
+
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     recipe->mashs_row = pb->objectName().toInt();
     qDebug() << "Edit mash row" << recipe->mashs_row;

mercurial