src/InventoryYeastPacks.cpp

changeset 480
94b3def5d778
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/InventoryYeastPacks.cpp	Mon Jan 30 17:05:13 2023 +0100
@@ -0,0 +1,175 @@
+/**
+ * InventoryYeastPacks.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 "InventoryYeastPacks.h"
+#include "EditYeastPack.h"
+#include "MainWindow.h"
+#include "config.h"
+#include "global.h"
+
+
+InventoryYeastPacks::InventoryYeastPacks(QWidget *parent) : QDialog(parent)
+{
+    qDebug() << "InventoryYeastPacks start";
+
+    gridLayout = new QGridLayout(this);
+    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
+    tableYeastPacks = new QTableWidget(this);
+    tableYeastPacks->setObjectName(QString::fromUtf8("tableYeastPacks"));
+    tableYeastPacks->setEnabled(true);
+    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+    sizePolicy.setHorizontalStretch(0);
+    sizePolicy.setVerticalStretch(0);
+    tableYeastPacks->setSizePolicy(sizePolicy);
+    tableYeastPacks->setMinimumSize(QSize(824, 0));
+    gridLayout->addWidget(tableYeastPacks, 0, 0, 1, 1);
+
+    groupBox = new QGroupBox(this);
+    groupBox->setObjectName(QString::fromUtf8("groupBox"));
+    groupBox->setEnabled(true);
+    groupBox->setFlat(false);
+    horizontalLayout = new QHBoxLayout(groupBox);
+    horizontalLayout->setSpacing(6);
+    horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
+    horizontalLayout->setContentsMargins(0, 0, 0, 0);
+
+    quitButton = new QPushButton(groupBox);
+    quitButton->setObjectName(QString::fromUtf8("quitButton"));
+    quitButton->setMinimumSize(QSize(80, 24));
+    quitButton->setText(tr("Quit"));
+    QIcon icon;
+    icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
+    quitButton->setIcon(icon);
+    horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
+
+    exportButton = new QPushButton(groupBox);
+    exportButton->setObjectName(QString::fromUtf8("exportButton"));
+    exportButton->setMinimumSize(QSize(80, 24));
+    exportButton->setText(tr("Export"));
+    QIcon icon1;
+    icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off);
+    exportButton->setIcon(icon1);
+    horizontalLayout->addWidget(exportButton, 0, Qt::AlignCenter);
+
+    insertButton = new QPushButton(groupBox);
+    insertButton->setObjectName(QString::fromUtf8("insertButton"));
+    insertButton->setMinimumSize(QSize(80, 24));
+    insertButton->setText(tr("New"));
+    QIcon icon3;
+    icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
+    insertButton->setIcon(icon3);
+    horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
+    gridLayout->addWidget(groupBox, 1, 0, 1, 1);
+
+    connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryYeastPacks()));
+    connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
+    connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
+    connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
+    emit refreshTable();
+}
+
+
+void InventoryYeastPacks::refreshTable()
+{
+    QString w;
+    QWidget* pWidget;
+    QLabel *label;
+    QHBoxLayout* pLayout;
+
+    qDebug() << "InventoryYeastPacks reload";
+
+    QSqlQuery query("SELECT * FROM inventory_yeastpack ORDER BY laboratory,package");
+    const QStringList labels({tr("Laboratory"), tr("Package"), tr("Form"), tr("Size"), tr("Edit")});
+
+    /* origin supplier name type graintype color yield inventory Edit */
+    this->tableYeastPacks->setColumnCount(5);
+    this->tableYeastPacks->setColumnWidth(0, 250);	/* Laboratory	*/
+    this->tableYeastPacks->setColumnWidth(1, 250);	/* Package	*/
+    this->tableYeastPacks->setColumnWidth(2, 100);	/* Form		*/
+    this->tableYeastPacks->setColumnWidth(3, 100);	/* Size		*/
+    this->tableYeastPacks->setColumnWidth(4, 100);	/* Edit button	*/
+    this->tableYeastPacks->setRowCount(query.size());
+    this->tableYeastPacks->setHorizontalHeaderLabels(labels);
+    this->tableYeastPacks->verticalHeader()->hide();
+
+    QTableWidgetItem *rightitem = new QTableWidgetItem();
+    rightitem->setTextAlignment(Qt::AlignRight);
+
+    query.first();
+    for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
+	this->tableYeastPacks->setItem(ridx, 0, new QTableWidgetItem(query.value("laboratory").toString()));	/* Laboratory */
+	this->tableYeastPacks->setItem(ridx, 1, new QTableWidgetItem(query.value("package").toString()));	/* Name	*/
+	this->tableYeastPacks->setItem(ridx, 2, new QTableWidgetItem(QCoreApplication::translate("YeastForm", g_yeast_forms[query.value("form").toInt()])));
+
+	w = QString("");
+	if (query.value("form").toInt() == 1 || query.value("form").toInt() == 6) {
+	  w = QString("%1 gram").arg(query.value("size").toDouble() * 1000, 2, 'f', 1, '0');
+	} else {
+	  w = QString("%1 ml").arg(query.value("size").toDouble() * 1000, 2, 'f', 1, '0');
+	}
+	QTableWidgetItem *item = new QTableWidgetItem(w);
+	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
+	this->tableYeastPacks->setItem(ridx, 3, item);
+
+	/* Add the Edit button */
+	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()));
+	pLayout = new QHBoxLayout(pWidget);
+	pLayout->addWidget(btn_edit);
+	pLayout->setContentsMargins(5, 0, 5, 0);
+	pWidget->setLayout(pLayout);
+	this->tableYeastPacks->setCellWidget(ridx, 4, pWidget);
+	query.next();
+    }
+    emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
+}
+
+
+InventoryYeastPacks::~InventoryYeastPacks() {}
+
+
+void InventoryYeastPacks::edit(int recno)
+{
+    EditYeastPack 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 InventoryYeastPacks::on_editButton_clicked()
+{
+    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
+    int recno = pb->objectName().toInt();
+    edit(recno);
+}
+
+
+void InventoryYeastPacks::on_insertButton_clicked()
+{
+    edit(-1);
+}
+
+
+void InventoryYeastPacks::on_exportButton_clicked()
+{
+    QMessageBox::information(this, QGuiApplication::applicationDisplayName(), tr("BeerXML doesn't support export yeast packages."));
+}
+

mercurial