src/MoniSpindels.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 329
b57299738980
child 492
c3a781b4d35b
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.

/**
 * MoniSpindels.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 "MoniSpindels.h"
#include "DetailiSpindel.h"
#include "MainWindow.h"
#include "Utils.h"
#include "config.h"



/*
 * Build the table and buttons on the mainscreen.
 * Don't use a ui file, do it dynamicly.
 */
MoniSpindels::MoniSpindels(QWidget *parent) : QDialog(parent)
{
    qDebug() << "MoniSpindels start";

    gridLayout = new QGridLayout(this);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    tableiSpindels = new QTableWidget(this);
    tableiSpindels->setObjectName(QString::fromUtf8("tableiSpindels"));
    tableiSpindels->setEnabled(true);
    QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(tableiSpindels->sizePolicy().hasHeightForWidth());
    tableiSpindels->setSizePolicy(sizePolicy);
    tableiSpindels->setMinimumSize(QSize(1054, 0));
    gridLayout->addWidget(tableiSpindels, 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(fromMoniSpindels()));
    connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
    connect(parent, SIGNAL(updateiSpindels(QString)), this, SLOT(refreshiSpindels(QString)));
    emit refreshTable();
}


void MoniSpindels::refreshTable()
{
    QTableWidgetItem *item;

    qDebug() << "MoniSpindels reload";

    QSqlQuery query("SELECT record,alias,node,online,mode,temperature,gravity,beercode,beername FROM mon_ispindels ORDER BY alias");
    const QStringList labels({tr("Unit"), tr("Node"), tr("Status"), tr("Beer"), tr("Temperature"), tr("SG"), tr("Details")});

    this->tableiSpindels->setColumnCount(7);
    this->tableiSpindels->setColumnWidth(0, 150);	/* Alias	*/
    this->tableiSpindels->setColumnWidth(1, 120);	/* Node		*/
    this->tableiSpindels->setColumnWidth(2, 100);	/* Status	*/
    this->tableiSpindels->setColumnWidth(3, 390);	/* Beer		*/
    this->tableiSpindels->setColumnWidth(4,  90);	/* Temperature	*/
    this->tableiSpindels->setColumnWidth(5,  90);	/* Gravity	*/
    this->tableiSpindels->setColumnWidth(6,  90);	/* Edit button	*/
    this->tableiSpindels->setRowCount(query.size());
    this->tableiSpindels->setHorizontalHeaderLabels(labels);
    this->tableiSpindels->verticalHeader()->hide();
    /* Set the widget size to 1054 x 575 in the ui. */

    query.first();
    for (int i = 0 ; i < query.size() ; i++ ) {
	this->tableiSpindels->setItem(i, 0, new QTableWidgetItem(query.value("alias").toString()));
	this->tableiSpindels->setItem(i, 1, new QTableWidgetItem(query.value("node").toString()));

	if (query.value("online").toInt()) {
            item = new QTableWidgetItem(QString("Ok"));
        } else {
            item = new QTableWidgetItem(QString("Offline"));
            item->setForeground(QBrush(QColor(Qt::red)));
        }
        item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
        this->tableiSpindels->setItem(i, 2, item);

	if (query.value("mode").toString() == "ON") {
	    item = new QTableWidgetItem(query.value("beercode").toString()+" - "+query.value("beername").toString());
	    this->tableiSpindels->setItem(i, 3, item);
	} else {
	    this->tableiSpindels->setItem(i, 3, new QTableWidgetItem(QString("")));
	}

	if (query.value("online").toInt()) {
	    item = new QTableWidgetItem(QString("%1°C").arg(query.value("temperature").toDouble(), 4, 'f', 3, '0'));
	    item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
	    this->tableiSpindels->setItem(i, 4, item);
	    double sg = Utils::plato_to_sg(query.value("gravity").toDouble());
	    item = new QTableWidgetItem(QString("%1").arg(sg, 5, 'f', 4, '0'));
	    item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
	    this->tableiSpindels->setItem(i, 5, item);
	} else {
	    this->tableiSpindels->setItem(i, 4, new QTableWidgetItem(QString("")));
            this->tableiSpindels->setItem(i, 5, new QTableWidgetItem(QString("")));
	}

	/* Add the Edit button */
	QWidget* pWidget = new QWidget();
	QPushButton* btn_edit = new QPushButton();
	btn_edit->setObjectName(QString("%1").arg(query.value("record").toString()));	/* Send record with the button */
	btn_edit->setText(tr("Details"));
	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->tableiSpindels->setCellWidget(i, 6, pWidget);
	query.next();
    }
    emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
}


MoniSpindels::~MoniSpindels() {}


void MoniSpindels::refreshiSpindels(QString data)
{
    qDebug() << "refreshiSpindels" << data;
    emit refreshTable();
    emit updateiSpindel(data);
}


void MoniSpindels::edit(int recno)
{
    DetailiSpindel dialog(recno, this);
    dialog.setModal(true);
    dialog.exec();
}


void MoniSpindels::on_editButton_clicked()
{
    QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
    int recno = pb->objectName().toInt();
    edit(recno);
}

mercurial