Thu, 17 Feb 2022 19:57:32 +0100
Completed the global setup editor.
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/AboutDialog.cpp | file | annotate | diff | comparison | revisions | |
src/MainWindow.cpp | file | annotate | diff | comparison | revisions | |
src/Setup.cpp | file | annotate | diff | comparison | revisions | |
src/Setup.h | file | annotate | diff | comparison | revisions | |
src/bmsapp.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
ui/Setup.ui | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Wed Feb 16 22:11:29 2022 +0100 +++ b/CMakeLists.txt Thu Feb 17 19:57:32 2022 +0100 @@ -129,6 +129,8 @@ ${UIS} resources/icons.qrc resources/qdarkstyle/theme/style.qrc + resources/darkstyle.qrc + resources/darkorange.qrc ) # ===== Build the application =====
--- a/src/AboutDialog.cpp Wed Feb 16 22:11:29 2022 +0100 +++ b/src/AboutDialog.cpp Thu Feb 17 19:57:32 2022 +0100 @@ -20,12 +20,12 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) { - qDebug() << Q_FUNC_INFO; + qDebug() << "About start"; ui->setupUi(this); } AboutDialog::~AboutDialog() { - qDebug() << Q_FUNC_INFO; + qDebug() << "About done"; delete ui; }
--- a/src/MainWindow.cpp Wed Feb 16 22:11:29 2022 +0100 +++ b/src/MainWindow.cpp Thu Feb 17 19:57:32 2022 +0100 @@ -82,14 +82,13 @@ qDebug() << Q_FUNC_INFO; SetupWindow = new Setup(this); QObject::connect(SetupWindow, SIGNAL(firstWindow()), this, SLOT(fromSetup())); - this->hide(); // Close the main window - SetupWindow->show(); // Show a second window + this->hide(); // Close the main window + SetupWindow->show(); // Show a setup window } void MainWindow::on_actionAbout_triggered() { - qDebug() << Q_FUNC_INFO; AboutDialog dialog(this); dialog.setModal(true); dialog.exec();
--- a/src/Setup.cpp Wed Feb 16 22:11:29 2022 +0100 +++ b/src/Setup.cpp Thu Feb 17 19:57:32 2022 +0100 @@ -23,11 +23,84 @@ Setup::Setup(QWidget *parent) : QDialog(parent), ui(new Ui::Setup) { + QSqlQuery query; + qDebug() << "Setup start"; - ui->setupUi(this); + setWindowTitle( QString("BMSapp - %1 - Setup").arg(VERSIONSTRING) ); - setWindowTitle( QString("BMSapp - %1 - Setup").arg(VERSIONSTRING) ); + query.prepare("SELECT * FROM profile_setup WHERE record='1'"); + query.exec(); + query.next(); + + ui->breweryEdit->setText(query.value(1).toString()); // max 128 + + ui->fwhEdit->setValue(query.value(4).toInt()); + ui->mashhopEdit->setValue(query.value(3).toInt()); + ui->pelletEdit->setValue(query.value(5).toInt()); + ui->hopplugEdit->setValue(query.value(6).toInt()); + ui->wethopEdit->setValue(query.value(7).toInt()); + ui->cryohopEdit->setValue(query.value(8).toInt()); + connect(ui->fwhEdit, &QSpinBox::textChanged, this, &Setup::is_changed); + connect(ui->mashhopEdit, &QSpinBox::textChanged, this, &Setup::is_changed); + connect(ui->pelletEdit, &QSpinBox::textChanged, this, &Setup::is_changed); + connect(ui->hopplugEdit, &QSpinBox::textChanged, this, &Setup::is_changed); + connect(ui->wethopEdit, &QSpinBox::textChanged, this, &Setup::is_changed); + connect(ui->cryohopEdit, &QSpinBox::textChanged, this, &Setup::is_changed); + + ui->grainEdit->setValue(query.value(12).toDouble()); + ui->brixEdit->setValue(query.value(11).toDouble()); + connect(ui->grainEdit, &QDoubleSpinBox::textChanged, this, &Setup::is_changed); + connect(ui->brixEdit, &QDoubleSpinBox::textChanged, this, &Setup::is_changed); + + ui->colorEdit->addItem(tr("Morey")); + ui->colorEdit->addItem(tr("Mosher")); + ui->colorEdit->addItem(tr("Daniels")); + ui->colorEdit->addItem(tr("Halberstadt")); + ui->colorEdit->addItem(tr("Naudts")); + ui->colorEdit->setEditable(true); + ui->colorEdit->setCurrentIndex(query.value(10).toInt()); + connect(ui->colorEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); + + ui->ibuEdit->addItem(tr("Tinseth")); + ui->ibuEdit->addItem(tr("Rager")); + ui->ibuEdit->addItem(tr("Daniels")); + ui->ibuEdit->setEditable(true); + ui->ibuEdit->setCurrentIndex(query.value(9).toInt()); + connect(ui->ibuEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); + + QSqlQuery query2("SELECT record,name FROM inventory_waters"); + query2.first(); + int pos = -1; + ui->waterEdit->setEditable(true); + ui->waterEdit->setPlaceholderText(tr("Choose default water")); + for (int i = 0 ; i < query2.size() ; i++ ) { + ui->waterEdit->addItem(query2.value(1).toString()); + if (query2.value(0).toInt() == query.value(13).toInt()) { + pos = i; + } + query2.next(); + } + if (pos >= 0) + ui->waterEdit->setCurrentIndex(pos); + connect(ui->waterEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); + + QSqlQuery query3("SELECT DISTINCT laboratory FROM inventory_yeasts ORDER BY laboratory"); + query3.first(); + pos = -1; + ui->yeastEdit->setEditable(true); + ui->yeastEdit->setPlaceholderText(tr("Choose laboratory")); + for (int i = 0 ; i < query3.size() ; i++ ) { + ui->yeastEdit->addItem(query3.value(0).toString()); + if (QString::compare(query.value(14).toString(), query3.value(0).toString(), Qt::CaseSensitive) == 0) + pos = i; + query3.next(); + } + if (pos >= 0) + ui->yeastEdit->setCurrentIndex(pos); + connect(ui->yeastEdit, &QComboBox::currentTextChanged, this, &Setup::is_changed); + + // query.value(2).toString() logo varchar(1024) } @@ -38,8 +111,79 @@ } +/* + * Also called from the Quit button if there are changes to save. + */ +void Setup::on_saveButton_clicked() +{ + QSqlQuery query; + + /* + * Search record number of the current water. + */ + query.prepare("SELECT record FROM inventory_waters WHERE name=:name"); + query.bindValue(":name", ui->waterEdit->currentText()); + query.exec(); + query.first(); + int record = query.value(0).toInt(); + + /* + * Update all other data + */ + query.prepare("UPDATE profile_setup SET brewery_name=:brewery, factor_mashhop=:mashhop, factor_fwh=:fwh, factor_pellet=:pellet, " + "factor_plug=:plug, factor_wethop=:wet, factor_cryohop=:cryo, color_method=:color, ibu_method=:ibu, " + "brix_correction=:brix, grain_absorbtion=:grain, default_water=:water, my_yeastlab=:yeast WHERE record='1'"); + query.bindValue(":brewery", ui->breweryEdit->text()); + query.bindValue(":mashhop", ui->mashhopEdit->value()); + query.bindValue(":fwh", ui->fwhEdit->value()); + query.bindValue(":pellet", ui->pelletEdit->value()); + query.bindValue(":plug", ui->hopplugEdit->value()); + query.bindValue(":wet", ui->wethopEdit->value()); + query.bindValue(":cryo", ui->cryohopEdit->value()); + query.bindValue(":color", ui->colorEdit->currentIndex()); + query.bindValue(":ibu", ui->ibuEdit->currentIndex()); + query.bindValue(":brix", ui->brixEdit->value()); + query.bindValue(":grain", ui->grainEdit->value()); + query.bindValue(":water", record); + query.bindValue(":yeast", ui->yeastEdit->currentText()); + query.exec(); + if (query.lastError().isValid()) { + qDebug() << "Setup Save error:" << 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() << "Setup Saved"; + } + + this->fieldIsChanged = false; + setWindowTitle( QString("BMSapp - %1 - Setup").arg(VERSIONSTRING) ); +} + + void Setup::on_quitButton_clicked() { + if (this->fieldIsChanged) { + int rc = QMessageBox::warning(this, tr("Setup changed"), tr("The setup 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 setup page */ + } + } emit firstWindow(); } + +void Setup::is_changed() +{ + this->fieldIsChanged = true; + setWindowTitle( QString("BMSapp - %1 - Setup **").arg(VERSIONSTRING) ); +}
--- a/src/Setup.h Wed Feb 16 22:11:29 2022 +0100 +++ b/src/Setup.h Thu Feb 17 19:57:32 2022 +0100 @@ -20,12 +20,12 @@ private slots: void on_quitButton_clicked(); -// void on_insertButton_clicked(); -// void on_editButton_clicked(); -// void refreshTable(void); + void on_saveButton_clicked(); + void is_changed(); private: Ui::Setup *ui; + bool fieldIsChanged = false; }; #endif
--- a/src/bmsapp.h Wed Feb 16 22:11:29 2022 +0100 +++ b/src/bmsapp.h Thu Feb 17 19:57:32 2022 +0100 @@ -19,6 +19,8 @@ #include <QUuid> #include <QStyle> #include <QPlainTextEdit> +#include <QMessageBox> + #include "database/database.h"
--- a/src/main.cpp Wed Feb 16 22:11:29 2022 +0100 +++ b/src/main.cpp Thu Feb 17 19:57:32 2022 +0100 @@ -38,7 +38,10 @@ app.setOrganizationName("mbse"); /* Stylesheet setup */ - QFile f(":/qdarkstyle/theme/style.qss"); + //QFile f(":/qdarkstyle/theme/style.qss"); + //QFile f(":darkorange.qss"); + QFile f(":darkstyle/darkstyle.qss"); + //QFile f(":dummy"); if (!f.exists()) { printf("Unable to set stylesheet, file not found\n"); } else {
--- a/ui/Setup.ui Wed Feb 16 22:11:29 2022 +0100 +++ b/ui/Setup.ui Thu Feb 17 19:57:32 2022 +0100 @@ -15,7 +15,7 @@ </property> <layout class="QGridLayout" name="gridLayout"> <item row="0" column="0"> - <widget class="QWidget" name="widget" native="true"> + <widget class="QWidget" name="topWidget" native="true"> <widget class="QLabel" name="breweryLabel"> <property name="geometry"> <rect> @@ -473,7 +473,7 @@ <enum>QAbstractSpinBox::DefaultStepType</enum> </property> <property name="value"> - <double>1.010000000000000</double> + <double>1.000000000000000</double> </property> </widget> <widget class="QDoubleSpinBox" name="brixEdit"> @@ -507,7 +507,7 @@ <enum>QAbstractSpinBox::DefaultStepType</enum> </property> <property name="value"> - <double>1.040000000000000</double> + <double>1.000000000000000</double> </property> </widget> <widget class="QComboBox" name="colorEdit"> @@ -553,7 +553,7 @@ <rect> <x>990</x> <y>180</y> - <width>161</width> + <width>211</width> <height>23</height> </rect> </property> @@ -572,7 +572,7 @@ <rect> <x>990</x> <y>210</y> - <width>161</width> + <width>211</width> <height>23</height> </rect> </property> @@ -589,7 +589,7 @@ </widget> </item> <item row="1" column="0"> - <widget class="QWidget" name="widget" native="true"> + <widget class="QWidget" name="bottomWidget" native="true"> <property name="minimumSize"> <size> <width>0</width>