src/ProdInprod.cpp

Sat, 08 Jun 2024 15:54:30 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 08 Jun 2024 15:54:30 +0200
changeset 527
84091b9cb800
parent 301
fe6346211b5b
permissions
-rw-r--r--

Version 0.4.6a1. Added HLT equipment volume and deadspace settings. In EditProduct the target water selection is now sticky. Changed the water treatment tab. Added a row wich displays the salt adjustments. This can be selected between actual and target values. The treated water show can select between mash or sparge water. The total line will become the final water in the boil kettle. Database update function is expanded with the new settings. Added a popup message warning that the database is upgraded and user action is required for the equipment profiles.

/**
 * ProdInprod.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 "ProdInprod.h"
#include "MainWindow.h"
#include "EditProduct.h"
#include "config.h"
#include "global.h"


ProdInprod::ProdInprod(QWidget *parent) : QDialog(parent)
{
    qDebug() << "ProdInprod start";

    gridLayout = new QGridLayout(this);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    tableInprod = new QTableWidget(this);
    tableInprod->setObjectName(QString::fromUtf8("tableInprod"));
    tableInprod->setEnabled(true);
    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(tableInprod->sizePolicy().hasHeightForWidth());
    tableInprod->setSizePolicy(sizePolicy);
    tableInprod->setMinimumSize(QSize(1164, 0));
    gridLayout->addWidget(tableInprod, 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);

    insertButton = new QPushButton(groupBox);
    insertButton->setObjectName(QString::fromUtf8("insertButton"));
    insertButton->setMinimumSize(QSize(80, 24));
    insertButton->setText(tr("New"));
    QIcon icon1;
    icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
    insertButton->setIcon(icon1);
    horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
    gridLayout->addWidget(groupBox, 1, 0, 1, 1);

    connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProdInprod()));
    connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
    connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
    emit refreshTable();
}


void ProdInprod::refreshTable()
{
    QString w;
    QWidget* pWidget;
    QHBoxLayout* pLayout;

    qDebug() << "ProdInprod reload";
    QSqlQuery query("SELECT record,name,code,birth,stage,brew_date_start,package_date,st_name FROM products WHERE stage != '11' ORDER BY stage,code,birth");
    const QStringList labels({tr("Date"), tr("Code"), tr("Style"), tr("Product"), tr("Stage"), tr("Edit")});

    this->tableInprod->setColumnCount(6);
    this->tableInprod->setColumnWidth(0, 100);	/* Date		*/
    this->tableInprod->setColumnWidth(1, 100);	/* Code		*/
    this->tableInprod->setColumnWidth(2, 150);	/* Style	*/
    this->tableInprod->setColumnWidth(3, 500);	/* Product	*/
    this->tableInprod->setColumnWidth(4, 200);	/* Stage	*/
    this->tableInprod->setColumnWidth(5, 90);	/* Edit button	*/
    this->tableInprod->setRowCount(query.size());
    this->tableInprod->setHorizontalHeaderLabels(labels);
    this->tableInprod->verticalHeader()->hide();
    /* Set the widget size to 1064 x 575 in the ui. */

    query.first();
    for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {

	this->tableInprod->setItem(ridx, 0, new QTableWidgetItem(query.value("birth").toDate().toString("dd MMM yyyy")));
	this->tableInprod->setItem(ridx, 1, new QTableWidgetItem(query.value("code").toString()));
	this->tableInprod->setItem(ridx, 2, new QTableWidgetItem(query.value("st_name").toString()));
	this->tableInprod->setItem(ridx, 3, new QTableWidgetItem(query.value("name").toString()));

	int stage = query.value("stage").toInt();
	QString fase = QCoreApplication::translate("ProdStages", g_prod_stages[stage]);
	if (stage == PROD_STAGE_BREW) {
	    fase = QCoreApplication::translate("ProdStages", g_prod_stages[stage]) + tr(" on ") + query.value("brew_date_start").toDate().toString("dd MMM yyyy");
	} else if (stage == PROD_STAGE_CARBONATION) {
	    int timeDiff = query.value("package_date").toDate().daysTo(QDate::currentDate());
	    fase = QCoreApplication::translate("ProdStages", g_prod_stages[stage]) + QString(tr(" day %1 of day 14")).arg(timeDiff);
	} else if (stage == PROD_STAGE_MATURE) {
	    int timeDiff = query.value("package_date").toDate().daysTo(QDate::currentDate()) - 14;
	    fase = QCoreApplication::translate("ProdStages", g_prod_stages[stage]) + QString(tr(" day %1 of day 28")).arg(timeDiff);
	}
	this->tableInprod->setItem(ridx, 4, new QTableWidgetItem(fase));

	/* 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->tableInprod->setCellWidget(ridx, 5, pWidget);
        query.next();
    }

    emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
}


ProdInprod::~ProdInprod() {}


void ProdInprod::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 ProdInprod::on_editButton_clicked()
{
    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
    int recno = pb->objectName().toInt();
    edit(recno);
}


void ProdInprod::on_insertButton_clicked()
{
    edit(-1);
}

mercurial