# HG changeset patch # User Michiel Broek # Date 1645349664 -3600 # Node ID 15e5879df8dc4fdd2ab0a350cc856d124ae233c5 # Parent fcbbddcc22c1054f1fdf787c85a948ecafa16a3c In EditSupplier backports from EditFermentables including a Delete button. diff -r fcbbddcc22c1 -r 15e5879df8dc src/EditSupplier.cpp --- a/src/EditSupplier.cpp Sat Feb 19 22:17:09 2022 +0100 +++ b/src/EditSupplier.cpp Sun Feb 20 10:34:24 2022 +0100 @@ -53,12 +53,15 @@ connect(ui->emailEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); connect(ui->phoneEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); + + ui->saveButton->setEnabled(false); + ui->deleteButton->setEnabled((id >= 0) ? true:false); } EditSupplier::~EditSupplier() { - qDebug() << "EditSupplier closed"; + qDebug() << "EditSupplier done"; delete ui; emit entry_changed(); } @@ -84,7 +87,7 @@ } -void EditSupplier::onOKButtonClicked() +void EditSupplier::on_saveButton_clicked() { QSqlQuery query; @@ -127,26 +130,61 @@ } else { qDebug() << "EditSupplier Saved"; } + } - this->close(); - this->setResult(1); + ui->saveButton->setEnabled(false); + this->textIsChanged = false; + WindowTitle(); +} + + +void EditSupplier::on_deleteButton_clicked() +{ + QSqlQuery query; + + query.prepare("DELETE FROM inventory_suppliers WHERE record = :recno"); + query.bindValue(":recno", this->recno); + query.exec(); + if (query.lastError().isValid()) { + qDebug() << "EditSupplier" << query.lastError(); + QMessageBox::warning(this, tr("Database error"), + tr("MySQL error: %1\n%2\n%3") + .arg(query.lastError().nativeErrorCode()) + .arg(query.lastError().driverText()) + .arg(query.lastError().databaseText())); } else { - /* Not saving */ - this->close(); - this->setResult(0); + qDebug() << "EditSupllier Deleted" << this->recno; } + + this->close(); + this->setResult(1); } void EditSupplier::is_changed() { + ui->saveButton->setEnabled(true); this->textIsChanged = true; WindowTitle(); } -void EditSupplier::onCancelButtonClicked() +void EditSupplier::on_quitButton_clicked() { + if (this->textIsChanged) { + int rc = QMessageBox::warning(this, tr("Supplier changed"), tr("The supplier has been modified\n Save changes?"), + QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); + switch (rc) { + case QMessageBox::Save: + on_saveButton_clicked(); + break; /* Saved and then Quit */ + case QMessageBox::Discard: + break; /* Quit without Save */ + case QMessageBox::Cancel: + return; /* Return to the editor page */ + } + } + this->close(); - this->setResult(0); + this->setResult(1); } diff -r fcbbddcc22c1 -r 15e5879df8dc src/EditSupplier.h --- a/src/EditSupplier.h Sat Feb 19 22:17:09 2022 +0100 +++ b/src/EditSupplier.h Sun Feb 20 10:34:24 2022 +0100 @@ -20,8 +20,9 @@ ~EditSupplier(); private slots: - void onOKButtonClicked(); - void onCancelButtonClicked(); + void on_saveButton_clicked(); + void on_quitButton_clicked(); + void on_deleteButton_clicked(); void is_changed(); private: diff -r fcbbddcc22c1 -r 15e5879df8dc ui/EditSupplier.ui --- a/ui/EditSupplier.ui Sat Feb 19 22:17:09 2022 +0100 +++ b/ui/EditSupplier.ui Sun Feb 20 10:34:24 2022 +0100 @@ -16,196 +16,378 @@ - - - - - - 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 - - - - 16 - - - +31 123 45678 - - - - - - - Notes - - - - - - - Qt::ScrollBarAlwaysOff - - - Notes about this supplier - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - true - + + + + + 9 + 10 + 91 + 20 + + + + Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 9 + 40 + 91 + 16 + + + + Address: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 40 + 761 + 23 + + + + The street and housenumber + + + 128 + + + Address + + + + + + 9 + 70 + 91 + 16 + + + + City: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 70 + 761 + 23 + + + + 123 + + + City + + + + + + 9 + 100 + 91 + 16 + + + + Zip code: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 100 + 125 + 23 + + + + + 0 + 0 + + + + 16 + + + Zip code + + + + + + 9 + 130 + 91 + 16 + + + + Country: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 130 + 761 + 23 + + + + 128 + + + Country + + + + + + 9 + 160 + 91 + 16 + + + + Website: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 160 + 761 + 23 + + + + 128 + + + https://www.supplier.com + + + + + + 9 + 190 + 91 + 16 + + + + Email: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 190 + 761 + 23 + + + + 128 + + + sales@supplier.com + + + + + + 9 + 220 + 91 + 16 + + + + Phone: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 220 + 125 + 23 + + + + + 0 + 0 + + + + 16 + + + +31 123 45678 + + + + + + 9 + 250 + 91 + 16 + + + + Notes: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 110 + 250 + 761 + 131 + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + Notes about this supplier + + + + + + 110 + 10 + 761 + 23 + + + + + 0 + 0 + + + + 128 + + + Supplier name + + + + + + 100 + 510 + 80 + 23 + + + + Quit + + + + :/icons/silk/icons/silk/door_out.png:/icons/silk/icons/silk/door_out.png + + + + + + 800 + 510 + 80 + 23 + + + + Save + + + + :/icons/silk/icons/silk/disk.png:/icons/silk/icons/silk/disk.png + + + + + + 463 + 510 + 80 + 23 + + + + Delete + + + + :/icons/silk/icons/silk/delete.png:/icons/silk/icons/silk/delete.png + + - nameEdit addressEdit cityEdit zipEdit @@ -215,39 +397,8 @@ phoneEdit notesEdit - - - - buttonBox - accepted() - EditSupplier - onOKButtonClicked() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - EditSupplier - onCancelButtonClicked() - - - 316 - 260 - - - 286 - 274 - - - - + + + +