Mon, 14 Feb 2022 20:58:07 +0100
Added the EditSupplier popup window. It is now ready to validate the form data.
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/EditSupplier.cpp | file | annotate | diff | comparison | revisions | |
src/EditSupplier.h | file | annotate | diff | comparison | revisions | |
src/InventorySuppliers.cpp | file | annotate | diff | comparison | revisions | |
src/InventorySuppliers.h | file | annotate | diff | comparison | revisions | |
ui/EditSupplier.ui | file | annotate | diff | comparison | revisions |
--- 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 )
--- /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 <http://www.gnu.org/licenses/>. + */ +#include "EditSupplier.h" +#include "../ui/ui_EditSupplier.h" +#include "bmsapp.h" +#include <QDebug> +#include <QtSql> + + +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); +}
--- /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 <QDialog> + + +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
--- 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 <http://www.gnu.org/licenses/>. */ #include "InventorySuppliers.h" +#include "EditSupplier.h" #include "../ui/ui_InventorySuppliers.h" #include "config.h" +#include "bmsapp.h" #include <QDebug> #include <QtSql> @@ -24,12 +26,22 @@ #include <QTableWidget> + + + 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<QPushButton *>(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); }
--- 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
--- /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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <author>Michiel Broek</author> + <class>EditSupplier</class> + <widget class="QDialog" name="EditSupplier"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1024</width> + <height>560</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QWidget" name="widget" native="true"> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="nameLabel"> + <property name="text"> + <string>Name</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="nameEdit"> + <property name="maxLength"> + <number>128</number> + </property> + <property name="placeholderText"> + <string>Supplier name</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="addressLabel"> + <property name="text"> + <string>Address</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="addressEdit"> + <property name="toolTip"> + <string>The street and housenumber</string> + </property> + <property name="maxLength"> + <number>128</number> + </property> + <property name="placeholderText"> + <string>Address</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="cityLabel"> + <property name="text"> + <string>City</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="cityEdit"> + <property name="maxLength"> + <number>123</number> + </property> + <property name="placeholderText"> + <string>City</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="zipLabel"> + <property name="text"> + <string>Zip code</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="zipEdit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maxLength"> + <number>16</number> + </property> + <property name="placeholderText"> + <string>Zip code</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="countryLabel"> + <property name="text"> + <string>Country</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLineEdit" name="countryEdit"> + <property name="maxLength"> + <number>128</number> + </property> + <property name="placeholderText"> + <string>Country</string> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="webLabel"> + <property name="text"> + <string>Website</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QLineEdit" name="webEdit"> + <property name="maxLength"> + <number>128</number> + </property> + <property name="placeholderText"> + <string>https://www.supplier.com</string> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="emailLabel"> + <property name="text"> + <string>Email</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QLineEdit" name="emailEdit"> + <property name="maxLength"> + <number>128</number> + </property> + <property name="placeholderText"> + <string>sales@supplier.com</string> + </property> + </widget> + </item> + <item row="7" column="0"> + <widget class="QLabel" name="phoneLabel"> + <property name="text"> + <string>Phone</string> + </property> + </widget> + </item> + <item row="7" column="1"> + <widget class="QLineEdit" name="phoneEdit"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maxLength"> + <number>20</number> + </property> + <property name="placeholderText"> + <string>+31 123 45678</string> + </property> + </widget> + </item> + <item row="8" column="0"> + <widget class="QLabel" name="notesLabel"> + <property name="text"> + <string>Notes</string> + </property> + </widget> + </item> + <item row="8" column="1"> + <widget class="QTextEdit" name="notesEdit"> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="placeholderText"> + <string>Notes about this supplier</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + <property name="centerButtons"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>nameEdit</tabstop> + <tabstop>addressEdit</tabstop> + <tabstop>cityEdit</tabstop> + <tabstop>zipEdit</tabstop> + <tabstop>countryEdit</tabstop> + <tabstop>webEdit</tabstop> + <tabstop>emailEdit</tabstop> + <tabstop>phoneEdit</tabstop> + <tabstop>notesEdit</tabstop> + </tabstops> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>EditSupplier</receiver> + <slot>onOKButtonClicked()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>EditSupplier</receiver> + <slot>onCancelButtonClicked()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>