|
1 /** |
|
2 * InventoryWaters.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 "InventoryWaters.h" |
|
18 #include "EditWater.h" |
|
19 #include "../ui/ui_InventoryWaters.h" |
|
20 #include "config.h" |
|
21 #include "bmsapp.h" |
|
22 |
|
23 |
|
24 InventoryWaters::InventoryWaters(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryWaters) |
|
25 { |
|
26 qDebug() << "InventoryWaters start"; |
|
27 |
|
28 ui->setupUi(this); |
|
29 emit refreshTable(); |
|
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Inventory Waters").arg(VERSIONSTRING) ); |
|
32 } |
|
33 |
|
34 |
|
35 void InventoryWaters::refreshTable() |
|
36 { |
|
37 QString w; |
|
38 QWidget* pWidget; |
|
39 QLabel *label; |
|
40 QHBoxLayout* pLayout; |
|
41 |
|
42 qDebug() << "InventoryWaters reload"; |
|
43 |
|
44 QSqlQuery query("SELECT * FROM inventory_waters ORDER BY name"); |
|
45 const QStringList labels({tr("Name"), tr("Notes"), tr("Unlimited"), tr("Stock"), tr("Edit")}); |
|
46 |
|
47 ui->tableWaters->setColumnCount(5); |
|
48 ui->tableWaters->setColumnWidth(0, 200); /* Name */ |
|
49 ui->tableWaters->setColumnWidth(1, 500); /* Notes */ |
|
50 ui->tableWaters->setColumnWidth(2, 75); /* Unlimited */ |
|
51 ui->tableWaters->setColumnWidth(3, 75); /* Stock */ |
|
52 ui->tableWaters->setColumnWidth(4, 80); /* Edit button */ |
|
53 ui->tableWaters->setRowCount(query.size()); |
|
54 ui->tableWaters->setHorizontalHeaderLabels(labels); |
|
55 ui->tableWaters->verticalHeader()->hide(); |
|
56 ui->tableWaters->setFixedSize(930 + 24, 640); /* Even if this is too large, it works */ |
|
57 |
|
58 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
|
59 rightitem->setTextAlignment(Qt::AlignRight); |
|
60 |
|
61 query.first(); |
|
62 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
|
63 ui->tableWaters->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
|
64 ui->tableWaters->setItem(ridx, 1, new QTableWidgetItem(query.value(10).toString())); /* Notes */ |
|
65 if (query.value(2).toInt()) { |
|
66 pWidget = new QWidget(); |
|
67 label = new QLabel; |
|
68 label->setPixmap(QPixmap(":icons/silk/tick.png")); |
|
69 pLayout = new QHBoxLayout(pWidget); |
|
70 pLayout->addWidget(label); |
|
71 pLayout->setAlignment(Qt::AlignCenter); |
|
72 pLayout->setContentsMargins(0, 0, 0, 0); |
|
73 pWidget->setLayout(pLayout); |
|
74 ui->tableWaters->setCellWidget(ridx, 2, pWidget); |
|
75 } else { |
|
76 ui->tableWaters->removeCellWidget(ridx, 2); |
|
77 } |
|
78 |
|
79 w = QString(""); |
|
80 if (query.value(12).toDouble() > 0) { |
|
81 w = QString("%1 L").arg(query.value(12).toDouble(), 2, 'f', 1, '0' ); |
|
82 } |
|
83 QTableWidgetItem *item = new QTableWidgetItem(w); |
|
84 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
|
85 ui->tableWaters->setItem(ridx, 3, item); |
|
86 |
|
87 /* Add the Edit button */ |
|
88 pWidget = new QWidget(); |
|
89 QPushButton* btn_edit = new QPushButton(); |
|
90 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
|
91 btn_edit->setText(tr("Edit")); |
|
92 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
|
93 pLayout = new QHBoxLayout(pWidget); |
|
94 pLayout->addWidget(btn_edit); |
|
95 pLayout->setContentsMargins(5, 0, 5, 0); |
|
96 pWidget->setLayout(pLayout); |
|
97 ui->tableWaters->setCellWidget(ridx, 4, pWidget); |
|
98 query.next(); |
|
99 } |
|
100 |
|
101 setWindowTitle( QString("BMSapp - %1 - Inventory Waters").arg(VERSIONSTRING) ); |
|
102 } |
|
103 |
|
104 |
|
105 InventoryWaters::~InventoryWaters() |
|
106 { |
|
107 qDebug() << "InventoryWaters done"; |
|
108 delete ui; |
|
109 } |
|
110 |
|
111 |
|
112 void InventoryWaters::edit(int recno) |
|
113 { |
|
114 qDebug() << "InventoryWaters edit:" << recno; |
|
115 |
|
116 EditWater dialog(recno, this); |
|
117 /* Signal from editor if a refresh is needed */ |
|
118 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
|
119 dialog.setModal(true); |
|
120 dialog.exec(); |
|
121 } |
|
122 |
|
123 |
|
124 void InventoryWaters::on_editButton_clicked() |
|
125 { |
|
126 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
|
127 int recno = pb->objectName().toInt(); |
|
128 qDebug() << Q_FUNC_INFO << recno; |
|
129 edit(recno); |
|
130 } |
|
131 |
|
132 |
|
133 void InventoryWaters::on_insertButton_clicked() |
|
134 { |
|
135 qDebug() << Q_FUNC_INFO; |
|
136 edit(-1); |
|
137 } |
|
138 |
|
139 |
|
140 void InventoryWaters::on_quitButton_clicked() |
|
141 { |
|
142 emit firstWindow(); |
|
143 } |
|
144 |