src/ProfileStyles.cpp

Fri, 29 Jul 2022 13:12:26 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 29 Jul 2022 13:12:26 +0200
changeset 373
b02aca4e926c
parent 90
2396457a8167
permissions
-rw-r--r--

First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.

/**
 * ProfileStyles.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 "ProfileStyles.h"
#include "EditProfileStyle.h"
#include "MainWindow.h"
#include "config.h"


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

    gridLayout = new QGridLayout(this);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    tableStyles = new QTableWidget(this);
    tableStyles->setObjectName(QString::fromUtf8("tableStyles"));
    tableStyles->setEnabled(true);
    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    tableStyles->setSizePolicy(sizePolicy);
    tableStyles->setMinimumSize(QSize(1049, 0));
    gridLayout->addWidget(tableStyles, 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 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(fromProfileStyles()));
    connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
    connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
    emit refreshTable();
}


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

    qDebug() << "ProfileStyles reload";

    QSqlQuery query("SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name");
    const QStringList labels({tr("Guide"), tr("Gr"), tr("Name"), tr("OG"), tr("OG"), tr("FG"), tr("FG"),
	tr("IBU"), tr("IBU"), tr("EBC"), tr("EBC"), tr("Co2"), tr("Co2"), tr("ABV"), tr("ABV"), tr("Edit")});

    this->tableStyles->setColumnCount(16);
    this->tableStyles->setColumnWidth(0, 100);	/* Guide	*/
    this->tableStyles->setColumnWidth(1,  25);	/* Group	*/
    this->tableStyles->setColumnWidth(2, 300);	/* Name		*/
    this->tableStyles->setColumnWidth(3,  50);	/* OG		*/
    this->tableStyles->setColumnWidth(4,  50);
    this->tableStyles->setColumnWidth(5,  50);	/* FG		*/
    this->tableStyles->setColumnWidth(6,  50);
    this->tableStyles->setColumnWidth(7,  40);	/* IBU		*/
    this->tableStyles->setColumnWidth(8,  40);
    this->tableStyles->setColumnWidth(9,  40);	/* EBC		*/
    this->tableStyles->setColumnWidth(10, 40);
    this->tableStyles->setColumnWidth(11, 40);	/* Co2		*/
    this->tableStyles->setColumnWidth(12, 40);
    this->tableStyles->setColumnWidth(13, 40);	/* ABV		*/
    this->tableStyles->setColumnWidth(14, 40);
    this->tableStyles->setColumnWidth(15, 80);	/* Edit button	*/
    this->tableStyles->setRowCount(query.size());
    this->tableStyles->setHorizontalHeaderLabels(labels);
    this->tableStyles->verticalHeader()->hide();

    QTableWidgetItem *rightitem = new QTableWidgetItem();
    rightitem->setTextAlignment(Qt::AlignRight);

    query.first();
    for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
	this->tableStyles->setItem(ridx, 0, new QTableWidgetItem(query.value(5).toString()));	/* Guide */
	this->tableStyles->setItem(ridx, 1, new QTableWidgetItem(query.value(4).toString()));	/* Goup */
	this->tableStyles->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString()));	/* Name */

	w = QString("%1").arg(query.value(7).toDouble(), 4, 'f', 3, '0' );      /* OG */
        QTableWidgetItem *item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 3, item);

	w = QString("%1").arg(query.value(8).toDouble(), 4, 'f', 3, '0' );      /* OG */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 4, item);

	w = QString("%1").arg(query.value(9).toDouble(), 4, 'f', 3, '0' );      /* FG */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 5, item);

	w = QString("%1").arg(query.value(10).toDouble(), 4, 'f', 3, '0' );      /* FG */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 6, item);

	w = QString("%1").arg(query.value(11).toDouble(), 1, 'f', 0, '0' );      /* IBU */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 7, item);

	w = QString("%1").arg(query.value(12).toDouble(), 1, 'f', 0, '0' );      /* IBU */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 8, item);

	w = QString("%1").arg(query.value(13).toDouble(), 1, 'f', 0, '0' );      /* EBC */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 9, item);

	w = QString("%1").arg(query.value(14).toDouble(), 1, 'f', 0, '0' );      /* EBC */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 10, item);

	w = QString("%1").arg(query.value(15).toDouble(), 2, 'f', 1, '0' );      /* Co2 */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 11, item);

	w = QString("%1").arg(query.value(16).toDouble(), 2, 'f', 1, '0' );      /* Co2 */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 12, item);

	w = QString("%1").arg(query.value(17).toDouble(), 2, 'f', 1, '0' );      /* ABV */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 13, item);

	w = QString("%1").arg(query.value(18).toDouble(), 2, 'f', 1, '0' );      /* ABV */
        item = new QTableWidgetItem(w);
        item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
        this->tableStyles->setItem(ridx, 14, item);

	/* Add the Edit button */
	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()));
	pLayout = new QHBoxLayout(pWidget);
	pLayout->addWidget(btn_edit);
	pLayout->setContentsMargins(5, 0, 5, 0);
	pWidget->setLayout(pLayout);
	this->tableStyles->setCellWidget(ridx, 15, pWidget);
	query.next();
    }
    emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
}


ProfileStyles::~ProfileStyles() {}


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


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

mercurial