# HG changeset patch # User Michiel Broek # Date 1644697483 -3600 # Node ID f8474f2c5db97e145bac698bb8207dad86d3956a # Parent 22baafbf770dfd61040a64c0dd049896a6b8e41f We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5 diff -r 22baafbf770d -r f8474f2c5db9 CMakeLists.txt --- a/CMakeLists.txt Fri Feb 11 16:00:06 2022 +0100 +++ b/CMakeLists.txt Sat Feb 12 21:24:43 2022 +0100 @@ -98,6 +98,7 @@ ${SRCDIR}/main.cpp ${SRCDIR}/bmsapp.cpp ${SRCDIR}/AboutDialog.cpp + ${SRCDIR}/InventorySuppliers.cpp ${SRCDIR}/MainWindow.cpp ${SRCDIR}/database/database.cpp ) @@ -105,12 +106,14 @@ set( HDRS ${SRCDIR}/bmsapp.h ${SRCDIR}/AboutDialog.h + ${SRCDIR}/InventorySuppliers.h ${SRCDIR}/MainWindow.h ${SRCDIR}/database/database.h ) set( UIS ${UIDIR}/AboutDialog.ui + ${UIDIR}/InventorySuppliers.ui ${UIDIR}/MainWindow.ui ) diff -r 22baafbf770d -r f8474f2c5db9 src/AboutDialog.cpp --- a/src/AboutDialog.cpp Fri Feb 11 16:00:06 2022 +0100 +++ b/src/AboutDialog.cpp Sat Feb 12 21:24:43 2022 +0100 @@ -16,13 +16,16 @@ */ #include "AboutDialog.h" #include "../ui/ui_AboutDialog.h" +#include AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) { + qDebug() << Q_FUNC_INFO; ui->setupUi(this); } AboutDialog::~AboutDialog() { + qDebug() << Q_FUNC_INFO; delete ui; } diff -r 22baafbf770d -r f8474f2c5db9 src/AboutDialog.h --- a/src/AboutDialog.h Fri Feb 11 16:00:06 2022 +0100 +++ b/src/AboutDialog.h Sat Feb 12 21:24:43 2022 +0100 @@ -3,6 +3,7 @@ #include + namespace Ui { class AboutDialog; } diff -r 22baafbf770d -r f8474f2c5db9 src/InventorySuppliers.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/InventorySuppliers.cpp Sat Feb 12 21:24:43 2022 +0100 @@ -0,0 +1,71 @@ +/** + * InventorySuppliers.cpp is part of bmsapp. + * + * bmsapp is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * bmsapp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "InventorySuppliers.h" +#include "../ui/ui_InventorySuppliers.h" +#include "config.h" + +#include +//#include +//#include +//#include +#include +#include + + + +InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers) +{ + qDebug() << Q_FUNC_INFO; + + QTableWidget* table = new QTableWidget(); + QSqlQuery query("SELECT * FROM inventory_suppliers ORDER BY name"); + + 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"}); + + 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++) { + QTableWidgetItem* item = new QTableWidgetItem(query.value(cidx).toString()); + table->setItem(ridx, cidx, item ); + //qDebug() << ridx << cidx << query.value(cidx).toString(); + } + query.next(); + } + table->show(); /* TODO: Uses a separate window */ + + ui->setupUi(this); + setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); +} + +InventorySuppliers::~InventorySuppliers() +{ + qDebug() << Q_FUNC_INFO; + delete ui; +} + + +void InventorySuppliers::on_changeButton_clicked() +{ + qDebug() << Q_FUNC_INFO; + emit firstWindow(); +} + diff -r 22baafbf770d -r f8474f2c5db9 src/InventorySuppliers.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/InventorySuppliers.h Sat Feb 12 21:24:43 2022 +0100 @@ -0,0 +1,28 @@ +#ifndef _INVENTORYSPUPPLIERS_H +#define _INVENTORYSPUPPLIERS_H + +#include + +namespace Ui { +class InventorySuppliers; +} + +class InventorySuppliers : public QDialog +{ + Q_OBJECT + +public: + explicit InventorySuppliers(QWidget *parent = nullptr); + ~InventorySuppliers(); + +signals: + void firstWindow(); + +private slots: + void on_changeButton_clicked(); + +private: + Ui::InventorySuppliers *ui; +}; + +#endif diff -r 22baafbf770d -r f8474f2c5db9 src/MainWindow.cpp --- a/src/MainWindow.cpp Fri Feb 11 16:00:06 2022 +0100 +++ b/src/MainWindow.cpp Sat Feb 12 21:24:43 2022 +0100 @@ -16,7 +16,9 @@ */ #include "MainWindow.h" #include "AboutDialog.h" +#include "InventorySuppliers.h" #include "../ui/ui_MainWindow.h" +#include "config.h" #include #include @@ -27,24 +29,48 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + qDebug() << Q_FUNC_INFO; ui->setupUi(this); + + setWindowTitle( QString("BMSapp - %1").arg(VERSIONSTRING) ); } MainWindow::~MainWindow() { + qDebug() << Q_FUNC_INFO; delete ui; } void MainWindow::on_actionExit_triggered() { + qDebug() << Q_FUNC_INFO; this->close(); } +void MainWindow::fromInventorySuppliers() +{ + qDebug() << Q_FUNC_INFO; + delete InventorySuppliersWindow; + this->show(); +} + + +void MainWindow::on_actionSuppliers_triggered() +{ + qDebug() << Q_FUNC_INFO; + InventorySuppliersWindow = new InventorySuppliers(this); + QObject::connect(InventorySuppliersWindow, SIGNAL(firstWindow()), this, SLOT(fromInventorySuppliers())); + this->hide(); // Close the main window + InventorySuppliersWindow->show(); // Show a second window +} + + void MainWindow::on_actionAbout_triggered() { + qDebug() << Q_FUNC_INFO; AboutDialog dialog(this); dialog.setModal(true); dialog.exec(); diff -r 22baafbf770d -r f8474f2c5db9 src/MainWindow.h --- a/src/MainWindow.h Fri Feb 11 16:00:06 2022 +0100 +++ b/src/MainWindow.h Sat Feb 12 21:24:43 2022 +0100 @@ -1,6 +1,8 @@ #ifndef _MAINWINDOW_H #define _MAINWINDOW_H +#include "InventorySuppliers.h" + #include #include #include @@ -20,12 +22,17 @@ private slots: void on_actionExit_triggered(); + void on_actionSuppliers_triggered(); void on_actionAbout_triggered(); public slots: + void fromInventorySuppliers(); private: Ui::MainWindow *ui; + + // Keep pointers to new windows. + InventorySuppliers *InventorySuppliersWindow; }; #endif diff -r 22baafbf770d -r f8474f2c5db9 src/bmsapp.cpp --- a/src/bmsapp.cpp Fri Feb 11 16:00:06 2022 +0100 +++ b/src/bmsapp.cpp Sat Feb 12 21:24:43 2022 +0100 @@ -46,17 +46,18 @@ -bool Bmsapp::initialize() +bool Bmsapp::initialize(bool useDevelop) { ensureDirectoriesExist(); readsettings(); + // QLocale german(QLocale::German,QLocale::Germany); + // QLocale::setDefault(german); + qDebug() << "Loading Database..."; db = new DataBase(); - db->connectToDataBase(); - - return true; + return db->openDataBase(useDevelop); } @@ -66,6 +67,7 @@ qDebug() << "BMSapp is cleaning up."; writesettings(); + db->closeDataBase(); } @@ -153,11 +155,12 @@ -int Bmsapp::run() { +int Bmsapp::run(bool useDevelop, bool startConfig) { int rc = 0; - if (! initialize()) { + qDebug() << Q_FUNC_INFO; + if (! initialize(useDevelop)) { cleanup(); return 1; } diff -r 22baafbf770d -r f8474f2c5db9 src/bmsapp.h --- a/src/bmsapp.h Fri Feb 11 16:00:06 2022 +0100 +++ b/src/bmsapp.h Sat Feb 12 21:24:43 2022 +0100 @@ -51,7 +51,7 @@ * @brief Blocking call that executes the application. * @return Exit code from the application. */ - static int run(); + static int run(bool useDevelop, bool startConfig); private: static MainWindow* m_mainWindow; @@ -66,7 +66,7 @@ * @brief Run before showing MainWindow, does all system setup. * @return false if anything goes awry, true if it's ok to start MainWindow. */ - static bool initialize(); + static bool initialize(bool useDevelop); /** * @brief Run after QApplication exits to clean up shit, close database, etc. diff -r 22baafbf770d -r f8474f2c5db9 src/database/database.cpp --- a/src/database/database.cpp Fri Feb 11 16:00:06 2022 +0100 +++ b/src/database/database.cpp Sat Feb 12 21:24:43 2022 +0100 @@ -21,22 +21,23 @@ { } - + + DataBase::~DataBase() { - -} - -void DataBase::connectToDataBase() -{ - this->openDataBase(); + } -bool DataBase::openDataBase() + +bool DataBase::openDataBase(bool develop) { QSettings settings(QSettings::IniFormat, QSettings::UserScope, "mbse", "bmsapp"); - settings.beginGroup("dbdev"); + if (develop) + settings.beginGroup("dbdev"); + else + settings.beginGroup("dbprod"); + qDebug() << settings.value("host").toString() << settings.value("port").toString() << settings.value("name").toString() << settings.value("user").toString() << settings.value("pass").toString(); db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName(settings.value("host").toString()); diff -r 22baafbf770d -r f8474f2c5db9 src/database/database.h --- a/src/database/database.h Fri Feb 11 16:00:06 2022 +0100 +++ b/src/database/database.h Sat Feb 12 21:24:43 2022 +0100 @@ -13,14 +13,11 @@ public: explicit DataBase(QObject *parent = 0); ~DataBase(); - void connectToDataBase(); - + bool openDataBase(bool develop); + void closeDataBase(); + private: QSqlDatabase db; - -private: - bool openDataBase(); - void closeDataBase(); }; diff -r 22baafbf770d -r f8474f2c5db9 src/main.cpp --- a/src/main.cpp Fri Feb 11 16:00:06 2022 +0100 +++ b/src/main.cpp Sat Feb 12 21:24:43 2022 +0100 @@ -46,13 +46,10 @@ /* Setup commandline parser */ QCommandLineParser parser; parser.setApplicationDescription("Brewery Management System Application."); - parser.addOptions({ - // A boolean option with multiple names (-f, --force) - {{"c", "config"}, - QCoreApplication::translate("main", "Start the configuration editor.")}, - {{"d", "develop"}, - QCoreApplication::translate("main", "Use the development database.")}, - }); + QCommandLineOption const startConfigOption({"c", "config"}, "Start the configuration editor."); + parser.addOption(startConfigOption); + QCommandLineOption const useDevelopOption({"d", "develop"}, "Use the development database."); + parser.addOption(useDevelopOption); parser.addHelpOption(); parser.addVersionOption(); parser.process(app); @@ -60,7 +57,7 @@ qDebug().noquote() << "Starting" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString(); try { - auto mainAppReturnValue = Bmsapp::run(); + auto mainAppReturnValue = Bmsapp::run(parser.isSet(useDevelopOption), parser.isSet(startConfigOption)); qDebug().noquote() << "Finished" << app.applicationName() << app.applicationVersion() << QDateTime::currentDateTime().toString(); return mainAppReturnValue; } diff -r 22baafbf770d -r f8474f2c5db9 ui/InventorySuppliers.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/InventorySuppliers.ui Sat Feb 12 21:24:43 2022 +0100 @@ -0,0 +1,67 @@ + + + InventorySuppliers + + + + 0 + 0 + 1280 + 640 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + changeButton + accepted() + InventorySuppliers + accept() + + + 248 + 254 + + + 157 + 274 + + + + + changeButton + rejected() + InventorySuppliers + reject() + + + 316 + 260 + + + 286 + 274 + + + + +