src/ProdOnCode.cpp

changeset 231
54b5abd46958
equal deleted inserted replaced
230:b68c0c61d261 231:54b5abd46958
1 /**
2 * ProdOnCode.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 "ProdOnCode.h"
18 #include "MainWindow.h"
19 #include "EditProduct.h"
20 #include "config.h"
21 #include "global.h"
22
23
24 ProdOnCode::ProdOnCode(QWidget *parent) : QDialog(parent)
25 {
26 qDebug() << "ProdOnCode start";
27
28 gridLayout = new QGridLayout(this);
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
30 tableOnCode = new QTableWidget(this);
31 tableOnCode->setObjectName(QString::fromUtf8("tableOnCode"));
32 tableOnCode->setEnabled(true);
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
34 sizePolicy.setHorizontalStretch(0);
35 sizePolicy.setVerticalStretch(0);
36 sizePolicy.setHeightForWidth(tableOnCode->sizePolicy().hasHeightForWidth());
37 tableOnCode->setSizePolicy(sizePolicy);
38 tableOnCode->setMinimumSize(QSize(1164, 0));
39 gridLayout->addWidget(tableOnCode, 0, 0, 1, 1);
40
41 groupBox = new QGroupBox(this);
42 groupBox->setObjectName(QString::fromUtf8("groupBox"));
43 groupBox->setEnabled(true);
44 groupBox->setFlat(false);
45
46 horizontalLayout = new QHBoxLayout(groupBox);
47 horizontalLayout->setSpacing(6);
48 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
49 horizontalLayout->setContentsMargins(0, 0, 0, 0);
50
51 quitButton = new QPushButton(groupBox);
52 quitButton->setObjectName(QString::fromUtf8("quitButton"));
53 quitButton->setMinimumSize(QSize(80, 24));
54 quitButton->setText(tr("Quit"));
55 QIcon icon;
56 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
57 quitButton->setIcon(icon);
58 horizontalLayout->addWidget(quitButton, 0, Qt::AlignCenter);
59 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
60
61 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProdOnCode()));
62 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
63 emit refreshTable();
64 }
65
66
67 void ProdOnCode::refreshTable()
68 {
69 QString w;
70 QWidget* pWidget;
71 QHBoxLayout* pLayout;
72
73 qDebug() << "ProdOnCode reload";
74 QSqlQuery query("SELECT record,name,st_name,og,fg,brew_date_start,code FROM products WHERE stage = '11' ORDER BY code,brew_date_start");
75 const QStringList labels({tr("Code"), tr("Name"), tr("Style"), tr("OG"), tr("FG"), tr("Date"), tr("Edit")});
76
77 this->tableOnCode->setColumnCount(7);
78 this->tableOnCode->setColumnWidth(0, 100); /* Code */
79 this->tableOnCode->setColumnWidth(1, 500); /* Product name */
80 this->tableOnCode->setColumnWidth(2, 200); /* Style */
81 this->tableOnCode->setColumnWidth(3, 75); /* OG */
82 this->tableOnCode->setColumnWidth(4, 75); /* FG */
83 this->tableOnCode->setColumnWidth(5, 100); /* Date */
84 this->tableOnCode->setColumnWidth(6, 90); /* Edit button */
85 this->tableOnCode->setRowCount(query.size());
86 this->tableOnCode->setHorizontalHeaderLabels(labels);
87 this->tableOnCode->verticalHeader()->hide();
88
89 query.first();
90 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
91
92 this->tableOnCode->setItem(ridx, 0, new QTableWidgetItem(query.value("code").toString()));
93 this->tableOnCode->setItem(ridx, 1, new QTableWidgetItem(query.value("name").toString()));
94 this->tableOnCode->setItem(ridx, 2, new QTableWidgetItem(query.value("st_name").toString()));
95 QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(query.value("og").toFloat(), 4, 'f', 3, '0' ));
96 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
97 this->tableOnCode->setItem(ridx, 3, item);
98
99 item = new QTableWidgetItem(QString("%1").arg(query.value("fg").toFloat(), 4, 'f', 3, '0' ));
100 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
101 this->tableOnCode->setItem(ridx, 4, item);
102
103 this->tableOnCode->setItem(ridx, 5, new QTableWidgetItem(query.value("brew_date_start").toDate().toString("dd MMM yyyy")));
104
105 /* Add the Edit button */
106 QWidget* pWidget = new QWidget();
107 QPushButton* btn_edit = new QPushButton();
108 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
109 btn_edit->setText(tr("Edit"));
110 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
111 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
112 pLayout->addWidget(btn_edit);
113 pLayout->setContentsMargins(5, 0, 5, 0);
114 pWidget->setLayout(pLayout);
115 this->tableOnCode->setCellWidget(ridx, 6, pWidget);
116 query.next();
117 }
118
119 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
120 }
121
122
123 ProdOnCode::~ProdOnCode() {}
124
125
126 void ProdOnCode::edit(int recno)
127 {
128 EditProduct dialog(recno, this);
129 /* Signal from editor if a refresh is needed */
130 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
131 dialog.setModal(true);
132 dialog.exec();
133 }
134
135
136 void ProdOnCode::on_editButton_clicked()
137 {
138 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
139 int recno = pb->objectName().toInt();
140 edit(recno);
141 }
142
143

mercurial