src/ProdOnName.cpp

changeset 228
c859e8efa470
equal deleted inserted replaced
227:7966bf14cc34 228:c859e8efa470
1 /**
2 * ProdOnName.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 "ProdOnName.h"
18 #include "MainWindow.h"
19 #include "EditProduct.h"
20 #include "config.h"
21 #include "global.h"
22
23
24 ProdOnName::ProdOnName(QWidget *parent) : QDialog(parent)
25 {
26 qDebug() << "ProdOnName start";
27
28 gridLayout = new QGridLayout(this);
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
30 tableOnName = new QTableWidget(this);
31 tableOnName->setObjectName(QString::fromUtf8("tableOnName"));
32 tableOnName->setEnabled(true);
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
34 sizePolicy.setHorizontalStretch(0);
35 sizePolicy.setVerticalStretch(0);
36 sizePolicy.setHeightForWidth(tableOnName->sizePolicy().hasHeightForWidth());
37 tableOnName->setSizePolicy(sizePolicy);
38 tableOnName->setMinimumSize(QSize(1164, 0));
39 gridLayout->addWidget(tableOnName, 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(fromProdOnName()));
62 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
63 emit refreshTable();
64 }
65
66
67 void ProdOnName::refreshTable()
68 {
69 QString w;
70 QWidget* pWidget;
71 QHBoxLayout* pLayout;
72
73 qDebug() << "ProdOnName reload";
74 QSqlQuery query("SELECT record,name,st_name,og,fg,brew_date_start,code FROM products WHERE stage = '11' ORDER BY name,brew_date_start");
75 const QStringList labels({tr("Name"), tr("Style"), tr("OG"), tr("FG"), tr("Date"), tr("Code"), tr("Edit")});
76
77 this->tableOnName->setColumnCount(7);
78 this->tableOnName->setColumnWidth(0, 500); /* Product name */
79 this->tableOnName->setColumnWidth(1, 200); /* Style */
80 this->tableOnName->setColumnWidth(2, 75); /* OG */
81 this->tableOnName->setColumnWidth(3, 75); /* FG */
82 this->tableOnName->setColumnWidth(4, 100); /* Date */
83 this->tableOnName->setColumnWidth(5, 100); /* Code */
84 this->tableOnName->setColumnWidth(6, 90); /* Edit button */
85 this->tableOnName->setRowCount(query.size());
86 this->tableOnName->setHorizontalHeaderLabels(labels);
87 this->tableOnName->verticalHeader()->hide();
88
89 query.first();
90 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
91
92 this->tableOnName->setItem(ridx, 0, new QTableWidgetItem(query.value("name").toString()));
93 this->tableOnName->setItem(ridx, 1, new QTableWidgetItem(query.value("st_name").toString()));
94 QTableWidgetItem *item = new QTableWidgetItem(QString("%1").arg(query.value("og").toFloat(), 4, 'f', 3, '0' ));
95 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
96 this->tableOnName->setItem(ridx, 2, item);
97
98 item = new QTableWidgetItem(QString("%1").arg(query.value("fg").toFloat(), 4, 'f', 3, '0' ));
99 item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
100 this->tableOnName->setItem(ridx, 3, item);
101
102 this->tableOnName->setItem(ridx, 4, new QTableWidgetItem(query.value("brew_date_start").toDate().toString("dd MMM yyyy")));
103 this->tableOnName->setItem(ridx, 5, new QTableWidgetItem(query.value("code").toString()));
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->tableOnName->setCellWidget(ridx, 6, pWidget);
116 query.next();
117 }
118
119 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
120 }
121
122
123 ProdOnName::~ProdOnName() {}
124
125
126 void ProdOnName::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 ProdOnName::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