Sat, 09 Jul 2022 23:05:25 +0200
Increased some labels sizes.
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" |
155
f671c599f65b
Moved more QStringList arrays to global.
Michiel Broek <mbroek@mbse.eu>
parents:
90
diff
changeset
|
21 | #include "global.h" |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
24 | InventoryMiscs::InventoryMiscs(QWidget *parent) : QDialog(parent) |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | qDebug() << "InventoryMiscs start"; |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
28 | gridLayout = new QGridLayout(this); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
29 | gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
30 | tableMiscs = new QTableWidget(this); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
31 | tableMiscs->setObjectName(QString::fromUtf8("tableMiscs")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
32 | tableMiscs->setEnabled(true); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
33 | QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
34 | sizePolicy.setHorizontalStretch(0); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
35 | sizePolicy.setVerticalStretch(0); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
36 | tableMiscs->setSizePolicy(sizePolicy); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
37 | tableMiscs->setMinimumSize(QSize(819, 0)); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
38 | gridLayout->addWidget(tableMiscs, 0, 0, 1, 1); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
39 | |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
40 | groupBox = new QGroupBox(this); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
41 | groupBox->setObjectName(QString::fromUtf8("groupBox")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
42 | groupBox->setEnabled(true); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
43 | groupBox->setFlat(false); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
44 | horizontalLayout = new QHBoxLayout(groupBox); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
45 | horizontalLayout->setSpacing(6); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
46 | horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
47 | horizontalLayout->setContentsMargins(0, 0, 0, 0); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
48 | |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
49 | quitButton = new QPushButton(groupBox); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
50 | quitButton->setObjectName(QString::fromUtf8("quitButton")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
51 | quitButton->setMinimumSize(QSize(80, 24)); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
52 | quitButton->setText(tr("Quit")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
53 | QIcon icon; |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
54 | 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
|
55 | quitButton->setIcon(icon); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
56 | horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
57 | |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
58 | exportButton = new QPushButton(groupBox); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
59 | exportButton->setObjectName(QString::fromUtf8("exportButton")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
60 | exportButton->setMinimumSize(QSize(80, 24)); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
61 | exportButton->setText(tr("Export")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
62 | QIcon icon1; |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
63 | 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
|
64 | exportButton->setIcon(icon1); |
290
93820a8ffbff
Removed unneeded import buttons from the inventory screens.
Michiel Broek <mbroek@mbse.eu>
parents:
155
diff
changeset
|
65 | horizontalLayout->addWidget(exportButton, 0, Qt::AlignCenter); |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
66 | |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
67 | insertButton = new QPushButton(groupBox); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
68 | insertButton->setObjectName(QString::fromUtf8("insertButton")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
69 | insertButton->setMinimumSize(QSize(80, 24)); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
70 | insertButton->setText(tr("New")); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
71 | QIcon icon3; |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
72 | 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
|
73 | insertButton->setIcon(icon3); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
74 | horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
75 | gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
76 | |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
77 | connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryMiscs())); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
78 | 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
|
79 | connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked())); |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
71
diff
changeset
|
80 | connect(this, SIGNAL(setStatus(QString)), parent, SLOT(statusMsg(QString))); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
81 | emit refreshTable(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
82 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
83 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
84 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
85 | void InventoryMiscs::refreshTable() |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
86 | { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | QString w; |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
88 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
89 | qDebug() << "InventoryMiscs reload"; |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
90 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
91 | QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name"); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
92 | 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
|
93 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
94 | /* 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
|
95 | this->tableMiscs->setColumnCount(6); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
96 | this->tableMiscs->setColumnWidth(0, 275); /* Name */ |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
97 | this->tableMiscs->setColumnWidth(1, 120); /* Type */ |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
98 | this->tableMiscs->setColumnWidth(2, 120); /* Use */ |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
99 | this->tableMiscs->setColumnWidth(3, 120); /* Time */ |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
100 | this->tableMiscs->setColumnWidth(4, 80); /* Stock */ |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
101 | this->tableMiscs->setColumnWidth(5, 80); /* Edit button */ |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
102 | this->tableMiscs->setRowCount(query.size()); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
103 | this->tableMiscs->setHorizontalHeaderLabels(labels); |
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
104 | this->tableMiscs->verticalHeader()->hide(); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
105 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
106 | QTableWidgetItem *rightitem = new QTableWidgetItem(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
107 | rightitem->setTextAlignment(Qt::AlignRight); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
108 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
109 | query.first(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
110 | 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
|
111 | this->tableMiscs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
301
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
112 | this->tableMiscs->setItem(ridx, 1, new QTableWidgetItem(QCoreApplication::translate("MiscType", g_misc_types[query.value(2).toInt()])));/* Type */ |
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
113 | this->tableMiscs->setItem(ridx, 2, new QTableWidgetItem(QCoreApplication::translate("MiscUse", g_misc_uses[query.value(3).toInt()]))); /* Use */ |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
114 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
115 | w = QString(""); /* Use time */ |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
116 | if (query.value(4).toInt() > 0) { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
117 | if (query.value(4).toInt() == 1) |
301
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
118 | w = QString(tr("1 minute")); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
119 | else if (query.value(4).toInt() < 180) |
301
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
120 | w = QString(tr("%1 minutes")).arg(query.value(4).toInt()); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
121 | else if (query.value(4).toInt() < 1440) |
301
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
122 | w = QString(tr("%1 hours")).arg(query.value(4).toInt() / 60); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
123 | else if (query.value(4).toInt() == 1440) |
301
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
124 | w = QString(tr("1 day")); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
125 | else |
301
fe6346211b5b
Finally the translation of string arrays is working.
Michiel Broek <mbroek@mbse.eu>
parents:
290
diff
changeset
|
126 | w = QString(tr("%1 days")).arg(query.value(4).toInt() / 1440); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
127 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
128 | QTableWidgetItem *item = new QTableWidgetItem(w); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
129 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
130 | this->tableMiscs->setItem(ridx, 3, item); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
131 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
132 | w = QString(""); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
133 | if (query.value(9).toDouble() > 0) { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
134 | if (query.value(5).toInt()) { /* Amount is weight */ |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
135 | 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
|
136 | } else { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
137 | 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
|
138 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
139 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
140 | item = new QTableWidgetItem(w); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
141 | item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
142 | this->tableMiscs->setItem(ridx, 4, item); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
143 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
144 | /* Add the Edit button */ |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
145 | QWidget* pWidget = new QWidget(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
146 | QPushButton* btn_edit = new QPushButton(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
147 | 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
|
148 | btn_edit->setText(tr("Edit")); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
149 | connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | QHBoxLayout* pLayout = new QHBoxLayout(pWidget); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | pLayout->addWidget(btn_edit); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | pLayout->setContentsMargins(5, 0, 5, 0); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | pWidget->setLayout(pLayout); |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
154 | this->tableMiscs->setCellWidget(ridx, 5, pWidget); |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | query.next(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | } |
79
e726db72da3c
All inventory and profiles now show the items sizes in the statusbar.
Michiel Broek <mbroek@mbse.eu>
parents:
71
diff
changeset
|
157 | 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
|
158 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
160 | |
71
5bd0d7be0167
Inventory Miscs now on the mainscreen.
Michiel Broek <mbroek@mbse.eu>
parents:
45
diff
changeset
|
161 | InventoryMiscs::~InventoryMiscs() {} |
28
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
162 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
163 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
164 | void InventoryMiscs::edit(int recno) |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
165 | { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
166 | EditMisc dialog(recno, this); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
167 | /* Signal from editor if a refresh is needed */ |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
168 | connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
169 | dialog.setModal(true); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
170 | dialog.exec(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
171 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
172 | |
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 | void InventoryMiscs::on_editButton_clicked() |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
175 | { |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
176 | QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
177 | int recno = pb->objectName().toInt(); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
178 | edit(recno); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
179 | } |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
180 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
181 | |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
182 | void InventoryMiscs::on_insertButton_clicked() |
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 | edit(-1); |
93a70b1502ca
Added the inventory miscs table.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
185 | } |
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 | |
45 | 188 | void InventoryMiscs::on_exportButton_clicked() |
189 | { | |
190 | qDebug() << Q_FUNC_INFO; | |
191 | ||
192 | QSqlQuery query("SELECT * FROM inventory_miscs ORDER BY name"); | |
193 | const QStringList types({ "Spice", "Herb", "Flavor", "Fining", "Water agent", "Other", "Other" }); | |
194 | /* 'Spice', 'Herb', 'Flavor', 'Fining', 'Water agent', 'Yeast nutrient', 'Other' */ | |
195 | /* We use more misc types then beerxml knows about, so we send known names */ | |
196 | /* instead of what we internally use. */ | |
197 | const QStringList uses({ "Secondary", "Mash", "Boil", "Primary", "Secondary", "Bottling" }); | |
198 | /* 'Starter', 'Mash', 'Boil', 'Primary', 'Secondary', 'Bottling' */ | |
199 | /* Stupid beerxml leaves us no other choice then to map a starter ingredient to secondary */ | |
200 | ||
201 | QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QDir::homePath() + "/miscs.xml", tr("Files (*.xml)")); | |
202 | if (fileName == 0) { | |
203 | QMessageBox::warning(this, tr("Save File"), tr("No XML file selected.")); | |
204 | return; | |
205 | } | |
206 | ||
207 | QFile file(fileName); | |
208 | file.open(QIODevice::WriteOnly); | |
209 | ||
210 | QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(&file); | |
211 | xmlWriter->writeStartDocument(); | |
212 | xmlWriter->setAutoFormatting(true); | |
213 | xmlWriter->setAutoFormattingIndent(1); | |
214 | xmlWriter->writeStartElement("MISCS"); | |
215 | ||
216 | query.first(); | |
217 | for (int i = 0 ; i < query.size() ; i++ ) { | |
218 | xmlWriter->writeStartElement("MISC"); | |
219 | xmlWriter->writeTextElement("VERSION", "1"); | |
220 | xmlWriter->writeTextElement("NAME", query.value(1).toString()); | |
221 | xmlWriter->writeTextElement("TYPE", types[query.value(2).toInt()]); | |
222 | xmlWriter->writeTextElement("AMOUNT_IS_WEIGHT", query.value(5).toInt() ? "TRUE":"FALSE"); | |
223 | xmlWriter->writeTextElement("USE", uses[query.value(3).toInt()]); | |
224 | if (query.value(4).toDouble() > 0) | |
225 | xmlWriter->writeTextElement("TIME", QString::number(query.value(4).toDouble(), 'f', 3)); | |
226 | if (query.value(10).toDouble() > 0) | |
227 | xmlWriter->writeTextElement("COST", QString::number(query.value(10).toDouble(), 'f', 5)); | |
228 | xmlWriter->writeTextElement("ALWAYS_ON_STOCK", query.value(8).toInt() ? "TRUE":"FALSE"); | |
229 | if (query.value(7).toString().length()) | |
230 | xmlWriter->writeTextElement("NOTES", query.value(7).toString()); | |
231 | if (query.value(6).toString().length()) | |
232 | xmlWriter->writeTextElement("USE_FOR", query.value(6).toString()); | |
233 | ||
234 | xmlWriter->writeEndElement(); | |
235 | query.next(); | |
236 | } | |
237 | ||
238 | xmlWriter->writeEndElement(); | |
239 | xmlWriter->writeEndDocument(); | |
240 | QMessageBox::information(this, tr("Save File"), tr("XML export ready")); | |
241 | ||
242 | file.close(); | |
243 | } | |
244 |