Inventory Yeasts now on the mainscreen.

Sun, 20 Mar 2022 16:49:50 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 20 Mar 2022 16:49:50 +0100
changeset 70
556b4202c5e7
parent 69
228cb2a01acf
child 71
5bd0d7be0167

Inventory Yeasts now on the mainscreen.

src/InventoryYeasts.cpp file | annotate | diff | comparison | revisions
src/InventoryYeasts.h file | annotate | diff | comparison | revisions
src/MainWindow.cpp file | annotate | diff | comparison | revisions
ui/InventoryYeasts.ui file | annotate | diff | comparison | revisions
--- a/src/InventoryYeasts.cpp	Sun Mar 20 16:13:26 2022 +0100
+++ b/src/InventoryYeasts.cpp	Sun Mar 20 16:49:50 2022 +0100
@@ -16,19 +16,78 @@
  */
 #include "InventoryYeasts.h"
 #include "EditYeast.h"
-#include "../ui/ui_InventoryYeasts.h"
+#include "MainWindow.h"
 #include "config.h"
 #include "bmsapp.h"
 
 
-InventoryYeasts::InventoryYeasts(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryYeasts)
+InventoryYeasts::InventoryYeasts(QWidget *parent) : QDialog(parent)
 {
     qDebug() << "InventoryYeasts start";
 
-    ui->setupUi(this);
+    gridLayout = new QGridLayout(this);
+    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
+    tableYeasts = new QTableWidget(this);
+    tableYeasts->setObjectName(QString::fromUtf8("tableYeasts"));
+    tableYeasts->setEnabled(true);
+    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+    sizePolicy.setHorizontalStretch(0);
+    sizePolicy.setVerticalStretch(0);
+    tableYeasts->setSizePolicy(sizePolicy);
+    tableYeasts->setMinimumSize(QSize(1094, 0));
+    gridLayout->addWidget(tableYeasts, 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::AlignRight);
+
+    importButton = new QPushButton(groupBox);
+    importButton->setObjectName(QString::fromUtf8("importButton"));
+    importButton->setMinimumSize(QSize(80, 24));
+    importButton->setText(tr("Import"));
+    QIcon icon2;
+    icon2.addFile(QString::fromUtf8(":/icons/silk/database_add.png"), QSize(), QIcon::Normal, QIcon::Off);
+    importButton->setIcon(icon2);
+    horizontalLayout->addWidget(importButton, 0, Qt::AlignRight);
+
+    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(fromInventoryYeasts()));
+    connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
+    connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
+//    connect(importButton, SIGNAL(clicked()), this, SLOT(on_importButton_clicked()));
     emit refreshTable();
-
-    setWindowTitle( QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING) );
 }
 
 
@@ -47,43 +106,42 @@
     const QStringList form({tr("Liquid"), tr("Dry"), tr("Slant"), tr("Culture"), tr("Frozen"), tr("Bottle"), tr("Dried")});
 
     /* origin supplier name type graintype color yield inventory Edit */
-    ui->tableYeasts->setColumnCount(11);
-    ui->tableYeasts->setColumnWidth(0, 120);	/* Laboratory	*/
-    ui->tableYeasts->setColumnWidth(1, 120);	/* Product ID	*/
-    ui->tableYeasts->setColumnWidth(2, 250);	/* Name		*/
-    ui->tableYeasts->setColumnWidth(3,  70);	/* Type		*/
-    ui->tableYeasts->setColumnWidth(4,  70);	/* Form		*/
-    ui->tableYeasts->setColumnWidth(5,  80);	/* SVG		*/
-    ui->tableYeasts->setColumnWidth(6,  80);	/* Tolerance	*/
-    ui->tableYeasts->setColumnWidth(7,  60);	/* POF+		*/
-    ui->tableYeasts->setColumnWidth(8,  60);	/* STA1		*/
-    ui->tableYeasts->setColumnWidth(9,  80);	/* Stock	*/
-    ui->tableYeasts->setColumnWidth(10, 80);	/* Edit button	*/
-    ui->tableYeasts->setRowCount(query.size());
-    ui->tableYeasts->setHorizontalHeaderLabels(labels);
-    ui->tableYeasts->verticalHeader()->hide();
-    ui->tableYeasts->setFixedSize(1070 + 24, 640);	/* Even if this is too large, it works */
+    this->tableYeasts->setColumnCount(11);
+    this->tableYeasts->setColumnWidth(0, 120);	/* Laboratory	*/
+    this->tableYeasts->setColumnWidth(1, 120);	/* Product ID	*/
+    this->tableYeasts->setColumnWidth(2, 250);	/* Name		*/
+    this->tableYeasts->setColumnWidth(3,  70);	/* Type		*/
+    this->tableYeasts->setColumnWidth(4,  70);	/* Form		*/
+    this->tableYeasts->setColumnWidth(5,  80);	/* SVG		*/
+    this->tableYeasts->setColumnWidth(6,  80);	/* Tolerance	*/
+    this->tableYeasts->setColumnWidth(7,  60);	/* POF+		*/
+    this->tableYeasts->setColumnWidth(8,  60);	/* STA1		*/
+    this->tableYeasts->setColumnWidth(9,  80);	/* Stock	*/
+    this->tableYeasts->setColumnWidth(10, 80);	/* Edit button	*/
+    this->tableYeasts->setRowCount(query.size());
+    this->tableYeasts->setHorizontalHeaderLabels(labels);
+    this->tableYeasts->verticalHeader()->hide();
 
     QTableWidgetItem *rightitem = new QTableWidgetItem();
     rightitem->setTextAlignment(Qt::AlignRight);
 
     query.first();
     for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
-	ui->tableYeasts->setItem(ridx, 0, new QTableWidgetItem(query.value(4).toString()));	/* Laboratory */
-	ui->tableYeasts->setItem(ridx, 1, new QTableWidgetItem(query.value(5).toString()));	/* Product id */
-	ui->tableYeasts->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString()));	/* Name	*/
-	ui->tableYeasts->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()]));	/* Type */
-	ui->tableYeasts->setItem(ridx, 4, new QTableWidgetItem(form[query.value(3).toInt()]));	/* Form */
+	this->tableYeasts->setItem(ridx, 0, new QTableWidgetItem(query.value(4).toString()));	/* Laboratory */
+	this->tableYeasts->setItem(ridx, 1, new QTableWidgetItem(query.value(5).toString()));	/* Product id */
+	this->tableYeasts->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString()));	/* Name	*/
+	this->tableYeasts->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()]));	/* Type */
+	this->tableYeasts->setItem(ridx, 4, new QTableWidgetItem(form[query.value(3).toInt()]));	/* Form */
 	w = QString("%1 %").arg(query.value(9).toDouble(), 2, 'f', 1, '0' );	/* Attenuation% */
 	QTableWidgetItem *item = new QTableWidgetItem(w);
         item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
-        ui->tableYeasts->setItem(ridx, 5, item);
+        this->tableYeasts->setItem(ridx, 5, item);
 	w = QString("");
 	if (query.value(10).toDouble() > 0)
 	    w = QString("%1 %").arg(query.value(10).toDouble(), 2, 'f', 1, '0' );	/* Alcohol% */
         item = new QTableWidgetItem(w);
         item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
-        ui->tableYeasts->setItem(ridx, 6, item);
+        this->tableYeasts->setItem(ridx, 6, item);
 
 	if (query.value(24).toInt()) {
 	    pWidget = new QWidget();
@@ -94,9 +152,9 @@
 	    pLayout->setAlignment(Qt::AlignCenter);
             pLayout->setContentsMargins(0, 0, 0, 0);
             pWidget->setLayout(pLayout);
-	    ui->tableYeasts->setCellWidget(ridx, 7, pWidget);
+	    this->tableYeasts->setCellWidget(ridx, 7, pWidget);
 	} else {
-	    ui->tableYeasts->removeCellWidget(ridx, 7);
+	    this->tableYeasts->removeCellWidget(ridx, 7);
 	}
         if (query.value(19).toInt()) {
             pWidget = new QWidget();
@@ -107,9 +165,9 @@
             pLayout->setAlignment(Qt::AlignCenter);
             pLayout->setContentsMargins(0, 0, 0, 0);
             pWidget->setLayout(pLayout);
-            ui->tableYeasts->setCellWidget(ridx, 8, pWidget);
+            this->tableYeasts->setCellWidget(ridx, 8, pWidget);
         } else {
-	    ui->tableYeasts->removeCellWidget(ridx, 8);
+	    this->tableYeasts->removeCellWidget(ridx, 8);
 	}
 
 	w = QString("");
@@ -126,7 +184,7 @@
 	}
 	item = new QTableWidgetItem(w);
 	item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
-	ui->tableYeasts->setItem(ridx, 9, item);
+	this->tableYeasts->setItem(ridx, 9, item);
 
 	/* Add the Edit button */
 	pWidget = new QWidget();
@@ -138,25 +196,17 @@
 	pLayout->addWidget(btn_edit);
 	pLayout->setContentsMargins(5, 0, 5, 0);
 	pWidget->setLayout(pLayout);
-	ui->tableYeasts->setCellWidget(ridx, 10, pWidget);
+	this->tableYeasts->setCellWidget(ridx, 10, pWidget);
 	query.next();
     }
-
-    setWindowTitle( QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING) );
 }
 
 
-InventoryYeasts::~InventoryYeasts()
-{
-    qDebug() << "InventoryYeasts done";
-    delete ui;
-}
+InventoryYeasts::~InventoryYeasts() {}
 
 
 void InventoryYeasts::edit(int recno)
 {
-    qDebug() << "InventoryYeasts edit:" << recno;
-
     EditYeast dialog(recno, this);
     /* Signal from editor if a refresh is needed */
     connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
@@ -169,14 +219,12 @@
 {
     QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
     int recno = pb->objectName().toInt();
-    qDebug() << Q_FUNC_INFO << recno;
     edit(recno);
 }
 
 
 void InventoryYeasts::on_insertButton_clicked()
 {
-    qDebug() << Q_FUNC_INFO;
     edit(-1);
 }
 
@@ -241,9 +289,3 @@
     file.close();
 }
 
-
-void InventoryYeasts::on_quitButton_clicked()
-{
-    emit firstWindow();
-}
-
--- a/src/InventoryYeasts.h	Sun Mar 20 16:13:26 2022 +0100
+++ b/src/InventoryYeasts.h	Sun Mar 20 16:49:50 2022 +0100
@@ -2,6 +2,12 @@
 #define _INVENTORYYEASTS_H
 
 #include <QDialog>
+#include <QtWidgets/QGridLayout>
+#include <QtWidgets/QGroupBox>
+#include <QtWidgets/QHBoxLayout>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QTableWidget>
 
 namespace Ui {
 class InventoryYeasts;
@@ -15,18 +21,22 @@
     explicit InventoryYeasts(QWidget *parent = nullptr);
     ~InventoryYeasts();
 
-signals:
-    void firstWindow();
-
 private slots:
-    void on_quitButton_clicked();
     void on_insertButton_clicked();
     void on_editButton_clicked();
     void on_exportButton_clicked();
     void refreshTable(void);
 
 private:
-    Ui::InventoryYeasts *ui;
+    QGridLayout *gridLayout;
+    QTableWidget *tableYeasts;
+    QGroupBox *groupBox;
+    QHBoxLayout *horizontalLayout;
+    QPushButton *quitButton;
+    QPushButton *exportButton;
+    QPushButton *importButton;
+    QPushButton *insertButton;
+
     void edit(int recno);
 };
 
--- a/src/MainWindow.cpp	Sun Mar 20 16:13:26 2022 +0100
+++ b/src/MainWindow.cpp	Sun Mar 20 16:49:50 2022 +0100
@@ -139,8 +139,11 @@
 void MainWindow::fromInventoryYeasts()
 {
     qDebug() << Q_FUNC_INFO;
+    ui->mainStack->setCurrentIndex(-1);
+    ui->mainStack->removeWidget(InventoryYeastsWindow);
     delete InventoryYeastsWindow;
-    this->show();
+    setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) );
+    ui->menuBar->setVisible(true);
 }
 
 
@@ -148,9 +151,11 @@
 {
     qDebug() << Q_FUNC_INFO;
     InventoryYeastsWindow = new InventoryYeasts(this);
-    QObject::connect(InventoryYeastsWindow, SIGNAL(firstWindow()), this, SLOT(fromInventoryYeasts()));
-    this->hide();    // Close the main window
-    InventoryYeastsWindow->show();  // Show a second window
+    int index = ui->mainStack->count();
+    ui->mainStack->addWidget(InventoryYeastsWindow);
+    ui->mainStack->setCurrentIndex(index);
+    setWindowTitle(QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING));
+    ui->menuBar->setVisible(false);
 }
 
 
--- a/ui/InventoryYeasts.ui	Sun Mar 20 16:13:26 2022 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>InventoryYeasts</class>
- <widget class="QDialog" name="InventoryYeasts">
-  <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="tableYeasts">
-     <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>
-          <normaloff>:icons/silk/door_out.png</normaloff>:icons/silk/door_out.png</iconset>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QPushButton" name="exportButton">
-        <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>Export</string>
-        </property>
-        <property name="icon">
-         <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
-          <normaloff>:/icons/silk/database_save.png</normaloff>:/icons/silk/database_save.png</iconset>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QPushButton" name="importButton">
-        <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>Import</string>
-        </property>
-        <property name="icon">
-         <iconset resource="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc">
-          <normaloff>:/icons/silk/database_add.png</normaloff>:/icons/silk/database_add.png</iconset>
-        </property>
-       </widget>
-      </item>
-      <item>
-       <widget class="QPushButton" name="insertButton">
-        <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>New</string>
-        </property>
-        <property name="icon">
-         <iconset>
-          <normaloff>:icons/silk/table_row_insert.png</normaloff>: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>

mercurial