Fri, 20 May 2022 22:06:06 +0200
Version 0.2.1. Updated translations.
/** * ProfileFerments.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 "ProfileFerments.h" #include "EditProfileFerment.h" #include "MainWindow.h" #include "config.h" #include "Utils.h" ProfileFerments::ProfileFerments(QWidget *parent) : QDialog(parent) { qDebug() << "ProfileFerments start"; gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); tableFerments = new QTableWidget(this); tableFerments->setObjectName(QString::fromUtf8("tableFerments")); tableFerments->setEnabled(true); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); tableFerments->setSizePolicy(sizePolicy); tableFerments->setMinimumSize(QSize(1004, 0)); gridLayout->addWidget(tableFerments, 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(fromProfileFerments())); connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); emit refreshTable(); } void ProfileFerments::refreshTable() { QString w; QWidget* pWidget; QHBoxLayout* pLayout; qDebug() << "ProfileFerments reload"; QSqlQuery query("SELECT * FROM profile_fermentation ORDER BY name"); const QStringList labels({tr("Name"), tr("Start low"), tr("Start high"), tr("Sensor"), tr("Steps"), tr("Duration"), tr("Edit")}); this->tableFerments->setColumnCount(7); this->tableFerments->setColumnWidth(0, 450); /* Name */ this->tableFerments->setColumnWidth(1, 90); /* Min temp */ this->tableFerments->setColumnWidth(2, 90); /* Max temp */ this->tableFerments->setColumnWidth(3, 75); /* Sensor */ this->tableFerments->setColumnWidth(4, 75); /* Steps */ this->tableFerments->setColumnWidth(5, 120); /* Duration */ this->tableFerments->setColumnWidth(6, 80); /* Edit button */ this->tableFerments->setRowCount(query.size()); this->tableFerments->setHorizontalHeaderLabels(labels); this->tableFerments->verticalHeader()->hide(); QTableWidgetItem *rightitem = new QTableWidgetItem(); rightitem->setTextAlignment(Qt::AlignRight); query.first(); for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { this->tableFerments->setItem(ridx, 0, new QTableWidgetItem(query.value(2).toString())); /* Name */ w = QString("%1 °C").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Min start temp */ QTableWidgetItem *item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableFerments->setItem(ridx, 1, item); w = QString("%1 °C").arg(query.value(4).toDouble(), 2, 'f', 1, '0' ); /* Max start temp */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); this->tableFerments->setItem(ridx, 2, item); w = (query.value(5).toInt()) ? tr("Fridge") : tr("Beer"); /* Initial sensor */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); this->tableFerments->setItem(ridx, 3, item); w = QString("%1").arg(query.value(6).toInt()); /* Number of steps */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); this->tableFerments->setItem(ridx, 4, item); w = Utils::hours_to_string(query.value(7).toInt()); /* Duration */ item = new QTableWidgetItem(w); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); this->tableFerments->setItem(ridx, 5, 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->tableFerments->setCellWidget(ridx, 6, pWidget); query.next(); } emit setStatus(QString(tr("Total items: %1")).arg(query.size())); } ProfileFerments::~ProfileFerments() {} void ProfileFerments::edit(int recno) { EditProfileFerment 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 ProfileFerments::on_editButton_clicked() { QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); int recno = pb->objectName().toInt(); edit(recno); } void ProfileFerments::on_insertButton_clicked() { edit(-1); }