src/MoniSpindels.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 503
61c114afb0ee
child 537
48de0f61e5ea
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.

/**
 * 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 "CalibrateiSpindel.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)
{
#ifdef DEBUG_MONITOR
    qDebug() << "MoniSpindels start";
#endif

    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;

    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("Cal"), tr("Details")});

    this->tableiSpindels->setColumnCount(8);
    this->tableiSpindels->setColumnWidth(0, 150);	/* Alias	*/
    this->tableiSpindels->setColumnWidth(1, 120);	/* Node		*/
    this->tableiSpindels->setColumnWidth(2, 100);	/* Status	*/
    this->tableiSpindels->setColumnWidth(3, 330);	/* Beer		*/
    this->tableiSpindels->setColumnWidth(4,  90);	/* Temperature	*/
    this->tableiSpindels->setColumnWidth(5,  90);	/* Gravity	*/
    this->tableiSpindels->setColumnWidth(6,  60);	/* Calibrate	*/
    this->tableiSpindels->setColumnWidth(7,  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 Calibrate button */
        QWidget* cWidget = new QWidget();
        QPushButton* btn_cal = new QPushButton();
        btn_cal->setObjectName(QString("%1").arg(query.value("record").toString()));   /* Send record with the button */
        btn_cal->setText(tr("Cal"));
        connect(btn_cal, SIGNAL(clicked()), this, SLOT(on_calButton_clicked()));
        QHBoxLayout* cLayout = new QHBoxLayout(cWidget);
        cLayout->addWidget(btn_cal);
        cLayout->setContentsMargins(5, 0, 5, 0);
        cWidget->setLayout(cLayout);
        this->tableiSpindels->setCellWidget(i, 6, cWidget);

	/* Add the Details 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, 7, pWidget);
	query.next();
    }
    emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
}


MoniSpindels::~MoniSpindels() {}


void MoniSpindels::refreshiSpindels(QString 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);
}


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


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

mercurial