Thu, 20 Apr 2023 17:23:44 +0200
Fixed recipe editor add yeast crash.
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * InventoryEquipments.cpp is part of bmsapp. |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * bmsapp is free software: you can redistribute it and/or modify |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * it under the terms of the GNU General Public License as published by |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * the Free Software Foundation, either version 3 of the License, or |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * (at your option) any later version. |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * bmsapp is distributed in the hope that it will be useful, |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * GNU General Public License for more details. |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * You should have received a copy of the GNU General Public License |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | */ |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | #include "InventoryEquipments.h" |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | #include "EditEquipment.h" |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
19 | #include "MainWindow.h" |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | #include "config.h" |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
23 | InventoryEquipments::InventoryEquipments(QWidget *parent) : QDialog(parent) |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | { |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | qDebug() << "InventoryEquipments start"; |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
27 | gridLayout = new QGridLayout(this); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
28 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
29 | tableEquipments = new QTableWidget(this); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
30 | tableEquipments->setObjectName(QString::fromUtf8("tableEquipments")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
31 | tableEquipments->setEnabled(true); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
32 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
33 | sizePolicy.setHorizontalStretch(0); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
34 | sizePolicy.setVerticalStretch(0); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
35 | tableEquipments->setSizePolicy(sizePolicy); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
36 | tableEquipments->setMinimumSize(QSize(1144, 0)); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
37 | gridLayout->addWidget(tableEquipments, 0, 0, 1, 1); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
38 | |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
39 | groupBox = new QGroupBox(this); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
40 | groupBox->setObjectName(QString::fromUtf8("groupBox")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
41 | groupBox->setEnabled(true); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
42 | groupBox->setFlat(false); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
43 | horizontalLayout = new QHBoxLayout(groupBox); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
44 | horizontalLayout->setSpacing(6); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
45 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
46 | horizontalLayout->setContentsMargins(0, 0, 0, 0); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
47 | |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
48 | quitButton = new QPushButton(groupBox); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
49 | quitButton->setObjectName(QString::fromUtf8("quitButton")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
50 | quitButton->setMinimumSize(QSize(80, 24)); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
51 | quitButton->setText(tr("Quit")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
52 | QIcon icon; |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
53 | icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
54 | quitButton->setIcon(icon); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
55 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
56 | |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
57 | exportButton = new QPushButton(groupBox); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
58 | exportButton->setObjectName(QString::fromUtf8("exportButton")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
59 | exportButton->setMinimumSize(QSize(80, 24)); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
60 | exportButton->setText(tr("Export")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
61 | QIcon icon1; |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
62 | icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
63 | exportButton->setIcon(icon1); |
275
f472f9773782
Added import from xml, equipments and beerstyles.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
64 | horizontalLayout->addWidget(exportButton, 0, Qt::AlignCenter); |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
65 | |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
66 | insertButton = new QPushButton(groupBox); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
67 | insertButton->setObjectName(QString::fromUtf8("insertButton")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
68 | insertButton->setMinimumSize(QSize(80, 24)); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
69 | insertButton->setText(tr("New")); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
70 | QIcon icon3; |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
71 | icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
72 | insertButton->setIcon(icon3); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
73 | horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
74 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
75 | |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
76 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryEquipments())); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
77 | connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
78 | connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked())); |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
73
diff
changeset
|
79 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
80 | emit refreshTable(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | } |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | void InventoryEquipments::refreshTable() |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | { |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | QString w; |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | qDebug() << "InventoryEquipments reload"; |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | QSqlQuery query("SELECT * FROM inventory_equipments ORDER BY name"); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | const QStringList labels({tr("Name"), tr("Boil volume"), tr("Batch size"), tr("Notes"), tr("Edit")}); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
93 | this->tableEquipments->setColumnCount(5); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
94 | this->tableEquipments->setColumnWidth(0, 180); /* Name */ |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
95 | this->tableEquipments->setColumnWidth(1, 90); /* Boil volume */ |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
96 | this->tableEquipments->setColumnWidth(2, 90); /* Batch size */ |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
97 | this->tableEquipments->setColumnWidth(3, 680); /* Notes */ |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
98 | this->tableEquipments->setColumnWidth(4, 80); /* Edit button */ |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
99 | this->tableEquipments->setRowCount(query.size()); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
100 | this->tableEquipments->setHorizontalHeaderLabels(labels); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
101 | this->tableEquipments->verticalHeader()->hide(); |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
102 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
103 | QTableWidgetItem *rightitem = new QTableWidgetItem(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
104 | rightitem->setTextAlignment(Qt::AlignRight); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | query.first(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
108 | this->tableEquipments->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | w = QString("%1 L").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Boil volume */ |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | QTableWidgetItem *item = new QTableWidgetItem(w); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
111 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
112 | this->tableEquipments->setItem(ridx, 1, item); |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
113 | w = QString("%1 L").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Batch size */ |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | item = new QTableWidgetItem(w); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
116 | this->tableEquipments->setItem(ridx, 2, item); |
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
117 | this->tableEquipments->setItem(ridx, 3, new QTableWidgetItem(query.value(16).toString())); /* Notes */ |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
118 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | /* Add the Edit button */ |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
120 | QWidget* pWidget = new QWidget(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | QPushButton* btn_edit = new QPushButton(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
122 | btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | btn_edit->setText(tr("Edit")); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
124 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | QHBoxLayout* pLayout = new QHBoxLayout(pWidget); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
126 | pLayout->addWidget(btn_edit); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | pLayout->setContentsMargins(5, 0, 5, 0); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | pWidget->setLayout(pLayout); |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
129 | this->tableEquipments->setCellWidget(ridx, 4, pWidget); |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
130 | query.next(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | } |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
73
diff
changeset
|
132 | emit setStatus(QString(tr("Total items: %1")).arg(query.size())); |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | } |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | |
73
ebd2fc719b1a
Inventory Equipments now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
47
diff
changeset
|
136 | InventoryEquipments::~InventoryEquipments() {} |
30
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
138 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | void InventoryEquipments::edit(int recno) |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | { |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | EditEquipment dialog(recno, this); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
142 | /* Signal from editor if a refresh is needed */ |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | dialog.setModal(true); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
145 | dialog.exec(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | } |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
148 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | void InventoryEquipments::on_editButton_clicked() |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | { |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | int recno = pb->objectName().toInt(); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | edit(recno); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | } |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | void InventoryEquipments::on_insertButton_clicked() |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | { |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | edit(-1); |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | } |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
161 | |
0fec6a1abd13
Added inventory equipment table and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | |
47 | 163 | void InventoryEquipments::on_exportButton_clicked() |
164 | { | |
165 | qDebug() << Q_FUNC_INFO; | |
166 | ||
167 | QSqlQuery query("SELECT * FROM inventory_equipments ORDER BY name"); | |
168 | ||
169 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/equipments.xml", tr("Files (*.xml)")); | |
170 | if (fileName == 0) { | |
171 | QMessageBox::warning(this, tr("Save File"), tr("No XML file selected.")); | |
172 | return; | |
173 | } | |
174 | ||
175 | QFile file(fileName); | |
176 | file.open(QIODevice::WriteOnly); | |
177 | ||
178 | QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); | |
179 | xmlWriter->writeStartDocument(); | |
180 | xmlWriter->setAutoFormatting(true); | |
181 | xmlWriter->setAutoFormattingIndent(1); | |
182 | xmlWriter->writeStartElement("EQUIPMENTS"); | |
183 | ||
184 | query.first(); | |
185 | for (int i = 0 ; i < query.size() ; i++ ) { | |
186 | xmlWriter->writeStartElement("EQUIPMENT"); | |
187 | xmlWriter->writeTextElement("VERSION", "1"); | |
188 | xmlWriter->writeTextElement("NAME", query.value(1).toString()); | |
189 | xmlWriter->writeTextElement("NOTES", query.value(16).toString()); | |
190 | xmlWriter->writeTextElement("BOIL_SIZE", QString::number(query.value(2).toDouble(), 'f', 4)); | |
191 | xmlWriter->writeTextElement("BATCH_SIZE", QString::number(query.value(3).toDouble(), 'f', 4)); | |
192 | xmlWriter->writeTextElement("TUN_VOLUME", QString::number(query.value(4).toDouble(), 'f', 5)); | |
193 | xmlWriter->writeTextElement("TUN_WEIGHT", QString::number(query.value(5).toDouble(), 'f', 5)); | |
194 | xmlWriter->writeTextElement("TUN_SPECIFIC_HEAT", QString::number(query.value(6).toDouble(), 'f', 5)); | |
195 | xmlWriter->writeTextElement("TUN_HEIGHT", QString::number(query.value(8).toDouble(), 'f', 5)); | |
196 | xmlWriter->writeTextElement("TRUB_CHILLER_LOSS", QString::number(query.value(10).toDouble(), 'f', 5)); | |
197 | xmlWriter->writeTextElement("EVAP_RATE", QString::number(query.value(11).toDouble(), 'f', 5)); | |
198 | xmlWriter->writeTextElement("BOIL_TIME", QString::number(query.value(12).toDouble(), 'f', 5)); | |
199 | xmlWriter->writeTextElement("CALC_BOIL_VOLUME", query.value(13).toInt() ? "TRUE":"FALSE"); | |
200 | xmlWriter->writeTextElement("TOP_UP_KETTLE", QString::number(query.value(14).toDouble(), 'f', 5)); | |
201 | xmlWriter->writeTextElement("HOP_UTILIZATION", QString::number(query.value(15).toDouble(), 'f', 5)); | |
202 | xmlWriter->writeTextElement("LAUTER_VOLUME", QString::number(query.value(17).toDouble(), 'f', 5)); | |
203 | xmlWriter->writeTextElement("LAUTER_HEIGHT", QString::number(query.value(18).toDouble(), 'f', 5)); | |
204 | xmlWriter->writeTextElement("LAUTER_DEADSPACE", QString::number(query.value(19).toDouble(), 'f', 5)); | |
205 | xmlWriter->writeTextElement("KETTLE_VOLUME", QString::number(query.value(20).toDouble(), 'f', 5)); | |
206 | xmlWriter->writeTextElement("KETTLE_HEIGHT", QString::number(query.value(21).toDouble(), 'f', 5)); | |
207 | xmlWriter->writeTextElement("MASH_VOLUME", QString::number(query.value(22).toDouble(), 'f', 5)); | |
208 | xmlWriter->writeTextElement("EFFICIENCY", QString::number(query.value(24).toDouble(), 'f', 5)); | |
209 | xmlWriter->writeEndElement(); | |
210 | query.next(); | |
211 | } | |
212 | ||
213 | xmlWriter->writeEndElement(); | |
214 | xmlWriter->writeEndDocument(); | |
215 | QMessageBox::information(this, tr("Save File"), tr("XML export ready")); | |
216 | ||
217 | file.close(); | |
218 | } | |
219 | ||
220 |