Fri, 20 May 2022 22:06:06 +0200
Version 0.2.1. Updated translations.
24 | 1 | /** |
2 | * InventoryHops.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 "InventoryHops.h" | |
18 | #include "EditHop.h" | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
19 | #include "MainWindow.h" |
24 | 20 | #include "config.h" |
155
f671c599f65b
Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
21 | #include "global.h" |
24 | 22 | |
23 | ||
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
24 | InventoryHops::InventoryHops(QWidget *parent) : QDialog(parent) |
24 | 25 | { |
26 | qDebug() << "InventoryHops start"; | |
27 | ||
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
28 | gridLayout = new QGridLayout(this); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
29 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
30 | tableHops = new QTableWidget(this); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
31 | tableHops->setObjectName(QString::fromUtf8("tableHops")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
32 | tableHops->setEnabled(true); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
33 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
34 | sizePolicy.setHorizontalStretch(0); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
35 | sizePolicy.setVerticalStretch(0); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
36 | //sizePolicy.setHeightForWidth(tableHops->sizePolicy().hasHeightForWidth()); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
37 | tableHops->setSizePolicy(sizePolicy); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
38 | tableHops->setMinimumSize(QSize(1124, 0)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
39 | gridLayout->addWidget(tableHops, 0, 0, 1, 1); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
40 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
41 | groupBox = new QGroupBox(this); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
42 | groupBox->setObjectName(QString::fromUtf8("groupBox")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
43 | groupBox->setEnabled(true); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
44 | groupBox->setFlat(false); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
45 | horizontalLayout = new QHBoxLayout(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
46 | horizontalLayout->setSpacing(6); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
47 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
48 | horizontalLayout->setContentsMargins(0, 0, 0, 0); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
49 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
50 | quitButton = new QPushButton(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
51 | quitButton->setObjectName(QString::fromUtf8("quitButton")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
52 | quitButton->setMinimumSize(QSize(80, 24)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
53 | quitButton->setText(tr("Quit")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
54 | QIcon icon; |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
55 | icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
56 | quitButton->setIcon(icon); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
57 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
58 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
59 | exportButton = new QPushButton(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
60 | exportButton->setObjectName(QString::fromUtf8("exportButton")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
61 | exportButton->setMinimumSize(QSize(80, 24)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
62 | exportButton->setText(tr("Export")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
63 | QIcon icon1; |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
64 | icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
65 | exportButton->setIcon(icon1); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
66 | horizontalLayout->addWidget(exportButton, 0, Qt::AlignRight); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
67 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
68 | importButton = new QPushButton(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
69 | importButton->setObjectName(QString::fromUtf8("importButton")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
70 | importButton->setMinimumSize(QSize(80, 24)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
71 | importButton->setText(tr("Import")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
72 | QIcon icon2; |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
73 | icon2.addFile(QString::fromUtf8(":/icons/silk/database_add.png"), QSize(), QIcon::Normal, QIcon::Off); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
74 | importButton->setIcon(icon2); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
75 | horizontalLayout->addWidget(importButton, 0, Qt::AlignRight); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
76 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
77 | insertButton = new QPushButton(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
78 | insertButton->setObjectName(QString::fromUtf8("insertButton")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
79 | insertButton->setMinimumSize(QSize(80, 24)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
80 | insertButton->setText(tr("New")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
81 | QIcon icon3; |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
82 | icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
83 | insertButton->setIcon(icon3); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
84 | horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
85 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
86 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
87 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryHops())); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
88 | connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
89 | connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked())); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
90 | // connect(importButton, SIGNAL(clicked()), this, SLOT(on_importButton_clicked())); |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
69
diff
changeset
|
91 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); |
24 | 92 | emit refreshTable(); |
93 | } | |
94 | ||
95 | ||
96 | void InventoryHops::refreshTable() | |
97 | { | |
98 | QString w; | |
99 | ||
100 | qDebug() << "InventoryHops reload"; | |
101 | ||
102 | QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name"); | |
103 | const QStringList labels({tr("Origin"), tr("Name"), tr("Type"), tr("Form"), tr("Alpha"), tr("Beta"), tr("Cohumulone"), tr("HSI"), tr("Harvest"), tr("Stock"), tr("Edit")}); | |
104 | ||
105 | /* origin supplier name type graintype color yield inventory Edit */ | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
106 | this->tableHops->setColumnCount(11); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
107 | this->tableHops->setColumnWidth(0, 130); /* Origin */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
108 | this->tableHops->setColumnWidth(1, 250); /* Name */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
109 | this->tableHops->setColumnWidth(2, 80); /* Type */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
110 | this->tableHops->setColumnWidth(3, 80); /* Form */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
111 | this->tableHops->setColumnWidth(4, 80); /* Alpha */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
112 | this->tableHops->setColumnWidth(5, 80); /* Beta */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
113 | this->tableHops->setColumnWidth(6, 80); /* cohumulone */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
114 | this->tableHops->setColumnWidth(7, 80); /* HSI */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
115 | this->tableHops->setColumnWidth(8, 80); /* Harvest date */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
116 | this->tableHops->setColumnWidth(9, 80); /* Stock */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
117 | this->tableHops->setColumnWidth(10, 80); /* Edit button */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
118 | this->tableHops->setRowCount(query.size()); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
119 | this->tableHops->setHorizontalHeaderLabels(labels); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
120 | this->tableHops->verticalHeader()->hide(); |
24 | 121 | |
122 | QTableWidgetItem *rightitem = new QTableWidgetItem(); | |
123 | rightitem->setTextAlignment(Qt::AlignRight); | |
124 | ||
125 | query.first(); | |
126 | for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
127 | this->tableHops->setItem(ridx, 0, new QTableWidgetItem(query.value(12).toString())); /* Origin */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
128 | this->tableHops->setItem(ridx, 1, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
155
f671c599f65b
Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
129 | this->tableHops->setItem(ridx, 2, new QTableWidgetItem(hop_types[query.value(9).toInt()])); /* Type */ |
f671c599f65b
Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
130 | this->tableHops->setItem(ridx, 3, new QTableWidgetItem(hop_forms[query.value(10).toInt()])); /* Form */ |
24 | 131 | w = QString("%1 %").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Alpha% */ |
132 | QTableWidgetItem *item = new QTableWidgetItem(w); | |
133 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
134 | this->tableHops->setItem(ridx, 4, item); |
24 | 135 | w = QString("%1 %").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Beta% */ |
136 | item = new QTableWidgetItem(w); | |
137 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
138 | this->tableHops->setItem(ridx, 5, item); |
24 | 139 | |
140 | w = QString("%1 %").arg(query.value(6).toDouble(), 2, 'f', 1, '0' ); /* Cohumulone */ | |
141 | item = new QTableWidgetItem(w); | |
142 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
143 | this->tableHops->setItem(ridx, 6, item); |
24 | 144 | |
145 | w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' ); /* HSI */ | |
146 | item = new QTableWidgetItem(w); | |
147 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
148 | this->tableHops->setItem(ridx, 7, item); |
24 | 149 | |
150 | if (query.value(15).toDouble() > 0) | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
151 | this->tableHops->setItem(ridx, 8, new QTableWidgetItem(query.value(17).toString())); /* Harvest */ |
24 | 152 | else |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
153 | this->tableHops->setItem(ridx, 8, new QTableWidgetItem(QString(""))); |
24 | 154 | |
155 | w = QString(""); | |
156 | if (query.value(15).toDouble() > 0) { | |
157 | if (query.value(15).toDouble() < 1.000) { | |
158 | w = QString("%1 gr").arg(query.value(15).toDouble() * 1000.0, 2, 'f', 1, '0' ); | |
159 | } else { | |
160 | w = QString("%1 kg").arg(query.value(15).toDouble(), 4, 'f', 3, '0' ); | |
161 | } | |
162 | } | |
163 | item = new QTableWidgetItem(w); | |
164 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
165 | this->tableHops->setItem(ridx, 9, item); |
24 | 166 | |
167 | /* Add the Edit button */ | |
168 | QWidget* pWidget = new QWidget(); | |
169 | QPushButton* btn_edit = new QPushButton(); | |
170 | btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ | |
171 | btn_edit->setText(tr("Edit")); | |
172 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); | |
173 | QHBoxLayout* pLayout = new QHBoxLayout(pWidget); | |
174 | pLayout->addWidget(btn_edit); | |
175 | pLayout->setContentsMargins(5, 0, 5, 0); | |
176 | pWidget->setLayout(pLayout); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
177 | this->tableHops->setCellWidget(ridx, 10, pWidget); |
24 | 178 | query.next(); |
179 | } | |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
69
diff
changeset
|
180 | emit setStatus(QString(tr("Total items: %1")).arg(query.size())); |
24 | 181 | } |
182 | ||
183 | ||
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
184 | InventoryHops::~InventoryHops() {} |
24 | 185 | |
186 | ||
187 | void InventoryHops::edit(int recno) | |
188 | { | |
189 | EditHop dialog(recno, this); | |
190 | /* Signal from editor if a refresh is needed */ | |
191 | connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); | |
192 | dialog.setModal(true); | |
193 | dialog.exec(); | |
194 | } | |
195 | ||
196 | ||
197 | void InventoryHops::on_editButton_clicked() | |
198 | { | |
199 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
200 | int recno = pb->objectName().toInt(); | |
201 | edit(recno); | |
202 | } | |
203 | ||
204 | ||
205 | void InventoryHops::on_insertButton_clicked() | |
206 | { | |
207 | edit(-1); | |
208 | } | |
209 | ||
210 | ||
44
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
211 | void InventoryHops::on_exportButton_clicked() |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
212 | { |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
213 | qDebug() << Q_FUNC_INFO; |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
214 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
215 | QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
216 | const QStringList types({ "Bittering", "Aroma", "Both" }); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
217 | const QStringList forms({ "Pellet", "Plug", "Leaf", "Leaf", "Pellet" }); |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
218 | /* "Leaf Wet", "Cryo" */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
219 | /* We use more hop forms then beerxml knows about, so we send known names */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
220 | /* instead of what we internally use. */ |
44
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
221 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
222 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/hops.xml", tr("Files (*.xml)")); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
223 | if (fileName == 0) { |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
224 | QMessageBox::warning(this, tr("Save File"), tr("No XML file selected.")); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
225 | return; |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
226 | } |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
227 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
228 | QFile file(fileName); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
229 | file.open(QIODevice::WriteOnly); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
230 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
231 | QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
232 | xmlWriter->writeStartDocument(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
233 | xmlWriter->setAutoFormatting(true); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
234 | xmlWriter->setAutoFormattingIndent(1); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
235 | xmlWriter->writeStartElement("HOPS"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
236 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
237 | query.first(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
238 | for (int i = 0 ; i < query.size() ; i++ ) { |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
239 | xmlWriter->writeStartElement("HOP"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
240 | xmlWriter->writeTextElement("VERSION", "1"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
241 | xmlWriter->writeTextElement("NAME", query.value(1).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
242 | if (query.value(11).toString().length()) |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
243 | xmlWriter->writeTextElement("NOTES", query.value(11).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
244 | xmlWriter->writeTextElement("ALWAYS_ON_STOCK", query.value(14).toInt() ? "TRUE":"FALSE"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
245 | xmlWriter->writeTextElement("ALPHA", QString::number(query.value(2).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
246 | xmlWriter->writeTextElement("BETA", QString::number(query.value(3).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
247 | xmlWriter->writeTextElement("HUMULENE", QString::number(query.value(4).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
248 | xmlWriter->writeTextElement("CAROPHYLLENE", QString::number(query.value(5).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
249 | xmlWriter->writeTextElement("COHUMULONE", QString::number(query.value(6).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
250 | xmlWriter->writeTextElement("MYRCENE", QString::number(query.value(7).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
251 | xmlWriter->writeTextElement("TOTAL_OIL", QString::number(query.value(19).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
252 | xmlWriter->writeTextElement("HSI", QString::number(query.value(8).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
253 | xmlWriter->writeTextElement("TYPE", types[query.value(9).toInt()]); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
254 | xmlWriter->writeTextElement("FORM", forms[query.value(10).toInt()]); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
255 | xmlWriter->writeTextElement("ORIGIN", query.value(12).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
256 | if (query.value(13).toString().length()) |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
257 | xmlWriter->writeTextElement("SUBSTITUTES", query.value(13).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
258 | if (query.value(16).toDouble() > 0) |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
259 | xmlWriter->writeTextElement("COST", QString::number(query.value(16).toDouble(), 'f', 4)); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
260 | xmlWriter->writeEndElement(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
261 | query.next(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
262 | } |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
263 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
264 | xmlWriter->writeEndElement(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
265 | xmlWriter->writeEndDocument(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
266 | QMessageBox::information(this, tr("Save File"), tr("XML export ready")); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
267 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
268 | file.close(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
269 | } |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
270 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
271 |