49 #include "QtLessAnnoyingDoubleSpinBox.hh" 53 QtLessAnnoyingDoubleSpinBox::QtLessAnnoyingDoubleSpinBox(QWidget* _qwidget ) : QDoubleSpinBox(_qwidget)
57 QValidator::State QtLessAnnoyingDoubleSpinBox::validate(QString& text,
int&)
const 59 QString copy = strip_prefix_suffix(text) +
"0";
64 return QValidator::Acceptable;
66 return QValidator::Invalid;
69 double QtLessAnnoyingDoubleSpinBox::valueFromText(
const QString &text)
const 71 QString copy = strip_prefix_suffix(text);
74 double value = copy.toDouble(&ok);
76 double factor = std::pow(10.0, decimals() );
77 value = double(
long(value *
double(factor) + 0.5) ) / factor;
85 QString QtLessAnnoyingDoubleSpinBox::strip_prefix_suffix(
const QString& text)
const 87 int lenpre = prefix().length();
88 int lensuf = suffix().length();
90 return text.mid( lenpre, text.length() - lenpre -lensuf ).simplified();