# HG changeset patch # User Michiel Broek # Date 1644868687 -3600 # Node ID 8aa2bd9ba9e82801761d9477ffe6fe3d8e7f22ba # Parent 85656dc481314bbd86fe96c617e45e93ec90bfd5 Added the EditSupplier popup window. It is now ready to validate the form data. diff -r 85656dc48131 -r 8aa2bd9ba9e8 CMakeLists.txt --- a/CMakeLists.txt Sun Feb 13 20:24:33 2022 +0100 +++ b/CMakeLists.txt Mon Feb 14 20:58:07 2022 +0100 @@ -99,6 +99,7 @@ ${SRCDIR}/bmsapp.cpp ${SRCDIR}/AboutDialog.cpp ${SRCDIR}/InventorySuppliers.cpp + ${SRCDIR}/EditSupplier.cpp ${SRCDIR}/MainWindow.cpp ${SRCDIR}/database/database.cpp ) @@ -107,6 +108,7 @@ ${SRCDIR}/bmsapp.h ${SRCDIR}/AboutDialog.h ${SRCDIR}/InventorySuppliers.h + ${SRCDIR}/EditSupplier.h ${SRCDIR}/MainWindow.h ${SRCDIR}/database/database.h ) @@ -114,6 +116,7 @@ set( UIS ${UIDIR}/AboutDialog.ui ${UIDIR}/InventorySuppliers.ui + ${UIDIR}/EditSupplier.ui ${UIDIR}/MainWindow.ui ) diff -r 85656dc48131 -r 8aa2bd9ba9e8 src/EditSupplier.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EditSupplier.cpp Mon Feb 14 20:58:07 2022 +0100 @@ -0,0 +1,78 @@ +/** + * EditSupplier.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 "EditSupplier.h" +#include "../ui/ui_EditSupplier.h" +#include "bmsapp.h" +#include +#include + + +EditSupplier::EditSupplier(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditSupplier) +{ + QSqlQuery query; + + qDebug() << Q_FUNC_INFO << id; + ui->setupUi(this); + + if (id < 0) { + setWindowTitle( QString("BMSapp - Add new supplier")); + } else { + setWindowTitle( QString("BMSapp - Edit supplier %1").arg(id)); + query.prepare("SELECT * FROM inventory_suppliers WHERE record = :recno"); + query.bindValue(":recno", id); + query.exec(); + query.next(); + + ui->nameEdit->setText(query.value(1).toString()); + ui->addressEdit->setText(query.value(2).toString()); + ui->cityEdit->setText(query.value(3).toString()); + ui->zipEdit->setText(query.value(4).toString()); + ui->countryEdit->setText(query.value(5).toString()); + ui->webEdit->setText(query.value(6).toString()); + ui->emailEdit->setText(query.value(7).toString()); + ui->phoneEdit->setText(query.value(8).toString()); + ui->notesEdit->setText(query.value(9).toString()); + } +} + + +EditSupplier::~EditSupplier() +{ + qDebug() << Q_FUNC_INFO; + delete ui; +} + + +void EditSupplier::onOKButtonClicked() +{ + qDebug() << Q_FUNC_INFO << "Ok, check for valid data"; + + /* If there are errors in the form, show a message and do "return;" */ + + /* Save or insert the data */ + + this->close(); + this->setResult(1); +} + + +void EditSupplier::onCancelButtonClicked() +{ + qDebug() << Q_FUNC_INFO; + this->close(); + this->setResult(0); +} diff -r 85656dc48131 -r 8aa2bd9ba9e8 src/EditSupplier.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EditSupplier.h Mon Feb 14 20:58:07 2022 +0100 @@ -0,0 +1,27 @@ +#ifndef _EDITSPUPPLIER_H +#define _EDITSPUPPLIER_H + +#include + + +namespace Ui { +class EditSupplier; +} + +class EditSupplier : public QDialog +{ + Q_OBJECT + +public: + explicit EditSupplier(int id, QWidget *parent = 0); + ~EditSupplier(); + +private slots: + void onOKButtonClicked(); + void onCancelButtonClicked(); + +private: + Ui::EditSupplier *ui; +}; + +#endif diff -r 85656dc48131 -r 8aa2bd9ba9e8 src/InventorySuppliers.cpp --- a/src/InventorySuppliers.cpp Sun Feb 13 20:24:33 2022 +0100 +++ b/src/InventorySuppliers.cpp Mon Feb 14 20:58:07 2022 +0100 @@ -15,8 +15,10 @@ * along with this program. If not, see . */ #include "InventorySuppliers.h" +#include "EditSupplier.h" #include "../ui/ui_InventorySuppliers.h" #include "config.h" +#include "bmsapp.h" #include #include @@ -24,12 +26,22 @@ #include + + + InventorySuppliers::InventorySuppliers(QWidget *parent) : QDialog(parent), ui(new Ui::InventorySuppliers) { qDebug() << Q_FUNC_INFO; ui->setupUi(this); + InventorySuppliers::loadTable(); + setWindowTitle( QString("BMSapp - %1 - Inventory Suppliers").arg(VERSIONSTRING) ); +} + + +void InventorySuppliers::loadTable(void) +{ 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")}); @@ -85,21 +97,32 @@ } +bool InventorySuppliers::edit(int recno) +{ + qDebug() << Q_FUNC_INFO << recno; + + EditSupplier dialog(recno, this); + dialog.setModal(true); + int rc = dialog.exec(); /* rc 0 == cancel, rc 1 == ok */ + + qDebug() << Q_FUNC_INFO << recno << rc; + return false; +} + + void InventorySuppliers::on_editButton_clicked() { QPushButton *pb = qobject_cast(QObject::sender()); int recno = pb->objectName().toInt(); qDebug() << Q_FUNC_INFO << recno; - - // Call editor with recno + edit(recno); } void InventorySuppliers::on_insertButton_clicked() { qDebug() << Q_FUNC_INFO; - - // Call editor with -1 + edit(-1); } diff -r 85656dc48131 -r 8aa2bd9ba9e8 src/InventorySuppliers.h --- a/src/InventorySuppliers.h Sun Feb 13 20:24:33 2022 +0100 +++ b/src/InventorySuppliers.h Mon Feb 14 20:58:07 2022 +0100 @@ -25,6 +25,8 @@ private: Ui::InventorySuppliers *ui; + bool edit(int recno); + void loadTable(void); }; #endif diff -r 85656dc48131 -r 8aa2bd9ba9e8 ui/EditSupplier.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/EditSupplier.ui Mon Feb 14 20:58:07 2022 +0100 @@ -0,0 +1,253 @@ + + + Michiel Broek + EditSupplier + + + + 0 + 0 + 1024 + 560 + + + + Dialog + + + + + + + + + Name + + + + + + + 128 + + + Supplier name + + + + + + + Address + + + + + + + The street and housenumber + + + 128 + + + Address + + + + + + + City + + + + + + + 123 + + + City + + + + + + + Zip code + + + + + + + + 0 + 0 + + + + 16 + + + Zip code + + + + + + + Country + + + + + + + 128 + + + Country + + + + + + + Website + + + + + + + 128 + + + https://www.supplier.com + + + + + + + Email + + + + + + + 128 + + + sales@supplier.com + + + + + + + Phone + + + + + + + + 0 + 0 + + + + 20 + + + +31 123 45678 + + + + + + + Notes + + + + + + + Qt::ScrollBarAlwaysOff + + + Notes about this supplier + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + nameEdit + addressEdit + cityEdit + zipEdit + countryEdit + webEdit + emailEdit + phoneEdit + notesEdit + + + + + buttonBox + accepted() + EditSupplier + onOKButtonClicked() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EditSupplier + onCancelButtonClicked() + + + 316 + 260 + + + 286 + 274 + + + + +