Thu, 17 Feb 2022 21:41:52 +0100
Fixed missing arrows on combobox and spinboxes in the qdarkstyle theme. Changed suppliers editor icon in the menu.
/** * 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" EditSupplier::EditSupplier(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditSupplier) { QSqlQuery query; qDebug() << "EditSupplier record:" << id; ui->setupUi(this); this->recno = id; WindowTitle(); if (id >= 0) { 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->setPlainText(query.value(9).toString()); } 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())); } EditSupplier::~EditSupplier() { qDebug() << "EditSupplier closed"; delete ui; emit entry_changed(); } /* * 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; /* If there are errors in the form, show a message and do "return;" */ if (ui->nameEdit->text().length() < 2) { QMessageBox::warning(this, tr("Edit Supplier"), tr("Name empty or too short.")); return; } 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"); } else { query.prepare("UPDATE inventory_suppliers SET name = :name, address = :address, city = :city, zip = :zip, " "country = :country, website = :web, email = :email, phone = :phone, notes = :notes WHERE record = :recno"); } query.bindValue(":name", ui->nameEdit->text()); query.bindValue(":address", ui->addressEdit->text()); query.bindValue(":city", ui->cityEdit->text()); query.bindValue(":zip", ui->zipEdit->text()); query.bindValue(":country", ui->countryEdit->text()); query.bindValue(":web", ui->webEdit->text()); query.bindValue(":email", ui->emailEdit->text()); query.bindValue(":phone", ui->phoneEdit->text()); query.bindValue(":notes", ui->notesEdit->toPlainText()); if (this->recno == -1) { query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36)); } else { 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 { qDebug() << "EditSupplier Saved"; } this->close(); this->setResult(1); } else { /* Not saving */ this->close(); this->setResult(0); } } void EditSupplier::is_changed() { this->textIsChanged = true; WindowTitle(); } void EditSupplier::onCancelButtonClicked() { this->close(); this->setResult(0); }