src/InventorySuppliers.cpp

Sun, 13 Feb 2022 15:15:03 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 13 Feb 2022 15:15:03 +0100
changeset 7
51fbea52551e
parent 6
f8474f2c5db9
child 8
ac4e363c09a7
permissions
-rw-r--r--

The suppliers table now shows on the right screen.

6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * InventorySuppliers.cpp is part of bmsapp.
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * bmsapp is free software: you can redistribute it and/or modify
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * the Free Software Foundation, either version 3 of the License, or
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * (at your option) any later version.
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 *
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * bmsapp is distributed in the hope that it will be useful,
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * GNU General Public License for more details.
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 *
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 */
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "InventorySuppliers.h"
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "../ui/ui_InventorySuppliers.h"
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "config.h"
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 #include <QDebug>
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 #include <QtSql>
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include <QTableWidget>
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers)
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 {
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 qDebug() << Q_FUNC_INFO;
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
7
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
30 ui->setupUi(this);
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
31
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
32 ui->tableSuppliers = new QTableWidget(ui->tableSuppliers);
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name");
7
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
34 const QStringList labels({tr("Record"), tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")});
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
7
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
36 ui->tableSuppliers->setColumnCount(7);
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
37 ui->tableSuppliers->setColumnWidth(0, 50); /* Record */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
38 ui->tableSuppliers->setColumnWidth(1, 250); /* Name */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
39 ui->tableSuppliers->setColumnWidth(2, 250); /* Address */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
40 ui->tableSuppliers->setColumnWidth(3, 200); /* City */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
41 ui->tableSuppliers->setColumnWidth(4, 120); /* Country */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
42 ui->tableSuppliers->setColumnWidth(5, 120); /* Phone */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
43 ui->tableSuppliers->setColumnWidth(6, 150); /* Edit button */
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
44 ui->tableSuppliers->setRowCount(query.size());
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
45 ui->tableSuppliers->setHorizontalHeaderLabels(labels);
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
46 ui->tableSuppliers->verticalHeader()->hide();
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
47 ui->tableSuppliers->setFixedSize(1280, 640); /* Even if this is too large, it works */
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 qDebug() << query.record().count() << query.size();
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 // So far, so good.
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 query.first();
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
7
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
53 for (int cidx = 0 ; cidx < 4; cidx++) {
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 QTableWidgetItem* item = new QTableWidgetItem(query.value(cidx).toString());
7
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
55 ui->tableSuppliers->setItem(ridx, cidx, item );
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 }
7
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
57 QTableWidgetItem* item = new QTableWidgetItem(query.value(5).toString());
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
58 ui->tableSuppliers->setItem(ridx, 4, item );
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
59 item = new QTableWidgetItem(query.value(8).toString());
51fbea52551e The suppliers table now shows on the right screen.
Michiel Broek <mbroek@mbse.eu>
parents: 6
diff changeset
60 ui->tableSuppliers->setItem(ridx, 5, item );
6
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 query.next();
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 }
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) );
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 }
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 InventorySuppliers::~InventorySuppliers()
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 {
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 qDebug() << Q_FUNC_INFO;
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 delete ui;
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 }
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 void InventorySuppliers::on_changeButton_clicked()
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 {
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 qDebug() << Q_FUNC_INFO;
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 emit firstWindow();
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 }
f8474f2c5db9 We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79

mercurial