src/InventoryMiscs.cpp

changeset 28
93a70b1502ca
child 45
4024b389f689
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/InventoryMiscs.cpp	Fri Feb 25 10:51:36 2022 +0100
@@ -0,0 +1,154 @@
+/**
+ * InventoryMiscs.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 "InventoryMiscs.h"
+#include "EditMisc.h"
+#include "../ui/ui_InventoryMiscs.h"
+#include "config.h"
+#include "bmsapp.h"
+
+
+InventoryMiscs::InventoryMiscs(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryMiscs)
+{
+    qDebug() << "InventoryMiscs start";
+
+    ui->setupUi(this);
+    emit refreshTable();
+
+    setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) );
+}
+
+
+void InventoryMiscs::refreshTable()
+{
+    QString w;
+
+    qDebug() << "InventoryMiscs reload";
+
+    QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name");
+    const QStringList labels({tr("Name"), tr("Type"), tr("Use"), tr("Time"), tr("Stock"), tr("Edit")});
+    const QStringList types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")});
+    const QStringList use({tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling")});
+
+    /* origin supplier name type graintype color yield inventory Edit */
+    ui->tableMiscs->setColumnCount(6);
+    ui->tableMiscs->setColumnWidth(0, 275);	/* Name		*/
+    ui->tableMiscs->setColumnWidth(1, 120);	/* Type		*/
+    ui->tableMiscs->setColumnWidth(2, 120);	/* Use 		*/
+    ui->tableMiscs->setColumnWidth(3, 120);	/* Time		*/
+    ui->tableMiscs->setColumnWidth(4,  80);	/* Stock	*/
+    ui->tableMiscs->setColumnWidth(5,  80);	/* Edit button	*/
+    ui->tableMiscs->setRowCount(query.size());
+    ui->tableMiscs->setHorizontalHeaderLabels(labels);
+    ui->tableMiscs->verticalHeader()->hide();
+    ui->tableMiscs->setFixedSize(795 + 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->tableMiscs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString()));	/* Name */
+	ui->tableMiscs->setItem(ridx, 1, new QTableWidgetItem(types[query.value(2).toInt()]));	/* Type */
+	ui->tableMiscs->setItem(ridx, 2, new QTableWidgetItem(use[query.value(3).toInt()]));	/* Use */
+
+	w = QString("");	/* Use time */
+	if (query.value(4).toInt() > 0) {
+	  if (query.value(4).toInt() == 1)
+	    w = QString("1 minute");
+	  else if (query.value(4).toInt() < 180)
+	    w = QString("%1 minutes").arg(query.value(4).toInt());
+	  else if (query.value(4).toInt() < 1440)
+	    w = QString("%1 hours").arg(query.value(4).toInt() / 60);
+	  else if (query.value(4).toInt() == 1440)
+	    w = QString("1 day");
+	  else
+	    w = QString("%1 days").arg(query.value(4).toInt() / 1440);
+	}
+	QTableWidgetItem *item = new QTableWidgetItem(w);
+        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+        ui->tableMiscs->setItem(ridx, 3, item);
+
+	w = QString("");
+	if (query.value(9).toDouble() > 0) {
+	  if (query.value(5).toInt()) { /* Amount is weight */
+	    w = QString("%1 gr").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' );
+	  } else {
+            w = QString("%1 ml").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' );
+	  }
+	}
+	item = new QTableWidgetItem(w);
+	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+	ui->tableMiscs->setItem(ridx, 4, 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->tableMiscs->setCellWidget(ridx, 5, pWidget);
+	query.next();
+    }
+
+    setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) );
+}
+
+
+InventoryMiscs::~InventoryMiscs()
+{
+    qDebug() << "InventoryMiscs done";
+    delete ui;
+}
+
+
+void InventoryMiscs::edit(int recno)
+{
+    qDebug() << "InventoryMiscs edit:" << recno;
+
+    EditMisc 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 InventoryMiscs::on_editButton_clicked()
+{
+    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
+    int recno = pb->objectName().toInt();
+    qDebug() << Q_FUNC_INFO << recno;
+    edit(recno);
+}
+
+
+void InventoryMiscs::on_insertButton_clicked()
+{
+    qDebug() << Q_FUNC_INFO;
+    edit(-1);
+}
+
+
+void InventoryMiscs::on_quitButton_clicked()
+{
+    emit firstWindow();
+}
+

mercurial