--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/InventoryEquipments.cpp Sun Feb 27 20:45:41 2022 +0100 @@ -0,0 +1,130 @@ +/** + * InventoryEquipments.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 "InventoryEquipments.h" +#include "EditEquipment.h" +#include "../ui/ui_InventoryEquipments.h" +#include "config.h" +#include "bmsapp.h" + + +InventoryEquipments::InventoryEquipments(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryEquipments) +{ + qDebug() << "InventoryEquipments start"; + + ui->setupUi(this); + emit refreshTable(); + + setWindowTitle( QString("BMSapp - %1 - Inventory Equipments").arg(VERSIONSTRING) ); +} + + +void InventoryEquipments::refreshTable() +{ + QString w; + + qDebug() << "InventoryEquipments reload"; + + QSqlQuery query("SELECT * FROM inventory_equipments ORDER BY name"); + const QStringList labels({tr("Name"), tr("Boil volume"), tr("Batch size"), tr("Notes"), tr("Edit")}); + const QStringList types({tr("Bittering"), tr("Aroma"), tr("Both")}); + const QStringList form({tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf Wet"), tr("Cryo")}); + + ui->tableEquipments->setColumnCount(5); + ui->tableEquipments->setColumnWidth(0, 180); /* Name */ + ui->tableEquipments->setColumnWidth(1, 80); /* Boil volume */ + ui->tableEquipments->setColumnWidth(2, 80); /* Batch size */ + ui->tableEquipments->setColumnWidth(3, 680); /* Notes */ + ui->tableEquipments->setColumnWidth(4, 80); /* Edit button */ + ui->tableEquipments->setRowCount(query.size()); + ui->tableEquipments->setHorizontalHeaderLabels(labels); + ui->tableEquipments->verticalHeader()->hide(); + ui->tableEquipments->setFixedSize(1100 + 24, 640); /* Even if this is too large, it works */ + + QTableWidgetItem *rightitem = new QTableWidgetItem(); + rightitem->setTextAlignment(Qt::AlignRight); + + query.first(); + for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { + ui->tableEquipments->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ + w = QString("%1 L").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Boil volume */ + QTableWidgetItem *item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableEquipments->setItem(ridx, 1, item); + w = QString("%1 L").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Batch size */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableEquipments->setItem(ridx, 2, item); + ui->tableEquipments->setItem(ridx, 3, new QTableWidgetItem(query.value(16).toString())); /* Notes */ + + /* 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); + ui->tableEquipments->setCellWidget(ridx, 4, pWidget); + query.next(); + } + + setWindowTitle( QString("BMSapp - %1 - Inventory Equipments").arg(VERSIONSTRING) ); +} + + +InventoryEquipments::~InventoryEquipments() +{ + qDebug() << "InventoryEquipments done"; + delete ui; +} + + +void InventoryEquipments::edit(int recno) +{ + qDebug() << "InventoryEquipments edit:" << recno; + + EditEquipment 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 InventoryEquipments::on_editButton_clicked() +{ + QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); + int recno = pb->objectName().toInt(); + qDebug() << Q_FUNC_INFO << recno; + edit(recno); +} + + +void InventoryEquipments::on_insertButton_clicked() +{ + qDebug() << Q_FUNC_INFO; + edit(-1); +} + + +void InventoryEquipments::on_quitButton_clicked() +{ + emit firstWindow(); +} +