Mon, 18 Jul 2022 17:04:02 +0200
Redesign of the water tabs in product and recipe editors. Prepare for sparge water salt additions. Acid additions are now automatic or manual for mash and sparge. Fixed error in acid calculation strength. Fixed phophoric SG value.
/** * ProfileWaters.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 "ProfileWaters.h" #include "EditProfileWater.h" #include "MainWindow.h" #include "config.h" ProfileWaters::ProfileWaters(QWidget *parent) : QDialog(parent) { qDebug() << "ProfileWaters start"; gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); tableWaters = new QTableWidget(this); tableWaters->setObjectName(QString::fromUtf8("tableWaters")); tableWaters->setEnabled(true); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); tableWaters->setSizePolicy(sizePolicy); tableWaters->setMinimumSize(QSize(1154, 0)); gridLayout->addWidget(tableWaters, 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(fromProfileWaters())); connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); emit refreshTable(); } void ProfileWaters::refreshTable() { QString w; QWidget* pWidget; QHBoxLayout* pLayout; qDebug() << "ProfileWaters reload"; QSqlQuery query("SELECT * FROM profile_water ORDER BY name"); const QStringList labels({tr("Name"), tr("Notes"), tr("Ca"), tr("Mg"), tr("Na"), tr("CaCO3"), tr("Cl"), tr("SO4"), tr("pH"), tr("Edit")}); this->tableWaters->setColumnCount(10); this->tableWaters->setColumnWidth(0, 150); /* Name */ this->tableWaters->setColumnWidth(1, 375); /* Notes */ this->tableWaters->setColumnWidth(2, 75); /* Ca */ this->tableWaters->setColumnWidth(3, 75); /* Mg */ this->tableWaters->setColumnWidth(4, 75); /* Na */ this->tableWaters->setColumnWidth(5, 75); /* CaCO3 */ this->tableWaters->setColumnWidth(6, 75); /* Cl */ this->tableWaters->setColumnWidth(7, 75); /* SO4 */ this->tableWaters->setColumnWidth(8, 75); /* pH */ this->tableWaters->setColumnWidth(9, 80); /* Edit button */ this->tableWaters->setRowCount(query.size()); this->tableWaters->setHorizontalHeaderLabels(labels); this->tableWaters->verticalHeader()->hide(); QTableWidgetItem *rightitem = new QTableWidgetItem(); rightitem->setTextAlignment(Qt::AlignRight); query.first(); for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { this->tableWaters->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ this->tableWaters->setItem(ridx, 1, new QTableWidgetItem(query.value(9).toString())); /* Notes */ w = QString("%1").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Ca */ QTableWidgetItem *item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 2, item); w = QString("%1").arg(query.value(7).toDouble(), 2, 'f', 1, '0' ); /* Mg */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 3, item); w = QString("%1").arg(query.value(6).toDouble(), 2, 'f', 1, '0' ); /* Na */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 4, item); w = QString("%1").arg(query.value(10).toDouble(), 2, 'f', 1, '0' ); /* CaCO3 */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 5, item); w = QString("%1").arg(query.value(5).toDouble(), 2, 'f', 1, '0' ); /* Cl */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 6, item); w = QString("%1").arg(query.value(4).toDouble(), 2, 'f', 1, '0' ); /* SO4 */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 7, item); w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' ); /* pH */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableWaters->setItem(ridx, 8, 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->tableWaters->setCellWidget(ridx, 9, pWidget); query.next(); } emit setStatus(QString(tr("Total items: %1")).arg(query.size())); } ProfileWaters::~ProfileWaters() {} void ProfileWaters::edit(int recno) { EditProfileWater 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 ProfileWaters::on_editButton_clicked() { QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); int recno = pb->objectName().toInt(); edit(recno); } void ProfileWaters::on_insertButton_clicked() { edit(-1); }