Skip to content

Commit

Permalink
Merge pull request #721 from matty0ung/3.0.7
Browse files Browse the repository at this point in the history
Fix for #719
  • Loading branch information
matty0ung committed Feb 25, 2023
2 parents 104daba + c2ca3e8 commit 9fb1f14
Show file tree
Hide file tree
Showing 120 changed files with 2,431 additions and 1,592 deletions.
22 changes: 11 additions & 11 deletions src/AlcoholTool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* AlcoholTool.cpp is part of Brewtarget, and is Copyright the following
* authors 2009-2021
* authors 2009-2023
* - Matt Young <mfsy@yahoo.com>
* - Ryan Hoobler <rhoob@yahoo.com>
*
Expand All @@ -24,14 +24,14 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QLocale>
#include <QPushButton>
#include <QSpacerItem>
#include <QVBoxLayout>
#include <QWidget>

#include "Algorithms.h"
#include "BtLineEdit.h"
#include "Localization.h"
#include "PersistentSettings.h"
#include "measurement/SystemOfMeasurement.h"
#include "widgets/ToggleSwitch.h"
Expand Down Expand Up @@ -145,26 +145,26 @@ class AlcoholTool::impl {
}

void updateCalculatedFields() {
double og = this->input_og->toSI().quantity;
double fg = this->input_fg->toSI().quantity;
double og = this->input_og->toCanonical().quantity();
double fg = this->input_fg->toCanonical().quantity();
if (this->enableAdvancedInputs->isChecked()) {
// User wants temperature correction
double calibrationTempInC = this->input_calibration_temperature->toSI().quantity;
double ogReadTempInC = this->input_og_temperature->toSI().quantity;
double fgReadTempInC = this->input_fg_temperature->toSI().quantity;
double calibrationTempInC = this->input_calibration_temperature->toCanonical().quantity();
double ogReadTempInC = this->input_og_temperature->toCanonical().quantity();
double fgReadTempInC = this->input_fg_temperature->toCanonical().quantity();
if (0.0 == calibrationTempInC || 0.0 == ogReadTempInC) {
og = 0.0;
this->corrected_og->setText("? sg");
} else {
og = Algorithms::correctSgForTemperature(og, ogReadTempInC, calibrationTempInC);
this->corrected_og->setText(QLocale().toString(og, 'f', 3).append(" sg"));
this->corrected_og->setText(Localization::getLocale().toString(og, 'f', 3).append(" sg"));
}
if (0.0 == calibrationTempInC || 0.0 == fgReadTempInC) {
fg = 0.0;
this->corrected_fg->setText("? sg");
} else {
fg = Algorithms::correctSgForTemperature(fg, fgReadTempInC, calibrationTempInC);
this->corrected_fg->setText(QLocale().toString(fg, 'f', 3).append(" sg"));
this->corrected_fg->setText(Localization::getLocale().toString(fg, 'f', 3).append(" sg"));
}
}

Expand All @@ -181,7 +181,7 @@ class AlcoholTool::impl {
// So, if ABV is, say, 5.179% the call to QLocale::toString() below will correctly round it to 5.18% and the user
// can decide whether to use 5.1% or 5.2% on labels etc.
//
this->output_result->setText(QLocale().toString(abv, 'f', 2).append("%"));
this->output_result->setText(Localization::getLocale().toString(abv, 'f', 2).append("%"));
return;
}

Expand Down Expand Up @@ -257,7 +257,7 @@ class AlcoholTool::impl {
this->enableAdvancedInputs->isChecked(),
PersistentSettings::Sections::alcoholTool);
PersistentSettings::insert(hydrometerCalibrationTemperatureInC,
this->input_calibration_temperature->toSI().quantity,
this->input_calibration_temperature->toCanonical().quantity(),
PersistentSettings::Sections::alcoholTool);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ double Algorithms::correctSgForTemperature(double measuredSg, double readingTemp
// https://onlinelibrary.wiley.com/doi/pdf/10.1002/j.2050-0416.1970.tb03327.x for a rather old example.) Hence the
// use of non-SI units -- because the people in question were working in Fahrenheit.
//
double tr = Measurement::Units::fahrenheit.fromSI(readingTempInC);
double tc = Measurement::Units::fahrenheit.fromSI(calibrationTempInC);
double tr = Measurement::Units::fahrenheit.fromCanonical(readingTempInC);
double tc = Measurement::Units::fahrenheit.fromCanonical(calibrationTempInC);

double correctedSg = measuredSg * (
(1.00130346 - 0.000134722124 * tr + 0.00000204052596 * intPow(tr,2) - 0.00000000232820948 * intPow(tr,3)) /
Expand Down
27 changes: 14 additions & 13 deletions src/BrewNoteWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void BrewNoteWidget::updateSG() {
return;
}

this->bNoteObs->setSg(lineEdit_SG->toSI().quantity);
this->bNoteObs->setSg(lineEdit_SG->toCanonical().quantity());
return;
}

Expand All @@ -155,7 +155,7 @@ void BrewNoteWidget::updateVolumeIntoBK_l() {
return;
}

this->bNoteObs->setVolumeIntoBK_l(lineEdit_volIntoBK->toSI().quantity);
this->bNoteObs->setVolumeIntoBK_l(lineEdit_volIntoBK->toCanonical().quantity());
return;
}

Expand All @@ -164,7 +164,7 @@ void BrewNoteWidget::updateStrikeTemp_c() {
return;
}

this->bNoteObs->setStrikeTemp_c(lineEdit_strikeTemp->toSI().quantity);
this->bNoteObs->setStrikeTemp_c(lineEdit_strikeTemp->toCanonical().quantity());
return;
}

Expand All @@ -173,7 +173,7 @@ void BrewNoteWidget::updateMashFinTemp_c() {
return;
}

this->bNoteObs->setMashFinTemp_c(lineEdit_mashFinTemp->toSI().quantity);
this->bNoteObs->setMashFinTemp_c(lineEdit_mashFinTemp->toCanonical().quantity());
return;
}

Expand All @@ -182,7 +182,7 @@ void BrewNoteWidget::updateOG() {
return;
}

this->bNoteObs->setOg(lineEdit_OG->toSI().quantity);
this->bNoteObs->setOg(lineEdit_OG->toCanonical().quantity());
return;
}

Expand All @@ -191,7 +191,7 @@ void BrewNoteWidget::updatePostBoilVolume_l() {
return;
}

this->bNoteObs->setPostBoilVolume_l(lineEdit_postBoilVol->toSI().quantity);
this->bNoteObs->setPostBoilVolume_l(lineEdit_postBoilVol->toCanonical().quantity());
this->showChanges();
return;
}
Expand All @@ -201,7 +201,7 @@ void BrewNoteWidget::updateVolumeIntoFerm_l() {
return;
}

this->bNoteObs->setVolumeIntoFerm_l(lineEdit_volIntoFerm->toSI().quantity);
this->bNoteObs->setVolumeIntoFerm_l(lineEdit_volIntoFerm->toCanonical().quantity());
this->showChanges();
return;
}
Expand All @@ -211,7 +211,7 @@ void BrewNoteWidget::updatePitchTemp_c() {
return;
}

this->bNoteObs->setPitchTemp_c(lineEdit_pitchTemp->toSI().quantity);
this->bNoteObs->setPitchTemp_c(lineEdit_pitchTemp->toCanonical().quantity());
this->showChanges();
return;
}
Expand All @@ -221,7 +221,7 @@ void BrewNoteWidget::updateFG() {
return;
}

this->bNoteObs->setFg(lineEdit_FG->toSI().quantity);
this->bNoteObs->setFg(lineEdit_FG->toCanonical().quantity());
this->showChanges();
return;
}
Expand All @@ -231,7 +231,7 @@ void BrewNoteWidget::updateFinalVolume_l() {
return;
}

this->bNoteObs->setFinalVolume_l(lineEdit_finalVol->toSI().quantity);
this->bNoteObs->setFinalVolume_l(lineEdit_finalVol->toCanonical().quantity());
// this->showChanges();
return;
}
Expand All @@ -254,7 +254,8 @@ void BrewNoteWidget::updateNotes() {
return;
}

void BrewNoteWidget::changed(QMetaProperty /*prop*/, QVariant /*val*/) {
void BrewNoteWidget::changed([[maybe_unused]] QMetaProperty prop,
[[maybe_unused]] QVariant val) {
if (this->sender() != this->bNoteObs) {
return;
}
Expand All @@ -263,7 +264,7 @@ void BrewNoteWidget::changed(QMetaProperty /*prop*/, QVariant /*val*/) {
return;
}

void BrewNoteWidget::showChanges(QString field) {
void BrewNoteWidget::showChanges([[maybe_unused]] QString field) {
if (this->bNoteObs == nullptr) {
return;
}
Expand Down Expand Up @@ -296,6 +297,6 @@ void BrewNoteWidget::showChanges(QString field) {
return;
}

void BrewNoteWidget::focusOutEvent(QFocusEvent *e) {
void BrewNoteWidget::focusOutEvent([[maybe_unused]] QFocusEvent * e) {
return;
}
3 changes: 1 addition & 2 deletions src/BtDigitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <QDebug>
#include <QFrame>
#include <QLocale>
#include <QSettings>

#include "Localization.h"
Expand Down Expand Up @@ -138,7 +137,7 @@ void BtDigitWidget::display(QString str) {
static bool converted;

this->pimpl->m_lastNum = Localization::toDouble(str, &converted);
this->pimpl->m_lastPrec = str.length() - str.lastIndexOf(QLocale().decimalPoint()) - 1;
this->pimpl->m_lastPrec = str.length() - str.lastIndexOf(Localization::getLocale().decimalPoint()) - 1;
if (converted) {
this->display(this->pimpl->m_lastNum, this->pimpl->m_lastPrec);
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/BtFieldType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

namespace {
EnumStringMapping const nonPhysicalQuantityToName {
{"Date" , NonPhysicalQuantity::Date },
{"String" , NonPhysicalQuantity::String },
{"Count" , NonPhysicalQuantity::Count },
{"Percentage", NonPhysicalQuantity::Percentage}
{"Date" , NonPhysicalQuantity::Date },
{"String" , NonPhysicalQuantity::String },
{"Count" , NonPhysicalQuantity::Count },
{"Percentage" , NonPhysicalQuantity::Percentage },
{"Bool" , NonPhysicalQuantity::Bool },
{"Dimensionless", NonPhysicalQuantity::Dimensionless},
};
}

Expand Down
9 changes: 8 additions & 1 deletion src/BtFieldType.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ enum class NonPhysicalQuantity {
Date,
String,
Count,
Percentage
Percentage,
Bool,
/**
* \brief This is for a number that has no units, not even pseudo ones. It is currently a bit over-used -- ie there
* are places we are using this (typically via BtNumberOnlyEdit) where we probably should be using a
* \c PhysicalQuantity. We should fix these over time.
*/
Dimensionless,
};

/**
Expand Down
12 changes: 6 additions & 6 deletions src/BtLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "model/Style.h"
#include "model/Recipe.h"
#include "PersistentSettings.h"
#include "utils/OptionalToStream.h"
#include "utils/OptionalHelpers.h"
#include "widgets/UnitAndScalePopUpMenu.h"

BtLabel::BtLabel(QWidget *parent,
Expand All @@ -43,12 +43,12 @@ BtLabel::BtLabel(QWidget *parent,

BtLabel::~BtLabel() = default;

void BtLabel::enterEvent(QEvent* event) {
void BtLabel::enterEvent([[maybe_unused]] QEvent * event) {
this->textEffect(true);
return;
}

void BtLabel::leaveEvent(QEvent* event) {
void BtLabel::leaveEvent([[maybe_unused]] QEvent * event) {
this->textEffect(false);
return;
}
Expand Down Expand Up @@ -141,9 +141,9 @@ void BtLabel::initializeMenu() {
Measurement::PhysicalQuantity physicalQuantity = std::get<Measurement::PhysicalQuantity>(this->fieldType);

this->contextMenu = UnitAndScalePopUpMenu::create(this->btParent,
physicalQuantity,
forcedSystemOfMeasurement,
forcedRelativeScale);
physicalQuantity,
forcedSystemOfMeasurement,
forcedRelativeScale);
return;
}

Expand Down
65 changes: 21 additions & 44 deletions src/BtLineEdit.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* BtLineEdit.cpp is part of Brewtarget, and is Copyright the following
* authors 2009-2021:
* authors 2009-2023:
* - Matt Young <mfsy@yahoo.com>
* - Mik Firestone <mikfire@gmail.com>
* - Philip Greggory Lee <rocketman768@gmail.com>
Expand Down Expand Up @@ -33,7 +33,7 @@
#include "measurement/UnitSystem.h"
#include "model/NamedEntity.h"
#include "PersistentSettings.h"
#include "utils/OptionalToStream.h"
#include "utils/OptionalHelpers.h"

namespace {
int const min_text_size = 8;
Expand Down Expand Up @@ -182,7 +182,9 @@ void BtLineEdit::setText(NamedEntity * element, int precision) {

char const * const propertyName = this->editField.toLatin1().constData();
QVariant const propertyValue = element->property(propertyName);
qDebug() << Q_FUNC_INFO << "Read property" << propertyName << "of" << *element << "as" << propertyValue;
qDebug() <<
Q_FUNC_INFO << "Read property" << this->editField << "(" << propertyName << ") of" << *element << "as" <<
propertyValue;
bool force = false;
auto const myFieldType = this->getFieldType();
if (std::holds_alternative<NonPhysicalQuantity>(myFieldType) &&
Expand Down Expand Up @@ -295,37 +297,22 @@ void BtLineEdit::setDisplaySize(bool recalculate) {
return;
}

BtGenericEdit::BtGenericEdit(QWidget *parent) : BtLineEdit(parent, NonPhysicalQuantity::String, nullptr) {
return;
}

BtMassEdit::BtMassEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Mass, &Measurement::Units::kilograms) {
return;
}

BtVolumeEdit::BtVolumeEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Volume, &Measurement::Units::liters) {
return;
}

BtTemperatureEdit::BtTemperatureEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Temperature, &Measurement::Units::celsius, 1) {
return;
}

BtTimeEdit::BtTimeEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Time, &Measurement::Units::minutes, 3) {
return;
}

BtDensityEdit::BtDensityEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Density, &Measurement::Units::sp_grav) {
return;
}

BtColorEdit::BtColorEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Color, &Measurement::Units::srm) {
return;
}

BtStringEdit::BtStringEdit(QWidget *parent) : BtLineEdit(parent, NonPhysicalQuantity::String, nullptr) {
return;
}
BtGenericEdit ::BtGenericEdit (QWidget *parent) : BtLineEdit(parent, NonPhysicalQuantity::String , nullptr ) { return; }
BtMassEdit ::BtMassEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Mass , &Measurement::Units::kilograms ) { return; }
BtVolumeEdit ::BtVolumeEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Volume , &Measurement::Units::liters ) { return; }
BtTimeEdit ::BtTimeEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Time , &Measurement::Units::minutes , 3) { return; }
BtTemperatureEdit ::BtTemperatureEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Temperature , &Measurement::Units::celsius , 1) { return; }
BtColorEdit ::BtColorEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Color , &Measurement::Units::srm ) { return; }
BtDensityEdit ::BtDensityEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Density , &Measurement::Units::sp_grav ) { return; }
BtDiastaticPowerEdit::BtDiastaticPowerEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::DiastaticPower, &Measurement::Units::lintner ) { return; }
BtAcidityEdit ::BtAcidityEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Acidity , &Measurement::Units::pH ) { return; }
BtBitternessEdit ::BtBitternessEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Bitterness , &Measurement::Units::ibu ) { return; }
BtCarbonationEdit ::BtCarbonationEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Carbonation , &Measurement::Units::carbonationVolumes ) { return; }
BtConcentrationEdit ::BtConcentrationEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Concentration , &Measurement::Units::partsPerMillion ) { return; }
BtViscosityEdit ::BtViscosityEdit (QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Viscosity , &Measurement::Units::centipoise ) { return; }
BtStringEdit ::BtStringEdit (QWidget *parent) : BtLineEdit(parent, NonPhysicalQuantity::String , nullptr ) { return; }
BtPercentageEdit ::BtPercentageEdit (QWidget *parent) : BtLineEdit(parent, NonPhysicalQuantity::Percentage , nullptr , 0) { return; }
BtDimensionlessEdit ::BtDimensionlessEdit (QWidget *parent) : BtLineEdit(parent, NonPhysicalQuantity::Dimensionless , nullptr , 3) { return; }

BtMixedEdit::BtMixedEdit(QWidget *parent) : BtLineEdit(parent, Measurement::PhysicalQuantity::Mixed) {
// This is probably pure evil I will later regret
Expand All @@ -345,13 +332,3 @@ void BtMixedEdit::setIsWeight(bool state) {
this->onLineChanged();
return;
}

BtDiastaticPowerEdit::BtDiastaticPowerEdit(QWidget *parent) :
BtLineEdit(parent, Measurement::PhysicalQuantity::DiastaticPower, &Measurement::Units::lintner) {
return;
}

BtPercentageEdit::BtPercentageEdit(QWidget *parent) :
BtLineEdit(parent, NonPhysicalQuantity::Percentage, nullptr, 0) {
return;
}
Loading

0 comments on commit 9fb1f14

Please sign in to comment.