src/InventoryFermentables.cpp

changeset 68
abac28effb21
parent 44
5a9a159c2d34
child 78
3a6cba2dd05d
equal deleted inserted replaced
67:55aa8c3146ee 68:abac28effb21
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 "InventoryFermentables.h" 17 #include "InventoryFermentables.h"
18 #include "EditFermentable.h" 18 #include "EditFermentable.h"
19 #include "../ui/ui_InventoryFermentables.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 InventoryFermentables::InventoryFermentables(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryFermentables) 24 InventoryFermentables::InventoryFermentables(QWidget *parent) : QDialog(parent)
25 { 25 {
26 qDebug() << "InventoryFermentables start"; 26 qDebug() << "InventoryFermentables start";
27 27
28 ui->setupUi(this); 28 gridLayout = new QGridLayout(this);
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
30 tableFermentables = new QTableWidget(this);
31 tableFermentables->setObjectName(QString::fromUtf8("tableFermentables"));
32 tableFermentables->setEnabled(true);
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
34 sizePolicy.setHorizontalStretch(0);
35 sizePolicy.setVerticalStretch(0);
36 //sizePolicy.setHeightForWidth(tableFermentables->sizePolicy().hasHeightForWidth());
37 tableFermentables->setSizePolicy(sizePolicy);
38 tableFermentables->setMinimumSize(QSize(1074, 0));
39 gridLayout->addWidget(tableFermentables, 0, 0, 1, 1);
40
41 groupBox = new QGroupBox(this);
42 groupBox->setObjectName(QString::fromUtf8("groupBox"));
43 groupBox->setEnabled(true);
44 groupBox->setFlat(false);
45 horizontalLayout = new QHBoxLayout(groupBox);
46 horizontalLayout->setSpacing(6);
47 horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
48 horizontalLayout->setContentsMargins(0, 0, 0, 0);
49
50 quitButton = new QPushButton(groupBox);
51 quitButton->setObjectName(QString::fromUtf8("quitButton"));
52 quitButton->setMinimumSize(QSize(80, 24));
53 quitButton->setText(tr("Quit"));
54 QIcon icon;
55 icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off);
56 quitButton->setIcon(icon);
57 horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft);
58
59 exportButton = new QPushButton(groupBox);
60 exportButton->setObjectName(QString::fromUtf8("exportButton"));
61 exportButton->setMinimumSize(QSize(80, 24));
62 exportButton->setText(tr("Export"));
63 QIcon icon1;
64 icon1.addFile(QString::fromUtf8(":/icons/silk/database_save.png"), QSize(), QIcon::Normal, QIcon::Off);
65 exportButton->setIcon(icon1);
66 horizontalLayout->addWidget(exportButton, 0, Qt::AlignRight);
67
68 importButton = new QPushButton(groupBox);
69 importButton->setObjectName(QString::fromUtf8("importButton"));
70 importButton->setMinimumSize(QSize(80, 24));
71 importButton->setText(tr("Import"));
72 QIcon icon2;
73 icon2.addFile(QString::fromUtf8(":/icons/silk/database_add.png"), QSize(), QIcon::Normal, QIcon::Off);
74 importButton->setIcon(icon2);
75 horizontalLayout->addWidget(importButton, 0, Qt::AlignRight);
76
77 insertButton = new QPushButton(groupBox);
78 insertButton->setObjectName(QString::fromUtf8("insertButton"));
79 insertButton->setMinimumSize(QSize(80, 24));
80 insertButton->setText(tr("New"));
81 QIcon icon3;
82 icon3.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off);
83 insertButton->setIcon(icon3);
84 horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight);
85 gridLayout->addWidget(groupBox, 1, 0, 1, 1);
86
87 connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventoryFermentables()));
88 connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked()));
89 connect(exportButton, SIGNAL(clicked()), this, SLOT(on_exportButton_clicked()));
90 // connect(importButton, SIGNAL(clicked()), this, SLOT(on_importButton_clicked()));
29 emit refreshTable(); 91 emit refreshTable();
30
31 setWindowTitle( QString("BMSapp - %1 - Inventory Fermentables").arg(VERSIONSTRING) );
32 } 92 }
33 93
34 94
35 void InventoryFermentables::refreshTable() 95 void InventoryFermentables::refreshTable()
36 { 96 {
42 const QStringList labels({tr("Origin"), tr("Supplier"), tr("Name"), tr("Type"), tr("Grain"), tr("Color"), tr("Yield"), tr("Stock"), tr("Edit")}); 102 const QStringList labels({tr("Origin"), tr("Supplier"), tr("Name"), tr("Type"), tr("Grain"), tr("Color"), tr("Yield"), tr("Stock"), tr("Edit")});
43 const QStringList types({tr("Grain"), tr("Sugar"), tr("Extract"), tr("Dry extract"), tr("Adjunct")}); 103 const QStringList types({tr("Grain"), tr("Sugar"), tr("Extract"), tr("Dry extract"), tr("Adjunct")});
44 const QStringList graintypes({tr("Base"), tr("Roast"), tr("Crystal"), tr("Kilned"), tr("Sour Malt"), tr("Special"), tr("No malt")}); 104 const QStringList graintypes({tr("Base"), tr("Roast"), tr("Crystal"), tr("Kilned"), tr("Sour Malt"), tr("Special"), tr("No malt")});
45 105
46 /* origin supplier name type graintype color yield inventory Edit */ 106 /* origin supplier name type graintype color yield inventory Edit */
47 ui->tableFermentables->setColumnCount(9); 107 this->tableFermentables->setColumnCount(9);
48 ui->tableFermentables->setColumnWidth(0, 130); /* Origin */ 108 this->tableFermentables->setColumnWidth(0, 130); /* Origin */
49 ui->tableFermentables->setColumnWidth(1, 170); /* Supplier */ 109 this->tableFermentables->setColumnWidth(1, 170); /* Supplier */
50 ui->tableFermentables->setColumnWidth(2, 250); /* Name */ 110 this->tableFermentables->setColumnWidth(2, 250); /* Name */
51 ui->tableFermentables->setColumnWidth(3, 90); /* Type */ 111 this->tableFermentables->setColumnWidth(3, 90); /* Type */
52 ui->tableFermentables->setColumnWidth(4, 90); /* Graintype */ 112 this->tableFermentables->setColumnWidth(4, 90); /* Graintype */
53 ui->tableFermentables->setColumnWidth(5, 80); /* Color */ 113 this->tableFermentables->setColumnWidth(5, 80); /* Color */
54 ui->tableFermentables->setColumnWidth(6, 80); /* Yield */ 114 this->tableFermentables->setColumnWidth(6, 80); /* Yield */
55 ui->tableFermentables->setColumnWidth(7, 80); /* Stock */ 115 this->tableFermentables->setColumnWidth(7, 80); /* Stock */
56 ui->tableFermentables->setColumnWidth(8, 80); /* Edit button */ 116 this->tableFermentables->setColumnWidth(8, 80); /* Edit button */
57 ui->tableFermentables->setRowCount(query.size()); 117 this->tableFermentables->setRowCount(query.size());
58 ui->tableFermentables->setHorizontalHeaderLabels(labels); 118 this->tableFermentables->setHorizontalHeaderLabels(labels);
59 ui->tableFermentables->verticalHeader()->hide(); 119 this->tableFermentables->verticalHeader()->hide();
60 ui->tableFermentables->setFixedSize(1050 + 24, 640); /* Even if this is too large, it works */ 120 //ui->tableFermentables->setFixedSize(1050 + 24, 640); /* Even if this is too large, it works */
61 121
62 QTableWidgetItem *rightitem = new QTableWidgetItem(); 122 QTableWidgetItem *rightitem = new QTableWidgetItem();
63 rightitem->setTextAlignment(Qt::AlignRight); 123 rightitem->setTextAlignment(Qt::AlignRight);
64 124
65 query.first(); 125 query.first();
66 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { 126 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
67 ui->tableFermentables->setItem(ridx, 0, new QTableWidgetItem(query.value(6).toString())); 127 this->tableFermentables->setItem(ridx, 0, new QTableWidgetItem(query.value(6).toString()));
68 ui->tableFermentables->setItem(ridx, 1, new QTableWidgetItem(query.value(7).toString())); 128 this->tableFermentables->setItem(ridx, 1, new QTableWidgetItem(query.value(7).toString()));
69 ui->tableFermentables->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString())); 129 this->tableFermentables->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString()));
70 ui->tableFermentables->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()])); 130 this->tableFermentables->setItem(ridx, 3, new QTableWidgetItem(types[query.value(2).toInt()]));
71 ui->tableFermentables->setItem(ridx, 4, new QTableWidgetItem(graintypes[query.value(20).toInt()])); 131 this->tableFermentables->setItem(ridx, 4, new QTableWidgetItem(graintypes[query.value(20).toInt()]));
72 w = QString("%1 EBC").arg(query.value(4).toDouble(), 1, 'f', 0, '0' ); 132 w = QString("%1 EBC").arg(query.value(4).toDouble(), 1, 'f', 0, '0' );
73 QTableWidgetItem *item = new QTableWidgetItem(w); 133 QTableWidgetItem *item = new QTableWidgetItem(w);
74 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 134 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
75 ui->tableFermentables->setItem(ridx, 5, item); 135 this->tableFermentables->setItem(ridx, 5, item);
76 w = QString("%1 %").arg(query.value(3).toFloat(), 3, 'f', 1, '0' ); 136 w = QString("%1 %").arg(query.value(3).toFloat(), 3, 'f', 1, '0' );
77 item = new QTableWidgetItem(w); 137 item = new QTableWidgetItem(w);
78 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 138 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
79 ui->tableFermentables->setItem(ridx, 6, item); 139 this->tableFermentables->setItem(ridx, 6, item);
80 w = QString(""); 140 w = QString("");
81 if (query.value(21).toDouble() > 0) { 141 if (query.value(21).toDouble() > 0) {
82 if (query.value(21).toDouble() < 1.000) { 142 if (query.value(21).toDouble() < 1.000) {
83 w = QString("%1 gr").arg(query.value(21).toDouble() * 1000.0, 1, 'f', 0, '0' ); 143 w = QString("%1 gr").arg(query.value(21).toDouble() * 1000.0, 1, 'f', 0, '0' );
84 } else { 144 } else {
85 w = QString("%1 kg").arg(query.value(21).toDouble(), 4, 'f', 3, '0' ); 145 w = QString("%1 kg").arg(query.value(21).toDouble(), 4, 'f', 3, '0' );
86 } 146 }
87 } 147 }
88 item = new QTableWidgetItem(w); 148 item = new QTableWidgetItem(w);
89 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); 149 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
90 ui->tableFermentables->setItem(ridx, 7, item); 150 this->tableFermentables->setItem(ridx, 7, item);
91 151
92 /* Add the Edit button */ 152 /* Add the Edit button */
93 QWidget* pWidget = new QWidget(); 153 QWidget* pWidget = new QWidget();
94 QPushButton* btn_edit = new QPushButton(); 154 QPushButton* btn_edit = new QPushButton();
95 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ 155 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */
97 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); 157 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked()));
98 QHBoxLayout* pLayout = new QHBoxLayout(pWidget); 158 QHBoxLayout* pLayout = new QHBoxLayout(pWidget);
99 pLayout->addWidget(btn_edit); 159 pLayout->addWidget(btn_edit);
100 pLayout->setContentsMargins(5, 0, 5, 0); 160 pLayout->setContentsMargins(5, 0, 5, 0);
101 pWidget->setLayout(pLayout); 161 pWidget->setLayout(pLayout);
102 ui->tableFermentables->setCellWidget(ridx, 8, pWidget); 162 this->tableFermentables->setCellWidget(ridx, 8, pWidget);
103 query.next(); 163 query.next();
104 } 164 }
105 165
106 setWindowTitle( QString("BMSapp - %1 - Inventory Fermentables").arg(VERSIONSTRING) ); 166 setWindowTitle( QString("BMSapp - %1 - Inventory Fermentables").arg(VERSIONSTRING) );
107 } 167 }
108 168
109 169
110 InventoryFermentables::~InventoryFermentables() 170 InventoryFermentables::~InventoryFermentables()
111 { 171 {
112 qDebug() << "InventoryFermentables done"; 172 qDebug() << "InventoryFermentables done";
113 delete ui;
114 } 173 }
115 174
116 175
117 void InventoryFermentables::edit(int recno) 176 void InventoryFermentables::edit(int recno)
118 { 177 {
128 187
129 void InventoryFermentables::on_editButton_clicked() 188 void InventoryFermentables::on_editButton_clicked()
130 { 189 {
131 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender()); 190 QPushButton *pb = qobject_cast<QPushButton *>(QObject::sender());
132 int recno = pb->objectName().toInt(); 191 int recno = pb->objectName().toInt();
133 qDebug() << Q_FUNC_INFO << recno;
134 edit(recno); 192 edit(recno);
135 } 193 }
136 194
137 195
138 void InventoryFermentables::on_insertButton_clicked() 196 void InventoryFermentables::on_insertButton_clicked()
139 { 197 {
140 qDebug() << Q_FUNC_INFO;
141 edit(-1); 198 edit(-1);
142 } 199 }
143 200
144 201
145 void InventoryFermentables::on_exportButton_clicked() 202 void InventoryFermentables::on_exportButton_clicked()
206 QMessageBox::information(this, tr("Save File"), tr("XML export ready")); 263 QMessageBox::information(this, tr("Save File"), tr("XML export ready"));
207 264
208 file.close(); 265 file.close();
209 } 266 }
210 267
211
212 void InventoryFermentables::on_quitButton_clicked()
213 {
214 emit firstWindow();
215 }
216

mercurial