Added Inventory Fermentables table.

Fri, 18 Feb 2022 15:53:02 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 18 Feb 2022 15:53:02 +0100
changeset 19
c94edc758a5b
parent 18
d0ca50776b0b
child 20
fcbbddcc22c1

Added Inventory Fermentables table.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/InventoryFermentables.cpp file | annotate | diff | comparison | revisions
src/InventoryFermentables.h file | annotate | diff | comparison | revisions
src/InventorySuppliers.cpp file | annotate | diff | comparison | revisions
src/MainWindow.cpp file | annotate | diff | comparison | revisions
src/MainWindow.h file | annotate | diff | comparison | revisions
ui/EditFermentable.ui file | annotate | diff | comparison | revisions
ui/InventoryFermentables.ui file | annotate | diff | comparison | revisions
ui/InventorySuppliers.ui file | annotate | diff | comparison | revisions
ui/MainWindow.ui file | annotate | diff | comparison | revisions
--- 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 =====
--- /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 <http://www.gnu.org/licenses/>.
+ */
+#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<QPushButton *>(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();
+}
+
--- /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 <QDialog>
+
+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
--- 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) );
 }
--- 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;
--- 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 <QMainWindow>
@@ -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;
 };
 
--- /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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>editFermentable</class>
+ <widget class="QDialog" name="editFermentable">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>1280</width>
+    <height>640</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="2" column="0">
+    <widget class="QWidget" name="bottomWidget" native="true">
+     <property name="minimumSize">
+      <size>
+       <width>0</width>
+       <height>24</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>16777215</width>
+       <height>24</height>
+      </size>
+     </property>
+     <widget class="QPushButton" name="quitButton">
+      <property name="geometry">
+       <rect>
+        <x>10</x>
+        <y>0</y>
+        <width>80</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string>Quit</string>
+      </property>
+      <property name="icon">
+       <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+        <normaloff>:/icons/silk/icons/silk/door_out.png</normaloff>:/icons/silk/icons/silk/door_out.png</iconset>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="saveButton">
+      <property name="geometry">
+       <rect>
+        <x>1170</x>
+        <y>0</y>
+        <width>80</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Save</string>
+      </property>
+      <property name="icon">
+       <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+        <normaloff>:/icons/silk/icons/silk/disk.png</normaloff>:/icons/silk/icons/silk/disk.png</iconset>
+      </property>
+     </widget>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QWidget" name="topWidget" native="true"/>
+   </item>
+  </layout>
+ </widget>
+ <resources>
+  <include location="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"/>
+ </resources>
+ <connections/>
+</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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>InventoryFermentables</class>
+ <widget class="QDialog" name="InventoryFermentables">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>1280</width>
+    <height>640</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QTableWidget" name="tableFermentables">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QGroupBox" name="groupBox">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+     <property name="flat">
+      <bool>false</bool>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <property name="spacing">
+       <number>6</number>
+      </property>
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <property name="topMargin">
+       <number>0</number>
+      </property>
+      <property name="rightMargin">
+       <number>0</number>
+      </property>
+      <property name="bottomMargin">
+       <number>0</number>
+      </property>
+      <item alignment="Qt::AlignLeft">
+       <widget class="QPushButton" name="quitButton">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>80</width>
+          <height>24</height>
+         </size>
+        </property>
+        <property name="text">
+         <string>Quit</string>
+        </property>
+        <property name="icon">
+         <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+          <normaloff>:/icons/silk/icons/silk/door_out.png</normaloff>:/icons/silk/icons/silk/door_out.png</iconset>
+        </property>
+       </widget>
+      </item>
+      <item alignment="Qt::AlignRight">
+       <widget class="QPushButton" name="insertButton">
+        <property name="minimumSize">
+         <size>
+          <width>80</width>
+          <height>24</height>
+         </size>
+        </property>
+        <property name="text">
+         <string>New</string>
+        </property>
+        <property name="icon">
+         <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
+          <normaloff>:/icons/silk/icons/silk/table_row_insert.png</normaloff>:/icons/silk/icons/silk/table_row_insert.png</iconset>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources>
+  <include location="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"/>
+ </resources>
+ <connections/>
+</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 @@
       </property>
       <item alignment="Qt::AlignLeft">
        <widget class="QPushButton" name="quitButton">
+        <property name="minimumSize">
+         <size>
+          <width>80</width>
+          <height>24</height>
+         </size>
+        </property>
         <property name="text">
          <string>Quit</string>
         </property>
@@ -58,6 +64,12 @@
       </item>
       <item alignment="Qt::AlignRight">
        <widget class="QPushButton" name="insertButton">
+        <property name="minimumSize">
+         <size>
+          <width>80</width>
+          <height>24</height>
+         </size>
+        </property>
         <property name="text">
          <string>New</string>
         </property>
--- 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 @@
   </action>
   <action name="actionFermentables">
    <property name="enabled">
-    <bool>false</bool>
+    <bool>true</bool>
    </property>
    <property name="icon">
     <iconset resource="../resources/icons.qrc">

mercurial