Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly closes #166 and #158 #336

Merged
merged 1 commit into from
Jan 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/BtLineEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BtLineEdit::BtLineEdit(QWidget *parent, Unit::UnitType type) :
_forceUnit = Unit::noUnit;
_forceScale = Unit::noScale;
*/

connect(this,SIGNAL(editingFinished()),this,SLOT(lineChanged()));
}

Expand Down Expand Up @@ -146,7 +146,7 @@ double BtLineEdit::toSI(Unit::unitDisplay oldUnit,Unit::unitScale oldScale,bool

// get the qstringToSI() from the unit system, using the found unit.
// Force the issue in qstringToSI() unless dspScale is Unit::noScale.

return temp->qstringToSI(text(), works, dspScale != Unit::noScale, dspScale);
}
else if ( _type == Unit::String )
Expand Down Expand Up @@ -183,7 +183,7 @@ double BtLineEdit::toDouble(bool* ok)
{
QRegExp amtUnit;

if ( ok )
if ( ok )
*ok = true;
// Make sure we get the right decimal point (. or ,) and the right grouping
// separator (, or .). Some locales write 1.000,10 and other write
Expand Down Expand Up @@ -219,12 +219,19 @@ void BtLineEdit::setText( BeerXMLElement* element, int precision )
display = element->property(_editField.toLatin1().constData()).toString();
else if ( element->property(_editField.toLatin1().constData()).canConvert(QVariant::Double) )
{
// Get the amount
bool ok = false;
QString tmp = element->property(_editField.toLatin1().constData()).toString();
amount = Brewtarget::toDouble(tmp, &ok);
if ( !ok )
Brewtarget::logW( QString("%1 could not convert %2 (%3:%4) to double").arg(Q_FUNC_INFO).arg(tmp).arg(_section).arg(_editField) );
// Get the value from the element, and put it in a QVariant
QVariant tmp = element->property(_editField.toLatin1().constData());
// It is important here to use QVariant::toDouble() instead of going
// through toString() and then Brewtarget::toDouble().
amount = tmp.toDouble(&ok);
if ( !ok ) {
Brewtarget::logW( QString("%1 could not convert %2 (%3:%4) to double")
.arg(Q_FUNC_INFO)
.arg(tmp.toString())
.arg(_section)
.arg(_editField) );
}

display = displayAmount(amount, precision);
}
Expand Down Expand Up @@ -260,7 +267,7 @@ void BtLineEdit::setText( QVariant amount, int precision)
int BtLineEdit::type() const { return (int)_type; }
QString BtLineEdit::editField() const { return _editField; }
QString BtLineEdit::configSection()
{
{
if ( _section.isEmpty() ) {
setConfigSection("");
}
Expand All @@ -270,8 +277,8 @@ QString BtLineEdit::configSection()

// Once we require >qt5.5, we can replace this noise with
// QMetaEnum::fromType()
QString BtLineEdit::forcedUnit() const
{
QString BtLineEdit::forcedUnit() const
{
const QMetaObject &mo = Unit::staticMetaObject;
int index = mo.indexOfEnumerator("unitDisplay");
QMetaEnum unitEnum = mo.enumerator(index);
Expand All @@ -280,7 +287,7 @@ QString BtLineEdit::forcedUnit() const
}

QString BtLineEdit::forcedScale() const
{
{
const QMetaObject &mo = Unit::staticMetaObject;
int index = mo.indexOfEnumerator("unitScale");
QMetaEnum scaleEnum = mo.enumerator(index);
Expand All @@ -292,29 +299,29 @@ void BtLineEdit::setType(int type) { _type = (Unit::UnitType)type;}
void BtLineEdit::setEditField( QString editField) { _editField = editField; }

// The cascade looks a little odd, but it is intentional.
void BtLineEdit::setConfigSection( QString configSection)
void BtLineEdit::setConfigSection( QString configSection)
{
_section = configSection;
_section = configSection;

if ( _section.isEmpty() )
_section = btParent->property("configSection").toString();

if ( _section.isEmpty() )
if ( _section.isEmpty() )
_section = btParent->objectName();
}

// previous comment about qt5.5 applies
void BtLineEdit::setForcedUnit( QString forcedUnit )
{
void BtLineEdit::setForcedUnit( QString forcedUnit )
{
const QMetaObject &mo = Unit::staticMetaObject;
int index = mo.indexOfEnumerator("unitDisplay");
QMetaEnum unitEnum = mo.enumerator(index);

_forceUnit = (Unit::unitDisplay)unitEnum.keyToValue(forcedUnit.toStdString().c_str());
}

void BtLineEdit::setForcedScale( QString forcedScale )
{
void BtLineEdit::setForcedScale( QString forcedScale )
{
const QMetaObject &mo = Unit::staticMetaObject;
int index = mo.indexOfEnumerator("unitScale");
QMetaEnum unitEnum = mo.enumerator(index);
Expand Down