Sat, 19 Mar 2022 22:59:11 +0100
Finally found out how to make these databases work on a single main window. And it's dynamic too.
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/InventorySuppliers.cpp | file | annotate | diff | comparison | revisions | |
src/InventorySuppliers.h | file | annotate | diff | comparison | revisions | |
src/MainWindow.cpp | file | annotate | diff | comparison | revisions | |
src/MainWindow.h | file | annotate | diff | comparison | revisions | |
ui/InventorySuppliers.ui | file | annotate | diff | comparison | revisions | |
ui/MainWindow.ui | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Sat Mar 19 19:22:58 2022 +0100 +++ b/CMakeLists.txt Sat Mar 19 22:59:11 2022 +0100 @@ -166,7 +166,6 @@ set( UIS ${UIDIR}/AboutDialog.ui - ${UIDIR}/InventorySuppliers.ui ${UIDIR}/EditSupplier.ui ${UIDIR}/InventoryFermentables.ui ${UIDIR}/EditFermentable.ui
--- a/src/InventorySuppliers.cpp Sat Mar 19 19:22:58 2022 +0100 +++ b/src/InventorySuppliers.cpp Sat Mar 19 22:59:11 2022 +0100 @@ -17,17 +17,58 @@ #include "InventorySuppliers.h" #include "EditSupplier.h" #include "MainWindow.h" -#include "../ui/ui_InventorySuppliers.h" #include "config.h" #include "bmsapp.h" -InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers) +InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent) /*, ui(new Ui::InventorySuppliers)*/ { qDebug() << "InventorySuppliers start"; - ui->setupUi(this); + gridLayout = new QGridLayout(this); + gridLayout->setObjectName(QString::fromUtf8("gridLayout")); + tableSuppliers = new QTableWidget(this); + tableSuppliers->setObjectName(QString::fromUtf8("tableSuppliers")); + tableSuppliers->setEnabled(true); + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(tableSuppliers->sizePolicy().hasHeightForWidth()); + tableSuppliers->setSizePolicy(sizePolicy); + tableSuppliers->setMinimumSize(QSize(1054, 0)); + gridLayout->addWidget(tableSuppliers, 0, 0, 1, 1); + + groupBox = new QGroupBox(this); + groupBox->setObjectName(QString::fromUtf8("groupBox")); + groupBox->setEnabled(true); + groupBox->setFlat(false); + horizontalLayout = new QHBoxLayout(groupBox); + horizontalLayout->setSpacing(6); + horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); + horizontalLayout->setContentsMargins(0, 0, 0, 0); + quitButton = new QPushButton(groupBox); + quitButton->setObjectName(QString::fromUtf8("quitButton")); + quitButton->setMinimumSize(QSize(80, 24)); + QIcon icon; + icon.addFile(QString::fromUtf8(":icons/silk/door_out.png"), QSize(), QIcon::Normal, QIcon::Off); + quitButton->setIcon(icon); + horizontalLayout->addWidget(quitButton, 0, Qt::AlignLeft); + + insertButton = new QPushButton(groupBox); + insertButton->setObjectName(QString::fromUtf8("insertButton")); + insertButton->setMinimumSize(QSize(80, 24)); + QIcon icon1; + icon1.addFile(QString::fromUtf8(":icons/silk/table_row_insert.png"), QSize(), QIcon::Normal, QIcon::Off); + insertButton->setIcon(icon1); + horizontalLayout->addWidget(insertButton, 0, Qt::AlignRight); + + gridLayout->addWidget(groupBox, 1, 0, 1, 1); + + //retranslateUi(this); + + connect(quitButton, SIGNAL(clicked()), parent, SLOT(fromInventorySuppliers())); + connect(insertButton, SIGNAL(clicked()), this, SLOT(on_insertButton_clicked())); emit refreshTable(); } @@ -39,25 +80,25 @@ QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); const QStringList labels({tr("Name"), tr("Address"), tr("City"), tr("Country"), tr("Phone"), tr("Edit")}); - ui->tableSuppliers->setColumnCount(6); - ui->tableSuppliers->setColumnWidth(0, 250); /* Name */ - ui->tableSuppliers->setColumnWidth(1, 250); /* Address */ - ui->tableSuppliers->setColumnWidth(2, 200); /* City */ - ui->tableSuppliers->setColumnWidth(3, 120); /* Country */ - ui->tableSuppliers->setColumnWidth(4, 120); /* Phone */ - ui->tableSuppliers->setColumnWidth(5, 90); /* Edit button */ - ui->tableSuppliers->setRowCount(query.size()); - ui->tableSuppliers->setHorizontalHeaderLabels(labels); - ui->tableSuppliers->verticalHeader()->hide(); + this->tableSuppliers->setColumnCount(6); + this->tableSuppliers->setColumnWidth(0, 250); /* Name */ + this->tableSuppliers->setColumnWidth(1, 250); /* Address */ + this->tableSuppliers->setColumnWidth(2, 200); /* City */ + this->tableSuppliers->setColumnWidth(3, 120); /* Country */ + this->tableSuppliers->setColumnWidth(4, 120); /* Phone */ + this->tableSuppliers->setColumnWidth(5, 90); /* Edit button */ + this->tableSuppliers->setRowCount(query.size()); + this->tableSuppliers->setHorizontalHeaderLabels(labels); + this->tableSuppliers->verticalHeader()->hide(); /* Set the widget size to 1054 x 575 in the ui. */ query.first(); for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { - ui->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); - ui->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); - ui->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString())); - ui->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString())); - ui->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString())); + this->tableSuppliers->setItem(ridx, 0, new QTableWidgetItem(query.value(1).toString())); + this->tableSuppliers->setItem(ridx, 1, new QTableWidgetItem(query.value(2).toString())); + this->tableSuppliers->setItem(ridx, 2, new QTableWidgetItem(query.value(3).toString())); + this->tableSuppliers->setItem(ridx, 3, new QTableWidgetItem(query.value(5).toString())); + this->tableSuppliers->setItem(ridx, 4, new QTableWidgetItem(query.value(8).toString())); /* Add the Edit button */ QWidget* pWidget = new QWidget(); @@ -69,7 +110,7 @@ pLayout->addWidget(btn_edit); pLayout->setContentsMargins(5, 0, 5, 0); pWidget->setLayout(pLayout); - ui->tableSuppliers->setCellWidget(ridx, 5, pWidget); + this->tableSuppliers->setCellWidget(ridx, 5, pWidget); query.next(); } } @@ -78,7 +119,6 @@ InventorySuppliers::~InventorySuppliers() { qDebug() << "InventorySuppliers done"; -// delete ui; } @@ -109,12 +149,3 @@ edit(-1); } - -void InventorySuppliers::on_quitButton_clicked() -{ - qDebug() << Q_FUNC_INFO; - - MainWindow a; - a.fromInventorySuppliers(); -} -
--- a/src/InventorySuppliers.h Sat Mar 19 19:22:58 2022 +0100 +++ b/src/InventorySuppliers.h Sat Mar 19 22:59:11 2022 +0100 @@ -2,6 +2,12 @@ #define _INVENTORYSPUPPLIERS_H #include <QDialog> +#include <QtWidgets/QGridLayout> +#include <QtWidgets/QGroupBox> +#include <QtWidgets/QHBoxLayout> +#include <QtWidgets/QHeaderView> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QTableWidget> namespace Ui { class InventorySuppliers; @@ -15,17 +21,22 @@ explicit InventorySuppliers(QWidget *parent = nullptr); ~InventorySuppliers(); -signals: - void firstWindow(); +//signals: +// void firstWindow(); private slots: - void on_quitButton_clicked(); void on_insertButton_clicked(); void on_editButton_clicked(); void refreshTable(void); private: - Ui::InventorySuppliers *ui; + QGridLayout *gridLayout; + QTableWidget *tableSuppliers; + QGroupBox *groupBox; + QHBoxLayout *horizontalLayout; + QPushButton *quitButton; + QPushButton *insertButton; + void edit(int recno); };
--- a/src/MainWindow.cpp Sat Mar 19 19:22:58 2022 +0100 +++ b/src/MainWindow.cpp Sat Mar 19 22:59:11 2022 +0100 @@ -37,6 +37,9 @@ #include <QDebug> #include <QStandardItem> #include <QWidget> +#include <QtWidgets/QTableWidget> +#include <QtWidgets/QGroupBox> +#include <QtWidgets/QPushButton> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -65,8 +68,11 @@ void MainWindow::fromInventorySuppliers() { qDebug() << Q_FUNC_INFO; -// delete InventorySuppliersWindow; - ui->mainStack->setCurrentIndex(0); + qDebug() << "fromInventorySuppliers() start"; + ui->mainStack->setCurrentIndex(-1); + ui->mainStack->removeWidget(InventorySuppliersWindow); + qDebug() << ui->mainStack->count(); + delete InventorySuppliersWindow; setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) ); qDebug() << "fromInventorySuppliers() done"; } @@ -75,11 +81,11 @@ void MainWindow::on_actionSuppliers_triggered() { qDebug() << Q_FUNC_INFO; + InventorySuppliersWindow = new InventorySuppliers(this); -// QObject::connect(InventorySuppliersWindow, SIGNAL(firstWindow()), this, SLOT(fromInventorySuppliers())); + ui->mainStack->addWidget(InventorySuppliersWindow); qDebug() << ui->mainStack->count(); - ui->mainStack->setCurrentIndex(1); -// connect(InventorySuppliersWindow, SIGNAL(firstWindow()), this, SLOT(fromInventorySuppliers())); + ui->mainStack->setCurrentIndex(2); setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING)); }
--- a/src/MainWindow.h Sat Mar 19 19:22:58 2022 +0100 +++ b/src/MainWindow.h Sat Mar 19 22:59:11 2022 +0100 @@ -31,6 +31,8 @@ explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + InventorySuppliers *InventorySuppliersWindow; + private slots: void on_actionExit_triggered(); void on_actionSuppliers_triggered(); @@ -67,7 +69,6 @@ Ui::MainWindow *ui; // Keep pointers to new windows. - InventorySuppliers *InventorySuppliersWindow; InventoryFermentables *InventoryFermentablesWindow; InventoryHops *InventoryHopsWindow; InventoryYeasts *InventoryYeastsWindow;
--- a/ui/InventorySuppliers.ui Sat Mar 19 19:22:58 2022 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>InventorySuppliers</class> - <widget class="QDialog" name="InventorySuppliers"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>1280</width> - <height>640</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0"> - <widget class="QTableWidget" name="tableSuppliers"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>1054</width> - <height>0</height> - </size> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QGroupBox" name="groupBox"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="flat"> - <bool>false</bool> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="spacing"> - <number>6</number> - </property> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item alignment="Qt::AlignLeft"> - <widget class="QPushButton" name="quitButton"> - <property name="minimumSize"> - <size> - <width>80</width> - <height>24</height> - </size> - </property> - <property name="text"> - <string>Quit</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:icons/silk/door_out.png</normaloff>:icons/silk/door_out.png</iconset> - </property> - </widget> - </item> - <item alignment="Qt::AlignRight"> - <widget class="QPushButton" name="insertButton"> - <property name="minimumSize"> - <size> - <width>80</width> - <height>24</height> - </size> - </property> - <property name="text"> - <string>New</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:icons/silk/table_row_insert.png</normaloff>:icons/silk/table_row_insert.png</iconset> - </property> - </widget> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - <resources> - <include location="../../../../../../home/mbroek/MyProjects/bmsapp/resources/icons.qrc"/> - </resources> - <connections/> -</ui>
--- a/ui/MainWindow.ui Sat Mar 19 19:22:58 2022 +0100 +++ b/ui/MainWindow.ui Sat Mar 19 22:59:11 2022 +0100 @@ -26,7 +26,7 @@ <enum>Qt::NoFocus</enum> </property> <widget class="QWidget" name="page"/> - <widget class="InventorySuppliers" name="pageIS"/> + <widget class="QWidget" name="pageIS"/> </widget> </item> </layout> @@ -351,14 +351,6 @@ </action> </widget> <layoutdefault spacing="6" margin="11"/> - <customwidgets> - <customwidget> - <class>InventorySuppliers</class> - <extends>QWidget</extends> - <header>InventorySuppliers.h</header> - <container>1</container> - </customwidget> - </customwidgets> <resources> <include location="../resources/icons.qrc"/> </resources>