src/InventoryYeasts.cpp

Mon, 21 Mar 2022 12:08:41 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 21 Mar 2022 12:08:41 +0100
changeset 79
e726db72da3c
parent 70
556b4202c5e7
child 90
2396457a8167
permissions
-rw-r--r--

All inventory and profiles now show the items sizes in the statusbar.

25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * InventoryYeasts.cpp is part of bmsapp.
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "InventoryYeasts.h"
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "EditYeast.h"
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
19 #include "MainWindow.h"
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include "config.h"
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 #include "bmsapp.h"
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
24 InventoryYeasts::InventoryYeasts(QWidget *parent) : QDialog(parent)
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 qDebug() << "InventoryYeasts start";
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
28 gridLayout = new QGridLayout(this);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
30 tableYeasts = new QTableWidget(this);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
31 tableYeasts->setObjectName(QString::fromUtf8("tableYeasts"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
32 tableYeasts->setEnabled(true);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
34 sizePolicy.setHorizontalStretch(0);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
35 sizePolicy.setVerticalStretch(0);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
36 tableYeasts->setSizePolicy(sizePolicy);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
37 tableYeasts->setMinimumSize(QSize(1094, 0));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
38 gridLayout->addWidget(tableYeasts, 0, 0, 1, 1);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
39
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
40 groupBox = new QGroupBox(this);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
41 groupBox->setObjectName(QString::fromUtf8("groupBox"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
42 groupBox->setEnabled(true);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
43 groupBox->setFlat(false);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
44 horizontalLayout = new QHBoxLayout(groupBox);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
45 horizontalLayout->setSpacing(6);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
46 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
47 horizontalLayout->setContentsMargins(0, 0, 0, 0);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
48
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
49 quitButton = new QPushButton(groupBox);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
50 quitButton->setObjectName(QString::fromUtf8("quitButton"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
51 quitButton->setMinimumSize(QSize(80, 24));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
52 quitButton->setText(tr("Quit"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
53 QIcon icon;
556b4202c5e7 Inventory Yeasts 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);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
55 quitButton->setIcon(icon);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
56 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
57
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
58 exportButton = new QPushButton(groupBox);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
59 exportButton->setObjectName(QString::fromUtf8("exportButton"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
60 exportButton->setMinimumSize(QSize(80, 24));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
61 exportButton->setText(tr("Export"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
62 QIcon icon1;
556b4202c5e7 Inventory Yeasts 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);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
64 exportButton->setIcon(icon1);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
65 horizontalLayout->addWidget(exportButton, 0, Qt::AlignRight);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
66
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
67 importButton = new QPushButton(groupBox);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
68 importButton->setObjectName(QString::fromUtf8("importButton"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
69 importButton->setMinimumSize(QSize(80, 24));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
70 importButton->setText(tr("Import"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
71 QIcon icon2;
556b4202c5e7 Inventory Yeasts 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);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
73 importButton->setIcon(icon2);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
74 horizontalLayout->addWidget(importButton, 0, Qt::AlignRight);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
75
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
76 insertButton = new QPushButton(groupBox);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
77 insertButton->setObjectName(QString::fromUtf8("insertButton"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
78 insertButton->setMinimumSize(QSize(80, 24));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
79 insertButton->setText(tr("New"));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
80 QIcon icon3;
556b4202c5e7 Inventory Yeasts 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);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
82 insertButton->setIcon(icon3);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
83 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
84 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
85
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
86 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryYeasts()));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
87 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
88 connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
556b4202c5e7 Inventory Yeasts 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: 70
diff changeset
90 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 emit refreshTable();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 void InventoryYeasts::refreshTable()
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 QString w;
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 QWidget* pWidget;
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 QLabel *label;
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 QHBoxLayout* pLayout;
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 qDebug() << "InventoryYeasts reload";
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 QSqlQuery query("SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name");
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 const QStringList labels({tr("Laboratory"), tr("Product id"), tr("Name"), tr("Type"), tr("Form"), tr("SVG %"), tr("Tol %"), tr("POF+"), tr("STA1"), tr("Stock"), tr("Edit")});
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 const QStringList types({tr("Lager"), tr("Ale"), tr("Wheat"), tr("Wine"), tr("Champagne"), tr("Brett"), tr("Kveik"), tr("Hybrid")});
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 const QStringList form({tr("Liquid"), tr("Dry"), tr("Slant"), tr("Culture"), tr("Frozen"), tr("Bottle"), tr("Dried")});
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 /* origin supplier name type graintype color yield inventory Edit */
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
110 this->tableYeasts->setColumnCount(11);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
111 this->tableYeasts->setColumnWidth(0, 120); /* Laboratory */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
112 this->tableYeasts->setColumnWidth(1, 120); /* Product ID */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
113 this->tableYeasts->setColumnWidth(2, 250); /* Name */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
114 this->tableYeasts->setColumnWidth(3, 70); /* Type */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
115 this->tableYeasts->setColumnWidth(4, 70); /* Form */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
116 this->tableYeasts->setColumnWidth(5, 80); /* SVG */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
117 this->tableYeasts->setColumnWidth(6, 80); /* Tolerance */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
118 this->tableYeasts->setColumnWidth(7, 60); /* POF+ */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
119 this->tableYeasts->setColumnWidth(8, 60); /* STA1 */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
120 this->tableYeasts->setColumnWidth(9, 80); /* Stock */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
121 this->tableYeasts->setColumnWidth(10, 80); /* Edit button */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
122 this->tableYeasts->setRowCount(query.size());
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
123 this->tableYeasts->setHorizontalHeaderLabels(labels);
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
124 this->tableYeasts->verticalHeader()->hide();
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 QTableWidgetItem *rightitem = new QTableWidgetItem();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 rightitem->setTextAlignment(Qt::AlignRight);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 query.first();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
131 this->tableYeasts->setItem(ridx, 0, new QTableWidgetItem(query.value(4).toString())); /* Laboratory */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
132 this->tableYeasts->setItem(ridx, 1, new QTableWidgetItem(query.value(5).toString())); /* Product id */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
133 this->tableYeasts->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString())); /* Name */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
134 this->tableYeasts->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()])); /* Type */
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
135 this->tableYeasts->setItem(ridx, 4, new QTableWidgetItem(form[query.value(3).toInt()])); /* Form */
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 w = QString("%1 %").arg(query.value(9).toDouble(), 2, 'f', 1, '0' ); /* Attenuation% */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 QTableWidgetItem *item = new QTableWidgetItem(w);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
139 this->tableYeasts->setItem(ridx, 5, item);
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 w = QString("");
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 if (query.value(10).toDouble() > 0)
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 w = QString("%1 %").arg(query.value(10).toDouble(), 2, 'f', 1, '0' ); /* Alcohol% */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 item = new QTableWidgetItem(w);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
145 this->tableYeasts->setItem(ridx, 6, item);
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 if (query.value(24).toInt()) {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 pWidget = new QWidget();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 label = new QLabel;
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 label->setPixmap(QPixmap(":icons/silk/tick.png"));
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 pLayout = new QHBoxLayout(pWidget);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 pLayout->addWidget(label);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 pLayout->setAlignment(Qt::AlignCenter);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 pLayout->setContentsMargins(0, 0, 0, 0);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 pWidget->setLayout(pLayout);
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
156 this->tableYeasts->setCellWidget(ridx, 7, pWidget);
29
76846c99f827 Added inventory water editor and table. In Yeasts table make sure the fields without a tickmark are empty. Removed Utils::Round function, not reliable.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
157 } else {
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
158 this->tableYeasts->removeCellWidget(ridx, 7);
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 if (query.value(19).toInt()) {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 pWidget = new QWidget();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 label = new QLabel;
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 label->setPixmap(QPixmap(":icons/silk/tick.png"));
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 pLayout = new QHBoxLayout(pWidget);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 pLayout->addWidget(label);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 pLayout->setAlignment(Qt::AlignCenter);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 pLayout->setContentsMargins(0, 0, 0, 0);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 pWidget->setLayout(pLayout);
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
169 this->tableYeasts->setCellWidget(ridx, 8, pWidget);
29
76846c99f827 Added inventory water editor and table. In Yeasts table make sure the fields without a tickmark are empty. Removed Utils::Round function, not reliable.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
170 } else {
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
171 this->tableYeasts->removeCellWidget(ridx, 8);
29
76846c99f827 Added inventory water editor and table. In Yeasts table make sure the fields without a tickmark are empty. Removed Utils::Round function, not reliable.
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
172 }
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 w = QString("");
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 if (query.value(14).toDouble() > 0) {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 if (query.value(3).toInt() == 0 && query.value(14).toDouble() > 1) { /* Liquid yeast, multiple packs */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 w = QString("%1 packs").arg(query.value(14).toDouble(), 1, 'f', 0, '0');
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 } else if (query.value(3).toInt() == 0) { /* Liquid yeast */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 w = QString("%1 pack").arg(query.value(14).toDouble(), 1, 'f', 0, '0');
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 } else if (query.value(3).toInt() == 1 || query.value(3).toInt() == 6) { /* Dry or dried */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 w = QString("%1 gram").arg(query.value(14).toDouble() * 1000, 2, 'f', 1, '0');
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 } else { /* Any other form */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 w = QString("%1 ml").arg(query.value(14).toDouble() * 1000, 2, 'f', 1, '0');
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 item = new QTableWidgetItem(w);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
188 this->tableYeasts->setItem(ridx, 9, item);
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 /* Add the Edit button */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 pWidget = new QWidget();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 QPushButton* btn_edit = new QPushButton();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 btn_edit->setText(tr("Edit"));
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 pLayout = new QHBoxLayout(pWidget);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 pLayout->addWidget(btn_edit);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 pLayout->setContentsMargins(5, 0, 5, 0);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 pWidget->setLayout(pLayout);
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
200 this->tableYeasts->setCellWidget(ridx, 10, pWidget);
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 query.next();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 }
79
e726db72da3c All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents: 70
diff changeset
203 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206
70
556b4202c5e7 Inventory Yeasts now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
207 InventoryYeasts::~InventoryYeasts() {}
25
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 void InventoryYeasts::edit(int recno)
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 EditYeast dialog(recno, this);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 /* Signal from editor if a refresh is needed */
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 dialog.setModal(true);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 dialog.exec();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 void InventoryYeasts::on_editButton_clicked()
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 int recno = pb->objectName().toInt();
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 edit(recno);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 void InventoryYeasts::on_insertButton_clicked()
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229 {
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 edit(-1);
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 }
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232
a9da2744609e Added inventory yeasts editor. Fixed resource icons location.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233
44
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
234 void InventoryYeasts::on_exportButton_clicked()
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
235 {
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
236 qDebug() << Q_FUNC_INFO;
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
237
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
238 QSqlQuery query("SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
239 const QStringList types({ "Lager", "Ale", "Wheat", "Wine", "Champagne", "Other", "Other", "Other" });
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
240 /* "Lager", "Ale", "Wheat", "Wine", "Champagne", "Brett", "Kveik", "Hybrid" */
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
241 /* We use more yeat forms then beerxml knows about, so we send known names */
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
242 /* instead of what we internally use. */
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
243 const QStringList forms({ "Liquid", "Dry", "Slant", "Culture", "Culture", "Culture", "Dry" });
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
244 /* "Liquid", "Dry", "Slant", "Culture", "Frozen", "Bottle", "Dried" */
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
245 const QStringList flocs({ "Low", "Medium", "High", "Very high" });
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
246
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
247 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/yeasts.xml", tr("Files (*.xml)"));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
248 if (fileName == 0) {
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
249 QMessageBox::warning(this, tr("Save File"), tr("No XML file selected."));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
250 return;
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
251 }
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
252
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
253 QFile file(fileName);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
254 file.open(QIODevice::WriteOnly);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
255
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
256 QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
257 xmlWriter->writeStartDocument();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
258 xmlWriter->setAutoFormatting(true);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
259 xmlWriter->setAutoFormattingIndent(1);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
260 xmlWriter->writeStartElement("YEASTS");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
261
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
262 query.first();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
263 for (int i = 0 ; i < query.size() ; i++ ) {
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
264 xmlWriter->writeStartElement("YEAST");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
265 xmlWriter->writeTextElement("VERSION", "1");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
266 xmlWriter->writeTextElement("NAME", query.value(1).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
267 xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
268 xmlWriter->writeTextElement("FORM", forms[query.value(3).toInt()]);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
269 xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", (query.value(3).toInt() == 1 || query.value(3).toInt() == 6) ? "TRUE":"FALSE");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
270 xmlWriter->writeTextElement("LABORATORY", query.value(4).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
271 if (query.value(5).toString().length())
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
272 xmlWriter->writeTextElement("PRODUCT_ID", query.value(5).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
273 xmlWriter->writeTextElement("MIN_TEMPERATURE", QString::number(query.value(6).toDouble(), 'f', 4));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
274 xmlWriter->writeTextElement("MAX_TEMPERATURE", QString::number(query.value(7).toDouble(), 'f', 4));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
275 xmlWriter->writeTextElement("ATTENUATION", QString::number(query.value(9).toDouble(), 'f', 4));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
276 xmlWriter->writeTextElement("ADD_TO_SECONDARY", "FALSE");
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
277 xmlWriter->writeTextElement("FLOCCULATION", flocs[query.value(8).toInt()]);
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
278 xmlWriter->writeTextElement("MAX_REUSE", QString::number(query.value(13).toInt()));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
279 if (query.value(15).toDouble() > 0)
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
280 xmlWriter->writeTextElement("COST", QString::number(query.value(15).toDouble(), 'f', 5));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
281 if (query.value(11).toString().length())
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
282 xmlWriter->writeTextElement("NOTES", query.value(11).toString());
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
283 xmlWriter->writeEndElement();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
284 query.next();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
285 }
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
286
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
287 xmlWriter->writeEndElement();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
288 xmlWriter->writeEndDocument();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
289 QMessageBox::information(this, tr("Save File"), tr("XML export ready"));
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
290
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
291 file.close();
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
292 }
5a9a159c2d34 Added yeasts and hops XML exports.
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
293

mercurial