18 #include "EditSupplier.h" |
18 #include "EditSupplier.h" |
19 #include "../ui/ui_InventorySuppliers.h" |
19 #include "../ui/ui_InventorySuppliers.h" |
20 #include "config.h" |
20 #include "config.h" |
21 #include "bmsapp.h" |
21 #include "bmsapp.h" |
22 |
22 |
23 #include <QDebug> |
|
24 #include <QtSql> |
|
25 #include <QtWidgets> |
|
26 #include <QTableWidget> |
|
27 |
|
28 |
|
29 |
|
30 |
23 |
31 |
24 |
32 InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers) |
25 InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers) |
33 { |
26 { |
34 qDebug() << Q_FUNC_INFO; |
27 qDebug() << "InventorySuppliers start"; |
35 |
28 |
36 ui->setupUi(this); |
29 ui->setupUi(this); |
37 emit refreshTable(); |
30 emit refreshTable(); |
38 |
31 |
39 setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); |
32 setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); |
42 |
35 |
43 void InventorySuppliers::refreshTable() |
36 void InventorySuppliers::refreshTable() |
44 { |
37 { |
45 qDebug() << "slot" << Q_FUNC_INFO; |
38 qDebug() << "slot" << Q_FUNC_INFO; |
46 |
39 |
47 ui->tableSuppliers = new QTableWidget(ui->tableSuppliers); |
|
48 emit ui->tableSuppliers->clearContents(); |
|
49 QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); |
40 QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); |
50 const QStringList labels({tr("Record"), tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")}); |
41 const QStringList labels({tr("Record"), tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")}); |
51 |
|
52 // ui->tableSuppliers->clear(); |
|
53 // ui->tableSuppliers->setRowCount(0); |
|
54 // ui->tableSuppliers->setColumnCount(0); |
|
55 |
42 |
56 ui->tableSuppliers->setColumnCount(7); |
43 ui->tableSuppliers->setColumnCount(7); |
57 ui->tableSuppliers->setColumnWidth(0, 50); /* Record */ |
44 ui->tableSuppliers->setColumnWidth(0, 50); /* Record */ |
58 ui->tableSuppliers->setColumnWidth(1, 250); /* Name */ |
45 ui->tableSuppliers->setColumnWidth(1, 250); /* Name */ |
59 ui->tableSuppliers->setColumnWidth(2, 250); /* Address */ |
46 ui->tableSuppliers->setColumnWidth(2, 250); /* Address */ |
64 ui->tableSuppliers->setRowCount(query.size()); |
51 ui->tableSuppliers->setRowCount(query.size()); |
65 ui->tableSuppliers->setHorizontalHeaderLabels(labels); |
52 ui->tableSuppliers->setHorizontalHeaderLabels(labels); |
66 ui->tableSuppliers->verticalHeader()->hide(); |
53 ui->tableSuppliers->verticalHeader()->hide(); |
67 ui->tableSuppliers->setFixedSize(1280, 640); /* Even if this is too large, it works */ |
54 ui->tableSuppliers->setFixedSize(1280, 640); /* Even if this is too large, it works */ |
68 |
55 |
69 qDebug() << query.record().count() << query.size(); |
56 // qDebug() << query.record().count() << query.size(); |
70 // So far, so good. |
|
71 query.first(); |
57 query.first(); |
72 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
58 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { |
73 for (int cidx = 0 ; cidx < 4; cidx++) { |
59 for (int cidx = 0 ; cidx < 4; cidx++) { |
74 QTableWidgetItem* item = new QTableWidgetItem(query.value(cidx).toString()); |
60 QTableWidgetItem* item = new QTableWidgetItem(query.value(cidx).toString()); |
75 ui->tableSuppliers->setItem(ridx, cidx, item ); |
61 ui->tableSuppliers->setItem(ridx, cidx, item ); |
76 } |
62 } |
|
63 // qDebug() << ridx << "record:" << query.value(0).toString() << " name:" << query.value(1).toString(); |
77 QTableWidgetItem* item = new QTableWidgetItem(query.value(5).toString()); |
64 QTableWidgetItem* item = new QTableWidgetItem(query.value(5).toString()); |
78 ui->tableSuppliers->setItem(ridx, 4, item ); |
65 ui->tableSuppliers->setItem(ridx, 4, item ); |
79 item = new QTableWidgetItem(query.value(8).toString()); |
66 item = new QTableWidgetItem(query.value(8).toString()); |
80 ui->tableSuppliers->setItem(ridx, 5, item ); |
67 ui->tableSuppliers->setItem(ridx, 5, item ); |
81 /* Add the Edit button */ |
68 /* Add the Edit button */ |
90 pLayout->setContentsMargins(0, 0, 0, 0); |
77 pLayout->setContentsMargins(0, 0, 0, 0); |
91 pWidget->setLayout(pLayout); |
78 pWidget->setLayout(pLayout); |
92 ui->tableSuppliers->setCellWidget(ridx, 6, pWidget); |
79 ui->tableSuppliers->setCellWidget(ridx, 6, pWidget); |
93 query.next(); |
80 query.next(); |
94 } |
81 } |
|
82 // qDebug() << "table ready"; |
95 |
83 |
96 setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); |
84 setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); |
97 } |
85 } |
98 |
86 |
99 |
87 |
100 InventorySuppliers::~InventorySuppliers() |
88 InventorySuppliers::~InventorySuppliers() |
101 { |
89 { |
102 qDebug() << Q_FUNC_INFO; |
90 qDebug() << "InventorySuppliers done"; |
103 delete ui; |
91 delete ui; |
104 } |
92 } |
105 |
93 |
106 |
94 |
107 void InventorySuppliers::edit(int recno) |
95 void InventorySuppliers::edit(int recno) |
108 { |
96 { |
109 qDebug() << Q_FUNC_INFO << recno; |
97 qDebug() << "InventorySuppliers edit:" << recno; |
110 |
98 |
111 EditSupplier dialog(recno, this); |
99 EditSupplier dialog(recno, this); |
112 /* Signal from editor if a refresh is needed */ |
100 /* Signal from editor if a refresh is needed */ |
113 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
101 connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); |
114 |
|
115 dialog.setModal(true); |
102 dialog.setModal(true); |
116 dialog.exec(); |
103 dialog.exec(); |
117 |
|
118 qDebug() << Q_FUNC_INFO << "Back from edit record:" << recno; |
|
119 } |
104 } |
120 |
105 |
121 |
106 |
122 void InventorySuppliers::on_editButton_clicked() |
107 void InventorySuppliers::on_editButton_clicked() |
123 { |
108 { |