Commit 2785ce5e authored by SZPYRKA Jean-Luc's avatar SZPYRKA Jean-Luc

fixed some decimals pb

parent dcda50c4
...@@ -43,7 +43,7 @@ int main(int argc, char **argv) ...@@ -43,7 +43,7 @@ int main(int argc, char **argv)
qInfo() << "real_parameter (dbl)=" << value; qInfo() << "real_parameter (dbl)=" << value;
}); });
dtk::d_real scientific_parameter = 1.23456; dtk::d_real scientific_parameter = 8.654321;
scientific_parameter.setDocumentation("A real parameter."); scientific_parameter.setDocumentation("A real parameter.");
scientific_parameter.setDecimals(6); scientific_parameter.setDecimals(6);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
class dtkDoubleSpinBoxPrivate class dtkDoubleSpinBoxPrivate
{ {
public: public:
int decimals;
QDoubleValidator *validator; QDoubleValidator *validator;
bool scientific; bool scientific;
}; };
...@@ -26,8 +25,6 @@ dtkDoubleSpinBox::dtkDoubleSpinBox(QDoubleValidator::Notation notation, QWidget ...@@ -26,8 +25,6 @@ dtkDoubleSpinBox::dtkDoubleSpinBox(QDoubleValidator::Notation notation, QWidget
{ {
d = new dtkDoubleSpinBoxPrivate; d = new dtkDoubleSpinBoxPrivate;
d->decimals = 9;
d->validator = new QDoubleValidator(); d->validator = new QDoubleValidator();
d->validator->setNotation(notation); d->validator->setNotation(notation);
this->lineEdit()->setValidator(d->validator); this->lineEdit()->setValidator(d->validator);
...@@ -36,41 +33,39 @@ dtkDoubleSpinBox::dtkDoubleSpinBox(QDoubleValidator::Notation notation, QWidget ...@@ -36,41 +33,39 @@ dtkDoubleSpinBox::dtkDoubleSpinBox(QDoubleValidator::Notation notation, QWidget
this->setMaximum(std::numeric_limits<double>::max()); // instead of default 99.99 this->setMaximum(std::numeric_limits<double>::max()); // instead of default 99.99
this->setMaximum(std::numeric_limits<double>::lowest()); this->setMaximum(std::numeric_limits<double>::lowest());
this->setDecimals(d->decimals); this->setDecimals(12);
} }
dtkDoubleSpinBox::~dtkDoubleSpinBox(void) dtkDoubleSpinBox::~dtkDoubleSpinBox(void)
{ {
} }
int dtkDoubleSpinBox::decimals() const
{
return d->decimals;
}
void dtkDoubleSpinBox::setDecimals(int value)
{
qDebug() << Q_FUNC_INFO << "decimal = " << value;
d->decimals = value;
}
QString dtkDoubleSpinBox::textFromValue ( double value ) const QString dtkDoubleSpinBox::textFromValue ( double value ) const
{ {
QString strValue; QString strValue;
if (d->scientific) if (d->scientific)
strValue = QString::number(value, 'e', d->decimals); strValue = QString::number(value, 'e', this->decimals());
else else
strValue = QString::number(value, 'f', d->decimals); strValue = QString::number(value, 'f', this->decimals());
qDebug() << Q_FUNC_INFO << "value =" << value << "text =" << strValue; //qDebug() << Q_FUNC_INFO << "value =" << value << "text =" << strValue;
return strValue; return strValue;
} }
double dtkDoubleSpinBox::valueFromText ( const QString & text ) const double dtkDoubleSpinBox::valueFromText ( const QString & text ) const
{ {
double dblValue = text.toDouble(); bool ok;
qDebug() << Q_FUNC_INFO << "text =" << text << "value =" << dblValue; double dblValue = text.toDouble(&ok);
QString strValue;
if (d->scientific)
strValue = QString::number(dblValue, 'e', this->decimals());
else
strValue = QString::number(dblValue, 'f', this->decimals());
//qDebug() << Q_FUNC_INFO << "text =" << text << "value =" << strValue << "ok=" << ok;
return dblValue; return dblValue;
} }
...@@ -80,7 +75,7 @@ QValidator::State dtkDoubleSpinBox::validate(QString &text, int &pos) const ...@@ -80,7 +75,7 @@ QValidator::State dtkDoubleSpinBox::validate(QString &text, int &pos) const
bool input_check; bool input_check;
text.toDouble(&input_check); text.toDouble(&input_check);
qDebug() << Q_FUNC_INFO << "text =" << text << "pos =" << pos << "validate =" << input_check; //qDebug() << Q_FUNC_INFO << "text =" << text << "pos =" << pos << "validate =" << input_check;
return (input_check ? QValidator::Acceptable : QValidator::Invalid); return (input_check ? QValidator::Acceptable : QValidator::Invalid);
} }
......
...@@ -33,11 +33,8 @@ public: ...@@ -33,11 +33,8 @@ public:
~dtkDoubleSpinBox(void); ~dtkDoubleSpinBox(void);
public: public:
int decimals() const;
void setDecimals(int);
QString textFromValue ( double ) const; QString textFromValue ( double ) const;
double valueFromText ( const QString& ) const; double valueFromText ( const QString& ) const;
QValidator::State validate(QString&, int&) const; QValidator::State validate(QString&, int&) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment