The suppliers table now shows on the right screen.

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

The suppliers table now shows on the right screen.

src/InventorySuppliers.cpp file | annotate | diff | comparison | revisions
ui/InventorySuppliers.ui file | annotate | diff | comparison | revisions
--- a/src/InventorySuppliers.cpp	Sat Feb 12 21:24:43 2022 +0100
+++ b/src/InventorySuppliers.cpp	Sun Feb 13 15:15:03 2022 +0100
@@ -19,40 +19,48 @@
 #include "config.h"
 
 #include <QDebug>
-//#include <QSqlTableModel>
-//#include <QTableView>
-//#include <QtWidgets>
 #include <QtSql>
 #include <QTableWidget>
 
 
-
 InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers)
 {
     qDebug() << Q_FUNC_INFO;
 
-    QTableWidget* table = new QTableWidget();
+    ui->setupUi(this);
+
+    ui->tableSuppliers = new QTableWidget(ui->tableSuppliers);
     QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name");
+    const QStringList labels({tr("Record"), tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")});
 
-    table->setColumnCount(query.record().count() - 1);	/* Skip the last uuid column */
-    table->setRowCount(query.size());
-
-    table->setHorizontalHeaderLabels({"record", "name", "address", "city", "zip", "country", "website", "email", "phone", "remark"});
+    ui->tableSuppliers->setColumnCount(7);
+    ui->tableSuppliers->setColumnWidth(0, 50);	/* Record	*/
+    ui->tableSuppliers->setColumnWidth(1, 250);	/* Name		*/
+    ui->tableSuppliers->setColumnWidth(2, 250);	/* Address	*/
+    ui->tableSuppliers->setColumnWidth(3, 200);	/* City		*/
+    ui->tableSuppliers->setColumnWidth(4, 120);	/* Country	*/
+    ui->tableSuppliers->setColumnWidth(5, 120);	/* Phone	*/
+    ui->tableSuppliers->setColumnWidth(6, 150);	/* Edit button	*/
+    ui->tableSuppliers->setRowCount(query.size());
+    ui->tableSuppliers->setHorizontalHeaderLabels(labels);
+    ui->tableSuppliers->verticalHeader()->hide();
+    ui->tableSuppliers->setFixedSize(1280, 640);	/* Even if this is too large, it works */
 
     qDebug() << query.record().count() << query.size();
     // So far, so good.
     query.first();
     for (int ridx = 0 ; ridx < query.size() ; ridx++ ) {
-	for (int cidx = 0 ; cidx < query.record().count() - 1; cidx++) {
+	for (int cidx = 0 ; cidx < 4; cidx++) {
 	    QTableWidgetItem* item = new QTableWidgetItem(query.value(cidx).toString());
-	    table->setItem(ridx, cidx, item );
-	    //qDebug() << ridx << cidx << query.value(cidx).toString();
+	    ui->tableSuppliers->setItem(ridx, cidx, item );
 	}
+	QTableWidgetItem* item = new QTableWidgetItem(query.value(5).toString());
+	ui->tableSuppliers->setItem(ridx, 4, item );
+	item = new QTableWidgetItem(query.value(8).toString());
+        ui->tableSuppliers->setItem(ridx, 5, item );
 	query.next();
     }
-    table->show(); /* TODO: Uses a separate window */
 
-    ui->setupUi(this);
     setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) );
 }
 
--- a/ui/InventorySuppliers.ui	Sat Feb 12 21:24:43 2022 +0100
+++ b/ui/InventorySuppliers.ui	Sun Feb 13 15:15:03 2022 +0100
@@ -15,7 +15,11 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <widget class="QTableWidget" name="mytable"/>
+    <widget class="QTableWidget" name="tableSuppliers">
+     <property name="enabled">
+      <bool>true</bool>
+     </property>
+    </widget>
    </item>
    <item>
     <widget class="QDialogButtonBox" name="changeButton">

mercurial