src/InventoryMiscs.cpp

changeset 28
93a70b1502ca
child 45
4024b389f689
equal deleted inserted replaced
27:94da58c66913 28:93a70b1502ca
1 /**
2 * InventoryMiscs.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 "InventoryMiscs.h"
18 #include "EditMisc.h"
19 #include "../ui/ui_InventoryMiscs.h"
20 #include "config.h"
21 #include "bmsapp.h"
22
23
24 InventoryMiscs::InventoryMiscs(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryMiscs)
25 {
26 qDebug() << "InventoryMiscs start";
27
28 ui->setupUi(this);
29 emit refreshTable();
30
31 setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) );
32 }
33
34
35 void InventoryMiscs::refreshTable()
36 {
37 QString w;
38
39 qDebug() << "InventoryMiscs reload";
40
41 QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name");
42 const QStringList labels({tr("Name"), tr("Type"), tr("Use"), tr("Time"), tr("Stock"), tr("Edit")});
43 const QStringList types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")});
44 const QStringList use({tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling")});
45
46 /* origin supplier name type graintype color yield inventory Edit */
47 ui->tableMiscs->setColumnCount(6);
48 ui->tableMiscs->setColumnWidth(0, 275); /* Name */
49 ui->tableMiscs->setColumnWidth(1, 120); /* Type */
50 ui->tableMiscs->setColumnWidth(2, 120); /* Use */
51 ui->tableMiscs->setColumnWidth(3, 120); /* Time */
52 ui->tableMiscs->setColumnWidth(4, 80); /* Stock */
53 ui->tableMiscs->setColumnWidth(5, 80); /* Edit button */
54 ui->tableMiscs->setRowCount(query.size());
55 ui->tableMiscs->setHorizontalHeaderLabels(labels);
56 ui->tableMiscs->verticalHeader()->hide();
57 ui->tableMiscs->setFixedSize(795 + 24, 640); /* Even if this is too large, it works */
58
59 QTableWidgetItem *rightitem = new QTableWidgetItem();
60 rightitem->setTextAlignment(Qt::AlignRight);
61
62 query.first();
63 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
64 ui->tableMiscs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */
65 ui->tableMiscs->setItem(ridx, 1, new QTableWidgetItem(types[query.value(2).toInt()])); /* Type */
66 ui->tableMiscs->setItem(ridx, 2, new QTableWidgetItem(use[query.value(3).toInt()])); /* Use */
67
68 w = QString(""); /* Use time */
69 if (query.value(4).toInt() > 0) {
70 if (query.value(4).toInt() == 1)
71 w = QString("1 minute");
72 else if (query.value(4).toInt() < 180)
73 w = QString("%1 minutes").arg(query.value(4).toInt());
74 else if (query.value(4).toInt() < 1440)
75 w = QString("%1 hours").arg(query.value(4).toInt() / 60);
76 else if (query.value(4).toInt() == 1440)
77 w = QString("1 day");
78 else
79 w = QString("%1 days").arg(query.value(4).toInt() / 1440);
80 }
81 QTableWidgetItem *item = new QTableWidgetItem(w);
82 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
83 ui->tableMiscs->setItem(ridx, 3, item);
84
85 w = QString("");
86 if (query.value(9).toDouble() > 0) {
87 if (query.value(5).toInt()) { /* Amount is weight */
88 w = QString("%1 gr").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' );
89 } else {
90 w = QString("%1 ml").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' );
91 }
92 }
93 item = new QTableWidgetItem(w);
94 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
95 ui->tableMiscs->setItem(ridx, 4, item);
96
97 /* Add the Edit button */
98 QWidget* pWidget = new QWidget();
99 QPushButton* btn_edit = new QPushButton();
100 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
101 btn_edit->setText(tr("Edit"));
102 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
103 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
104 pLayout->addWidget(btn_edit);
105 pLayout->setContentsMargins(5, 0, 5, 0);
106 pWidget->setLayout(pLayout);
107 ui->tableMiscs->setCellWidget(ridx, 5, pWidget);
108 query.next();
109 }
110
111 setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) );
112 }
113
114
115 InventoryMiscs::~InventoryMiscs()
116 {
117 qDebug() << "InventoryMiscs done";
118 delete ui;
119 }
120
121
122 void InventoryMiscs::edit(int recno)
123 {
124 qDebug() << "InventoryMiscs edit:" << recno;
125
126 EditMisc dialog(recno, this);
127 /* Signal from editor if a refresh is needed */
128 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
129 dialog.setModal(true);
130 dialog.exec();
131 }
132
133
134 void InventoryMiscs::on_editButton_clicked()
135 {
136 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
137 int recno = pb->objectName().toInt();
138 qDebug() << Q_FUNC_INFO << recno;
139 edit(recno);
140 }
141
142
143 void InventoryMiscs::on_insertButton_clicked()
144 {
145 qDebug() << Q_FUNC_INFO;
146 edit(-1);
147 }
148
149
150 void InventoryMiscs::on_quitButton_clicked()
151 {
152 emit firstWindow();
153 }
154

mercurial