src/ProdInprod.cpp

changeset 173
8514932b61aa
child 175
f1ed3a2a94e9
equal deleted inserted replaced
172:b93f5e5afc67 173:8514932b61aa
1 /**
2 * ProdInprod.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 "ProdInprod.h"
18 #include "MainWindow.h"
19 #include "config.h"
20 #include "global.h"
21
22
23 ProdInprod::ProdInprod(QWidget *parent) : QDialog(parent)
24 {
25 qDebug() << "ProdInprod start";
26
27 gridLayout = new QGridLayout(this);
28 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
29 tableInprod = new QTableWidget(this);
30 tableInprod->setObjectName(QString::fromUtf8("tableInprod"));
31 tableInprod->setEnabled(true);
32 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
33 sizePolicy.setHorizontalStretch(0);
34 sizePolicy.setVerticalStretch(0);
35 sizePolicy.setHeightForWidth(tableInprod->sizePolicy().hasHeightForWidth());
36 tableInprod->setSizePolicy(sizePolicy);
37 tableInprod->setMinimumSize(QSize(1164, 0));
38 gridLayout->addWidget(tableInprod, 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
45 horizontalLayout = new QHBoxLayout(groupBox);
46 horizontalLayout->setSpacing(6);
47 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
48 horizontalLayout->setContentsMargins(0, 0, 0, 0);
49
50 quitButton = new QPushButton(groupBox);
51 quitButton->setObjectName(QString::fromUtf8("quitButton"));
52 quitButton->setMinimumSize(QSize(80, 24));
53 quitButton->setText(tr("Quit"));
54 QIcon icon;
55 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
56 quitButton->setIcon(icon);
57 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
58
59 insertButton = new QPushButton(groupBox);
60 insertButton->setObjectName(QString::fromUtf8("insertButton"));
61 insertButton->setMinimumSize(QSize(80, 24));
62 insertButton->setText(tr("New"));
63 QIcon icon1;
64 icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
65 insertButton->setIcon(icon1);
66 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
67 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
68
69 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromProdInprod()));
70 //connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
71 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
72 emit refreshTable();
73 }
74
75
76 void ProdInprod::refreshTable()
77 {
78 QString w;
79 QWidget* pWidget;
80 QHBoxLayout* pLayout;
81
82 qDebug() << "ProdInprod reload";
83 QSqlQuery query("SELECT record,name,code,birth,stage,brew_date_start,package_date,st_name FROM products WHERE stage != '11' ORDER BY stage,code,birth");
84 const QStringList labels({tr("Date"), tr("Code"), tr("Style"), tr("Product"), tr("Stage"), tr("Edit")});
85
86 this->tableInprod->setColumnCount(6);
87 this->tableInprod->setColumnWidth(0, 100); /* Date */
88 this->tableInprod->setColumnWidth(1, 100); /* Code */
89 this->tableInprod->setColumnWidth(2, 150); /* Style */
90 this->tableInprod->setColumnWidth(3, 500); /* Product */
91 this->tableInprod->setColumnWidth(4, 200); /* Stage */
92 this->tableInprod->setColumnWidth(5, 90); /* Edit button */
93 this->tableInprod->setRowCount(query.size());
94 this->tableInprod->setHorizontalHeaderLabels(labels);
95 this->tableInprod->verticalHeader()->hide();
96 /* Set the widget size to 1064 x 575 in the ui. */
97
98 query.first();
99 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
100
101 this->tableInprod->setItem(ridx, 0, new QTableWidgetItem(query.value("birth").toDate().toString("dd MMM yyyy")));
102 this->tableInprod->setItem(ridx, 1, new QTableWidgetItem(query.value("code").toString()));
103 this->tableInprod->setItem(ridx, 2, new QTableWidgetItem(query.value("st_name").toString()));
104 this->tableInprod->setItem(ridx, 3, new QTableWidgetItem(query.value("name").toString()));
105
106 int stage = query.value("stage").toInt();
107 QString fase = prod_stages[stage];
108 if (stage == PROD_STAGE_BREW) {
109 fase = prod_stages[stage] + tr(" on ") + query.value("brew_date_start").toDate().toString("dd MMM yyyy");
110 } else if (stage == PROD_STAGE_CARBONATION) {
111 int timeDiff = query.value("package_date").toDate().daysTo(QDate::currentDate());
112 fase = prod_stages[stage] + QString(tr(" day %1 of day 14")).arg(timeDiff);
113 } else if (stage == PROD_STAGE_MATURE) {
114 int timeDiff = query.value("package_date").toDate().daysTo(QDate::currentDate()) - 14;
115 fase = prod_stages[stage] + QString(tr(" day %1 of day 28")).arg(timeDiff);
116 }
117 this->tableInprod->setItem(ridx, 4, new QTableWidgetItem(fase));
118
119 /* Add the Edit button */
120 QWidget* pWidget = new QWidget();
121 QPushButton* btn_edit = new QPushButton();
122 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
123 btn_edit->setText(tr("Edit"));
124 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
125 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
126 pLayout->addWidget(btn_edit);
127 pLayout->setContentsMargins(5, 0, 5, 0);
128 pWidget->setLayout(pLayout);
129 this->tableInprod->setCellWidget(ridx, 5, pWidget);
130 query.next();
131 }
132
133 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
134 }
135
136
137 ProdInprod::~ProdInprod() {}
138
139
140 void ProdInprod::edit(int recno)
141 {
142 // EditProfileMash dialog(recno, this);
143 /* Signal from editor if a refresh is needed */
144 // connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
145 // dialog.setModal(true);
146 // dialog.exec();
147 }
148
149
150 void ProdInprod::on_editButton_clicked()
151 {
152 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
153 int recno = pb->objectName().toInt();
154 edit(recno);
155 }
156
157

mercurial