19 #include "../ui/ui_InventoryWaters.h" |
19 #include "../ui/ui_InventoryWaters.h" |
20 #include "config.h" |
20 #include "config.h" |
21 #include "bmsapp.h" |
21 #include "bmsapp.h" |
22 |
22 |
23 |
23 |
24 InventoryWaters::InventoryWaters(QWidget *parent) : QDialog(parent), ui(new Ui::InventoryWaters) |
24 InventoryWaters::InventoryWaters(QWidget *parent) : QDialog(parent) |
25 { |
25 { |
26 qDebug() << "InventoryWaters start"; |
26 qDebug() << "InventoryWaters start"; |
27 |
27 |
28 ui->setupUi(this); |
28 gridLayout = new QGridLayout(this); |
|
29 gridLayout->setObjectName(QString::fromUtf8("gridLayout")); |
|
30 tableWaters = new QTableWidget(this); |
|
31 tableWaters->setObjectName(QString::fromUtf8("tableWaters")); |
|
32 tableWaters->setEnabled(true); |
|
33 QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
|
34 sizePolicy.setHorizontalStretch(0); |
|
35 sizePolicy.setVerticalStretch(0); |
|
36 tableWaters->setSizePolicy(sizePolicy); |
|
37 tableWaters->setMinimumSize(QSize(954, 0)); |
|
38 gridLayout->addWidget(tableWaters, 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(fromInventoryWaters())); |
|
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 Waters").arg(VERSIONSTRING) ); |
|
32 } |
91 } |
33 |
92 |
34 |
93 |
35 void InventoryWaters::refreshTable() |
94 void InventoryWaters::refreshTable() |
36 { |
95 { |
42 qDebug() << "InventoryWaters reload"; |
101 qDebug() << "InventoryWaters reload"; |
43 |
102 |
44 QSqlQuery query("SELECT * FROM inventory_waters ORDER BY name"); |
103 QSqlQuery query("SELECT * FROM inventory_waters ORDER BY name"); |
45 const QStringList labels({tr("Name"), tr("Notes"), tr("Unlimited"), tr("Stock"), tr("Edit")}); |
104 const QStringList labels({tr("Name"), tr("Notes"), tr("Unlimited"), tr("Stock"), tr("Edit")}); |
46 |
105 |
47 ui->tableWaters->setColumnCount(5); |
106 this->tableWaters->setColumnCount(5); |
48 ui->tableWaters->setColumnWidth(0, 200); /* Name */ |
107 this->tableWaters->setColumnWidth(0, 200); /* Name */ |
49 ui->tableWaters->setColumnWidth(1, 500); /* Notes */ |
108 this->tableWaters->setColumnWidth(1, 500); /* Notes */ |
50 ui->tableWaters->setColumnWidth(2, 75); /* Unlimited */ |
109 this->tableWaters->setColumnWidth(2, 75); /* Unlimited */ |
51 ui->tableWaters->setColumnWidth(3, 75); /* Stock */ |
110 this->tableWaters->setColumnWidth(3, 75); /* Stock */ |
52 ui->tableWaters->setColumnWidth(4, 80); /* Edit button */ |
111 this->tableWaters->setColumnWidth(4, 80); /* Edit button */ |
53 ui->tableWaters->setRowCount(query.size()); |
112 this->tableWaters->setRowCount(query.size()); |
54 ui->tableWaters->setHorizontalHeaderLabels(labels); |
113 this->tableWaters->setHorizontalHeaderLabels(labels); |
55 ui->tableWaters->verticalHeader()->hide(); |
114 this->tableWaters->verticalHeader()->hide(); |
56 ui->tableWaters->setFixedSize(930 + 24, 640); /* Even if this is too large, it works */ |
|
57 |
115 |
58 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
116 QTableWidgetItem *rightitem = new QTableWidgetItem(); |
59 rightitem->setTextAlignment(Qt::AlignRight); |
117 rightitem->setTextAlignment(Qt::AlignRight); |
60 |
118 |
61 query.first(); |
119 query.first(); |
62 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
120 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
63 ui->tableWaters->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
121 this->tableWaters->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); /* Name */ |
64 ui->tableWaters->setItem(ridx, 1, new QTableWidgetItem(query.value(10).toString())); /* Notes */ |
122 this->tableWaters->setItem(ridx, 1, new QTableWidgetItem(query.value(10).toString())); /* Notes */ |
65 if (query.value(2).toInt()) { |
123 if (query.value(2).toInt()) { |
66 pWidget = new QWidget(); |
124 pWidget = new QWidget(); |
67 label = new QLabel; |
125 label = new QLabel; |
68 label->setPixmap(QPixmap(":icons/silk/tick.png")); |
126 label->setPixmap(QPixmap(":icons/silk/tick.png")); |
69 pLayout = new QHBoxLayout(pWidget); |
127 pLayout = new QHBoxLayout(pWidget); |
70 pLayout->addWidget(label); |
128 pLayout->addWidget(label); |
71 pLayout->setAlignment(Qt::AlignCenter); |
129 pLayout->setAlignment(Qt::AlignCenter); |
72 pLayout->setContentsMargins(0, 0, 0, 0); |
130 pLayout->setContentsMargins(0, 0, 0, 0); |
73 pWidget->setLayout(pLayout); |
131 pWidget->setLayout(pLayout); |
74 ui->tableWaters->setCellWidget(ridx, 2, pWidget); |
132 this->tableWaters->setCellWidget(ridx, 2, pWidget); |
75 } else { |
133 } else { |
76 ui->tableWaters->removeCellWidget(ridx, 2); |
134 this->tableWaters->removeCellWidget(ridx, 2); |
77 } |
135 } |
78 |
136 |
79 w = QString(""); |
137 w = QString(""); |
80 if (query.value(12).toDouble() > 0) { |
138 if (query.value(12).toDouble() > 0) { |
81 w = QString("%1 L").arg(query.value(12).toDouble(), 2, 'f', 1, '0' ); |
139 w = QString("%1 L").arg(query.value(12).toDouble(), 2, 'f', 1, '0' ); |
82 } |
140 } |
83 QTableWidgetItem *item = new QTableWidgetItem(w); |
141 QTableWidgetItem *item = new QTableWidgetItem(w); |
84 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
142 item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); |
85 ui->tableWaters->setItem(ridx, 3, item); |
143 this->tableWaters->setItem(ridx, 3, item); |
86 |
144 |
87 /* Add the Edit button */ |
145 /* Add the Edit button */ |
88 pWidget = new QWidget(); |
146 pWidget = new QWidget(); |
89 QPushButton* btn_edit = new QPushButton(); |
147 QPushButton* btn_edit = new QPushButton(); |
90 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
148 btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ |
92 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
150 connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); |
93 pLayout = new QHBoxLayout(pWidget); |
151 pLayout = new QHBoxLayout(pWidget); |
94 pLayout->addWidget(btn_edit); |
152 pLayout->addWidget(btn_edit); |
95 pLayout->setContentsMargins(5, 0, 5, 0); |
153 pLayout->setContentsMargins(5, 0, 5, 0); |
96 pWidget->setLayout(pLayout); |
154 pWidget->setLayout(pLayout); |
97 ui->tableWaters->setCellWidget(ridx, 4, pWidget); |
155 this->tableWaters->setCellWidget(ridx, 4, pWidget); |
98 query.next(); |
156 query.next(); |
99 } |
157 } |
100 |
158 } |
101 setWindowTitle( QString("BMSapp - %1 - Inventory Waters").arg(VERSIONSTRING) ); |
159 |
102 } |
160 |
103 |
161 InventoryWaters::~InventoryWaters() {} |
104 |
|
105 InventoryWaters::~InventoryWaters() |
|
106 { |
|
107 qDebug() << "InventoryWaters done"; |
|
108 delete ui; |
|
109 } |
|
110 |
162 |
111 |
163 |
112 void InventoryWaters::edit(int recno) |
164 void InventoryWaters::edit(int recno) |
113 { |
165 { |
114 qDebug() << "InventoryWaters edit:" << recno; |
|
115 |
|
116 EditWater dialog(recno, this); |
166 EditWater dialog(recno, this); |
117 /* Signal from editor if a refresh is needed */ |
167 /* Signal from editor if a refresh is needed */ |
118 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
168 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
119 dialog.setModal(true); |
169 dialog.setModal(true); |
120 dialog.exec(); |
170 dialog.exec(); |