Wed, 20 Apr 2022 22:48:20 +0200
Implemented the last widgets on the first tab and added the needed functions for them such as scaling the recipe. This is the last part of the recipe editor, now ready for testing.
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" |
21 | ||
22 | ||
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
23 | InventoryHops::InventoryHops(QWidget *parent) : QDialog(parent) |
24 | 24 | { |
25 | qDebug() << "InventoryHops start"; | |
26 | ||
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
27 | gridLayout = new QGridLayout(this); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
28 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
29 | tableHops = new QTableWidget(this); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
30 | tableHops->setObjectName(QString::fromUtf8("tableHops")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
31 | tableHops->setEnabled(true); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
32 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
33 | sizePolicy.setHorizontalStretch(0); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
34 | sizePolicy.setVerticalStretch(0); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
35 | //sizePolicy.setHeightForWidth(tableHops->sizePolicy().hasHeightForWidth()); |
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); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
65 | horizontalLayout->addWidget(exportButton, 0, Qt::AlignRight); |
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 | importButton = new QPushButton(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
68 | importButton->setObjectName(QString::fromUtf8("importButton")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
69 | importButton->setMinimumSize(QSize(80, 24)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
70 | importButton->setText(tr("Import")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
71 | QIcon icon2; |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
72 | 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
|
73 | importButton->setIcon(icon2); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
74 | horizontalLayout->addWidget(importButton, 0, Qt::AlignRight); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
75 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
76 | insertButton = new QPushButton(groupBox); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
77 | insertButton->setObjectName(QString::fromUtf8("insertButton")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
78 | insertButton->setMinimumSize(QSize(80, 24)); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
79 | insertButton->setText(tr("New")); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
80 | QIcon icon3; |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
81 | 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
|
82 | insertButton->setIcon(icon3); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
83 | horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
84 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
85 | |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
86 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryHops())); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
87 | 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
|
88 | 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
|
89 | // 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
|
90 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); |
24 | 91 | emit refreshTable(); |
92 | } | |
93 | ||
94 | ||
95 | void InventoryHops::refreshTable() | |
96 | { | |
97 | QString w; | |
98 | ||
99 | qDebug() << "InventoryHops reload"; | |
100 | ||
101 | QSqlQuery query("SELECT * FROM inventory_hops ORDER BY origin,name"); | |
102 | 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")}); | |
103 | const QStringList types({tr("Bittering"), tr("Aroma"), tr("Both")}); | |
104 | const QStringList form({tr("Pellet"), tr("Plug"), tr("Leaf"), tr("Leaf Wet"), tr("Cryo")}); | |
105 | ||
106 | /* 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
|
107 | this->tableHops->setColumnCount(11); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
108 | this->tableHops->setColumnWidth(0, 130); /* Origin */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
109 | this->tableHops->setColumnWidth(1, 250); /* Name */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
110 | this->tableHops->setColumnWidth(2, 80); /* Type */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
111 | this->tableHops->setColumnWidth(3, 80); /* Form */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
112 | this->tableHops->setColumnWidth(4, 80); /* Alpha */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
113 | this->tableHops->setColumnWidth(5, 80); /* Beta */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
114 | this->tableHops->setColumnWidth(6, 80); /* cohumulone */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
115 | this->tableHops->setColumnWidth(7, 80); /* HSI */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
116 | this->tableHops->setColumnWidth(8, 80); /* Harvest date */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
117 | this->tableHops->setColumnWidth(9, 80); /* Stock */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
118 | this->tableHops->setColumnWidth(10, 80); /* Edit button */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
119 | this->tableHops->setRowCount(query.size()); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
120 | this->tableHops->setHorizontalHeaderLabels(labels); |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
121 | this->tableHops->verticalHeader()->hide(); |
24 | 122 | |
123 | QTableWidgetItem *rightitem = new QTableWidgetItem(); | |
124 | rightitem->setTextAlignment(Qt::AlignRight); | |
125 | ||
126 | query.first(); | |
127 | 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
|
128 | 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
|
129 | this->tableHops->setItem(ridx, 1, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
130 | this->tableHops->setItem(ridx, 2, new QTableWidgetItem(types[query.value(9).toInt()])); /* Type */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
131 | this->tableHops->setItem(ridx, 3, new QTableWidgetItem(form[query.value(10).toInt()])); /* Form */ |
24 | 132 | w = QString("%1 %").arg(query.value(2).toDouble(), 2, 'f', 1, '0' ); /* Alpha% */ |
133 | QTableWidgetItem *item = new QTableWidgetItem(w); | |
134 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
135 | this->tableHops->setItem(ridx, 4, item); |
24 | 136 | w = QString("%1 %").arg(query.value(3).toDouble(), 2, 'f', 1, '0' ); /* Beta% */ |
137 | item = new QTableWidgetItem(w); | |
138 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
139 | this->tableHops->setItem(ridx, 5, item); |
24 | 140 | |
141 | w = QString("%1 %").arg(query.value(6).toDouble(), 2, 'f', 1, '0' ); /* Cohumulone */ | |
142 | item = new QTableWidgetItem(w); | |
143 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
144 | this->tableHops->setItem(ridx, 6, item); |
24 | 145 | |
146 | w = QString("%1").arg(query.value(8).toDouble(), 2, 'f', 1, '0' ); /* HSI */ | |
147 | item = new QTableWidgetItem(w); | |
148 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
149 | this->tableHops->setItem(ridx, 7, item); |
24 | 150 | |
151 | if (query.value(15).toDouble() > 0) | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
152 | this->tableHops->setItem(ridx, 8, new QTableWidgetItem(query.value(17).toString())); /* Harvest */ |
24 | 153 | else |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
154 | this->tableHops->setItem(ridx, 8, new QTableWidgetItem(QString(""))); |
24 | 155 | |
156 | w = QString(""); | |
157 | if (query.value(15).toDouble() > 0) { | |
158 | if (query.value(15).toDouble() < 1.000) { | |
159 | w = QString("%1 gr").arg(query.value(15).toDouble() * 1000.0, 2, 'f', 1, '0' ); | |
160 | } else { | |
161 | w = QString("%1 kg").arg(query.value(15).toDouble(), 4, 'f', 3, '0' ); | |
162 | } | |
163 | } | |
164 | item = new QTableWidgetItem(w); | |
165 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
166 | this->tableHops->setItem(ridx, 9, item); |
24 | 167 | |
168 | /* Add the Edit button */ | |
169 | QWidget* pWidget = new QWidget(); | |
170 | QPushButton* btn_edit = new QPushButton(); | |
171 | btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ | |
172 | btn_edit->setText(tr("Edit")); | |
173 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); | |
174 | QHBoxLayout* pLayout = new QHBoxLayout(pWidget); | |
175 | pLayout->addWidget(btn_edit); | |
176 | pLayout->setContentsMargins(5, 0, 5, 0); | |
177 | pWidget->setLayout(pLayout); | |
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
178 | this->tableHops->setCellWidget(ridx, 10, pWidget); |
24 | 179 | query.next(); |
180 | } | |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
69
diff
changeset
|
181 | emit setStatus(QString(tr("Total items: %1")).arg(query.size())); |
24 | 182 | } |
183 | ||
184 | ||
69
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
185 | InventoryHops::~InventoryHops() {} |
24 | 186 | |
187 | ||
188 | void InventoryHops::edit(int recno) | |
189 | { | |
190 | EditHop dialog(recno, this); | |
191 | /* Signal from editor if a refresh is needed */ | |
192 | connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); | |
193 | dialog.setModal(true); | |
194 | dialog.exec(); | |
195 | } | |
196 | ||
197 | ||
198 | void InventoryHops::on_editButton_clicked() | |
199 | { | |
200 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); | |
201 | int recno = pb->objectName().toInt(); | |
202 | edit(recno); | |
203 | } | |
204 | ||
205 | ||
206 | void InventoryHops::on_insertButton_clicked() | |
207 | { | |
208 | edit(-1); | |
209 | } | |
210 | ||
211 | ||
44
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
212 | void InventoryHops::on_exportButton_clicked() |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
213 | { |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
214 | qDebug() << Q_FUNC_INFO; |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
215 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
216 | 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
|
217 | const QStringList types({ "Bittering", "Aroma", "Both" }); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
218 | 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
|
219 | /* "Leaf Wet", "Cryo" */ |
228cb2a01acf
Inventory Hops now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
44
diff
changeset
|
220 | /* 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
|
221 | /* instead of what we internally use. */ |
44
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
222 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
223 | 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
|
224 | if (fileName == 0) { |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
225 | 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
|
226 | return; |
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 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
229 | QFile file(fileName); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
230 | file.open(QIODevice::WriteOnly); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
231 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
232 | QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
233 | xmlWriter->writeStartDocument(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
234 | xmlWriter->setAutoFormatting(true); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
235 | xmlWriter->setAutoFormattingIndent(1); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
236 | xmlWriter->writeStartElement("HOPS"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
237 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
238 | query.first(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
239 | for (int i = 0 ; i < query.size() ; i++ ) { |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
240 | xmlWriter->writeStartElement("HOP"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
241 | xmlWriter->writeTextElement("VERSION", "1"); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
242 | xmlWriter->writeTextElement("NAME", query.value(1).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
243 | if (query.value(11).toString().length()) |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
244 | xmlWriter->writeTextElement("NOTES", query.value(11).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
245 | 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
|
246 | 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
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | 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
|
251 | 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
|
252 | 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
|
253 | 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
|
254 | xmlWriter->writeTextElement("TYPE", types[query.value(9).toInt()]); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
255 | xmlWriter->writeTextElement("FORM", forms[query.value(10).toInt()]); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
256 | xmlWriter->writeTextElement("ORIGIN", query.value(12).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
257 | if (query.value(13).toString().length()) |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
258 | xmlWriter->writeTextElement("SUBSTITUTES", query.value(13).toString()); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
259 | if (query.value(16).toDouble() > 0) |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
260 | 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
|
261 | xmlWriter->writeEndElement(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
262 | query.next(); |
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 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
265 | xmlWriter->writeEndElement(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
266 | xmlWriter->writeEndDocument(); |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
267 | 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
|
268 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
269 | file.close(); |
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 | |
5a9a159c2d34
Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
272 |