Skip to content

Commit

Permalink
Merge pull request #5 from LIHPC-Computational-Geometry/Issue#96
Browse files Browse the repository at this point in the history
Issue#96 : enable default formatting in DoubleTextField
  • Loading branch information
CharlesPignerol authored Mar 6, 2024
2 parents 49fd804 + 877af78 commit 8af0768
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/QtUtil/QtDoubleTextField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ USE_ENCODING_AUTODETECTION

QtDoubleTextField::QtDoubleTextField (QWidget* parent, bool autoValidation, const char* name)
: QtValidatedTextField (parent, autoValidation, name)
, _keepIosBaseDefault(false)
{
createGui ( );
} // QtDoubleTextField::QtDoubleTextField


QtDoubleTextField::QtDoubleTextField (double value, QWidget* parent, bool autoValidation, const char* name)
: QtValidatedTextField (parent, autoValidation, name)
, _keepIosBaseDefault(false)
{
createGui ( );
setValue (value);
} // QtDoubleTextField::QtDoubleTextField


QtDoubleTextField::QtDoubleTextField (const QtDoubleTextField&)
QtDoubleTextField::QtDoubleTextField (const QtDoubleTextField& field)
: QtValidatedTextField (0, 0)
, _keepIosBaseDefault(field._keepIosBaseDefault)
{
assert (0 && "QtDoubleTextField::QtDoubleTextField is not allowed.");
} // QtDoubleTextField::QtDoubleTextField (const QtDoubleTextField&)
Expand Down Expand Up @@ -102,10 +105,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 +166,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 8af0768

Please sign in to comment.