# HG changeset patch # User Michiel Broek # Date 1647360054 -3600 # Node ID eb6c564192f41d2205e43e1c0fc0bc5983f02244 # Parent 2d8dbbc1ffab4c0bf37cb9caa3b33bda7b3f1070 Added styles tables and editor. diff -r 2d8dbbc1ffab -r eb6c564192f4 CMakeLists.txt --- a/CMakeLists.txt Mon Mar 14 16:56:59 2022 +0100 +++ b/CMakeLists.txt Tue Mar 15 17:00:54 2022 +0100 @@ -119,6 +119,8 @@ ${SRCDIR}/EditProfileWater.cpp ${SRCDIR}/ProfileMashs.cpp ${SRCDIR}/EditProfileMash.cpp + ${SRCDIR}/ProfileStyles.cpp + ${SRCDIR}/EditProfileStyle.cpp ${SRCDIR}/Setup.cpp ${SRCDIR}/Utils.cpp ${SRCDIR}/PrinterDialog.cpp @@ -148,6 +150,8 @@ ${SRCDIR}/EditProfileWater.h ${SRCDIR}/ProfileMashs.h ${SRCDIR}/EditProfileMash.h + ${SRCDIR}/ProfileStyles.h + ${SRCDIR}/EditProfileStyle.h ${SRCDIR}/Setup.h ${SRCDIR}/Utils.h ${SRCDIR}/PrinterDialog.h @@ -176,6 +180,8 @@ ${UIDIR}/EditProfileWater.ui ${UIDIR}/ProfileMashs.ui ${UIDIR}/EditProfileMash.ui + ${UIDIR}/ProfileStyles.ui + ${UIDIR}/EditProfileStyle.ui ${UIDIR}/Setup.ui ${UIDIR}/MainWindow.ui ) diff -r 2d8dbbc1ffab -r eb6c564192f4 src/EditProfileStyle.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EditProfileStyle.cpp Tue Mar 15 17:00:54 2022 +0100 @@ -0,0 +1,359 @@ +/** + * EditProfileStyle.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 "EditProfileStyle.h" +#include "../ui/ui_EditProfileStyle.h" +#include "bmsapp.h" + + +EditProfileStyle::EditProfileStyle(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditProfileStyle) +{ + QSqlQuery query; + + qDebug() << "EditProfileStyle record:" << id; + ui->setupUi(this); + this->recno = id; + + WindowTitle(); + + ui->typeEdit->addItem(tr("Lager")); + ui->typeEdit->addItem(tr("Ale")); + ui->typeEdit->addItem(tr("Mead")); + ui->typeEdit->addItem(tr("Wheat")); + ui->typeEdit->addItem(tr("Mixed")); + ui->typeEdit->addItem(tr("Cider")); + + if (id >= 0) { + query.prepare("SELECT * FROM profile_styles WHERE record = :recno"); + query.bindValue(":recno", id); + query.exec(); + query.next(); + + ui->styleEdit->setText(query.value(1).toString()); + ui->catEdit->setText(query.value(2).toString()); + ui->catnrEdit->setValue(query.value(3).toInt()); + ui->groupEdit->setText(query.value(4).toString()); + ui->guideEdit->setText(query.value(5).toString()); + ui->typeEdit->setCurrentIndex(query.value(6).toInt()); + ui->ogminEdit->setValue(query.value(7).toDouble()); + ui->ogmaxEdit->setValue(query.value(8).toDouble()); + ui->fgminEdit->setValue(query.value(9).toDouble()); + ui->fgmaxEdit->setValue(query.value(10).toDouble()); + ui->ibuminEdit->setValue(query.value(11).toDouble()); + ui->ibumaxEdit->setValue(query.value(12).toDouble()); + ui->ebcminEdit->setValue(query.value(13).toDouble()); + ui->ebcmaxEdit->setValue(query.value(14).toDouble()); + ui->co2minEdit->setValue(query.value(15).toDouble()); + ui->co2maxEdit->setValue(query.value(16).toDouble()); + ui->abvminEdit->setValue(query.value(17).toDouble()); + ui->abvmaxEdit->setValue(query.value(18).toDouble()); + ui->notesEdit->setPlainText(query.value(19).toString()); + ui->profileEdit->setPlainText(query.value(20).toString()); + ui->ingredientsEdit->setPlainText(query.value(21).toString()); + ui->examplesEdit->setPlainText(query.value(22).toString()); + } else { + /* Set some defaults */ + ui->catnrEdit->setValue(0); + ui->guideEdit->setText("BKG 2019"); + ui->typeEdit->setCurrentIndex(0); + ui->ogminEdit->setValue(1.030); + ui->ogmaxEdit->setValue(1.060); + ui->fgminEdit->setValue(1.005); + ui->fgmaxEdit->setValue(1.010); + ui->ibuminEdit->setValue(20); + ui->ibumaxEdit->setValue(30); + ui->ebcminEdit->setValue(52); + ui->ebcmaxEdit->setValue(79); + ui->co2minEdit->setValue(2.0); + ui->co2maxEdit->setValue(2.5); + ui->abvminEdit->setValue(4.0); + ui->abvmaxEdit->setValue(5.0); + } + connect(ui->styleEdit, &QLineEdit::textChanged, this, &EditProfileStyle::is_changed); + connect(ui->catEdit, &QLineEdit::textChanged, this, &EditProfileStyle::is_changed); + connect(ui->catnrEdit, &QSpinBox::textChanged, this, &EditProfileStyle::is_changed); + connect(ui->groupEdit, &QLineEdit::textChanged, this, &EditProfileStyle::is_changed); + connect(ui->guideEdit, &QLineEdit::textChanged, this, &EditProfileStyle::is_changed); + connect(ui->typeEdit, &QComboBox::currentTextChanged, this, &EditProfileStyle::is_changed); + connect(ui->ogminEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::ogmin_changed); + connect(ui->ogmaxEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::ogmax_changed); + connect(ui->fgminEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::fgmin_changed); + connect(ui->fgmaxEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::fgmax_changed); + connect(ui->ibuminEdit, &QSpinBox::textChanged, this, &EditProfileStyle::ibumin_changed); + connect(ui->ibumaxEdit, &QSpinBox::textChanged, this, &EditProfileStyle::ibumax_changed); + connect(ui->ebcminEdit, &QSpinBox::textChanged, this, &EditProfileStyle::ebcmin_changed); + connect(ui->ebcmaxEdit, &QSpinBox::textChanged, this, &EditProfileStyle::ebcmax_changed); + connect(ui->co2minEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::co2min_changed); + connect(ui->co2maxEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::co2max_changed); + connect(ui->abvminEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::abvmin_changed); + connect(ui->abvmaxEdit, &QDoubleSpinBox::textChanged, this, &EditProfileStyle::abvmax_changed); + connect(ui->notesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); + connect(ui->profileEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); + connect(ui->ingredientsEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); + connect(ui->examplesEdit, SIGNAL(textChanged()), this, SLOT(is_changed())); + + ui->saveButton->setEnabled(false); + ui->deleteButton->setEnabled((id >= 0) ? true:false); +} + + +EditProfileStyle::~EditProfileStyle() +{ + qDebug() << "EditProfileStyle done"; + delete ui; + emit entry_changed(); +} + + +/* + * Window header, mark any change with '**' + */ +void EditProfileStyle::WindowTitle() +{ + QString txt; + + if (this->recno < 0) { + txt = QString(tr("BMSapp - Add new brewing water")); + } else { + txt = QString(tr("BMSapp - Edit brewing water %1").arg(this->recno)); + } + + if (this->textIsChanged) { + txt.append((QString(" **"))); + } + setWindowTitle(txt); +} + + +void EditProfileStyle::on_saveButton_clicked() +{ + QSqlQuery query; + + /* If there are errors in the form, show a message and do "return;" */ + if (ui->styleEdit->text().length() < 2) { + QMessageBox::warning(this, tr("Edit Style"), tr("Beer style is empty or too short.")); + return; + } + + if (this->textIsChanged) { + if (this->recno == -1) { + query.prepare("INSERT INTO profile_styles SET name=:name, category=:category, " + "category_number=:catnr, style_letter=:group, style_guide=:guide, type=:type, " + "og_min=:og_min, og_max=:og_max, fg_min=:fg_min, fg_max=:fg_max, ibu_min=:ibu_min, " + "ibu_max=:ibu_max, color_min=:ebc_min, color_max=:ebc_max, carb_min=:co2_min, " + "carb_max=:co2_max, abv_min=:abv_min, abv_max=:abv_max, notes=:notes, " + "profile=:profile, ingredients=:ingredients, examples=:examples, uuid=:uuid"); + } else { + query.prepare("UPDATE profile_styles SET name=:name, category=:category, " + "category_number=:catnr, style_letter=:group, style_guide=:guide, type=:type, " + "og_min=:og_min, og_max=:og_max, fg_min=:fg_min, fg_max=:fg_max, ibu_min=:ibu_min, " + "ibu_max=:ibu_max, color_min=:ebc_min, color_max=:ebc_max, carb_min=:co2_min, " + "carb_max=:co2_max, abv_min=:abv_min, abv_max=:abv_max, notes=:notes, " + "profile=:profile, ingredients=:ingredients, examples=:examples WHERE record=:recno"); + } + query.bindValue(":name", ui->styleEdit->text()); + query.bindValue(":category", ui->catEdit->text()); + query.bindValue(":catnr", QString("%1").arg(ui->catnrEdit->value())); + query.bindValue(":group", ui->groupEdit->text()); + query.bindValue(":guide", ui->guideEdit->text()); + query.bindValue(":type", ui->typeEdit->currentIndex()); + query.bindValue(":og_min", QString("%1").arg(ui->ogminEdit->value(), 4, 'f', 3, '0')); + query.bindValue(":og_max", QString("%1").arg(ui->ogmaxEdit->value(), 4, 'f', 3, '0')); + query.bindValue(":fg_min", QString("%1").arg(ui->fgminEdit->value(), 4, 'f', 3, '0')); + query.bindValue(":fg_max", QString("%1").arg(ui->fgmaxEdit->value(), 4, 'f', 3, '0')); + query.bindValue(":ibu_min", QString("%1").arg(ui->ibuminEdit->value(), 1, 'f', 0, '0')); + query.bindValue(":ibu_max", QString("%1").arg(ui->ibumaxEdit->value(), 1, 'f', 0, '0')); + query.bindValue(":ebc_min", QString("%1").arg(ui->ebcminEdit->value(), 1, 'f', 0, '0')); + query.bindValue(":ebc_max", QString("%1").arg(ui->ebcmaxEdit->value(), 1, 'f', 0, '0')); + query.bindValue(":co2_min", QString("%1").arg(ui->co2minEdit->value(), 2, 'f', 1, '0')); + query.bindValue(":co2_max", QString("%1").arg(ui->co2maxEdit->value(), 2, 'f', 1, '0')); + query.bindValue(":abv_min", QString("%1").arg(ui->abvminEdit->value(), 2, 'f', 1, '0')); + query.bindValue(":abv_max", QString("%1").arg(ui->abvmaxEdit->value(), 2, 'f', 1, '0')); + query.bindValue(":notes", ui->notesEdit->toPlainText()); + query.bindValue(":profile", ui->profileEdit->toPlainText()); + query.bindValue(":ingredients", ui->ingredientsEdit->toPlainText()); + query.bindValue(":examples", ui->examplesEdit->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() << "EditProfileStyle" << 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() << "EditProfileStyle Saved"; + } + } + + ui->saveButton->setEnabled(false); + this->textIsChanged = false; + WindowTitle(); +} + + +void EditProfileStyle::on_deleteButton_clicked() +{ + QSqlQuery query; + + query.prepare("DELETE FROM profile_styles WHERE record = :recno"); + query.bindValue(":recno", this->recno); + query.exec(); + if (query.lastError().isValid()) { + qDebug() << "EditProfileStyle" << 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() << "EditProfileStyle Deleted" << this->recno; + } + + this->close(); + this->setResult(1); +} + + +void EditProfileStyle::is_changed() +{ + ui->saveButton->setEnabled(true); + ui->deleteButton->setEnabled((this->recno >= 0) ? true:false); + this->textIsChanged = true; + WindowTitle(); +} + + +void EditProfileStyle::ogmin_changed() +{ + if (ui->ogminEdit->value() > (ui->ogmaxEdit->value() - 0.001)) + ui->ogmaxEdit->setValue(ui->ogminEdit->value() + 0.001); + is_changed(); +} + + +void EditProfileStyle::ogmax_changed() +{ + if (ui->ogmaxEdit->value() < (ui->ogminEdit->value() + 0.001)) + ui->ogminEdit->setValue(ui->ogmaxEdit->value() - 0.001); + is_changed(); +} + + +void EditProfileStyle::fgmin_changed() +{ + if (ui->fgminEdit->value() > (ui->fgmaxEdit->value() - 0.001)) + ui->fgmaxEdit->setValue(ui->fgminEdit->value() + 0.001); + is_changed(); +} + + +void EditProfileStyle::fgmax_changed() +{ + if (ui->fgmaxEdit->value() < (ui->fgminEdit->value() + 0.001)) + ui->fgminEdit->setValue(ui->fgmaxEdit->value() - 0.001); + is_changed(); +} + + +void EditProfileStyle::ibumin_changed() +{ + if (ui->ibuminEdit->value() > (ui->ibumaxEdit->value() - 1)) + ui->ibumaxEdit->setValue(ui->ibuminEdit->value() + 1); + is_changed(); +} + + +void EditProfileStyle::ibumax_changed() +{ + if (ui->ibumaxEdit->value() < (ui->ibuminEdit->value() + 1)) + ui->ibuminEdit->setValue(ui->ibumaxEdit->value() - 1); + is_changed(); +} + + +void EditProfileStyle::ebcmin_changed() +{ + if (ui->ebcminEdit->value() > (ui->ebcmaxEdit->value() - 1)) + ui->ebcmaxEdit->setValue(ui->ebcminEdit->value() + 1); + is_changed(); +} + + +void EditProfileStyle::ebcmax_changed() +{ + if (ui->ebcmaxEdit->value() < (ui->ebcminEdit->value() + 1)) + ui->ebcminEdit->setValue(ui->ebcmaxEdit->value() - 1); + is_changed(); +} + + +void EditProfileStyle::co2min_changed() +{ + if (ui->co2minEdit->value() > (ui->co2maxEdit->value() - 0.1)) + ui->co2maxEdit->setValue(ui->co2minEdit->value() + 0.1); + is_changed(); +} + + +void EditProfileStyle::co2max_changed() +{ + if (ui->co2maxEdit->value() < (ui->co2minEdit->value() + 0.1)) + ui->co2minEdit->setValue(ui->co2maxEdit->value() - 0.1); + is_changed(); +} + + +void EditProfileStyle::abvmin_changed() +{ + if (ui->abvminEdit->value() > (ui->abvmaxEdit->value() - 0.1)) + ui->abvmaxEdit->setValue(ui->abvminEdit->value() + 0.1); + is_changed(); +} + + +void EditProfileStyle::abvmax_changed() +{ + if (ui->abvmaxEdit->value() < (ui->abvminEdit->value() + 0.1)) + ui->abvminEdit->setValue(ui->abvmaxEdit->value() - 0.1); + is_changed(); +} + + +void EditProfileStyle::on_quitButton_clicked() +{ + if (this->textIsChanged) { + int rc = QMessageBox::warning(this, tr("Style changed"), tr("The style 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(1); +} diff -r 2d8dbbc1ffab -r eb6c564192f4 src/EditProfileStyle.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/EditProfileStyle.h Tue Mar 15 17:00:54 2022 +0100 @@ -0,0 +1,48 @@ +#ifndef _EDITPROFILESTYLE_H +#define _EDITPROFILESTYLE_H + +#include + + +namespace Ui { +class EditProfileStyle; +} + +class EditProfileStyle : public QDialog +{ + Q_OBJECT + +signals: + void entry_changed(); + +public: + explicit EditProfileStyle(int id, QWidget *parent = 0); + ~EditProfileStyle(); + +private slots: + void on_saveButton_clicked(); + void on_quitButton_clicked(); + void on_deleteButton_clicked(); + void is_changed(); + void ogmin_changed(); + void ogmax_changed(); + void fgmin_changed(); + void fgmax_changed(); + void ibumin_changed(); + void ibumax_changed(); + void ebcmin_changed(); + void ebcmax_changed(); + void co2min_changed(); + void co2max_changed(); + void abvmin_changed(); + void abvmax_changed(); + +private: + Ui::EditProfileStyle *ui; + int recno; + bool textIsChanged = false; + + void WindowTitle(); +}; + +#endif diff -r 2d8dbbc1ffab -r eb6c564192f4 src/MainWindow.cpp --- a/src/MainWindow.cpp Mon Mar 14 16:56:59 2022 +0100 +++ b/src/MainWindow.cpp Tue Mar 15 17:00:54 2022 +0100 @@ -25,6 +25,7 @@ #include "InventoryEquipments.h" #include "ProfileWaters.h" #include "ProfileMashs.h" +#include "ProfileStyles.h" #include "Setup.h" #include "PrinterDialog.h" #include "../ui/ui_MainWindow.h" @@ -236,6 +237,24 @@ } +void MainWindow::fromProfileStyles() +{ + qDebug() << Q_FUNC_INFO; + delete ProfileStylesWindow; + this->show(); +} + + +void MainWindow::on_actionStyles_profiles_triggered() +{ + qDebug() << Q_FUNC_INFO; + ProfileStylesWindow = new ProfileStyles(this); + QObject::connect(ProfileStylesWindow, SIGNAL(firstWindow()), this, SLOT(fromProfileStyles())); + this->hide(); // Close the main window + ProfileStylesWindow->show(); // Show a second window +} + + void MainWindow::fromSetup() { qDebug() << Q_FUNC_INFO; diff -r 2d8dbbc1ffab -r eb6c564192f4 src/MainWindow.h --- a/src/MainWindow.h Mon Mar 14 16:56:59 2022 +0100 +++ b/src/MainWindow.h Tue Mar 15 17:00:54 2022 +0100 @@ -10,6 +10,7 @@ #include "InventoryEquipments.h" #include "ProfileWaters.h" #include "ProfileMashs.h" +#include "ProfileStyles.h" #include "Setup.h" #include @@ -42,6 +43,7 @@ void on_actionYeast_bank_triggered(); void on_actionWater_profiles_triggered(); void on_actionMash_profiles_triggered(); + void on_actionStyles_profiles_triggered(); void on_actionSetup_triggered(); void on_actionAbout_triggered(); @@ -55,6 +57,7 @@ void fromInventoryEquipments(); void fromProfileWaters(); void fromProfileMashs(); + void fromProfileStyles(); void fromSetup(); private: @@ -70,6 +73,7 @@ InventoryEquipments *InventoryEquipmentsWindow; ProfileWaters *ProfileWatersWindow; ProfileMashs *ProfileMashsWindow; + ProfileStyles *ProfileStylesWindow; Setup *SetupWindow; }; diff -r 2d8dbbc1ffab -r eb6c564192f4 src/ProfileStyles.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ProfileStyles.cpp Tue Mar 15 17:00:54 2022 +0100 @@ -0,0 +1,196 @@ +/** + * ProfileStyles.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 "ProfileStyles.h" +#include "EditProfileStyle.h" +#include "../ui/ui_ProfileStyles.h" +#include "config.h" +#include "bmsapp.h" + + +ProfileStyles::ProfileStyles(QWidget *parent) : QDialog(parent), ui(new Ui::ProfileStyles) +{ + qDebug() << "ProfileStyles start"; + + ui->setupUi(this); + emit refreshTable(); + + setWindowTitle( QString("BMSapp - %1 - Profile Styles").arg(VERSIONSTRING) ); +} + + +void ProfileStyles::refreshTable() +{ + QString w; + QWidget* pWidget; + QLabel *label; + QHBoxLayout* pLayout; + + qDebug() << "ProfileStyles reload"; + + QSqlQuery query("SELECT * FROM profile_styles ORDER BY style_guide,style_letter,name"); + const QStringList labels({tr("Guide"), tr("Gr"), tr("Name"), tr("OG"), tr("OG"), tr("FG"), tr("FG"), + tr("IBU"), tr("IBU"), tr("EBC"), tr("EBC"), tr("Co2"), tr("Co2"), tr("ABV"), tr("ABV"), tr("Edit")}); + + ui->tableStyles->setColumnCount(16); + ui->tableStyles->setColumnWidth(0, 100); /* Guide */ + ui->tableStyles->setColumnWidth(1, 25); /* Group */ + ui->tableStyles->setColumnWidth(2, 300); /* Name */ + ui->tableStyles->setColumnWidth(3, 50); /* OG */ + ui->tableStyles->setColumnWidth(4, 50); + ui->tableStyles->setColumnWidth(5, 50); /* FG */ + ui->tableStyles->setColumnWidth(6, 50); + ui->tableStyles->setColumnWidth(7, 40); /* IBU */ + ui->tableStyles->setColumnWidth(8, 40); + ui->tableStyles->setColumnWidth(9, 40); /* EBC */ + ui->tableStyles->setColumnWidth(10, 40); + ui->tableStyles->setColumnWidth(11, 40); /* Co2 */ + ui->tableStyles->setColumnWidth(12, 40); + ui->tableStyles->setColumnWidth(13, 40); /* ABV */ + ui->tableStyles->setColumnWidth(14, 40); + ui->tableStyles->setColumnWidth(15, 80); /* Edit button */ + ui->tableStyles->setRowCount(query.size()); + ui->tableStyles->setHorizontalHeaderLabels(labels); + ui->tableStyles->verticalHeader()->hide(); + ui->tableStyles->setFixedSize(1025 + 24, 640); /* Even if this is too large, it works */ + + QTableWidgetItem *rightitem = new QTableWidgetItem(); + rightitem->setTextAlignment(Qt::AlignRight); + + query.first(); + for (int ridx = 0 ; ridx < query.size() ; ridx++ ) { + ui->tableStyles->setItem(ridx, 0, new QTableWidgetItem(query.value(5).toString())); /* Guide */ + ui->tableStyles->setItem(ridx, 1, new QTableWidgetItem(query.value(4).toString())); /* Goup */ + ui->tableStyles->setItem(ridx, 2, new QTableWidgetItem(query.value(1).toString())); /* Name */ + + w = QString("%1").arg(query.value(7).toDouble(), 4, 'f', 3, '0' ); /* OG */ + QTableWidgetItem *item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 3, item); + + w = QString("%1").arg(query.value(8).toDouble(), 4, 'f', 3, '0' ); /* OG */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 4, item); + + w = QString("%1").arg(query.value(9).toDouble(), 4, 'f', 3, '0' ); /* FG */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 5, item); + + w = QString("%1").arg(query.value(10).toDouble(), 4, 'f', 3, '0' ); /* FG */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 6, item); + + w = QString("%1").arg(query.value(11).toDouble(), 1, 'f', 0, '0' ); /* IBU */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 7, item); + + w = QString("%1").arg(query.value(12).toDouble(), 1, 'f', 0, '0' ); /* IBU */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 8, item); + + w = QString("%1").arg(query.value(13).toDouble(), 1, 'f', 0, '0' ); /* EBC */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 9, item); + + w = QString("%1").arg(query.value(14).toDouble(), 1, 'f', 0, '0' ); /* EBC */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 10, item); + + w = QString("%1").arg(query.value(15).toDouble(), 2, 'f', 1, '0' ); /* Co2 */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 11, item); + + w = QString("%1").arg(query.value(16).toDouble(), 2, 'f', 1, '0' ); /* Co2 */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 12, item); + + w = QString("%1").arg(query.value(17).toDouble(), 2, 'f', 1, '0' ); /* ABV */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 13, item); + + w = QString("%1").arg(query.value(18).toDouble(), 2, 'f', 1, '0' ); /* ABV */ + item = new QTableWidgetItem(w); + item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); + ui->tableStyles->setItem(ridx, 14, item); + + /* Add the Edit button */ + pWidget = new QWidget(); + QPushButton* btn_edit = new QPushButton(); + btn_edit->setObjectName(QString("%1").arg(query.value(0).toString())); /* Send record with the button */ + btn_edit->setText(tr("Edit")); + connect(btn_edit, SIGNAL(clicked()), this, SLOT(on_editButton_clicked())); + pLayout = new QHBoxLayout(pWidget); + pLayout->addWidget(btn_edit); + pLayout->setContentsMargins(5, 0, 5, 0); + pWidget->setLayout(pLayout); + ui->tableStyles->setCellWidget(ridx, 15, pWidget); + query.next(); + } + + setWindowTitle( QString("BMSapp - %1 - Profile Styles").arg(VERSIONSTRING) ); +} + + +ProfileStyles::~ProfileStyles() +{ + qDebug() << "ProfileStyles done"; + delete ui; +} + + +void ProfileStyles::edit(int recno) +{ + qDebug() << "ProfileStyles edit:" << recno; + + EditProfileStyle dialog(recno, this); + /* Signal from editor if a refresh is needed */ + connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); + dialog.setModal(true); + dialog.exec(); +} + + +void ProfileStyles::on_editButton_clicked() +{ + QPushButton *pb = qobject_cast(QObject::sender()); + int recno = pb->objectName().toInt(); + qDebug() << Q_FUNC_INFO << recno; + edit(recno); +} + + +void ProfileStyles::on_insertButton_clicked() +{ + qDebug() << Q_FUNC_INFO; + edit(-1); +} + + +void ProfileStyles::on_quitButton_clicked() +{ + emit firstWindow(); +} + diff -r 2d8dbbc1ffab -r eb6c564192f4 src/ProfileStyles.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ProfileStyles.h Tue Mar 15 17:00:54 2022 +0100 @@ -0,0 +1,32 @@ +#ifndef _PROFILESTYLES_H +#define _PROFILESTYLES_H + +#include + +namespace Ui { +class ProfileStyles; +} + +class ProfileStyles : public QDialog +{ + Q_OBJECT + +public: + explicit ProfileStyles(QWidget *parent = nullptr); + ~ProfileStyles(); + +signals: + void firstWindow(); + +private slots: + void on_quitButton_clicked(); + void on_insertButton_clicked(); + void on_editButton_clicked(); + void refreshTable(void); + +private: + Ui::ProfileStyles *ui; + void edit(int recno); +}; + +#endif diff -r 2d8dbbc1ffab -r eb6c564192f4 ui/EditProfileStyle.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/EditProfileStyle.ui Tue Mar 15 17:00:54 2022 +0100 @@ -0,0 +1,735 @@ + + + EditProfileStyle + + + + 0 + 0 + 1024 + 560 + + + + Dialog + + + + + + + + 20 + 10 + 121 + 20 + + + + Beer style: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 10 + 311 + 23 + + + + 128 + + + Name of the beer style + + + + + + 150 + 130 + 791 + 81 + + + + Remarks about this style. + + + + + + 90 + 510 + 80 + 23 + + + + + 0 + 0 + + + + Quit + + + + :icons/silk/door_out.png:icons/silk/door_out.png + + + + + false + + + + 850 + 510 + 80 + 23 + + + + Save + + + + :icons/silk/disk.png:icons/silk/disk.png + + + + + false + + + + 463 + 510 + 80 + 23 + + + + Delete + + + + :icons/silk/delete.png:icons/silk/delete.png + + + + + + 500 + 10 + 121 + 20 + + + + Beer group: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 630 + 10 + 311 + 23 + + + + 128 + + + Name of the beer group + + + + + + 20 + 40 + 121 + 20 + + + + Category: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 500 + 40 + 121 + 20 + + + + Category number: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 40 + 311 + 23 + + + + 128 + + + BJCP beer category + + + + + + 630 + 40 + 101 + 24 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + 20 + 70 + 121 + 20 + + + + Profile: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 70 + 791 + 51 + + + + Profile description. + + + + + + 20 + 130 + 121 + 20 + + + + Remarks: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 20 + 220 + 121 + 20 + + + + Type: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 220 + 201 + 23 + + + + + + + 500 + 220 + 121 + 20 + + + + Style guide: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 630 + 220 + 311 + 23 + + + + 128 + + + The name of the style guide + + + + + + 20 + 250 + 121 + 20 + + + + Original Gravity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 20 + 280 + 121 + 20 + + + + Final Gravity: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 20 + 310 + 121 + 20 + + + + IBU: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 250 + 91 + 24 + + + + true + + + 3 + + + 1.000000000000000 + + + 2.000000000000000 + + + 0.001000000000000 + + + + + + 260 + 250 + 91 + 24 + + + + true + + + 3 + + + 1.000000000000000 + + + 2.000000000000000 + + + 0.001000000000000 + + + + + + 150 + 280 + 91 + 24 + + + + true + + + 3 + + + 1.000000000000000 + + + 2.000000000000000 + + + 0.001000000000000 + + + + + + 260 + 280 + 91 + 24 + + + + true + + + 3 + + + 1.000000000000000 + + + 2.000000000000000 + + + 0.001000000000000 + + + + + + 150 + 310 + 91 + 24 + + + + true + + + 999 + + + + + + 260 + 310 + 91 + 24 + + + + true + + + 999 + + + + + + 500 + 250 + 121 + 20 + + + + EBC: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 500 + 280 + 121 + 20 + + + + Co2: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 500 + 310 + 121 + 20 + + + + ABV: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 630 + 250 + 91 + 24 + + + + true + + + 999 + + + + + + 740 + 250 + 91 + 24 + + + + true + + + 999 + + + + + + 630 + 280 + 91 + 24 + + + + true + + + 1 + + + 0.100000000000000 + + + + + + 740 + 280 + 91 + 24 + + + + true + + + 1 + + + 0.100000000000000 + + + + + + 630 + 310 + 91 + 24 + + + + true + + + 1 + + + 0.100000000000000 + + + + + + 740 + 310 + 91 + 24 + + + + true + + + 1 + + + 0.100000000000000 + + + + + + 20 + 340 + 121 + 20 + + + + Ingredients: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 20 + 400 + 121 + 20 + + + + Examples: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 150 + 340 + 791 + 51 + + + + Ingredients used in this style. + + + + + + 150 + 400 + 791 + 81 + + + + Examples of this style. + + + + + + + + styleEdit + notesEdit + quitButton + deleteButton + saveButton + + + + + + diff -r 2d8dbbc1ffab -r eb6c564192f4 ui/MainWindow.ui --- a/ui/MainWindow.ui Mon Mar 14 16:56:59 2022 +0100 +++ b/ui/MainWindow.ui Tue Mar 15 17:00:54 2022 +0100 @@ -79,7 +79,7 @@ - + @@ -312,7 +312,7 @@ Mash schedules - + true diff -r 2d8dbbc1ffab -r eb6c564192f4 ui/ProfileStyles.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/ProfileStyles.ui Tue Mar 15 17:00:54 2022 +0100 @@ -0,0 +1,103 @@ + + + ProfileStyles + + + + 0 + 0 + 1280 + 640 + + + + Dialog + + + + + + true + + + + + + + true + + + false + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 80 + 24 + + + + Quit + + + + :icons/silk/door_out.png:icons/silk/door_out.png + + + + + + + + 0 + 0 + + + + + 80 + 24 + + + + New + + + + :icons/silk/table_row_insert.png:icons/silk/table_row_insert.png + + + + + + + + + + + + +