|
1 /** |
|
2 * InventoryEquipments.cpp is part of bmsapp. |
|
3 * |
|
4 * bmsapp is free software: you can redistribute it and/or modify |
|
5 * it under the terms of the GNU General Public License as published by |
|
6 * the Free Software Foundation, either version 3 of the License, or |
|
7 * (at your option) any later version. |
|
8 * |
|
9 * bmsapp is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 #include "InventoryEquipments.h" |
|
18 #include "EditEquipment.h" |
|
19 #include "../ui/ui_InventoryEquipments.h" |
|
20 #include "config.h" |
|
21 #include "bmsapp.h" |
|
22 |
|
23 |
|
24 InventoryEquipments::InventoryEquipments(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryEquipments) |
|
25 { |
|
26 qDebug() << "InventoryEquipments start"; |
|
27 |
|
28 ui->setupUi(this); |
|
29 emit refreshTable(); |
|
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Inventory Equipments").arg(VERSIONSTRING) ); |
|
32 } |
|
33 |
|
34 |
|
35 void InventoryEquipments::refreshTable() |
|
36 { |
|
37 QString w; |
|
38 |
|
39 qDebug() << "InventoryEquipments reload"; |
|
40 |
|
41 QSqlQuery query("SELECT * FROM inventory_equipments ORDER BY name"); |
|
42 const QStringList labels({tr("Name"), tr("Boil volume"), tr("Batch size"), tr("Notes"), tr("Edit")}); |
|
43 const QStringList types({tr("Bittering"), tr("Aroma"), tr("Both")}); |
|
44 const QStringList form({tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf Wet"), tr("Cryo")}); |
|
45 |
|
46 ui->tableEquipments->setColumnCount(5); |
|
47 ui->tableEquipments->setColumnWidth(0, 180); /* Name */ |
|
48 ui->tableEquipments->setColumnWidth(1, 80); /* Boil volume */ |
|
49 ui->tableEquipments->setColumnWidth(2, 80); /* Batch size */ |
|
50 ui->tableEquipments->setColumnWidth(3, 680); /* Notes */ |
|
51 ui->tableEquipments->setColumnWidth(4, 80); /* Edit button */ |
|
52 ui->tableEquipments->setRowCount(query.size()); |
|
53 ui->tableEquipments->setHorizontalHeaderLabels(labels); |
|
54 ui->tableEquipments->verticalHeader()->hide(); |
|
55 ui->tableEquipments->setFixedSize(1100 + 24, 640); /* Even if this is too large, it works */ |
|
56 |
|
57 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
|
58 rightitem->setTextAlignment(Qt::AlignRight); |
|
59 |
|
60 query.first(); |
|
61 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
|
62 ui->tableEquipments->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
|
63 w = QString("%1 L").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Boil volume */ |
|
64 QTableWidgetItem *item = new QTableWidgetItem(w); |
|
65 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
66 ui->tableEquipments->setItem(ridx, 1, item); |
|
67 w = QString("%1 L").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Batch size */ |
|
68 item = new QTableWidgetItem(w); |
|
69 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
70 ui->tableEquipments->setItem(ridx, 2, item); |
|
71 ui->tableEquipments->setItem(ridx, 3, new QTableWidgetItem(query.value(16).toString())); /* Notes */ |
|
72 |
|
73 /* Add the Edit button */ |
|
74 QWidget* pWidget = new QWidget(); |
|
75 QPushButton* btn_edit = new QPushButton(); |
|
76 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
|
77 btn_edit->setText(tr("Edit")); |
|
78 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
|
79 QHBoxLayout* pLayout = new QHBoxLayout(pWidget); |
|
80 pLayout->addWidget(btn_edit); |
|
81 pLayout->setContentsMargins(5, 0, 5, 0); |
|
82 pWidget->setLayout(pLayout); |
|
83 ui->tableEquipments->setCellWidget(ridx, 4, pWidget); |
|
84 query.next(); |
|
85 } |
|
86 |
|
87 setWindowTitle( QString("BMSapp - %1 - Inventory Equipments").arg(VERSIONSTRING) ); |
|
88 } |
|
89 |
|
90 |
|
91 InventoryEquipments::~InventoryEquipments() |
|
92 { |
|
93 qDebug() << "InventoryEquipments done"; |
|
94 delete ui; |
|
95 } |
|
96 |
|
97 |
|
98 void InventoryEquipments::edit(int recno) |
|
99 { |
|
100 qDebug() << "InventoryEquipments edit:" << recno; |
|
101 |
|
102 EditEquipment dialog(recno, this); |
|
103 /* Signal from editor if a refresh is needed */ |
|
104 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
|
105 dialog.setModal(true); |
|
106 dialog.exec(); |
|
107 } |
|
108 |
|
109 |
|
110 void InventoryEquipments::on_editButton_clicked() |
|
111 { |
|
112 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
113 int recno = pb->objectName().toInt(); |
|
114 qDebug() << Q_FUNC_INFO << recno; |
|
115 edit(recno); |
|
116 } |
|
117 |
|
118 |
|
119 void InventoryEquipments::on_insertButton_clicked() |
|
120 { |
|
121 qDebug() << Q_FUNC_INFO; |
|
122 edit(-1); |
|
123 } |
|
124 |
|
125 |
|
126 void InventoryEquipments::on_quitButton_clicked() |
|
127 { |
|
128 emit firstWindow(); |
|
129 } |
|
130 |