src/InventoryYeasts.cpp

changeset 25
a9da2744609e
child 29
76846c99f827
equal deleted inserted replaced
24:684c6e74cc1b 25:a9da2744609e
1 /**
2 * InventoryYeasts.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 "InventoryYeasts.h"
18 #include "EditYeast.h"
19 #include "../ui/ui_InventoryYeasts.h"
20 #include "config.h"
21 #include "bmsapp.h"
22
23
24 InventoryYeasts::InventoryYeasts(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryYeasts)
25 {
26 qDebug() << "InventoryYeasts start";
27
28 ui->setupUi(this);
29 emit refreshTable();
30
31 setWindowTitle( QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING) );
32 }
33
34
35 void InventoryYeasts::refreshTable()
36 {
37 QString w;
38 QWidget* pWidget;
39 QLabel *label;
40 QHBoxLayout* pLayout;
41
42 qDebug() << "InventoryYeasts reload";
43
44 QSqlQuery query("SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name");
45 const QStringList labels({tr("Laboratory"), tr("Product id"), tr("Name"), tr("Type"), tr("Form"), tr("SVG %"), tr("Tol %"), tr("POF+"), tr("STA1"), tr("Stock"), tr("Edit")});
46 const QStringList types({tr("Lager"), tr("Ale"), tr("Wheat"), tr("Wine"), tr("Champagne"), tr("Brett"), tr("Kveik"), tr("Hybrid")});
47 const QStringList form({tr("Liquid"), tr("Dry"), tr("Slant"), tr("Culture"), tr("Frozen"), tr("Bottle"), tr("Dried")});
48
49 /* origin supplier name type graintype color yield inventory Edit */
50 ui->tableYeasts->setColumnCount(11);
51 ui->tableYeasts->setColumnWidth(0, 120); /* Laboratory */
52 ui->tableYeasts->setColumnWidth(1, 120); /* Product ID */
53 ui->tableYeasts->setColumnWidth(2, 250); /* Name */
54 ui->tableYeasts->setColumnWidth(3, 70); /* Type */
55 ui->tableYeasts->setColumnWidth(4, 70); /* Form */
56 ui->tableYeasts->setColumnWidth(5, 80); /* SVG */
57 ui->tableYeasts->setColumnWidth(6, 80); /* Tolerance */
58 ui->tableYeasts->setColumnWidth(7, 60); /* POF+ */
59 ui->tableYeasts->setColumnWidth(8, 60); /* STA1 */
60 ui->tableYeasts->setColumnWidth(9, 80); /* Stock */
61 ui->tableYeasts->setColumnWidth(10, 80); /* Edit button */
62 ui->tableYeasts->setRowCount(query.size());
63 ui->tableYeasts->setHorizontalHeaderLabels(labels);
64 ui->tableYeasts->verticalHeader()->hide();
65 ui->tableYeasts->setFixedSize(1070 + 24, 640); /* Even if this is too large, it works */
66
67 QTableWidgetItem *rightitem = new QTableWidgetItem();
68 rightitem->setTextAlignment(Qt::AlignRight);
69
70 query.first();
71 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
72 ui->tableYeasts->setItem(ridx, 0, new QTableWidgetItem(query.value(4).toString())); /* Laboratory */
73 ui->tableYeasts->setItem(ridx, 1, new QTableWidgetItem(query.value(5).toString())); /* Product id */
74 ui->tableYeasts->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString())); /* Name */
75 ui->tableYeasts->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()])); /* Type */
76 ui->tableYeasts->setItem(ridx, 4, new QTableWidgetItem(form[query.value(3).toInt()])); /* Form */
77 w = QString("%1 %").arg(query.value(9).toDouble(), 2, 'f', 1, '0' ); /* Attenuation% */
78 QTableWidgetItem *item = new QTableWidgetItem(w);
79 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
80 ui->tableYeasts->setItem(ridx, 5, item);
81 w = QString("");
82 if (query.value(10).toDouble() > 0)
83 w = QString("%1 %").arg(query.value(10).toDouble(), 2, 'f', 1, '0' ); /* Alcohol% */
84 item = new QTableWidgetItem(w);
85 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
86 ui->tableYeasts->setItem(ridx, 6, item);
87
88 if (query.value(24).toInt()) {
89 pWidget = new QWidget();
90 label = new QLabel;
91 label->setPixmap(QPixmap(":icons/silk/tick.png"));
92 pLayout = new QHBoxLayout(pWidget);
93 pLayout->addWidget(label);
94 pLayout->setAlignment(Qt::AlignCenter);
95 pLayout->setContentsMargins(0, 0, 0, 0);
96 pWidget->setLayout(pLayout);
97 ui->tableYeasts->setCellWidget(ridx, 7, pWidget);
98 }
99 if (query.value(19).toInt()) {
100 pWidget = new QWidget();
101 label = new QLabel;
102 label->setPixmap(QPixmap(":icons/silk/tick.png"));
103 pLayout = new QHBoxLayout(pWidget);
104 pLayout->addWidget(label);
105 pLayout->setAlignment(Qt::AlignCenter);
106 pLayout->setContentsMargins(0, 0, 0, 0);
107 pWidget->setLayout(pLayout);
108 ui->tableYeasts->setCellWidget(ridx, 8, pWidget);
109 }
110
111 w = QString("");
112 if (query.value(14).toDouble() > 0) {
113 if (query.value(3).toInt() == 0 && query.value(14).toDouble() > 1) { /* Liquid yeast, multiple packs */
114 w = QString("%1 packs").arg(query.value(14).toDouble(), 1, 'f', 0, '0');
115 } else if (query.value(3).toInt() == 0) { /* Liquid yeast */
116 w = QString("%1 pack").arg(query.value(14).toDouble(), 1, 'f', 0, '0');
117 } else if (query.value(3).toInt() == 1 || query.value(3).toInt() == 6) { /* Dry or dried */
118 w = QString("%1 gram").arg(query.value(14).toDouble() * 1000, 2, 'f', 1, '0');
119 } else { /* Any other form */
120 w = QString("%1 ml").arg(query.value(14).toDouble() * 1000, 2, 'f', 1, '0');
121 }
122 }
123 item = new QTableWidgetItem(w);
124 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
125 ui->tableYeasts->setItem(ridx, 9, item);
126
127 /* Add the Edit button */
128 pWidget = new QWidget();
129 QPushButton* btn_edit = new QPushButton();
130 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
131 btn_edit->setText(tr("Edit"));
132 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
133 pLayout = new QHBoxLayout(pWidget);
134 pLayout->addWidget(btn_edit);
135 pLayout->setContentsMargins(5, 0, 5, 0);
136 pWidget->setLayout(pLayout);
137 ui->tableYeasts->setCellWidget(ridx, 10, pWidget);
138 query.next();
139 }
140
141 setWindowTitle( QString("BMSapp - %1 - Inventory Yeasts").arg(VERSIONSTRING) );
142 }
143
144
145 InventoryYeasts::~InventoryYeasts()
146 {
147 qDebug() << "InventoryYeasts done";
148 delete ui;
149 }
150
151
152 void InventoryYeasts::edit(int recno)
153 {
154 qDebug() << "InventoryYeasts edit:" << recno;
155
156 EditYeast dialog(recno, this);
157 /* Signal from editor if a refresh is needed */
158 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
159 dialog.setModal(true);
160 dialog.exec();
161 }
162
163
164 void InventoryYeasts::on_editButton_clicked()
165 {
166 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
167 int recno = pb->objectName().toInt();
168 qDebug() << Q_FUNC_INFO << recno;
169 edit(recno);
170 }
171
172
173 void InventoryYeasts::on_insertButton_clicked()
174 {
175 qDebug() << Q_FUNC_INFO;
176 edit(-1);
177 }
178
179
180 void InventoryYeasts::on_quitButton_clicked()
181 {
182 emit firstWindow();
183 }
184

mercurial