# HG changeset patch # User Michiel Broek # Date 1645195982 -3600 # Node ID c94edc758a5b169b5995160e65181a4747bea7ca # Parent d0ca50776b0b7810c8425e793b5d5c581f01fbb9 Added Inventory Fermentables table. diff -r d0ca50776b0b -r c94edc758a5b CMakeLists.txt --- a/CMakeLists.txt Thu Feb 17 21:41:52 2022 +0100 +++ b/CMakeLists.txt Fri Feb 18 15:53:02 2022 +0100 @@ -100,6 +100,7 @@ ${SRCDIR}/AboutDialog.cpp ${SRCDIR}/InventorySuppliers.cpp ${SRCDIR}/EditSupplier.cpp + ${SRCDIR}/InventoryFermentables.cpp ${SRCDIR}/Setup.cpp ${SRCDIR}/MainWindow.cpp ${SRCDIR}/database/database.cpp @@ -110,6 +111,7 @@ ${SRCDIR}/AboutDialog.h ${SRCDIR}/InventorySuppliers.h ${SRCDIR}/EditSupplier.h + ${SRCDIR}/InventoryFermentables.h ${SRCDIR}/Setup.h ${SRCDIR}/MainWindow.h ${SRCDIR}/database/database.h @@ -119,6 +121,7 @@ ${UIDIR}/AboutDialog.ui ${UIDIR}/InventorySuppliers.ui ${UIDIR}/EditSupplier.ui + ${UIDIR}/InventoryFermentables.ui ${UIDIR}/Setup.ui ${UIDIR}/MainWindow.ui ) @@ -129,7 +132,6 @@ ${UIS} resources/icons.qrc resources/qdarkstyle/theme/style.qrc - resources/darkorange.qrc ) # ===== Build the application ===== diff -r d0ca50776b0b -r c94edc758a5b src/InventoryFermentables.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/InventoryFermentables.cpp Fri Feb 18 15:53:02 2022 +0100 @@ -0,0 +1,150 @@ +/** + * InventoryFermentables.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 . + */ +#include "InventoryFermentables.h" +//#include "EditSupplier.h" +#include "../ui/ui_InventoryFermentables.h" +#include "config.h" +#include "bmsapp.h" + + +InventoryFermentables::InventoryFermentables(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryFermentables) +{ + qDebug() << "InventoryFermentables start"; + + ui->setupUi(this); + emit refreshTable(); + + setWindowTitle( QString("BMSapp - %1 - Inventory Fermentables").arg(VERSIONSTRING) ); +} + + +void InventoryFermentables::refreshTable() +{ + QString w; + + qDebug() << "slot" << Q_FUNC_INFO; + + QSqlQuery query("SELECT * FROM inventory_fermentables ORDER BY supplier,name"); + const QStringList labels({tr("Origin"), tr("Supplier"), tr("Name"), tr("Type"), tr("Grain"), tr("Color"), tr("Yield"), tr("Stock"), tr("Edit")}); + const QStringList types({tr("Grain"), tr("Sugar"), tr("Extract"), tr("Dry extract"), tr("Adjunct")}); + const QStringList graintypes({tr("Base"), tr("Roast"), tr("Crystal"), tr("Kilned"), tr("Sour Malt"), tr("Special"), tr("No malt")}); + + /* origin supplier name type graintype color yield inventory Edit */ + ui->tableFermentables->setColumnCount(9); + ui->tableFermentables->setColumnWidth(0, 130); /* Origin */ + ui->tableFermentables->setColumnWidth(1, 170); /* Supplier */ + ui->tableFermentables->setColumnWidth(2, 250); /* Name */ + ui->tableFermentables->setColumnWidth(3, 80); /* Type */ + ui->tableFermentables->setColumnWidth(4, 80); /* Graintype */ + ui->tableFermentables->setColumnWidth(5, 80); /* Color */ + ui->tableFermentables->setColumnWidth(6, 80); /* Yield */ + ui->tableFermentables->setColumnWidth(7, 80); /* Stock */ + ui->tableFermentables->setColumnWidth(8, 80); /* Edit button */ + ui->tableFermentables->setRowCount(query.size()); + ui->tableFermentables->setHorizontalHeaderLabels(labels); + ui->tableFermentables->verticalHeader()->hide(); + ui->tableFermentables->setFixedSize(/*1280*/ 1030 + 24, 640); /* Even if this is too large, it works */ + + QTableWidgetItem *rightitem = new QTableWidgetItem(); + rightitem->setTextAlignment(Qt::AlignRight); + + qDebug() << query.record().count() << query.size(); + query.first(); + for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { + ui->tableFermentables->setItem(ridx, 0, new QTableWidgetItem(query.value(6).toString())); + ui->tableFermentables->setItem(ridx, 1, new QTableWidgetItem(query.value(7).toString())); + ui->tableFermentables->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString())); + ui->tableFermentables->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()])); + ui->tableFermentables->setItem(ridx, 4, new QTableWidgetItem(graintypes[query.value(20).toInt()])); + w = QString("%1 EBC").arg(query.value(4).toDouble(), 1, 'f', 0, '0' ); + QTableWidgetItem *item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableFermentables->setItem(ridx, 5, item); + w = QString("%1 %").arg(query.value(3).toFloat(), 3, 'f', 1, '0' ); + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableFermentables->setItem(ridx, 6, item); + w = QString(""); + if (query.value(21).toDouble() > 0) { + if (query.value(21).toDouble() < 1.000) { + w = QString("%1 gr").arg(query.value(21).toDouble() * 1000.0, 1, 'f', 0, '0' ); + } else { + w = QString("%1 kg").arg(query.value(21).toDouble(), 4, 'f', 3, '0' ); + } + } + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableFermentables->setItem(ridx, 7, 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->tableFermentables->setCellWidget(ridx, 8, pWidget); + query.next(); + } + + setWindowTitle( QString("BMSapp - %1 - Inventory Fermentables").arg(VERSIONSTRING) ); +} + + +InventoryFermentables::~InventoryFermentables() +{ + qDebug() << "InventoryFermentables done"; + delete ui; +} + + +void InventoryFermentables::edit(int recno) +{ + qDebug() << "InventoryFermentables edit:" << recno; + +// EditSupplier 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 InventoryFermentables::on_editButton_clicked() +{ + QPushButton *pb = qobject_cast(QObject::sender()); + int recno = pb->objectName().toInt(); + qDebug() << Q_FUNC_INFO << recno; + edit(recno); +} + + +void InventoryFermentables::on_insertButton_clicked() +{ + qDebug() << Q_FUNC_INFO; + edit(-1); +} + + +void InventoryFermentables::on_quitButton_clicked() +{ + emit firstWindow(); +} + diff -r d0ca50776b0b -r c94edc758a5b src/InventoryFermentables.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/InventoryFermentables.h Fri Feb 18 15:53:02 2022 +0100 @@ -0,0 +1,32 @@ +#ifndef _INVENTORYFERMENTABLES_H +#define _INVENTORYFERMENTABLES_H + +#include + +namespace Ui { +class InventoryFermentables; +} + +class InventoryFermentables : public QDialog +{ + Q_OBJECT + +public: + explicit InventoryFermentables(QWidget *parent = nullptr); + ~InventoryFermentables(); + +signals: + void firstWindow(); + +private slots: + void on_quitButton_clicked(); + void on_insertButton_clicked(); + void on_editButton_clicked(); + void refreshTable(void); + +private: + Ui::InventoryFermentables *ui; + void edit(int recno); +}; + +#endif diff -r d0ca50776b0b -r c94edc758a5b src/InventorySuppliers.cpp --- a/src/InventorySuppliers.cpp Thu Feb 17 21:41:52 2022 +0100 +++ b/src/InventorySuppliers.cpp Fri Feb 18 15:53:02 2022 +0100 @@ -73,13 +73,12 @@ connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); QHBoxLayout* pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_edit); - pLayout->setAlignment(Qt::AlignCenter); - pLayout->setContentsMargins(0, 0, 0, 0); +// pLayout->setAlignment(Qt::AlignCenter); + pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); ui->tableSuppliers->setCellWidget(ridx, 6, pWidget); query.next(); } -// qDebug() << "table ready"; setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); } diff -r d0ca50776b0b -r c94edc758a5b src/MainWindow.cpp --- a/src/MainWindow.cpp Thu Feb 17 21:41:52 2022 +0100 +++ b/src/MainWindow.cpp Fri Feb 18 15:53:02 2022 +0100 @@ -17,6 +17,7 @@ #include "MainWindow.h" #include "AboutDialog.h" #include "InventorySuppliers.h" +#include "InventoryFermentables.h" #include "Setup.h" #include "../ui/ui_MainWindow.h" #include "config.h" @@ -69,6 +70,24 @@ } +void MainWindow::fromInventoryFermentables() +{ + qDebug() << Q_FUNC_INFO; + delete InventoryFermentablesWindow; + this->show(); +} + + +void MainWindow::on_actionFermentables_triggered() +{ + qDebug() << Q_FUNC_INFO; + InventoryFermentablesWindow = new InventoryFermentables(this); + QObject::connect(InventoryFermentablesWindow, SIGNAL(firstWindow()), this, SLOT(fromInventoryFermentables())); + this->hide(); // Close the main window + InventoryFermentablesWindow->show(); // Show a second window +} + + void MainWindow::fromSetup() { qDebug() << Q_FUNC_INFO; diff -r d0ca50776b0b -r c94edc758a5b src/MainWindow.h --- a/src/MainWindow.h Thu Feb 17 21:41:52 2022 +0100 +++ b/src/MainWindow.h Fri Feb 18 15:53:02 2022 +0100 @@ -2,6 +2,7 @@ #define _MAINWINDOW_H #include "InventorySuppliers.h" +#include "InventoryFermentables.h" #include "Setup.h" #include @@ -24,11 +25,13 @@ private slots: void on_actionExit_triggered(); void on_actionSuppliers_triggered(); + void on_actionFermentables_triggered(); void on_actionSetup_triggered(); void on_actionAbout_triggered(); public slots: void fromInventorySuppliers(); + void fromInventoryFermentables(); void fromSetup(); private: @@ -36,6 +39,7 @@ // Keep pointers to new windows. InventorySuppliers *InventorySuppliersWindow; + InventoryFermentables *InventoryFermentablesWindow; Setup *SetupWindow; }; diff -r d0ca50776b0b -r c94edc758a5b ui/EditFermentable.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/EditFermentable.ui Fri Feb 18 15:53:02 2022 +0100 @@ -0,0 +1,82 @@ + + + editFermentable + + + + 0 + 0 + 1280 + 640 + + + + Dialog + + + + + + + 0 + 24 + + + + + 16777215 + 24 + + + + + + 10 + 0 + 80 + 23 + + + + + 0 + 0 + + + + Quit + + + + :/icons/silk/icons/silk/door_out.png:/icons/silk/icons/silk/door_out.png + + + + + + 1170 + 0 + 80 + 23 + + + + Save + + + + :/icons/silk/icons/silk/disk.png:/icons/silk/icons/silk/disk.png + + + + + + + + + + + + + + diff -r d0ca50776b0b -r c94edc758a5b ui/InventoryFermentables.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/InventoryFermentables.ui Fri Feb 18 15:53:02 2022 +0100 @@ -0,0 +1,97 @@ + + + InventoryFermentables + + + + 0 + 0 + 1280 + 640 + + + + Dialog + + + + + + true + + + + + + + true + + + false + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 80 + 24 + + + + Quit + + + + :/icons/silk/icons/silk/door_out.png:/icons/silk/icons/silk/door_out.png + + + + + + + + 80 + 24 + + + + New + + + + :/icons/silk/icons/silk/table_row_insert.png:/icons/silk/icons/silk/table_row_insert.png + + + + + + + + + + + + + diff -r d0ca50776b0b -r c94edc758a5b ui/InventorySuppliers.ui --- a/ui/InventorySuppliers.ui Thu Feb 17 21:41:52 2022 +0100 +++ b/ui/InventorySuppliers.ui Fri Feb 18 15:53:02 2022 +0100 @@ -47,6 +47,12 @@ + + + 80 + 24 + + Quit @@ -58,6 +64,12 @@ + + + 80 + 24 + + New diff -r d0ca50776b0b -r c94edc758a5b ui/MainWindow.ui --- a/ui/MainWindow.ui Thu Feb 17 21:41:52 2022 +0100 +++ b/ui/MainWindow.ui Fri Feb 18 15:53:02 2022 +0100 @@ -194,7 +194,7 @@ - false + true