Added archive products sorted on code.

Sat, 21 May 2022 20:26:25 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 21 May 2022 20:26:25 +0200
changeset 231
54b5abd46958
parent 230
b68c0c61d261
child 232
6d3ba9c44f95

Added archive products sorted on code.

CMakeLists.txt file | annotate | diff | comparison | revisions
src/MainWindow.cpp file | annotate | diff | comparison | revisions
src/MainWindow.h file | annotate | diff | comparison | revisions
src/ProdOnCode.cpp file | annotate | diff | comparison | revisions
src/ProdOnCode.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat May 21 19:45:14 2022 +0200
+++ b/CMakeLists.txt	Sat May 21 20:26:25 2022 +0200
@@ -162,6 +162,7 @@
     ${SRCDIR}/EditRecipe.cpp
     ${SRCDIR}/ProdInprod.cpp
     ${SRCDIR}/ProdOnName.cpp
+    ${SRCDIR}/ProdOnCode.cpp
     ${SRCDIR}/EditProduct.cpp
     ${SRCDIR}/Setup.cpp
     ${SRCDIR}/Utils.cpp
@@ -201,6 +202,7 @@
     ${SRCDIR}/EditRecipe.h
     ${SRCDIR}/ProdInprod.h
     ${SRCDIR}/ProdOnName.h
+    ${SRCDIR}/ProdOnCode.h
     ${SRCDIR}/EditProduct.h
     ${SRCDIR}/Setup.h
     ${SRCDIR}/Utils.h
--- a/src/MainWindow.cpp	Sat May 21 19:45:14 2022 +0200
+++ b/src/MainWindow.cpp	Sat May 21 20:26:25 2022 +0200
@@ -26,6 +26,7 @@
 #include "InventoryEquipments.h"
 #include "ProdInprod.h"
 #include "ProdOnName.h"
+#include "ProdOnCode.h"
 #include "ProfileWaters.h"
 #include "ProfileMashs.h"
 #include "ProfileStyles.h"
@@ -550,6 +551,30 @@
 }
 
 
+void MainWindow::fromProdOnCode()
+{
+    qDebug() << Q_FUNC_INFO;
+    ui->mainStack->setCurrentIndex(-1);
+    ui->mainStack->removeWidget(ProdOnCodeWindow);
+    delete ProdOnCodeWindow;
+    setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) );
+    ui->menuBar->setVisible(true);
+    statusBar()->clearMessage();
+}
+
+
+void MainWindow::on_actionOn_Code_triggered()
+{
+    qDebug() << Q_FUNC_INFO;
+    ProdOnCodeWindow = new ProdOnCode(this);
+    int index = ui->mainStack->count();
+    ui->mainStack->addWidget(ProdOnCodeWindow);
+    ui->mainStack->setCurrentIndex(index);
+    setWindowTitle(QString("BMSapp - %1 - Products archive on code").arg(VERSIONSTRING));
+    ui->menuBar->setVisible(false);
+}
+
+
 void MainWindow::fromProfileWaters()
 {
     qDebug() << Q_FUNC_INFO;
--- a/src/MainWindow.h	Sat May 21 19:45:14 2022 +0200
+++ b/src/MainWindow.h	Sat May 21 20:26:25 2022 +0200
@@ -11,6 +11,7 @@
 #include "InventoryEquipments.h"
 #include "ProdInprod.h"
 #include "ProdOnName.h"
+#include "ProdOnCode.h"
 #include "ProfileWaters.h"
 #include "ProfileMashs.h"
 #include "ProfileStyles.h"
@@ -110,6 +111,7 @@
     InventoryEquipments *InventoryEquipmentsWindow;
     ProdInprod *ProdInprodWindow;
     ProdOnName *ProdOnNameWindow;
+    ProdOnCode *ProdOnCodeWindow;
     ProfileWaters *ProfileWatersWindow;
     ProfileMashs *ProfileMashsWindow;
     ProfileStyles *ProfileStylesWindow;
@@ -120,6 +122,7 @@
     void on_actionExit_triggered();
     void on_actionProd_inprod_triggered();
     void on_actionOn_Name_triggered();
+    void on_actionOn_Code_triggered();
     void on_actionRecipes_triggered();
     void on_actionSuppliers_triggered();
     void on_actionFermentables_triggered();
@@ -148,6 +151,7 @@
     void fromInventoryEquipments();
     void fromProdInprod();
     void fromProdOnName();
+    void fromProdOnCode();
     void fromProfileWaters();
     void fromProfileMashs();
     void fromProfileStyles();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ProdOnCode.cpp	Sat May 21 20:26:25 2022 +0200
@@ -0,0 +1,143 @@
+/**
+ * ProdOnCode.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 "ProdOnCode.h"
+#include "MainWindow.h"
+#include "EditProduct.h"
+#include "config.h"
+#include "global.h"
+
+
+ProdOnCode::ProdOnCode(QWidget *parent) : QDialog(parent)
+{
+    qDebug() << "ProdOnCode start";
+
+    gridLayout = new QGridLayout(this);
+    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
+    tableOnCode = new QTableWidget(this);
+    tableOnCode->setObjectName(QString::fromUtf8("tableOnCode"));
+    tableOnCode->setEnabled(true);
+    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+    sizePolicy.setHorizontalStretch(0);
+    sizePolicy.setVerticalStretch(0);
+    sizePolicy.setHeightForWidth(tableOnCode->sizePolicy().hasHeightForWidth());
+    tableOnCode->setSizePolicy(sizePolicy);
+    tableOnCode->setMinimumSize(QSize(1164, 0));
+    gridLayout->addWidget(tableOnCode, 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::AlignCenter);
+    gridLayout->addWidget(groupBox, 1, 0, 1, 1);
+
+    connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProdOnCode()));
+    connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
+    emit refreshTable();
+}
+
+
+void ProdOnCode::refreshTable()
+{
+    QString w;
+    QWidget* pWidget;
+    QHBoxLayout* pLayout;
+
+    qDebug() << "ProdOnCode reload";
+    QSqlQuery query("SELECT record,name,st_name,og,fg,brew_date_start,code FROM products WHERE stage = '11' ORDER BY code,brew_date_start");
+    const QStringList labels({tr("Code"), tr("Name"), tr("Style"), tr("OG"), tr("FG"),  tr("Date"), tr("Edit")});
+
+    this->tableOnCode->setColumnCount(7);
+    this->tableOnCode->setColumnWidth(0, 100);  /* Code         */
+    this->tableOnCode->setColumnWidth(1, 500);	/* Product name	*/
+    this->tableOnCode->setColumnWidth(2, 200);	/* Style	*/
+    this->tableOnCode->setColumnWidth(3,  75);	/* OG		*/
+    this->tableOnCode->setColumnWidth(4,  75);	/* FG		*/
+    this->tableOnCode->setColumnWidth(5, 100);	/* Date		*/
+    this->tableOnCode->setColumnWidth(6, 90);	/* Edit button	*/
+    this->tableOnCode->setRowCount(query.size());
+    this->tableOnCode->setHorizontalHeaderLabels(labels);
+    this->tableOnCode->verticalHeader()->hide();
+
+    query.first();
+    for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
+
+	this->tableOnCode->setItem(ridx, 0, new QTableWidgetItem(query.value("code").toString()));
+	this->tableOnCode->setItem(ridx, 1, new QTableWidgetItem(query.value("name").toString()));
+	this->tableOnCode->setItem(ridx, 2, new QTableWidgetItem(query.value("st_name").toString()));
+	QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(query.value("og").toFloat(), 4, 'f', 3, '0' ));
+	item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+	this->tableOnCode->setItem(ridx, 3, item);
+
+	item = new QTableWidgetItem(QString("%1").arg(query.value("fg").toFloat(), 4, 'f', 3, '0' ));
+        item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
+        this->tableOnCode->setItem(ridx, 4, item);
+
+	this->tableOnCode->setItem(ridx, 5, new QTableWidgetItem(query.value("brew_date_start").toDate().toString("dd MMM yyyy")));
+
+	/* 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);
+        this->tableOnCode->setCellWidget(ridx, 6, pWidget);
+        query.next();
+    }
+
+    emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
+}
+
+
+ProdOnCode::~ProdOnCode() {}
+
+
+void ProdOnCode::edit(int recno)
+{
+    EditProduct 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 ProdOnCode::on_editButton_clicked()
+{
+    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
+    int recno = pb->objectName().toInt();
+    edit(recno);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ProdOnCode.h	Sat May 21 20:26:25 2022 +0200
@@ -0,0 +1,42 @@
+#ifndef _PRODONCODE_H
+#define _PRODONCODE_H
+
+#include <QDialog>
+#include <QtWidgets/QGridLayout>
+#include <QtWidgets/QGroupBox>
+#include <QtWidgets/QHBoxLayout>
+#include <QtWidgets/QHeaderView>
+#include <QtWidgets/QPushButton>
+#include <QtWidgets/QTableWidget>
+
+namespace Ui {
+class ProdOnCode;
+}
+
+class ProdOnCode : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit ProdOnCode(QWidget *parent = nullptr);
+    ~ProdOnCode();
+
+signals:
+    void setStatus(QString);
+
+private slots:
+    void on_editButton_clicked();
+    void refreshTable(void);
+
+private:
+    QGridLayout *gridLayout;
+    QTableWidget *tableOnCode;
+    QGroupBox *groupBox;
+    QHBoxLayout *horizontalLayout;
+    QPushButton *quitButton;
+    QPushButton *insertButton;
+
+    void edit(int recno);
+};
+
+#endif

mercurial