src/InventoryYeastPacks.cpp

changeset 480
94b3def5d778
equal deleted inserted replaced
479:28f0e43e9f08 480:94b3def5d778
1 /**
2 * InventoryYeastPacks.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 "InventoryYeastPacks.h"
18 #include "EditYeastPack.h"
19 #include "MainWindow.h"
20 #include "config.h"
21 #include "global.h"
22
23
24 InventoryYeastPacks::InventoryYeastPacks(QWidget *parent) : QDialog(parent)
25 {
26 qDebug() << "InventoryYeastPacks start";
27
28 gridLayout = new QGridLayout(this);
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
30 tableYeastPacks = new QTableWidget(this);
31 tableYeastPacks->setObjectName(QString::fromUtf8("tableYeastPacks"));
32 tableYeastPacks->setEnabled(true);
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
34 sizePolicy.setHorizontalStretch(0);
35 sizePolicy.setVerticalStretch(0);
36 tableYeastPacks->setSizePolicy(sizePolicy);
37 tableYeastPacks->setMinimumSize(QSize(824, 0));
38 gridLayout->addWidget(tableYeastPacks, 0, 0, 1, 1);
39
40 groupBox = new QGroupBox(this);
41 groupBox->setObjectName(QString::fromUtf8("groupBox"));
42 groupBox->setEnabled(true);
43 groupBox->setFlat(false);
44 horizontalLayout = new QHBoxLayout(groupBox);
45 horizontalLayout->setSpacing(6);
46 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
47 horizontalLayout->setContentsMargins(0, 0, 0, 0);
48
49 quitButton = new QPushButton(groupBox);
50 quitButton->setObjectName(QString::fromUtf8("quitButton"));
51 quitButton->setMinimumSize(QSize(80, 24));
52 quitButton->setText(tr("Quit"));
53 QIcon icon;
54 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
55 quitButton->setIcon(icon);
56 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
57
58 exportButton = new QPushButton(groupBox);
59 exportButton->setObjectName(QString::fromUtf8("exportButton"));
60 exportButton->setMinimumSize(QSize(80, 24));
61 exportButton->setText(tr("Export"));
62 QIcon icon1;
63 icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off);
64 exportButton->setIcon(icon1);
65 horizontalLayout->addWidget(exportButton, 0, Qt::AlignCenter);
66
67 insertButton = new QPushButton(groupBox);
68 insertButton->setObjectName(QString::fromUtf8("insertButton"));
69 insertButton->setMinimumSize(QSize(80, 24));
70 insertButton->setText(tr("New"));
71 QIcon icon3;
72 icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
73 insertButton->setIcon(icon3);
74 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
75 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
76
77 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryYeastPacks()));
78 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
79 connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
80 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
81 emit refreshTable();
82 }
83
84
85 void InventoryYeastPacks::refreshTable()
86 {
87 QString w;
88 QWidget* pWidget;
89 QLabel *label;
90 QHBoxLayout* pLayout;
91
92 qDebug() << "InventoryYeastPacks reload";
93
94 QSqlQuery query("SELECT * FROM inventory_yeastpack ORDER BY laboratory,package");
95 const QStringList labels({tr("Laboratory"), tr("Package"), tr("Form"), tr("Size"), tr("Edit")});
96
97 /* origin supplier name type graintype color yield inventory Edit */
98 this->tableYeastPacks->setColumnCount(5);
99 this->tableYeastPacks->setColumnWidth(0, 250); /* Laboratory */
100 this->tableYeastPacks->setColumnWidth(1, 250); /* Package */
101 this->tableYeastPacks->setColumnWidth(2, 100); /* Form */
102 this->tableYeastPacks->setColumnWidth(3, 100); /* Size */
103 this->tableYeastPacks->setColumnWidth(4, 100); /* Edit button */
104 this->tableYeastPacks->setRowCount(query.size());
105 this->tableYeastPacks->setHorizontalHeaderLabels(labels);
106 this->tableYeastPacks->verticalHeader()->hide();
107
108 QTableWidgetItem *rightitem = new QTableWidgetItem();
109 rightitem->setTextAlignment(Qt::AlignRight);
110
111 query.first();
112 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
113 this->tableYeastPacks->setItem(ridx, 0, new QTableWidgetItem(query.value("laboratory").toString())); /* Laboratory */
114 this->tableYeastPacks->setItem(ridx, 1, new QTableWidgetItem(query.value("package").toString())); /* Name */
115 this->tableYeastPacks->setItem(ridx, 2, new QTableWidgetItem(QCoreApplication::translate("YeastForm", g_yeast_forms[query.value("form").toInt()])));
116
117 w = QString("");
118 if (query.value("form").toInt() == 1 || query.value("form").toInt() == 6) {
119 w = QString("%1 gram").arg(query.value("size").toDouble() * 1000, 2, 'f', 1, '0');
120 } else {
121 w = QString("%1 ml").arg(query.value("size").toDouble() * 1000, 2, 'f', 1, '0');
122 }
123 QTableWidgetItem *item = new QTableWidgetItem(w);
124 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
125 this->tableYeastPacks->setItem(ridx, 3, 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 this->tableYeastPacks->setCellWidget(ridx, 4, pWidget);
138 query.next();
139 }
140 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
141 }
142
143
144 InventoryYeastPacks::~InventoryYeastPacks() {}
145
146
147 void InventoryYeastPacks::edit(int recno)
148 {
149 EditYeastPack dialog(recno, this);
150 /* Signal from editor if a refresh is needed */
151 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
152 dialog.setModal(true);
153 dialog.exec();
154 }
155
156
157 void InventoryYeastPacks::on_editButton_clicked()
158 {
159 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
160 int recno = pb->objectName().toInt();
161 edit(recno);
162 }
163
164
165 void InventoryYeastPacks::on_insertButton_clicked()
166 {
167 edit(-1);
168 }
169
170
171 void InventoryYeastPacks::on_exportButton_clicked()
172 {
173 QMessageBox::information(this, QGuiApplication::applicationDisplayName(), tr("BeerXML doesn't support export yeast packages."));
174 }
175

mercurial