# HG changeset patch # User Michiel Broek # Date 1645128024 -3600 # Node ID f0bcdbd3d36f529e9fc50f7e0c0573d87b8d1f1f # Parent a5d8e783a7b00b25ca3cd9c699669a86f3931fe7 Forgot one signal in Setup. EditSupplier now has signals to track edit changes. The Window header has ** mark if anything is changed. Added errors message boxes. diff -r a5d8e783a7b0 -r f0bcdbd3d36f src/EditSupplier.cpp --- a/src/EditSupplier.cpp Thu Feb 17 19:57:32 2022 +0100 +++ b/src/EditSupplier.cpp Thu Feb 17 21:00:24 2022 +0100 @@ -27,10 +27,8 @@ ui->setupUi(this); this->recno = id; - if (id < 0) { - setWindowTitle(QString("BMSapp - Add new supplier")); - } else { - setWindowTitle(QString("BMSapp - Edit supplier %1").arg(id)); + WindowTitle(); + if (id >= 0) { query.prepare("SELECT * FROM inventory_suppliers WHERE record = :recno"); query.bindValue(":recno", id); query.exec(); @@ -46,7 +44,15 @@ ui->phoneEdit->setText(query.value(8).toString()); ui->notesEdit->setPlainText(query.value(9).toString()); } - connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(onTextChanged())); + connect(ui->nameEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); + connect(ui->addressEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); + connect(ui->cityEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); + connect(ui->zipEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); + connect(ui->countryEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); + connect(ui->webEdit, &QLineEdit::textChanged, this, &EditSupplier::is_changed); + 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())); } @@ -58,27 +64,37 @@ } +/* + * Window header, mark any change with '**' + */ +void EditSupplier::WindowTitle() +{ + QString txt; + + if (this->recno < 0) { + txt = QString(tr("BMSapp - Add new supplier")); + } else { + txt = QString(tr("BMSapp - Edit supplier %1").arg(this->recno)); + } + + if (this->textIsChanged) { + txt.append((QString(" **"))); + } + setWindowTitle(txt); +} + + void EditSupplier::onOKButtonClicked() { QSqlQuery query; - bool modified, valid; - /* The notes field uses a signal textChanged() */ - modified = (ui->nameEdit->isModified() || ui->addressEdit->isModified() || ui->cityEdit->isModified() || - ui->zipEdit->isModified() || ui->countryEdit->isModified() || ui->webEdit->isModified() || - ui->emailEdit->isModified() || ui->phoneEdit->isModified() || this->textIsChanged); - - valid = true; /* If there are errors in the form, show a message and do "return;" */ if (ui->nameEdit->text().length() < 2) { -// QMessageBox msgBox; -// msgBox.setText("Name empty or too short."); -// msgBox.exec(); + QMessageBox::warning(this, tr("Edit Supplier"), tr("Name empty or too short.")); return; } - if (modified && valid) { - qDebug() << "EditSupplier do SQL"; + if (this->textIsChanged) { if (this->recno == -1) { query.prepare("INSERT INTO inventory_suppliers SET name = :name, address = :address, city = :city, zip = :zip, " "country = :country, website = :web, email = :email, phone = :phone, notes = :notes, uuid = :uuid"); @@ -102,7 +118,14 @@ } query.exec(); if (query.lastError().isValid()) { - qDebug() << query.lastError(); + 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 { + qDebug() << "EditSupplier Saved"; } this->close(); @@ -115,9 +138,10 @@ } -void EditSupplier::onTextChanged() +void EditSupplier::is_changed() { this->textIsChanged = true; + WindowTitle(); } diff -r a5d8e783a7b0 -r f0bcdbd3d36f src/EditSupplier.h --- a/src/EditSupplier.h Thu Feb 17 19:57:32 2022 +0100 +++ b/src/EditSupplier.h Thu Feb 17 21:00:24 2022 +0100 @@ -22,12 +22,14 @@ private slots: void onOKButtonClicked(); void onCancelButtonClicked(); - void onTextChanged(); + void is_changed(); private: Ui::EditSupplier *ui; int recno; bool textIsChanged = false; + + void WindowTitle(); }; #endif diff -r a5d8e783a7b0 -r f0bcdbd3d36f src/Setup.cpp --- a/src/Setup.cpp Thu Feb 17 19:57:32 2022 +0100 +++ b/src/Setup.cpp Thu Feb 17 21:00:24 2022 +0100 @@ -34,6 +34,7 @@ query.next(); ui->breweryEdit->setText(query.value(1).toString()); // max 128 + connect(ui->breweryEdit, &QLineEdit::textChanged, this, &Setup::is_changed); ui->fwhEdit->setValue(query.value(4).toInt()); ui->mashhopEdit->setValue(query.value(3).toInt());