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