Skip to content

Commit

Permalink
Issue#96 : enable default formatting in DoubleTextField
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoudot committed Mar 5, 2024
1 parent 49fd804 commit 8ceb786
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 13 additions & 5 deletions src/QtUtil/QtDoubleTextField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,17 @@ void QtDoubleTextField::setValue (double value)
} // if ((value < validator.bottom ( )) || (value > validator.top ( )))

// On évite de perdre des epsilons avec le format d'affichage par défaut des streams c++ :
UTF8String us;
us << (QDoubleValidator::StandardNotation == getNotation ( ) ? ios_base::fixed : ios_base::scientific);
us << IN_UTIL setprecision (validator.decimals ( )) << value;
setText (UTF8TOQSTRING (us));
if (_keepIosBaseDefault)
{
setText (QString::number(value));
}
else
{
UTF8String us;
us << (QDoubleValidator::StandardNotation == getNotation ( ) ? ios_base::fixed : ios_base::scientific);
us << IN_UTIL setprecision (validator.decimals ( )) << value;
setText (UTF8TOQSTRING (us));
}
getValue ( );
} // QtDoubleTextField::setValue

Expand Down Expand Up @@ -156,8 +163,9 @@ QDoubleValidator::Notation QtDoubleTextField::getNotation ( ) const
} // QtDoubleTextField::getNotation


void QtDoubleTextField::setNotation (QDoubleValidator::Notation notation)
void QtDoubleTextField::setNotation (QDoubleValidator::Notation notation, bool keepIosBaseDefault)
{
_keepIosBaseDefault = keepIosBaseDefault;
const QDoubleValidator& old = getValidator ( );
if (notation == old.notation ( ))
return;
Expand Down
4 changes: 3 additions & 1 deletion src/QtUtil/public/QtUtil/QtDoubleTextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class QtDoubleTextField : public QtValidatedTextField
/**
* @param La notation utilisée.
*/
virtual void setNotation (QDoubleValidator::Notation notation);
virtual void setNotation (QDoubleValidator::Notation notation, bool keepIosBaseDefault = false);


protected :
Expand Down Expand Up @@ -124,6 +124,8 @@ class QtDoubleTextField : public QtValidatedTextField

/** Opérateur de copie. Interdit. */
QtDoubleTextField& operator = (const QtDoubleTextField&);

bool _keepIosBaseDefault;
}; // class QtDoubleTextField


Expand Down

0 comments on commit 8ceb786

Please sign in to comment.