14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ |
16 */ |
17 #include "InventoryMiscs.h" |
17 #include "InventoryMiscs.h" |
18 #include "EditMisc.h" |
18 #include "EditMisc.h" |
19 #include "../ui/ui_InventoryMiscs.h" |
19 #include "MainWindow.h" |
20 #include "config.h" |
20 #include "config.h" |
21 #include "bmsapp.h" |
21 #include "bmsapp.h" |
22 |
22 |
23 |
23 |
24 InventoryMiscs::InventoryMiscs(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryMiscs) |
24 InventoryMiscs::InventoryMiscs(QWidget *parent) : QDialog(parent) |
25 { |
25 { |
26 qDebug() << "InventoryMiscs start"; |
26 qDebug() << "InventoryMiscs start"; |
27 |
27 |
28 ui->setupUi(this); |
28 gridLayout = new QGridLayout(this); |
|
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
|
30 tableMiscs = new QTableWidget(this); |
|
31 tableMiscs->setObjectName(QString::fromUtf8("tableMiscs")); |
|
32 tableMiscs->setEnabled(true); |
|
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
|
34 sizePolicy.setHorizontalStretch(0); |
|
35 sizePolicy.setVerticalStretch(0); |
|
36 tableMiscs->setSizePolicy(sizePolicy); |
|
37 tableMiscs->setMinimumSize(QSize(819, 0)); |
|
38 gridLayout->addWidget(tableMiscs, 0, 0, 1, 1); |
|
39 |
|
40 groupBox = new QGroupBox(this); |
|
41 groupBox->setObjectName(QString::fromUtf8("groupBox")); |
|
42 groupBox->setEnabled(true); |
|
43 groupBox->setFlat(false); |
|
44 horizontalLayout = new QHBoxLayout(groupBox); |
|
45 horizontalLayout->setSpacing(6); |
|
46 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); |
|
47 horizontalLayout->setContentsMargins(0, 0, 0, 0); |
|
48 |
|
49 quitButton = new QPushButton(groupBox); |
|
50 quitButton->setObjectName(QString::fromUtf8("quitButton")); |
|
51 quitButton->setMinimumSize(QSize(80, 24)); |
|
52 quitButton->setText(tr("Quit")); |
|
53 QIcon icon; |
|
54 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
55 quitButton->setIcon(icon); |
|
56 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); |
|
57 |
|
58 exportButton = new QPushButton(groupBox); |
|
59 exportButton->setObjectName(QString::fromUtf8("exportButton")); |
|
60 exportButton->setMinimumSize(QSize(80, 24)); |
|
61 exportButton->setText(tr("Export")); |
|
62 QIcon icon1; |
|
63 icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
64 exportButton->setIcon(icon1); |
|
65 horizontalLayout->addWidget(exportButton, 0, Qt::AlignRight); |
|
66 |
|
67 importButton = new QPushButton(groupBox); |
|
68 importButton->setObjectName(QString::fromUtf8("importButton")); |
|
69 importButton->setMinimumSize(QSize(80, 24)); |
|
70 importButton->setText(tr("Import")); |
|
71 QIcon icon2; |
|
72 icon2.addFile(QString::fromUtf8(":/icons/silk/database_add.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
73 importButton->setIcon(icon2); |
|
74 horizontalLayout->addWidget(importButton, 0, Qt::AlignRight); |
|
75 |
|
76 insertButton = new QPushButton(groupBox); |
|
77 insertButton->setObjectName(QString::fromUtf8("insertButton")); |
|
78 insertButton->setMinimumSize(QSize(80, 24)); |
|
79 insertButton->setText(tr("New")); |
|
80 QIcon icon3; |
|
81 icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); |
|
82 insertButton->setIcon(icon3); |
|
83 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); |
|
84 gridLayout->addWidget(groupBox, 1, 0, 1, 1); |
|
85 |
|
86 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryMiscs())); |
|
87 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); |
|
88 connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked())); |
|
89 // connect(importButton, SIGNAL(clicked()), this, SLOT(on_importButton_clicked())); |
29 emit refreshTable(); |
90 emit refreshTable(); |
30 |
|
31 setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) ); |
|
32 } |
91 } |
33 |
92 |
34 |
93 |
35 void InventoryMiscs::refreshTable() |
94 void InventoryMiscs::refreshTable() |
36 { |
95 { |
42 const QStringList labels({tr("Name"), tr("Type"), tr("Use"), tr("Time"), tr("Stock"), tr("Edit")}); |
101 const QStringList labels({tr("Name"), tr("Type"), tr("Use"), tr("Time"), tr("Stock"), tr("Edit")}); |
43 const QStringList types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")}); |
102 const QStringList types({tr("Spice"), tr("Herb"), tr("Flavor"), tr("Fining"), tr("Water agent"), tr("Yeast nutrient"), tr("Other")}); |
44 const QStringList use({tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling")}); |
103 const QStringList use({tr("Starter"), tr("Mash"), tr("Boil"), tr("Primary"), tr("Secondary"), tr("Bottling")}); |
45 |
104 |
46 /* origin supplier name type graintype color yield inventory Edit */ |
105 /* origin supplier name type graintype color yield inventory Edit */ |
47 ui->tableMiscs->setColumnCount(6); |
106 this->tableMiscs->setColumnCount(6); |
48 ui->tableMiscs->setColumnWidth(0, 275); /* Name */ |
107 this->tableMiscs->setColumnWidth(0, 275); /* Name */ |
49 ui->tableMiscs->setColumnWidth(1, 120); /* Type */ |
108 this->tableMiscs->setColumnWidth(1, 120); /* Type */ |
50 ui->tableMiscs->setColumnWidth(2, 120); /* Use */ |
109 this->tableMiscs->setColumnWidth(2, 120); /* Use */ |
51 ui->tableMiscs->setColumnWidth(3, 120); /* Time */ |
110 this->tableMiscs->setColumnWidth(3, 120); /* Time */ |
52 ui->tableMiscs->setColumnWidth(4, 80); /* Stock */ |
111 this->tableMiscs->setColumnWidth(4, 80); /* Stock */ |
53 ui->tableMiscs->setColumnWidth(5, 80); /* Edit button */ |
112 this->tableMiscs->setColumnWidth(5, 80); /* Edit button */ |
54 ui->tableMiscs->setRowCount(query.size()); |
113 this->tableMiscs->setRowCount(query.size()); |
55 ui->tableMiscs->setHorizontalHeaderLabels(labels); |
114 this->tableMiscs->setHorizontalHeaderLabels(labels); |
56 ui->tableMiscs->verticalHeader()->hide(); |
115 this->tableMiscs->verticalHeader()->hide(); |
57 ui->tableMiscs->setFixedSize(795 + 24, 640); /* Even if this is too large, it works */ |
|
58 |
116 |
59 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
117 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
60 rightitem->setTextAlignment(Qt::AlignRight); |
118 rightitem->setTextAlignment(Qt::AlignRight); |
61 |
119 |
62 query.first(); |
120 query.first(); |
63 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
121 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
64 ui->tableMiscs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
122 this->tableMiscs->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
65 ui->tableMiscs->setItem(ridx, 1, new QTableWidgetItem(types[query.value(2).toInt()])); /* Type */ |
123 this->tableMiscs->setItem(ridx, 1, new QTableWidgetItem(types[query.value(2).toInt()])); /* Type */ |
66 ui->tableMiscs->setItem(ridx, 2, new QTableWidgetItem(use[query.value(3).toInt()])); /* Use */ |
124 this->tableMiscs->setItem(ridx, 2, new QTableWidgetItem(use[query.value(3).toInt()])); /* Use */ |
67 |
125 |
68 w = QString(""); /* Use time */ |
126 w = QString(""); /* Use time */ |
69 if (query.value(4).toInt() > 0) { |
127 if (query.value(4).toInt() > 0) { |
70 if (query.value(4).toInt() == 1) |
128 if (query.value(4).toInt() == 1) |
71 w = QString("1 minute"); |
129 w = QString("1 minute"); |
78 else |
136 else |
79 w = QString("%1 days").arg(query.value(4).toInt() / 1440); |
137 w = QString("%1 days").arg(query.value(4).toInt() / 1440); |
80 } |
138 } |
81 QTableWidgetItem *item = new QTableWidgetItem(w); |
139 QTableWidgetItem *item = new QTableWidgetItem(w); |
82 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
140 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
83 ui->tableMiscs->setItem(ridx, 3, item); |
141 this->tableMiscs->setItem(ridx, 3, item); |
84 |
142 |
85 w = QString(""); |
143 w = QString(""); |
86 if (query.value(9).toDouble() > 0) { |
144 if (query.value(9).toDouble() > 0) { |
87 if (query.value(5).toInt()) { /* Amount is weight */ |
145 if (query.value(5).toInt()) { /* Amount is weight */ |
88 w = QString("%1 gr").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' ); |
146 w = QString("%1 gr").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' ); |
90 w = QString("%1 ml").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' ); |
148 w = QString("%1 ml").arg(query.value(9).toDouble() * 1000.0, 2, 'f', 1, '0' ); |
91 } |
149 } |
92 } |
150 } |
93 item = new QTableWidgetItem(w); |
151 item = new QTableWidgetItem(w); |
94 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
152 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
95 ui->tableMiscs->setItem(ridx, 4, item); |
153 this->tableMiscs->setItem(ridx, 4, item); |
96 |
154 |
97 /* Add the Edit button */ |
155 /* Add the Edit button */ |
98 QWidget* pWidget = new QWidget(); |
156 QWidget* pWidget = new QWidget(); |
99 QPushButton* btn_edit = new QPushButton(); |
157 QPushButton* btn_edit = new QPushButton(); |
100 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
158 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
102 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
160 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
103 QHBoxLayout* pLayout = new QHBoxLayout(pWidget); |
161 QHBoxLayout* pLayout = new QHBoxLayout(pWidget); |
104 pLayout->addWidget(btn_edit); |
162 pLayout->addWidget(btn_edit); |
105 pLayout->setContentsMargins(5, 0, 5, 0); |
163 pLayout->setContentsMargins(5, 0, 5, 0); |
106 pWidget->setLayout(pLayout); |
164 pWidget->setLayout(pLayout); |
107 ui->tableMiscs->setCellWidget(ridx, 5, pWidget); |
165 this->tableMiscs->setCellWidget(ridx, 5, pWidget); |
108 query.next(); |
166 query.next(); |
109 } |
167 } |
110 |
168 |
111 setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) ); |
169 setWindowTitle( QString("BMSapp - %1 - Inventory Miscs").arg(VERSIONSTRING) ); |
112 } |
170 } |
113 |
171 |
114 |
172 |
115 InventoryMiscs::~InventoryMiscs() |
173 InventoryMiscs::~InventoryMiscs() {} |
116 { |
|
117 qDebug() << "InventoryMiscs done"; |
|
118 delete ui; |
|
119 } |
|
120 |
174 |
121 |
175 |
122 void InventoryMiscs::edit(int recno) |
176 void InventoryMiscs::edit(int recno) |
123 { |
177 { |
124 qDebug() << "InventoryMiscs edit:" << recno; |
|
125 |
|
126 EditMisc dialog(recno, this); |
178 EditMisc dialog(recno, this); |
127 /* Signal from editor if a refresh is needed */ |
179 /* Signal from editor if a refresh is needed */ |
128 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
180 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
129 dialog.setModal(true); |
181 dialog.setModal(true); |
130 dialog.exec(); |
182 dialog.exec(); |