Skip to content

Commit 8ceb786

Browse files
committed
Issue#96 : enable default formatting in DoubleTextField
1 parent 49fd804 commit 8ceb786

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/QtUtil/QtDoubleTextField.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ void QtDoubleTextField::setValue (double value)
102102
} // if ((value < validator.bottom ( )) || (value > validator.top ( )))
103103

104104
// 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));
105+
if (_keepIosBaseDefault)
106+
{
107+
setText (QString::number(value));
108+
}
109+
else
110+
{
111+
UTF8String us;
112+
us << (QDoubleValidator::StandardNotation == getNotation ( ) ? ios_base::fixed : ios_base::scientific);
113+
us << IN_UTIL setprecision (validator.decimals ( )) << value;
114+
setText (UTF8TOQSTRING (us));
115+
}
109116
getValue ( );
110117
} // QtDoubleTextField::setValue
111118

@@ -156,8 +163,9 @@ QDoubleValidator::Notation QtDoubleTextField::getNotation ( ) const
156163
} // QtDoubleTextField::getNotation
157164

158165

159-
void QtDoubleTextField::setNotation (QDoubleValidator::Notation notation)
166+
void QtDoubleTextField::setNotation (QDoubleValidator::Notation notation, bool keepIosBaseDefault)
160167
{
168+
_keepIosBaseDefault = keepIosBaseDefault;
161169
const QDoubleValidator& old = getValidator ( );
162170
if (notation == old.notation ( ))
163171
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)