Sun, 12 Feb 2023 13:58:36 +0100
In monitor iSpindel: in the chart calculate the ranges, do't let the toolkit do that. Save the path for chart image download in the user settings. In the tooltip for the battery voltage line, also show the remaining battery capacity. In the monitor window show the battery capacity digit instead of allways 0. Updated the translations.
/** * ProdOnName.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 "ProdOnName.h" #include "MainWindow.h" #include "EditProduct.h" #include "config.h" #include "global.h" ProdOnName::ProdOnName(QWidget *parent) : QDialog(parent) { qDebug() << "ProdOnName start"; gridLayout = new QGridLayout(this); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); tableOnName = new QTableWidget(this); tableOnName->setObjectName(QString::fromUtf8("tableOnName")); tableOnName->setEnabled(true); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(tableOnName->sizePolicy().hasHeightForWidth()); tableOnName->setSizePolicy(sizePolicy); tableOnName->setMinimumSize(QSize(1164, 0)); gridLayout->addWidget(tableOnName, 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(fromProdOnName())); connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); emit refreshTable(); } void ProdOnName::refreshTable() { QString w; QWidget* pWidget; QHBoxLayout* pLayout; qDebug() << "ProdOnName reload"; QSqlQuery query("SELECT record,name,st_name,og,fg,brew_date_start,code FROM products WHERE stage = '11' ORDER BY name,brew_date_start"); const QStringList labels({tr("Name"), tr("Style"), tr("OG"), tr("FG"), tr("Date"), tr("Code"), tr("Edit")}); this->tableOnName->setColumnCount(7); this->tableOnName->setColumnWidth(0, 500); /* Product name */ this->tableOnName->setColumnWidth(1, 200); /* Style */ this->tableOnName->setColumnWidth(2, 75); /* OG */ this->tableOnName->setColumnWidth(3, 75); /* FG */ this->tableOnName->setColumnWidth(4, 100); /* Date */ this->tableOnName->setColumnWidth(5, 100); /* Code */ this->tableOnName->setColumnWidth(6, 90); /* Edit button */ this->tableOnName->setRowCount(query.size()); this->tableOnName->setHorizontalHeaderLabels(labels); this->tableOnName->verticalHeader()->hide(); query.first(); for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { this->tableOnName->setItem(ridx, 0, new QTableWidgetItem(query.value("name").toString())); this->tableOnName->setItem(ridx, 1, new QTableWidgetItem(query.value("st_name").toString())); QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(query.value("og").toFloat(), 4, 'f', 3, '0' )); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); this->tableOnName->setItem(ridx, 2, item); item = new QTableWidgetItem(QString("%1").arg(query.value("fg").toFloat(), 4, 'f', 3, '0' )); item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); this->tableOnName->setItem(ridx, 3, item); this->tableOnName->setItem(ridx, 4, new QTableWidgetItem(query.value("brew_date_start").toDate().toString("dd MMM yyyy"))); this->tableOnName->setItem(ridx, 5, new QTableWidgetItem(query.value("code").toString())); /* Add the Edit button */ QWidget* 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())); QHBoxLayout* pLayout = new QHBoxLayout(pWidget); pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); this->tableOnName->setCellWidget(ridx, 6, pWidget); query.next(); } emit setStatus(QString(tr("Total items: %1")).arg(query.size())); } ProdOnName::~ProdOnName() {} void ProdOnName::edit(int recno) { EditProduct 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 ProdOnName::on_editButton_clicked() { QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); int recno = pb->objectName().toInt(); edit(recno); }