# HG changeset patch # User Michiel Broek # Date 1648736643 -7200 # Node ID ef6048186cb32248b84482fa550880cca0a05c6b # Parent 380b1331ad2efefedcc38835a4b854cce5900a5a Added part of a beercolor plugin that needs a lot of work. Added some rangesliders in the recipe editor. Added EBC and SRM color mapping to QColor. diff -r 380b1331ad2e -r ef6048186cb3 CMakeLists.txt --- a/CMakeLists.txt Wed Mar 30 23:15:08 2022 +0200 +++ b/CMakeLists.txt Thu Mar 31 16:24:03 2022 +0200 @@ -150,6 +150,13 @@ ${GEN_MOC_FILES2} ) + QT_WRAP_CPP( GEN_MOC_FILES3 ${SRCDIR}/BeerColor.h designer/BeerColorPlugin.h) + add_library(bmsapp_beercolor SHARED + ${SRCDIR}/BeerColor.cpp + designer/BeerColorPlugin.cpp + ${GEN_MOC_FILES3} + ) + ELSE() set( SRCS @@ -186,6 +193,7 @@ ${SRCDIR}/database/database.cpp ${SRCDIR}/RangedSlider.cpp ${SRCDIR}/NullDateEdit.cpp + ${SRCDIR}/BeerColor.cpp ) set( HDRS @@ -221,6 +229,7 @@ ${SRCDIR}/database/database.h ${SRCDIR}/RangedSlider.h ${SRCDIR}/NullDateEdit.h + ${SRCDIR}/BeerColor.h ) set( UIS @@ -287,7 +296,7 @@ IF( ${BUILD_DESIGNER_PLUGINS} ) - INSTALL(TARGETS bmsapp_rangeslider bmsapp_nulldate + INSTALL(TARGETS bmsapp_rangeslider bmsapp_nulldate bmsapp_beercolor DESTINATION "${LIBPATH}/plugins/designer" ) diff -r 380b1331ad2e -r ef6048186cb3 designer/NullDateEditPlugin.cpp --- a/designer/NullDateEditPlugin.cpp Wed Mar 30 23:15:08 2022 +0200 +++ b/designer/NullDateEditPlugin.cpp Thu Mar 31 16:24:03 2022 +0200 @@ -83,12 +83,6 @@ { return "\n" " \n" - " \n" - " Date editor\n" - " \n" - " \n" - " Date editor that allows a null date.\n" - " \n" " \n" "\n"; } diff -r 380b1331ad2e -r ef6048186cb3 resources/icons.qrc --- a/resources/icons.qrc Wed Mar 30 23:15:08 2022 +0200 +++ b/resources/icons.qrc Thu Mar 31 16:24:03 2022 +0200 @@ -1009,6 +1009,7 @@ icons/bms/erlenmeyer.png icons/bms/fermenter.png icons/bms/fridge.png + icons/bms/glass.png icons/bms/graan.png icons/bms/hop.png icons/bms/mash.png diff -r 380b1331ad2e -r ef6048186cb3 resources/icons/bms/glass.png Binary file resources/icons/bms/glass.png has changed diff -r 380b1331ad2e -r ef6048186cb3 src/EditRecipe.cpp --- a/src/EditRecipe.cpp Wed Mar 30 23:15:08 2022 +0200 +++ b/src/EditRecipe.cpp Thu Mar 31 16:24:03 2022 +0200 @@ -17,6 +17,7 @@ #include "EditRecipe.h" #include "../ui/ui_EditRecipe.h" #include "MainWindow.h" +#include "Utils.h" EditRecipe::EditRecipe(int id, QWidget *parent) : QDialog(parent), ui(new Ui::EditRecipe) @@ -65,11 +66,45 @@ ui->boil_sizeEdit->setValue(query.value(25).toDouble()); ui->boil_timeEdit->setValue(query.value(26).toInt()); ui->efficiencyEdit->setValue(query.value(27).toDouble()); - // 28 est_og - // 29 est_fg - // 30 est_abv - // 31 est_color - // 32 color_method + + ui->est_ogEdit->setValue(query.value(28).toDouble()); + ui->est_ogShow->setRange(query.value(9).toDouble(), query.value(10).toDouble()); + ui->est_ogShow->setPrecision(3); + ui->est_ogShow->setTickMarks(0.010, 2); + ui->est_ogShow->setBackgroundBrush(QColor(121,201,121)); + ui->est_ogShow->setPreferredRangeBrush(QColor(0,127,0)); + ui->est_ogShow->setMarkerTextIsValue(true); + ui->est_ogShow->setValue(query.value(28).toDouble()); + + ui->est_fgEdit->setValue(query.value(29).toDouble()); + ui->est_fgShow->setRange(query.value(11).toDouble(), query.value(12).toDouble()); + ui->est_fgShow->setPrecision(3); + ui->est_fgShow->setTickMarks(0.010, 2); + ui->est_fgShow->setBackgroundBrush(QColor(121,201,121)); + ui->est_fgShow->setPreferredRangeBrush(QColor(0,127,0)); + ui->est_fgShow->setMarkerTextIsValue(true); + ui->est_fgShow->setValue(query.value(29).toDouble()); + + ui->est_abvEdit->setValue(query.value(30).toDouble()); + ui->est_abvShow->setRange(query.value(19).toDouble(), query.value(20).toDouble()); + ui->est_abvShow->setPrecision(1); + ui->est_abvShow->setTickMarks(1.0, 2); + ui->est_abvShow->setBackgroundBrush(QColor(121,201,121)); + ui->est_abvShow->setPreferredRangeBrush(QColor(0,127,0)); + ui->est_abvShow->setMarkerTextIsValue(true); + ui->est_abvShow->setValue(query.value(30).toDouble()); + + ui->est_colorEdit->setValue(query.value(31).toDouble()); + QColor color = Utils::ebc_to_color(query.value(31).toInt()); + ui->est_colorShow->setColor(color); + + color_methodEdit->addItem("Morey"); + color_methodEdit->addItem("Mosher"); + color_methodEdit->addItem("Daniels"); + color_methodEdit->addItem("Halberstadt"); + color_methodEdit->addItem("Naudts"); + color_methodEdit->setCurrentIndex(query.value(32).toInt()); + // 33 est_ibu // 34 ibu_method // 35 est_carb @@ -140,6 +175,8 @@ connect(ui->boil_timeEdit, &QSpinBox::textChanged, this, &EditRecipe::is_changed); connect(ui->efficiencyEdit, &QDoubleSpinBox::textChanged, this, &EditRecipe::is_changed); + connect(ui->color_methodEdit, &QComboBox::currentTextChanged, this, &EditRecipe::is_changed); + ui->saveButton->setEnabled(false); ui->deleteButton->setEnabled((id >= 0) ? true:false); } @@ -147,9 +184,10 @@ EditRecipe::~EditRecipe() { - qDebug() << "EditRecipe done"; + qDebug() << "EditRecipe done start"; delete ui; emit entry_changed(); + qDebug() << "EditRecipe done final"; } @@ -178,10 +216,10 @@ 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 Recipe"), tr("Name empty or too short.")); -// return; -// } + if (ui->nameEdit->text().length() < 2) { + QMessageBox::warning(this, tr("Edit Recipe"), tr("Name empty or too short.")); + return; + } if (this->textIsChanged) { if (this->recno == -1) { diff -r 380b1331ad2e -r ef6048186cb3 src/RecipesTree.cpp --- a/src/RecipesTree.cpp Wed Mar 30 23:15:08 2022 +0200 +++ b/src/RecipesTree.cpp Thu Mar 31 16:24:03 2022 +0200 @@ -358,6 +358,7 @@ return; } + qDebug() << "showRecipe 2"; /* * Fill in basic details of the selected recipe. */ @@ -365,9 +366,13 @@ query.prepare("SELECT batch_size,boil_size,boil_time,efficiency,est_og,est_fg,est_abv,est_color,color_method,est_ibu,ibu_method,est_carb,notes,name " "FROM recipes WHERE record=:record"); query.bindValue(":record", record); + qDebug() << "showRecipe 3"; query.exec(); + qDebug() << "showRecipe 4"; if (query.size() == 1) { + qDebug() << "showRecipe 5 ok"; query.first(); + qDebug() << "showRecipe 6"; volumeEdit->setValue(query.value(0).toDouble()); boilvolumeEdit->setValue(query.value(1).toDouble()); boiltimeEdit->setValue(query.value(2).toInt()); @@ -383,7 +388,9 @@ remarksEdit->setPlainText(query.value(12).toString()); recipeBox->setTitle(query.value(13).toString()); recipeBox->setEnabled(true); + qDebug() << "showRecipe 7"; } else { + qDebug() << "showRecipe 5 error"; qDebug() << "Error getting recipe record" << record; } } @@ -399,7 +406,8 @@ /* Signal from editor if a refresh is needed */ connect(&dialog, SIGNAL(entry_changed()), this, SLOT(refreshTable())); dialog.setModal(true); - dialog.exec(); + int rc = dialog.exec(); + qDebug() << "edit is ready rc=" << rc; } diff -r 380b1331ad2e -r ef6048186cb3 src/Utils.cpp --- a/src/Utils.cpp Wed Mar 30 23:15:08 2022 +0200 +++ b/src/Utils.cpp Thu Mar 31 16:24:03 2022 +0200 @@ -85,3 +85,76 @@ } +QColor Utils::srm_to_color(int srm) +{ + int i; + QColor result; + + i = round(srm * 10); + if (i < 0) + i = 0; + if (i > 299) + i = 299; + + const int R[] { + 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, //0 + 250, 250, 250, 250, 250, 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, //2 + 234, 233, 232, 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, //4 + 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 200, 199, 199, 198, 198, //6 + 197, 197, 196, 196, 195, 195, 194, 194, 193, 193, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, //8 + 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, //10 + 192, 192, 192, 192, 192, 192, 192, 192, 191, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, //12 + 179, 178, 177, 175, 174, 172, 171, 169, 168, 167, 195, 164, 162, 161, 159, 158, 157, 155, 154, 152, //14 + 151, 149, 148, 147, 145, 144, 142, 141, 139, 138, 137, 135, 134, 132, 131, 129, 128, 127, 125, 124, //16 + 122, 121, 119, 118, 117, 115, 114, 112, 111, 109, 108, 107, 105, 104, 102, 101, 99, 98, 97, 95, //18 + 94, 92, 91, 89, 88, 87, 85, 84, 82, 81, 79, 78, 77, 75, 74, 72, 71, 69, 68, 67, //20 + 65, 64, 62, 61, 59, 58, 57, 55, 54, 52, 51, 49, 48, 47, 45, 44, 43, 41, 39, 38, //22 + 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 32, 32, 31, 31, 30, 30, 29, 29, 28, 28, //24 + 27, 27, 26, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18, //26 + 17, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8}; + + const int G[] { + 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, + 250, 250, 250, 250, 250, 250, 249, 248, 247, 246, 245, 244, 242, 240, 238, 236, 234, 232, 230, 228, + 226, 224, 222, 220, 218, 216, 214, 212, 210, 208, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, + 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 148, + 146, 144, 142, 141, 140, 139, 139, 138, 137, 136, 136, 135, 134, 133, 133, 132, 131, 130, 130, 129, + 128, 127, 127, 126, 125, 124, 124, 123, 122, 121, 121, 120, 119, 118, 118, 117, 116, 115, 115, 114, + 113, 112, 112, 111, 110, 109, 109, 108, 107, 106, 106, 105, 104, 103, 103, 102, 101, 100, 100, 99, + 98, 97, 97, 96, 95, 94, 94, 93, 92, 91, 91, 90, 89, 88, 88, 87, 86, 85, 85, 84, + 83, 82, 82, 81, 80, 79, 78, 77, 76, 75, 75, 74, 73, 72, 72, 71, 70, 69, 69, 68, + 67, 66, 66, 65, 64, 63, 63, 62, 61, 60, 60, 59, 58, 57, 57, 56, 55, 54, 54, 53, + 52, 51, 51, 50, 49, 48, 48, 47, 46, 45, 45, 44, 43, 42, 42, 41, 40, 39, 39, 38, + 37, 36, 36, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28, 27, 27, 26, 25, 24, 24, 23, + 22, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 16, 16, + 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, + 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3}; + + const int B[] { + 210, 204, 199, 193, 188, 182, 177, 171, 166, 160, 155, 149, 144, 138, 133, 127, 122, 116, 111, 105, + 100, 94, 89, 83, 78, 72, 67, 61, 56, 50, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, + 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, + 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 56, 55, 55, 55, 55, 54, 54, 54, 54, 53, 53, 53, 53, 52, 52, 52, 52, 51, + 51, 51, 51, 50, 50, 50, 50, 49, 49, 48, 47, 47, 46, 45, 45, 44, 43, 43, 42, 41, + 41, 40, 39, 39, 38, 37, 37, 36, 35, 34, 33, 32, 31, 29, 28, 27, 26, 25, 24, 23, + 21, 20, 19, 18, 17, 16, 15, 13, 12, 11, 10, 9, 8, 9, 9, 10, 10, 11, 11, 12, + 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, + 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 17, 16, 16, 15, 15, + 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, + 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2}; + + result = QColor::fromRgb(R[i], G[i], B[i]); + return result; +} + + +QColor Utils::ebc_to_color(int ebc) +{ + return srm_to_color(ebc_to_srm(ebc)); +} + + diff -r 380b1331ad2e -r ef6048186cb3 src/Utils.h --- a/src/Utils.h Wed Mar 30 23:15:08 2022 +0200 +++ b/src/Utils.h Thu Mar 31 16:24:03 2022 +0200 @@ -2,6 +2,7 @@ #define _UTILS_H #include +#include /** @@ -17,7 +18,8 @@ double srm_to_ebc(double srm); QString hours_to_string(int hours); - + QColor srm_to_color(int srm); + QColor ebc_to_color(int ebc); } #endif diff -r 380b1331ad2e -r ef6048186cb3 ui/EditRecipe.ui --- a/ui/EditRecipe.ui Wed Mar 30 23:15:08 2022 +0200 +++ b/ui/EditRecipe.ui Thu Mar 31 16:24:03 2022 +0200 @@ -394,7 +394,7 @@ - 140 + 220 200 148 37 @@ -423,11 +423,115 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + 140 + 200 + 71 + 24 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + 3 + + + 0.980000000000000 + + + 2.000000000000000 + + + 0.001000000000000 + + + + + + 0 + 260 + 131 + 20 + + + + Estimated FG: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + - 90 - 350 + 0 + 320 + 131 + 20 + + + + Estimated ABV: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 0 + 380 + 131 + 20 + + + + Estimated Color EBC: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 140 + 260 + 71 + 24 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + 3 + + + 0.980000000000000 + + + 2.000000000000000 + + + 0.001000000000000 + + + + + + 220 + 260 148 37 @@ -439,11 +543,70 @@ Slider that shows if a value is in range. - + - 350 - 350 + 140 + 320 + 71 + 24 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + % + + + 1 + + + 0.000000000000000 + + + 80.000000000000000 + + + 0.100000000000000 + + + + + + 140 + 380 + 71 + 24 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + 0 + + + 0.000000000000000 + + + 400.000000000000000 + + + 1.000000000000000 + + + + + + 220 + 320 148 37 @@ -455,21 +618,15 @@ Slider that shows if a value is in range. - + - 660 - 360 - 101 - 24 + 590 + 270 + 90 + 130 - - Date editor - - - Date editor that allows a null date. - @@ -567,9 +724,9 @@ - NullDateEdit - QDateEdit -
NullDateEdit.h
+ BeerColor + QWidget +
BeerColor.h
RangedSlider