Skip to content

Commit 8af0768

Browse files
Merge pull request #5 from LIHPC-Computational-Geometry/Issue#96
Issue#96 : enable default formatting in DoubleTextField
2 parents 49fd804 + 877af78 commit 8af0768

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/QtUtil/QtDoubleTextField.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,24 @@ USE_ENCODING_AUTODETECTION
1919

2020
QtDoubleTextField::QtDoubleTextField (QWidget* parent, bool autoValidation, const char* name)
2121
: QtValidatedTextField (parent, autoValidation, name)
22+
, _keepIosBaseDefault(false)
2223
{
2324
createGui ( );
2425
} // QtDoubleTextField::QtDoubleTextField
2526

2627

2728
QtDoubleTextField::QtDoubleTextField (double value, QWidget* parent, bool autoValidation, const char* name)
2829
: QtValidatedTextField (parent, autoValidation, name)
30+
, _keepIosBaseDefault(false)
2931
{
3032
createGui ( );
3133
setValue (value);
3234
} // QtDoubleTextField::QtDoubleTextField
3335

3436

35-
QtDoubleTextField::QtDoubleTextField (const QtDoubleTextField&)
37+
QtDoubleTextField::QtDoubleTextField (const QtDoubleTextField& field)
3638
: QtValidatedTextField (0, 0)
39+
, _keepIosBaseDefault(field._keepIosBaseDefault)
3740
{
3841
assert (0 && "QtDoubleTextField::QtDoubleTextField is not allowed.");
3942
} // QtDoubleTextField::QtDoubleTextField (const QtDoubleTextField&)
@@ -102,10 +105,17 @@ void QtDoubleTextField::setValue (double value)
102105
} // if ((value < validator.bottom ( )) || (value > validator.top ( )))
103106

104107
// On évite de perdre des epsilons avec le format d'affichage par défaut des streams c++ :
105-
UTF8String us;
106-
us << (QDoubleValidator::StandardNotation == getNotation ( ) ? ios_base::fixed : ios_base::scientific);
107-
us << IN_UTIL setprecision (validator.decimals ( )) << value;
108-
setText (UTF8TOQSTRING (us));
108+
if (_keepIosBaseDefault)
109+
{
110+
setText (QString::number(value));
111+
}
112+
else
113+
{
114+
UTF8String us;
115+
us << (QDoubleValidator::StandardNotation == getNotation ( ) ? ios_base::fixed : ios_base::scientific);
116+
us << IN_UTIL setprecision (validator.decimals ( )) << value;
117+
setText (UTF8TOQSTRING (us));
118+
}
109119
getValue ( );
110120
} // QtDoubleTextField::setValue
111121

@@ -156,8 +166,9 @@ QDoubleValidator::Notation QtDoubleTextField::getNotation ( ) const
156166
} // QtDoubleTextField::getNotation
157167

158168

159-
void QtDoubleTextField::setNotation (QDoubleValidator::Notation notation)
169+
void QtDoubleTextField::setNotation (QDoubleValidator::Notation notation, bool keepIosBaseDefault)
160170
{
171+
_keepIosBaseDefault = keepIosBaseDefault;
161172
const QDoubleValidator& old = getValidator ( );
162173
if (notation == old.notation ( ))
163174
return;

src/QtUtil/public/QtUtil/QtDoubleTextField.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class QtDoubleTextField : public QtValidatedTextField
9090
/**
9191
* @param La notation utilisée.
9292
*/
93-
virtual void setNotation (QDoubleValidator::Notation notation);
93+
virtual void setNotation (QDoubleValidator::Notation notation, bool keepIosBaseDefault = false);
9494

9595

9696
protected :
@@ -124,6 +124,8 @@ class QtDoubleTextField : public QtValidatedTextField
124124

125125
/** Opérateur de copie. Interdit. */
126126
QtDoubleTextField& operator = (const QtDoubleTextField&);
127+
128+
bool _keepIosBaseDefault;
127129
}; // class QtDoubleTextField
128130

129131

0 commit comments

Comments
 (0)