Added hops editor.

Sun, 20 Feb 2022 20:22:49 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 20 Feb 2022 20:22:49 +0100
changeset 24
684c6e74cc1b
parent 23
1ac3fb2569c1
child 25
a9da2744609e

Added hops editor.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/EditFermentable.cpp file | annotate | diff | comparison | revisions
src/EditHop.cpp file | annotate | diff | comparison | revisions
src/EditHop.h file | annotate | diff | comparison | revisions
src/InventoryHops.cpp file | annotate | diff | comparison | revisions
src/InventoryHops.h file | annotate | diff | comparison | revisions
src/MainWindow.cpp file | annotate | diff | comparison | revisions
src/MainWindow.h file | annotate | diff | comparison | revisions
ui/EditHop.ui file | annotate | diff | comparison | revisions
ui/MainWindow.ui file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sun Feb 20 12:13:22 2022 +0100
+++ b/CMakeLists.txt	Sun Feb 20 20:22:49 2022 +0100
@@ -102,6 +102,8 @@
     ${SRCDIR}/EditSupplier.cpp
     ${SRCDIR}/InventoryFermentables.cpp
     ${SRCDIR}/EditFermentable.cpp
+    ${SRCDIR}/InventoryHops.cpp
+    ${SRCDIR}/EditHop.cpp
     ${SRCDIR}/Setup.cpp
     ${SRCDIR}/Utils.cpp
     ${SRCDIR}/MainWindow.cpp
@@ -116,6 +118,8 @@
     ${SRCDIR}/EditSupplier.h
     ${SRCDIR}/InventoryFermentables.h
     ${SRCDIR}/EditFermentable.h
+    ${SRCDIR}/InventoryHops.h
+    ${SRCDIR}/EditHop.h
     ${SRCDIR}/Setup.h
     ${SRCDIR}/Utils.h
     ${SRCDIR}/MainWindow.h
--- a/src/EditFermentable.cpp	Sun Feb 20 12:13:22 2022 +0100
+++ b/src/EditFermentable.cpp	Sun Feb 20 20:22:49 2022 +0100
@@ -100,6 +100,8 @@
 	ui->colorEdit->setValue(3);
 	ui->coarseEdit->setValue(3);
 	ui->moistureEdit->setValue(4);
+	ui->prodEdit->clear();
+        ui->thtEdit->clear();
     }
     connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditFermentable::is_changed);
     connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/EditHop.cpp	Sun Feb 20 20:22:49 2022 +0100
@@ -0,0 +1,259 @@
+/**
+ * EditHop.cpp is part of bmsapp.
+ *
+ * bmsapp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * bmsapp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "EditHop.h"
+#include "../ui/ui_EditHop.h"
+#include "bmsapp.h"
+
+
+EditHop::EditHop(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditHop)
+{
+    QSqlQuery query;
+
+    qDebug() << "EditHop record:" << id;
+    ui->setupUi(this);
+    this->recno = id;
+
+    WindowTitle();
+
+    ui->typeEdit->addItem(tr("Bittering"));
+    ui->typeEdit->addItem(tr("Aroma"));
+    ui->typeEdit->addItem(tr("Both"));
+
+    ui->formEdit->addItem(tr("Pellet"));
+    ui->formEdit->addItem(tr("Plug"));
+    ui->formEdit->addItem(tr("Leaf"));
+    ui->formEdit->addItem(tr("Leaf Wet"));	/* Not in beerxml */
+    ui->formEdit->addItem(tr("Cryo"));		/* Not in beerxml */
+
+    if (id >= 0) {
+	query.prepare("SELECT * FROM inventory_hops WHERE record = :recno");
+	query.bindValue(":recno", id);
+	query.exec();
+	query.next();
+
+	ui->nameEdit->setText(query.value(1).toString());
+	ui->alphaEdit->setValue(query.value(2).toDouble());
+	ui->betaEdit->setValue(query.value(3).toDouble());
+	ui->humuleneEdit->setValue(query.value(4).toDouble());
+	ui->caryEdit->setValue(query.value(5).toDouble());
+	ui->cohumuloneEdit->setValue(query.value(6).toDouble());
+	ui->myrceneEdit->setValue(query.value(7).toDouble());
+	ui->hsiEdit->setValue(query.value(8).toDouble());
+	ui->typeEdit->setCurrentIndex(query.value(9).toInt());
+	ui->formEdit->setCurrentIndex(query.value(10).toInt());
+	ui->notesEdit->setPlainText(query.value(11).toString());
+	ui->originEdit->setText(query.value(12).toString());
+	ui->substitutesEdit->setText(query.value(13).toString());
+	ui->alwaysEdit->setChecked(query.value(14).toInt() ? true:false);
+	ui->inventoryEdit->setValue(query.value(15).toDouble());
+	ui->costEdit->setValue(query.value(16).toDouble());
+	ui->valueEdit->setValue(query.value(15).toDouble() * query.value(16).toDouble());
+	if (query.value(17).toString().length() == 10) {
+            ui->prodEdit->setDate(query.value(17).toDate());
+        } else {
+            ui->prodEdit->clear();
+        }
+	if (query.value(18).toString().length() == 10) {
+	    ui->thtEdit->setDate(query.value(18).toDate());
+	} else {
+	    ui->thtEdit->clear();
+	}
+	ui->oilEdit->setValue(query.value(19).toDouble());
+    } else {
+	/* Set some defaults */
+	ui->typeEdit->setCurrentIndex(0);
+	ui->formEdit->setCurrentIndex(0);
+	ui->prodEdit->clear();
+	ui->thtEdit->clear();
+    }
+    connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditHop::is_changed);
+    connect(ui->alphaEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->betaEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->humuleneEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->caryEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->cohumuloneEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->myrceneEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->hsiEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditHop::is_changed);
+    connect(ui->formEdit, &QComboBox::currentTextChanged, this, &EditHop::is_changed);
+    connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed()));
+    connect(ui->originEdit, &QLineEdit::textChanged, this, &EditHop::is_changed);
+    connect(ui->substitutesEdit, &QLineEdit::textChanged, this, &EditHop::is_changed);
+    connect(ui->alwaysEdit, &QCheckBox::stateChanged, this, &EditHop::is_changed);
+    connect(ui->inventoryEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->costEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+    connect(ui->prodEdit, &QDateEdit::dateChanged, this, &EditHop::is_changed);
+    connect(ui->thtEdit, &QDateEdit::dateChanged, this, &EditHop::is_changed);
+    connect(ui->oilEdit, &QDoubleSpinBox::textChanged, this, &EditHop::is_changed);
+
+    ui->saveButton->setEnabled(false);
+    ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && id >= 0) ? true:false);
+}
+
+
+EditHop::~EditHop()
+{
+    qDebug() << "EditHop done";
+    delete ui;
+    emit entry_changed();
+}
+
+
+/*
+ * Window header, mark any change with '**'
+ */
+void EditHop::WindowTitle()
+{
+    QString txt;
+
+    if (this->recno < 0) {
+	txt = QString(tr("BMSapp - Add new hop"));
+    } else {
+	txt = QString(tr("BMSapp - Edit hop %1").arg(this->recno));
+    }
+
+    if (this->textIsChanged) {
+	txt.append((QString(" **")));
+    }
+    setWindowTitle(txt);
+}
+
+
+void EditHop::on_saveButton_clicked()
+{
+    QSqlQuery query;
+
+    /* If there are errors in the form, show a message and do "return;" */
+    if (ui->nameEdit->text().length() < 2) {
+	QMessageBox::warning(this, tr("Edit Hop"), tr("Name empty or too short."));
+	return;
+    }
+    if (ui->originEdit->text().length() < 2) {
+        QMessageBox::warning(this, tr("Edit Hop"), tr("Origin empty or too short."));
+        return;
+    }
+
+    if (this->textIsChanged) {
+    	if (this->recno == -1) {
+    	    query.prepare("INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, "
+		"humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, "
+		"hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, "
+		"always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, "
+		"tht_date=:tht, total_oil=:oil, uuid = :uuid");
+    	} else {
+	    query.prepare("UPDATE inventory_hops SET name=:name, alpha=:alpha, beta=:beta, "
+		"humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, "
+		"hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, "
+		"always_on_stock=:always, inventory=:inventory, cost=:cost, production_date=:prod, "
+                "tht_date=:tht, total_oil=:oil WHERE record = :recno");
+    	}
+	query.bindValue(":name", ui->nameEdit->text());
+	query.bindValue(":alpha", QString("%1").arg(ui->alphaEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":beta", QString("%1").arg(ui->betaEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":humulene", QString("%1").arg(ui->humuleneEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":cary", QString("%1").arg(ui->caryEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":cohumulone", QString("%1").arg(ui->cohumuloneEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":myrcene", QString("%1").arg(ui->myrceneEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":hsi", QString("%1").arg(ui->hsiEdit->value(), 2, 'f', 1, '0'));
+	query.bindValue(":type", ui->typeEdit->currentIndex());
+	query.bindValue(":form", ui->formEdit->currentIndex());
+	query.bindValue(":notes", ui->notesEdit->toPlainText());
+	query.bindValue(":origin", ui->originEdit->text());
+	query.bindValue(":substitutes", ui->substitutesEdit->text());
+	query.bindValue(":always", ui->alwaysEdit->isChecked() ? 1:0);
+	query.bindValue(":inventory", QString("%1").arg(ui->inventoryEdit->value(), 5, 'f', 4, '0'));
+	query.bindValue(":cost", QString("%1").arg(ui->costEdit->value(), 3, 'f', 2, '0'));
+	/* Uses https://www.qtcentre.org/threads/17295-How-to-put-empty-value-in-QDateEdit */
+	query.bindValue(":prod", ui->prodEdit->nullDate());
+	query.bindValue(":tht", ui->thtEdit->nullDate());
+	query.bindValue(":oil", QString("%1").arg(ui->oilEdit->value(), 2, 'f', 1, '0'));
+	if (this->recno == -1) {
+	    query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
+	} else {
+	    query.bindValue(":recno", this->recno);
+	}
+	query.exec();
+	if (query.lastError().isValid()) {
+	    qDebug() << "EditHop" << query.lastError();
+	    QMessageBox::warning(this, tr("Database error"),
+                        tr("MySQL error: %1\n%2\n%3")
+                        .arg(query.lastError().nativeErrorCode())
+                        .arg(query.lastError().driverText())
+                        .arg(query.lastError().databaseText()));
+	} else {
+	    qDebug() << "EditHop Saved";
+	}
+    }
+
+    ui->saveButton->setEnabled(false);
+    this->textIsChanged = false;
+    WindowTitle();
+}
+
+
+void EditHop::on_deleteButton_clicked()
+{
+    QSqlQuery query;
+
+    query.prepare("DELETE FROM inventory_hops WHERE record = :recno");
+    query.bindValue(":recno", this->recno);
+    query.exec();
+    if (query.lastError().isValid()) {
+	qDebug() << "EditHop" << query.lastError();
+	QMessageBox::warning(this, tr("Database error"),
+                        tr("MySQL error: %1\n%2\n%3")
+                        .arg(query.lastError().nativeErrorCode())
+                        .arg(query.lastError().driverText())
+                        .arg(query.lastError().databaseText()));
+    } else {
+	qDebug() << "EditHop Deleted" << this->recno;
+    }
+
+    this->close();
+    this->setResult(1);
+}
+
+
+void EditHop::is_changed()
+{
+    ui->valueEdit->setValue(ui->inventoryEdit->value() * ui->costEdit->value());
+    ui->saveButton->setEnabled(true);
+    ui->deleteButton->setEnabled((ui->inventoryEdit->value() == 0 && this->recno >= 0) ? true:false);
+    this->textIsChanged = true;
+    WindowTitle();
+}
+
+
+void EditHop::on_quitButton_clicked()
+{
+    if (this->textIsChanged) {
+	int rc = QMessageBox::warning(this, tr("Hop changed"), tr("The fermentable has been modified\n Save changes?"),
+                                QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
+        switch (rc) {
+            case QMessageBox::Save:
+                        on_saveButton_clicked();
+                        break;  /* Saved and then Quit */
+            case QMessageBox::Discard:
+                        break;  /* Quit without Save */
+            case QMessageBox::Cancel:
+                        return; /* Return to the editor page */
+        }
+    }
+
+    this->close();
+    this->setResult(1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/EditHop.h	Sun Feb 20 20:22:49 2022 +0100
@@ -0,0 +1,36 @@
+#ifndef _EDITHOP_H
+#define _EDITHOP_H
+
+#include <QDialog>
+
+
+namespace Ui {
+class EditHop;
+}
+
+class EditHop : public QDialog
+{
+    Q_OBJECT
+
+signals:
+    void entry_changed();
+
+public:
+    explicit EditHop(int id, QWidget *parent = 0);
+    ~EditHop();
+
+private slots:
+    void on_saveButton_clicked();
+    void on_quitButton_clicked();
+    void on_deleteButton_clicked();
+    void is_changed();
+
+private:
+    Ui::EditHop *ui;
+    int recno;
+    bool textIsChanged = false;
+
+    void WindowTitle();
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/InventoryHops.cpp	Sun Feb 20 20:22:49 2022 +0100
@@ -0,0 +1,166 @@
+/**
+ * InventoryHops.cpp is part of bmsapp.
+ *
+ * bmsapp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * bmsapp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "InventoryHops.h"
+#include "EditHop.h"
+#include "../ui/ui_InventoryHops.h"
+#include "config.h"
+#include "bmsapp.h"
+
+
+InventoryHops::InventoryHops(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryHops)
+{
+    qDebug() << "InventoryHops start";
+
+    ui->setupUi(this);
+    emit refreshTable();
+
+    setWindowTitle( QString("BMSapp - %1 - Inventory Hops").arg(VERSIONSTRING) );
+}
+
+
+void InventoryHops::refreshTable()
+{
+    QString w;
+
+    qDebug() << "InventoryHops reload";
+
+    QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name");
+    const QStringList labels({tr("Origin"), tr("Name"), tr("Type"), tr("Form"), tr("Alpha"), tr("Beta"), tr("Cohumulone"), tr("HSI"), tr("Harvest"), tr("Stock"), tr("Edit")});
+    const QStringList types({tr("Bittering"), tr("Aroma"), tr("Both")});
+    const QStringList form({tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf Wet"), tr("Cryo")});
+
+    /* origin supplier name type graintype color yield inventory Edit */
+    ui->tableHops->setColumnCount(11);
+    ui->tableHops->setColumnWidth(0, 130);	/* Origin	*/
+    ui->tableHops->setColumnWidth(1, 250);	/* Name		*/
+    ui->tableHops->setColumnWidth(2,  80);	/* Type		*/
+    ui->tableHops->setColumnWidth(3,  80);	/* Form		*/
+    ui->tableHops->setColumnWidth(4,  80);	/* Alpha	*/
+    ui->tableHops->setColumnWidth(5,  80);	/* Beta		*/
+    ui->tableHops->setColumnWidth(6,  80);	/* cohumulone	*/
+    ui->tableHops->setColumnWidth(7,  80);	/* HSI		*/
+    ui->tableHops->setColumnWidth(8,  80);	/* Harvest date	*/
+    ui->tableHops->setColumnWidth(9,  80);	/* Stock	*/
+    ui->tableHops->setColumnWidth(10, 80);	/* Edit button	*/
+    ui->tableHops->setRowCount(query.size());
+    ui->tableHops->setHorizontalHeaderLabels(labels);
+    ui->tableHops->verticalHeader()->hide();
+    ui->tableHops->setFixedSize(1100 + 24, 640);	/* Even if this is too large, it works */
+
+    QTableWidgetItem *rightitem = new QTableWidgetItem();
+    rightitem->setTextAlignment(Qt::AlignRight);
+
+    query.first();
+    for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
+	ui->tableHops->setItem(ridx, 0, new QTableWidgetItem(query.value(12).toString()));	/* Origin */
+	ui->tableHops->setItem(ridx, 1, new QTableWidgetItem(query.value(1).toString()));	/* Name	*/
+	ui->tableHops->setItem(ridx, 2, new QTableWidgetItem(types[query.value(9).toInt()]));	/* Type */
+	ui->tableHops->setItem(ridx, 3, new QTableWidgetItem(form[query.value(10).toInt()]));	/* Form */
+	w = QString("%1 %").arg(query.value(2).toDouble(), 2, 'f', 1, '0' );	/* Alpha% */
+	QTableWidgetItem *item = new QTableWidgetItem(w);
+        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->tableHops->setItem(ridx, 4, item);
+	w = QString("%1 %").arg(query.value(3).toDouble(), 2, 'f', 1, '0' );	/* Beta% */
+        item = new QTableWidgetItem(w);
+        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->tableHops->setItem(ridx, 5, item);
+
+	w = QString("%1 %").arg(query.value(6).toDouble(), 2, 'f', 1, '0' );    /* Cohumulone */
+        item = new QTableWidgetItem(w);
+        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->tableHops->setItem(ridx, 6, item);
+
+	w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' );    /* HSI */
+        item = new QTableWidgetItem(w);
+        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->tableHops->setItem(ridx, 7, item);
+
+	if (query.value(15).toDouble() > 0)
+	    ui->tableHops->setItem(ridx, 8, new QTableWidgetItem(query.value(17).toString()));  /* Harvest */
+	else
+	    ui->tableHops->setItem(ridx, 8, new QTableWidgetItem(QString("")));
+
+	w = QString("");
+	if (query.value(15).toDouble() > 0) {
+	  if (query.value(15).toDouble() < 1.000) {
+	    w = QString("%1 gr").arg(query.value(15).toDouble() * 1000.0, 2, 'f', 1, '0' );
+	  } else {
+            w = QString("%1 kg").arg(query.value(15).toDouble(), 4, 'f', 3, '0' );
+	  }
+	}
+	item = new QTableWidgetItem(w);
+	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+	ui->tableHops->setItem(ridx, 9, item);
+
+	/* Add the Edit button */
+	QWidget* pWidget = new QWidget();
+	QPushButton* btn_edit = new QPushButton();
+	btn_edit->setObjectName(QString("%1").arg(query.value(0).toString()));	/* Send record with the button */
+	btn_edit->setText(tr("Edit"));
+	connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
+	QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
+	pLayout->addWidget(btn_edit);
+	pLayout->setContentsMargins(5, 0, 5, 0);
+	pWidget->setLayout(pLayout);
+	ui->tableHops->setCellWidget(ridx, 10, pWidget);
+	query.next();
+    }
+
+    setWindowTitle( QString("BMSapp - %1 - Inventory Hops").arg(VERSIONSTRING) );
+}
+
+
+InventoryHops::~InventoryHops()
+{
+    qDebug() << "InventoryHops done";
+    delete ui;
+}
+
+
+void InventoryHops::edit(int recno)
+{
+    qDebug() << "InventoryHops edit:" << recno;
+
+    EditHop dialog(recno, this);
+    /* Signal from editor if a refresh is needed */
+    connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
+    dialog.setModal(true);
+    dialog.exec();
+}
+
+
+void InventoryHops::on_editButton_clicked()
+{
+    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
+    int recno = pb->objectName().toInt();
+    qDebug() << Q_FUNC_INFO << recno;
+    edit(recno);
+}
+
+
+void InventoryHops::on_insertButton_clicked()
+{
+    qDebug() << Q_FUNC_INFO;
+    edit(-1);
+}
+
+
+void InventoryHops::on_quitButton_clicked()
+{
+    emit firstWindow();
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/InventoryHops.h	Sun Feb 20 20:22:49 2022 +0100
@@ -0,0 +1,32 @@
+#ifndef _INVENTORYHOPS_H
+#define _INVENTORYHOPS_H
+
+#include <QDialog>
+
+namespace Ui {
+class InventoryHops;
+}
+
+class InventoryHops : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit InventoryHops(QWidget *parent = nullptr);
+    ~InventoryHops();
+
+signals:
+    void firstWindow();
+
+private slots:
+    void on_quitButton_clicked();
+    void on_insertButton_clicked();
+    void on_editButton_clicked();
+    void refreshTable(void);
+
+private:
+    Ui::InventoryHops *ui;
+    void edit(int recno);
+};
+
+#endif
--- a/src/MainWindow.cpp	Sun Feb 20 12:13:22 2022 +0100
+++ b/src/MainWindow.cpp	Sun Feb 20 20:22:49 2022 +0100
@@ -18,6 +18,7 @@
 #include "AboutDialog.h"
 #include "InventorySuppliers.h"
 #include "InventoryFermentables.h"
+#include "InventoryHops.h"
 #include "Setup.h"
 #include "../ui/ui_MainWindow.h"
 #include "config.h"
@@ -88,6 +89,24 @@
 }
 
 
+void MainWindow::fromInventoryHops()
+{
+    qDebug() << Q_FUNC_INFO;
+    delete InventoryHopsWindow;
+    this->show();
+}
+
+
+void MainWindow::on_actionHops_triggered()
+{
+    qDebug() << Q_FUNC_INFO;
+    InventoryHopsWindow = new InventoryHops(this);
+    QObject::connect(InventoryHopsWindow, SIGNAL(firstWindow()), this, SLOT(fromInventoryHops()));
+    this->hide();    // Close the main window
+    InventoryHopsWindow->show();  // Show a second window
+}
+
+
 void MainWindow::fromSetup()
 {
     qDebug() << Q_FUNC_INFO;
--- a/src/MainWindow.h	Sun Feb 20 12:13:22 2022 +0100
+++ b/src/MainWindow.h	Sun Feb 20 20:22:49 2022 +0100
@@ -3,6 +3,7 @@
 
 #include "InventorySuppliers.h"
 #include "InventoryFermentables.h"
+#include "InventoryHops.h"
 #include "Setup.h"
 
 #include <QMainWindow>
@@ -26,12 +27,14 @@
     void on_actionExit_triggered();
     void on_actionSuppliers_triggered();
     void on_actionFermentables_triggered();
+    void on_actionHops_triggered();
     void on_actionSetup_triggered();
     void on_actionAbout_triggered();
 
 public slots:
     void fromInventorySuppliers();
     void fromInventoryFermentables();
+    void fromInventoryHops();
     void fromSetup();
 
 private:
@@ -40,6 +43,7 @@
     // Keep pointers to new windows.
     InventorySuppliers *InventorySuppliersWindow;
     InventoryFermentables *InventoryFermentablesWindow;
+    InventoryHops * InventoryHopsWindow;
     Setup *SetupWindow;
 };
 
--- a/ui/EditHop.ui	Sun Feb 20 12:13:22 2022 +0100
+++ b/ui/EditHop.ui	Sun Feb 20 20:22:49 2022 +0100
@@ -52,7 +52,7 @@
       <property name="geometry">
        <rect>
         <x>5</x>
-        <y>410</y>
+        <y>350</y>
         <width>121</width>
         <height>20</height>
        </rect>
@@ -68,7 +68,7 @@
       <property name="geometry">
        <rect>
         <x>5</x>
-        <y>440</y>
+        <y>380</y>
         <width>121</width>
         <height>20</height>
        </rect>
@@ -84,7 +84,7 @@
       <property name="geometry">
        <rect>
         <x>5</x>
-        <y>470</y>
+        <y>410</y>
         <width>121</width>
         <height>20</height>
        </rect>
@@ -100,13 +100,13 @@
       <property name="geometry">
        <rect>
         <x>660</x>
-        <y>410</y>
+        <y>350</y>
         <width>141</width>
         <height>20</height>
        </rect>
       </property>
       <property name="text">
-       <string>Production date:</string>
+       <string>Harvest date:</string>
       </property>
       <property name="alignment">
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -116,13 +116,13 @@
       <property name="geometry">
        <rect>
         <x>660</x>
-        <y>440</y>
+        <y>380</y>
         <width>141</width>
         <height>20</height>
        </rect>
       </property>
       <property name="text">
-       <string>Best before date:</string>
+       <string>Best BeFore date:</string>
       </property>
       <property name="alignment">
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -141,7 +141,7 @@
        <number>128</number>
       </property>
       <property name="placeholderText">
-       <string>Name of the fermentable</string>
+       <string>Name of the hop</string>
       </property>
      </widget>
      <widget class="QPlainTextEdit" name="notesEdit">
@@ -161,7 +161,7 @@
       <property name="geometry">
        <rect>
         <x>140</x>
-        <y>410</y>
+        <y>350</y>
         <width>121</width>
         <height>24</height>
        </rect>
@@ -179,7 +179,7 @@
        <bool>true</bool>
       </property>
       <property name="decimals">
-       <number>3</number>
+       <number>4</number>
       </property>
       <property name="maximum">
        <double>100000.000000000000000</double>
@@ -195,7 +195,7 @@
       <property name="geometry">
        <rect>
         <x>140</x>
-        <y>440</y>
+        <y>380</y>
         <width>121</width>
         <height>24</height>
        </rect>
@@ -220,7 +220,7 @@
       <property name="geometry">
        <rect>
         <x>810</x>
-        <y>410</y>
+        <y>350</y>
         <width>121</width>
         <height>24</height>
        </rect>
@@ -246,7 +246,7 @@
       <property name="geometry">
        <rect>
         <x>810</x>
-        <y>440</y>
+        <y>380</y>
         <width>121</width>
         <height>24</height>
        </rect>
@@ -325,7 +325,7 @@
       <property name="geometry">
        <rect>
         <x>140</x>
-        <y>470</y>
+        <y>410</y>
         <width>107</width>
         <height>24</height>
        </rect>
@@ -339,6 +339,413 @@
       <property name="buttonSymbols">
        <enum>QAbstractSpinBox::NoButtons</enum>
       </property>
+      <property name="maximum">
+       <double>100000.000000000000000</double>
+      </property>
+     </widget>
+     <widget class="QComboBox" name="typeEdit">
+      <property name="geometry">
+       <rect>
+        <x>140</x>
+        <y>140</y>
+        <width>121</width>
+        <height>23</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QLabel" name="typeLabel">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>140</y>
+        <width>121</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Type hop:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="originLabel">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>170</y>
+        <width>121</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Origin:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="substitutesLabel">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>200</y>
+        <width>121</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Substitudes:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="hsiLabel">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>230</y>
+        <width>121</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="toolTip">
+       <string>Hop Stability Index</string>
+      </property>
+      <property name="text">
+       <string>HSI:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="oilLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>140</y>
+        <width>141</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Total oil:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="humuleneLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>170</y>
+        <width>141</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Humulene:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="caryLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>200</y>
+        <width>141</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Caryophyllene:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="myrceneLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>230</y>
+        <width>141</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Myrcene:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="cohumuloneLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>260</y>
+        <width>141</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Cohumulone:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="formLabel">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>260</y>
+        <width>121</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Form:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="alphaLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>290</y>
+        <width>141</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Alpha %:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="betaLabel">
+      <property name="geometry">
+       <rect>
+        <x>660</x>
+        <y>320</y>
+        <width>141</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Beta %:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLabel" name="alwaysLabel">
+      <property name="geometry">
+       <rect>
+        <x>5</x>
+        <y>320</y>
+        <width>121</width>
+        <height>20</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Always on stock:</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="originEdit">
+      <property name="geometry">
+       <rect>
+        <x>140</x>
+        <y>170</y>
+        <width>471</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="placeholderText">
+       <string>Country and place of origin</string>
+      </property>
+     </widget>
+     <widget class="QLineEdit" name="substitutesEdit">
+      <property name="geometry">
+       <rect>
+        <x>140</x>
+        <y>200</y>
+        <width>471</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="maxLength">
+       <number>256</number>
+      </property>
+      <property name="placeholderText">
+       <string>Substitutes that can be used for this hop</string>
+      </property>
+     </widget>
+     <widget class="QComboBox" name="formEdit">
+      <property name="geometry">
+       <rect>
+        <x>140</x>
+        <y>260</y>
+        <width>121</width>
+        <height>23</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="hsiEdit">
+      <property name="geometry">
+       <rect>
+        <x>140</x>
+        <y>230</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="toolTip">
+       <string>Hop Stability Index</string>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="oilEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>140</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="humuleneEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>170</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="caryEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>200</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="myrceneEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>230</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="cohumuloneEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>260</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="alphaEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>290</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QDoubleSpinBox" name="betaEdit">
+      <property name="geometry">
+       <rect>
+        <x>810</x>
+        <y>320</y>
+        <width>121</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="alignment">
+       <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+      </property>
+      <property name="decimals">
+       <number>1</number>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="alwaysEdit">
+      <property name="geometry">
+       <rect>
+        <x>140</x>
+        <y>320</y>
+        <width>85</width>
+        <height>21</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Yes</string>
+      </property>
      </widget>
     </widget>
    </item>
--- a/ui/MainWindow.ui	Sun Feb 20 12:13:22 2022 +0100
+++ b/ui/MainWindow.ui	Sun Feb 20 20:22:49 2022 +0100
@@ -206,7 +206,7 @@
   </action>
   <action name="actionHops">
    <property name="enabled">
-    <bool>false</bool>
+    <bool>true</bool>
    </property>
    <property name="icon">
     <iconset resource="../resources/icons.qrc">

mercurial