src/InventoryMiscs.cpp

Mon, 11 Apr 2022 17:33:38 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 11 Apr 2022 17:33:38 +0200
changeset 128
0f4eee875ea6
parent 90
2396457a8167
child 155
f671c599f65b
permissions
-rw-r--r--

More file splitting

28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * InventoryMiscs.cpp is part of bmsapp.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "InventoryMiscs.h"
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "EditMisc.h"
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
19 #include "MainWindow.h"
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 #include "config.h"
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
23 InventoryMiscs::InventoryMiscs(QWidget *parent) : QDialog(parent)
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 qDebug() << "InventoryMiscs start";
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
27 gridLayout = new QGridLayout(this);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
28 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
29 tableMiscs = new QTableWidget(this);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
30 tableMiscs->setObjectName(QString::fromUtf8("tableMiscs"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
31 tableMiscs->setEnabled(true);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
32 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
33 sizePolicy.setHorizontalStretch(0);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
34 sizePolicy.setVerticalStretch(0);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
35 tableMiscs->setSizePolicy(sizePolicy);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
36 tableMiscs->setMinimumSize(QSize(819, 0));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
37 gridLayout->addWidget(tableMiscs, 0, 0, 1, 1);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
38
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
39 groupBox = new QGroupBox(this);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
40 groupBox->setObjectName(QString::fromUtf8("groupBox"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
41 groupBox->setEnabled(true);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
42 groupBox->setFlat(false);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
43 horizontalLayout = new QHBoxLayout(groupBox);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
44 horizontalLayout->setSpacing(6);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
45 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
46 horizontalLayout->setContentsMargins(0, 0, 0, 0);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
47
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
48 quitButton = new QPushButton(groupBox);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
49 quitButton->setObjectName(QString::fromUtf8("quitButton"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
50 quitButton->setMinimumSize(QSize(80, 24));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
51 quitButton->setText(tr("Quit"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
52 QIcon icon;
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
53 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
54 quitButton->setIcon(icon);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
55 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
56
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
57 exportButton = new QPushButton(groupBox);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
58 exportButton->setObjectName(QString::fromUtf8("exportButton"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
59 exportButton->setMinimumSize(QSize(80, 24));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
60 exportButton->setText(tr("Export"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
61 QIcon icon1;
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
62 icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
63 exportButton->setIcon(icon1);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
64 horizontalLayout->addWidget(exportButton, 0, Qt::AlignRight);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
65
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
66 importButton = new QPushButton(groupBox);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
67 importButton->setObjectName(QString::fromUtf8("importButton"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
68 importButton->setMinimumSize(QSize(80, 24));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
69 importButton->setText(tr("Import"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
70 QIcon icon2;
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
71 icon2.addFile(QString::fromUtf8(":/icons/silk/database_add.png"), QSize(), QIcon::Normal, QIcon::Off);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
72 importButton->setIcon(icon2);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
73 horizontalLayout->addWidget(importButton, 0, Qt::AlignRight);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
74
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
75 insertButton = new QPushButton(groupBox);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
76 insertButton->setObjectName(QString::fromUtf8("insertButton"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
77 insertButton->setMinimumSize(QSize(80, 24));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
78 insertButton->setText(tr("New"));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
79 QIcon icon3;
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
80 icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
81 insertButton->setIcon(icon3);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
82 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
83 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
84
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
85 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryMiscs()));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
86 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
87 connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
88 // 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: 71
diff changeset
89 connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString)));
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 emit refreshTable();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 void InventoryMiscs::refreshTable()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 QString w;
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 qDebug() << "InventoryMiscs reload";
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 const QStringList labels({tr("Name"), tr("Type"), tr("Use"), tr("Time"), tr("Stock"), tr("Edit")});
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 const QStringList types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")});
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 const QStringList use({tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling")});
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 /* origin supplier name type graintype color yield inventory Edit */
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
106 this->tableMiscs->setColumnCount(6);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
107 this->tableMiscs->setColumnWidth(0, 275); /* Name */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
108 this->tableMiscs->setColumnWidth(1, 120); /* Type */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
109 this->tableMiscs->setColumnWidth(2, 120); /* Use */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
110 this->tableMiscs->setColumnWidth(3, 120); /* Time */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
111 this->tableMiscs->setColumnWidth(4, 80); /* Stock */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
112 this->tableMiscs->setColumnWidth(5, 80); /* Edit button */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
113 this->tableMiscs->setRowCount(query.size());
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
114 this->tableMiscs->setHorizontalHeaderLabels(labels);
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
115 this->tableMiscs->verticalHeader()->hide();
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 QTableWidgetItem *rightitem = new QTableWidgetItem();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 rightitem->setTextAlignment(Qt::AlignRight);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 query.first();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
122 this->tableMiscs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
123 this->tableMiscs->setItem(ridx, 1, new QTableWidgetItem(types[query.value(2).toInt()])); /* Type */
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
124 this->tableMiscs->setItem(ridx, 2, new QTableWidgetItem(use[query.value(3).toInt()])); /* Use */
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 w = QString(""); /* Use time */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 if (query.value(4).toInt() > 0) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 if (query.value(4).toInt() == 1)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 w = QString("1 minute");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 else if (query.value(4).toInt() < 180)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 w = QString("%1 minutes").arg(query.value(4).toInt());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 else if (query.value(4).toInt() < 1440)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 w = QString("%1 hours").arg(query.value(4).toInt() / 60);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 else if (query.value(4).toInt() == 1440)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 w = QString("1 day");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 else
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 w = QString("%1 days").arg(query.value(4).toInt() / 1440);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 QTableWidgetItem *item = new QTableWidgetItem(w);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
141 this->tableMiscs->setItem(ridx, 3, item);
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 w = QString("");
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 if (query.value(9).toDouble() > 0) {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 if (query.value(5).toInt()) { /* Amount is weight */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 w = QString("%1 gr").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' );
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 } else {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 w = QString("%1 ml").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' );
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 item = new QTableWidgetItem(w);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
153 this->tableMiscs->setItem(ridx, 4, item);
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 /* Add the Edit button */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 QWidget* pWidget = new QWidget();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 QPushButton* btn_edit = new QPushButton();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 btn_edit->setText(tr("Edit"));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 pLayout->addWidget(btn_edit);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 pLayout->setContentsMargins(5, 0, 5, 0);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 pWidget->setLayout(pLayout);
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
165 this->tableMiscs->setCellWidget(ridx, 5, pWidget);
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 query.next();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 }
79
e726db72da3c All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
168 emit setStatus(QString(tr("Total items: %1")).arg(query.size()));
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171
71
5bd0d7be0167 Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
172 InventoryMiscs::~InventoryMiscs() {}
28
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 void InventoryMiscs::edit(int recno)
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 EditMisc dialog(recno, this);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 /* Signal from editor if a refresh is needed */
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable()));
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 dialog.setModal(true);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 dialog.exec();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 void InventoryMiscs::on_editButton_clicked()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 int recno = pb->objectName().toInt();
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 edit(recno);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 void InventoryMiscs::on_insertButton_clicked()
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 {
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 edit(-1);
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 }
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197
93a70b1502ca Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198
45
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
199 void InventoryMiscs::on_exportButton_clicked()
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
200 {
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
201 qDebug() << Q_FUNC_INFO;
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
202
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
203 QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name");
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
204 const QStringList types({ "Spice", "Herb", "Flavor", "Fining", "Water agent", "Other", "Other" });
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
205 /* 'Spice', 'Herb', 'Flavor', 'Fining', 'Water agent', 'Yeast nutrient', 'Other' */
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
206 /* We use more misc types then beerxml knows about, so we send known names */
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
207 /* instead of what we internally use. */
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
208 const QStringList uses({ "Secondary", "Mash", "Boil", "Primary", "Secondary", "Bottling" });
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
209 /* 'Starter', 'Mash', 'Boil', 'Primary', 'Secondary', 'Bottling' */
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
210 /* Stupid beerxml leaves us no other choice then to map a starter ingredient to secondary */
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
211
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
212 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/miscs.xml", tr("Files (*.xml)"));
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
213 if (fileName == 0) {
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
214 QMessageBox::warning(this, tr("Save File"), tr("No XML file selected."));
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
215 return;
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
216 }
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
217
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
218 QFile file(fileName);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
219 file.open(QIODevice::WriteOnly);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
220
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
221 QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
222 xmlWriter->writeStartDocument();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
223 xmlWriter->setAutoFormatting(true);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
224 xmlWriter->setAutoFormattingIndent(1);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
225 xmlWriter->writeStartElement("MISCS");
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
226
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
227 query.first();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
228 for (int i = 0 ; i < query.size() ; i++ ) {
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
229 xmlWriter->writeStartElement("MISC");
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
230 xmlWriter->writeTextElement("VERSION", "1");
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
231 xmlWriter->writeTextElement("NAME", query.value(1).toString());
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
232 xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
233 xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", query.value(5).toInt() ? "TRUE":"FALSE");
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
234 xmlWriter->writeTextElement("USE", uses[query.value(3).toInt()]);
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
235 if (query.value(4).toDouble() > 0)
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
236 xmlWriter->writeTextElement("TIME", QString::number(query.value(4).toDouble(), 'f', 3));
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
237 if (query.value(10).toDouble() > 0)
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
238 xmlWriter->writeTextElement("COST", QString::number(query.value(10).toDouble(), 'f', 5));
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
239 xmlWriter->writeTextElement("ALWAYS_ON_STOCK", query.value(8).toInt() ? "TRUE":"FALSE");
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
240 if (query.value(7).toString().length())
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
241 xmlWriter->writeTextElement("NOTES", query.value(7).toString());
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
242 if (query.value(6).toString().length())
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
243 xmlWriter->writeTextElement("USE_FOR", query.value(6).toString());
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
244
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
245 xmlWriter->writeEndElement();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
246 query.next();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
247 }
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
248
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
249 xmlWriter->writeEndElement();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
250 xmlWriter->writeEndDocument();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
251 QMessageBox::information(this, tr("Save File"), tr("XML export ready"));
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
252
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
253 file.close();
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
254 }
4024b389f689 Added miscs XML export
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
255

mercurial