src/InventoryHops.cpp

changeset 24
684c6e74cc1b
child 44
5a9a159c2d34
--- /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();
+}
+

mercurial