src/MonFermenters.cpp

changeset 310
bdaac24b86ed
child 312
251b9aaae916
equal deleted inserted replaced
309:8678a0731737 310:bdaac24b86ed
1 /**
2 * MonFermenters.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 "MonFermenters.h"
18 #include "EditSupplier.h"
19 #include "MainWindow.h"
20 #include "config.h"
21
22
23
24 /*
25 * Build the table and buttons on the mainscreen.
26 * Don't use a ui file, do it dynamicly.
27 */
28 MonFermenters::MonFermenters(QWidget *parent) : QDialog(parent)
29 {
30 qDebug() << "MonFermenters start";
31
32 gridLayout = new QGridLayout(this);
33 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
34 tableSuppliers = new QTableWidget(this);
35 tableSuppliers->setObjectName(QString::fromUtf8("tableSuppliers"));
36 tableSuppliers->setEnabled(true);
37 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
38 sizePolicy.setHorizontalStretch(0);
39 sizePolicy.setVerticalStretch(0);
40 sizePolicy.setHeightForWidth(tableSuppliers->sizePolicy().hasHeightForWidth());
41 tableSuppliers->setSizePolicy(sizePolicy);
42 tableSuppliers->setMinimumSize(QSize(1054, 0));
43 gridLayout->addWidget(tableSuppliers, 0, 0, 1, 1);
44
45 groupBox = new QGroupBox(this);
46 groupBox->setObjectName(QString::fromUtf8("groupBox"));
47 groupBox->setEnabled(true);
48 groupBox->setFlat(false);
49 horizontalLayout = new QHBoxLayout(groupBox);
50 horizontalLayout->setSpacing(6);
51 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
52 horizontalLayout->setContentsMargins(0, 0, 0, 0);
53 quitButton = new QPushButton(groupBox);
54 quitButton->setObjectName(QString::fromUtf8("quitButton"));
55 quitButton->setMinimumSize(QSize(80, 24));
56 quitButton->setText(tr("Quit"));
57 QIcon icon;
58 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
59 quitButton->setIcon(icon);
60 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
61
62 insertButton = new QPushButton(groupBox);
63 insertButton->setObjectName(QString::fromUtf8("insertButton"));
64 insertButton->setMinimumSize(QSize(80, 24));
65 insertButton->setText(tr("New"));
66 QIcon icon1;
67 icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
68 insertButton->setIcon(icon1);
69 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
70 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
71
72 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromMonFermenters()));
73 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
74 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
75 emit refreshTable();
76 }
77
78
79 void MonFermenters::refreshTable()
80 {
81 qDebug() << "MonFermenters reload";
82
83 // query.exec("SELECT record,node,alias,online FROM mon_fermenters ORDER BY node,alias");
84 //
85 QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name");
86 const QStringList labels({tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")});
87
88 this->tableSuppliers->setColumnCount(6);
89 this->tableSuppliers->setColumnWidth(0, 250); /* Name */
90 this->tableSuppliers->setColumnWidth(1, 250); /* Address */
91 this->tableSuppliers->setColumnWidth(2, 200); /* City */
92 this->tableSuppliers->setColumnWidth(3, 120); /* Country */
93 this->tableSuppliers->setColumnWidth(4, 120); /* Phone */
94 this->tableSuppliers->setColumnWidth(5, 90); /* Edit button */
95 this->tableSuppliers->setRowCount(query.size());
96 this->tableSuppliers->setHorizontalHeaderLabels(labels);
97 this->tableSuppliers->verticalHeader()->hide();
98 /* Set the widget size to 1054 x 575 in the ui. */
99
100 query.first();
101 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
102 this->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString()));
103 this->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString()));
104 this->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString()));
105 this->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString()));
106 this->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString()));
107
108 /* Add the Edit button */
109 QWidget* pWidget = new QWidget();
110 QPushButton* btn_edit = new QPushButton();
111 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
112 btn_edit->setText(tr("Edit"));
113 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
114 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
115 pLayout->addWidget(btn_edit);
116 pLayout->setContentsMargins(5, 0, 5, 0);
117 pWidget->setLayout(pLayout);
118 this->tableSuppliers->setCellWidget(ridx, 5, pWidget);
119 query.next();
120 }
121 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
122 }
123
124
125 MonFermenters::~MonFermenters() {}
126
127
128 void MonFermenters::edit(int recno)
129 {
130 EditSupplier dialog(recno, this);
131 /* Signal from editor if a refresh is needed */
132 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
133 dialog.setModal(true);
134 dialog.exec();
135 }
136
137
138 void MonFermenters::on_editButton_clicked()
139 {
140 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
141 int recno = pb->objectName().toInt();
142 edit(recno);
143 }
144
145
146 void MonFermenters::on_insertButton_clicked()
147 {
148 edit(-1);
149 }
150

mercurial