|
1 /** |
|
2 * InventoryHops.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 "InventoryHops.h" |
|
18 #include "EditHop.h" |
|
19 #include "../ui/ui_InventoryHops.h" |
|
20 #include "config.h" |
|
21 #include "bmsapp.h" |
|
22 |
|
23 |
|
24 InventoryHops::InventoryHops(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryHops) |
|
25 { |
|
26 qDebug() << "InventoryHops start"; |
|
27 |
|
28 ui->setupUi(this); |
|
29 emit refreshTable(); |
|
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Inventory Hops").arg(VERSIONSTRING) ); |
|
32 } |
|
33 |
|
34 |
|
35 void InventoryHops::refreshTable() |
|
36 { |
|
37 QString w; |
|
38 |
|
39 qDebug() << "InventoryHops reload"; |
|
40 |
|
41 QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name"); |
|
42 const QStringList labels({tr("Origin"), tr("Name"), tr("Type"), tr("Form"), tr("Alpha"), tr("Beta"), tr("Cohumulone"), tr("HSI"), tr("Harvest"), tr("Stock"), 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 /* origin supplier name type graintype color yield inventory Edit */ |
|
47 ui->tableHops->setColumnCount(11); |
|
48 ui->tableHops->setColumnWidth(0, 130); /* Origin */ |
|
49 ui->tableHops->setColumnWidth(1, 250); /* Name */ |
|
50 ui->tableHops->setColumnWidth(2, 80); /* Type */ |
|
51 ui->tableHops->setColumnWidth(3, 80); /* Form */ |
|
52 ui->tableHops->setColumnWidth(4, 80); /* Alpha */ |
|
53 ui->tableHops->setColumnWidth(5, 80); /* Beta */ |
|
54 ui->tableHops->setColumnWidth(6, 80); /* cohumulone */ |
|
55 ui->tableHops->setColumnWidth(7, 80); /* HSI */ |
|
56 ui->tableHops->setColumnWidth(8, 80); /* Harvest date */ |
|
57 ui->tableHops->setColumnWidth(9, 80); /* Stock */ |
|
58 ui->tableHops->setColumnWidth(10, 80); /* Edit button */ |
|
59 ui->tableHops->setRowCount(query.size()); |
|
60 ui->tableHops->setHorizontalHeaderLabels(labels); |
|
61 ui->tableHops->verticalHeader()->hide(); |
|
62 ui->tableHops->setFixedSize(1100 + 24, 640); /* Even if this is too large, it works */ |
|
63 |
|
64 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
|
65 rightitem->setTextAlignment(Qt::AlignRight); |
|
66 |
|
67 query.first(); |
|
68 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
|
69 ui->tableHops->setItem(ridx, 0, new QTableWidgetItem(query.value(12).toString())); /* Origin */ |
|
70 ui->tableHops->setItem(ridx, 1, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
|
71 ui->tableHops->setItem(ridx, 2, new QTableWidgetItem(types[query.value(9).toInt()])); /* Type */ |
|
72 ui->tableHops->setItem(ridx, 3, new QTableWidgetItem(form[query.value(10).toInt()])); /* Form */ |
|
73 w = QString("%1 %").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Alpha% */ |
|
74 QTableWidgetItem *item = new QTableWidgetItem(w); |
|
75 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
76 ui->tableHops->setItem(ridx, 4, item); |
|
77 w = QString("%1 %").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Beta% */ |
|
78 item = new QTableWidgetItem(w); |
|
79 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
80 ui->tableHops->setItem(ridx, 5, item); |
|
81 |
|
82 w = QString("%1 %").arg(query.value(6).toDouble(), 2, 'f', 1, '0' ); /* Cohumulone */ |
|
83 item = new QTableWidgetItem(w); |
|
84 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
85 ui->tableHops->setItem(ridx, 6, item); |
|
86 |
|
87 w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' ); /* HSI */ |
|
88 item = new QTableWidgetItem(w); |
|
89 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
90 ui->tableHops->setItem(ridx, 7, item); |
|
91 |
|
92 if (query.value(15).toDouble() > 0) |
|
93 ui->tableHops->setItem(ridx, 8, new QTableWidgetItem(query.value(17).toString())); /* Harvest */ |
|
94 else |
|
95 ui->tableHops->setItem(ridx, 8, new QTableWidgetItem(QString(""))); |
|
96 |
|
97 w = QString(""); |
|
98 if (query.value(15).toDouble() > 0) { |
|
99 if (query.value(15).toDouble() < 1.000) { |
|
100 w = QString("%1 gr").arg(query.value(15).toDouble() * 1000.0, 2, 'f', 1, '0' ); |
|
101 } else { |
|
102 w = QString("%1 kg").arg(query.value(15).toDouble(), 4, 'f', 3, '0' ); |
|
103 } |
|
104 } |
|
105 item = new QTableWidgetItem(w); |
|
106 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
107 ui->tableHops->setItem(ridx, 9, item); |
|
108 |
|
109 /* Add the Edit button */ |
|
110 QWidget* pWidget = new QWidget(); |
|
111 QPushButton* btn_edit = new QPushButton(); |
|
112 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
|
113 btn_edit->setText(tr("Edit")); |
|
114 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
|
115 QHBoxLayout* pLayout = new QHBoxLayout(pWidget); |
|
116 pLayout->addWidget(btn_edit); |
|
117 pLayout->setContentsMargins(5, 0, 5, 0); |
|
118 pWidget->setLayout(pLayout); |
|
119 ui->tableHops->setCellWidget(ridx, 10, pWidget); |
|
120 query.next(); |
|
121 } |
|
122 |
|
123 setWindowTitle( QString("BMSapp - %1 - Inventory Hops").arg(VERSIONSTRING) ); |
|
124 } |
|
125 |
|
126 |
|
127 InventoryHops::~InventoryHops() |
|
128 { |
|
129 qDebug() << "InventoryHops done"; |
|
130 delete ui; |
|
131 } |
|
132 |
|
133 |
|
134 void InventoryHops::edit(int recno) |
|
135 { |
|
136 qDebug() << "InventoryHops edit:" << recno; |
|
137 |
|
138 EditHop dialog(recno, this); |
|
139 /* Signal from editor if a refresh is needed */ |
|
140 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
|
141 dialog.setModal(true); |
|
142 dialog.exec(); |
|
143 } |
|
144 |
|
145 |
|
146 void InventoryHops::on_editButton_clicked() |
|
147 { |
|
148 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
149 int recno = pb->objectName().toInt(); |
|
150 qDebug() << Q_FUNC_INFO << recno; |
|
151 edit(recno); |
|
152 } |
|
153 |
|
154 |
|
155 void InventoryHops::on_insertButton_clicked() |
|
156 { |
|
157 qDebug() << Q_FUNC_INFO; |
|
158 edit(-1); |
|
159 } |
|
160 |
|
161 |
|
162 void InventoryHops::on_quitButton_clicked() |
|
163 { |
|
164 emit firstWindow(); |
|
165 } |
|
166 |