src/InventoryHops.cpp

Fri, 29 Jul 2022 13:12:26 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 29 Jul 2022 13:12:26 +0200
changeset 373
b02aca4e926c
parent 301
fe6346211b5b
child 380
8f5c03ed4321
permissions
-rw-r--r--

First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.

24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * InventoryHops.cpp is part of bmsapp.
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "InventoryHops.h"
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 {
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "InventoryHops start";
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
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 tableHops->setSizePolicy(sizePolicy);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
37 tableHops->setMinimumSize(QSize(1124, 0));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
38 gridLayout->addWidget(tableHops, 0, 0, 1, 1);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
39
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
40 groupBox = new QGroupBox(this);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
41 groupBox->setObjectName(QString::fromUtf8("groupBox"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
42 groupBox->setEnabled(true);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
43 groupBox->setFlat(false);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
44 horizontalLayout = new QHBoxLayout(groupBox);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
45 horizontalLayout->setSpacing(6);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
46 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
47 horizontalLayout->setContentsMargins(0, 0, 0, 0);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
48
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
49 quitButton = new QPushButton(groupBox);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
50 quitButton->setObjectName(QString::fromUtf8("quitButton"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
51 quitButton->setMinimumSize(QSize(80, 24));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
52 quitButton->setText(tr("Quit"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
53 QIcon icon;
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
54 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
55 quitButton->setIcon(icon);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
56 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
57
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
58 exportButton = new QPushButton(groupBox);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
59 exportButton->setObjectName(QString::fromUtf8("exportButton"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
60 exportButton->setMinimumSize(QSize(80, 24));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
61 exportButton->setText(tr("Export"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
62 QIcon icon1;
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
63 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
64 exportButton->setIcon(icon1);
290
93820a8ffbff Removed unneeded import buttons from the inventory screens.
Michiel Broek <mbroek@mbse.eu>
parents: 155
diff changeset
65 horizontalLayout->addWidget(exportButton, 0, Qt::AlignCenter);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
66
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
67 insertButton = new QPushButton(groupBox);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
68 insertButton->setObjectName(QString::fromUtf8("insertButton"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
69 insertButton->setMinimumSize(QSize(80, 24));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
70 insertButton->setText(tr("New"));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
71 QIcon icon3;
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
72 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
73 insertButton->setIcon(icon3);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
74 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
75 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
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 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryHops()));
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
78 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
79 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: 69
diff changeset
80 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 emit refreshTable();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 }
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 void InventoryHops::refreshTable()
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 {
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 QString w;
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 qDebug() << "InventoryHops reload";
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name");
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 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")});
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 /* 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
95 this->tableHops->setColumnCount(11);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
96 this->tableHops->setColumnWidth(0, 130); /* Origin */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
97 this->tableHops->setColumnWidth(1, 250); /* Name */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
98 this->tableHops->setColumnWidth(2, 80); /* Type */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
99 this->tableHops->setColumnWidth(3, 80); /* Form */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
100 this->tableHops->setColumnWidth(4, 80); /* Alpha */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
101 this->tableHops->setColumnWidth(5, 80); /* Beta */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
102 this->tableHops->setColumnWidth(6, 80); /* cohumulone */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
103 this->tableHops->setColumnWidth(7, 80); /* HSI */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
104 this->tableHops->setColumnWidth(8, 80); /* Harvest date */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
105 this->tableHops->setColumnWidth(9, 80); /* Stock */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
106 this->tableHops->setColumnWidth(10, 80); /* Edit button */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
107 this->tableHops->setRowCount(query.size());
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
108 this->tableHops->setHorizontalHeaderLabels(labels);
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
109 this->tableHops->verticalHeader()->hide();
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 QTableWidgetItem *rightitem = new QTableWidgetItem();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 rightitem->setTextAlignment(Qt::AlignRight);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 query.first();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 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
116 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
117 this->tableHops->setItem(ridx, 1, new QTableWidgetItem(query.value(1).toString())); /* Name */
301
fe6346211b5b Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents: 290
diff changeset
118 this->tableHops->setItem(ridx, 2, new QTableWidgetItem(g_hop_types[query.value(9).toInt()])); /* Type */
fe6346211b5b Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents: 290
diff changeset
119 this->tableHops->setItem(ridx, 3, new QTableWidgetItem(QCoreApplication::translate("HopForm", g_hop_forms[query.value(10).toInt()]))); /* Form */
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 w = QString("%1 %").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Alpha% */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 QTableWidgetItem *item = new QTableWidgetItem(w);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
123 this->tableHops->setItem(ridx, 4, item);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 w = QString("%1 %").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Beta% */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 item = new QTableWidgetItem(w);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
127 this->tableHops->setItem(ridx, 5, item);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 w = QString("%1 %").arg(query.value(6).toDouble(), 2, 'f', 1, '0' ); /* Cohumulone */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 item = new QTableWidgetItem(w);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
132 this->tableHops->setItem(ridx, 6, item);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' ); /* HSI */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 item = new QTableWidgetItem(w);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
137 this->tableHops->setItem(ridx, 7, item);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138
373
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
139 if (query.value("inventory").toDouble() > 0)
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
140 this->tableHops->setItem(ridx, 8, new QTableWidgetItem(query.value("production_date").toString()));
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 else
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
142 this->tableHops->setItem(ridx, 8, new QTableWidgetItem(QString("")));
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 w = QString("");
373
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
145 if (query.value("inventory").toDouble() > 0) {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
146 if (query.value("form").toInt() < HOP_FORMS_CO2EXTRACT) {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
147 if (query.value("inventory").toDouble() < 1.000) {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
148 w = QString("%1 gr").arg(query.value("inventory").toDouble() * 1000.0, 2, 'f', 1, '0' );
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
149 } else {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
150 w = QString("%1 kg").arg(query.value("inventory").toDouble(), 4, 'f', 3, '0' );
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
151 }
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
152 } else {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
153 if (query.value("inventory").toDouble() < 1.000) {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
154 w = QString("%1 mL").arg(query.value("inventory").toDouble() * 1000.0, 2, 'f', 1, '0' );
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
155 } else {
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
156 w = QString("%1 L").arg(query.value("inventory").toDouble(), 4, 'f', 3, '0' );
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
157 }
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
158 }
b02aca4e926c First load of changes for hops. In EditHop load the dropdown buttons from the global table. Use named query fields. Added database utilisation and bu_factor fields for hop extracts. Added edit fields for these new fields. Added post boil SG, utilisation and bu_factor parameters to the toIBU function. Added hops form parameter to the hopFlavourContribution and hopAromaContribution display bars. In the hops inventory list dispay volumes instead of weight for hop extracts. Modified the TinsethIBU function to use utilisation and bu_factor parameters. Add calculations for co2 and iso hop extracts, this is work in progress. The toIBU function makes use of the preSG and postSG values to use the correct SG to caall the TinsethIBU function. This results in a bit lower IBU values mostly affecting the late additions. Added use hop at bottling for iso hop extracts like Tetra hops using the formula from BarthHaas.
Michiel Broek <mbroek@mbse.eu>
parents: 301
diff changeset
159 }
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 item = new QTableWidgetItem(w);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
162 this->tableHops->setItem(ridx, 9, item);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 /* Add the Edit button */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 QWidget* pWidget = new QWidget();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 QPushButton* btn_edit = new QPushButton();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 btn_edit->setText(tr("Edit"));
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 pLayout->addWidget(btn_edit);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 pLayout->setContentsMargins(5, 0, 5, 0);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 pWidget->setLayout(pLayout);
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
174 this->tableHops->setCellWidget(ridx, 10, pWidget);
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 query.next();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 }
79
e726db72da3c All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents: 69
diff changeset
177 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 }
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
69
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
181 InventoryHops::~InventoryHops() {}
24
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 void InventoryHops::edit(int recno)
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 {
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 EditHop dialog(recno, this);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 /* Signal from editor if a refresh is needed */
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 dialog.setModal(true);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 dialog.exec();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 }
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 void InventoryHops::on_editButton_clicked()
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 {
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 int recno = pb->objectName().toInt();
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 edit(recno);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 }
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 void InventoryHops::on_insertButton_clicked()
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203 {
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 edit(-1);
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 }
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206
684c6e74cc1b Added hops editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207
44
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
208 void InventoryHops::on_exportButton_clicked()
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
209 {
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
210 qDebug() << Q_FUNC_INFO;
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
211
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
212 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
213 const QStringList types({ "Bittering", "Aroma", "Both" });
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
214 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
215 /* "Leaf Wet", "Cryo" */
228cb2a01acf Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
216 /* 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
217 /* instead of what we internally use. */
44
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
218
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
219 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
220 if (fileName == 0) {
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
221 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
222 return;
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
223 }
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
224
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
225 QFile file(fileName);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
226 file.open(QIODevice::WriteOnly);
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 QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
229 xmlWriter->writeStartDocument();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
230 xmlWriter->setAutoFormatting(true);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
231 xmlWriter->setAutoFormattingIndent(1);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
232 xmlWriter->writeStartElement("HOPS");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
233
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
234 query.first();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
235 for (int i = 0 ; i < query.size() ; i++ ) {
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
236 xmlWriter->writeStartElement("HOP");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
237 xmlWriter->writeTextElement("VERSION", "1");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
238 xmlWriter->writeTextElement("NAME", query.value(1).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
239 if (query.value(11).toString().length())
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
240 xmlWriter->writeTextElement("NOTES", query.value(11).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 xmlWriter->writeTextElement("TYPE", types[query.value(9).toInt()]);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
251 xmlWriter->writeTextElement("FORM", forms[query.value(10).toInt()]);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
252 xmlWriter->writeTextElement("ORIGIN", query.value(12).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
253 if (query.value(13).toString().length())
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
254 xmlWriter->writeTextElement("SUBSTITUTES", query.value(13).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
255 if (query.value(16).toDouble() > 0)
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
256 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
257 xmlWriter->writeEndElement();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
258 query.next();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
259 }
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
260
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
261 xmlWriter->writeEndElement();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
262 xmlWriter->writeEndDocument();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
263 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
264
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
265 file.close();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
266 }
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

mercurial