/** * @author Ian Johnson * @version 1.0 */ #ifndef SLSQTVALIDATORS_H #define SLSQTVALIDATORS_H #ifndef IAN typedef double double32_t; typedef float float32_t; typedef int int32_t; #endif #include #include #include #include using std::cout; using std::endl; class SlsQtIntValidator:public QIntValidator{ public: SlsQtIntValidator(QWidget *parent):QIntValidator(parent){} virtual void fixup (QString& text) const { bool ok = 1; int v = text.toInt(&ok); if(!ok){ v = text.toDouble(&ok); if(ok) text = QString::number(v); else text = QString::number(0); fixup(text); } if(vtop()) text = QString::number(top()); } }; class SlsQtDoubleValidator:public QDoubleValidator{ public: SlsQtDoubleValidator(QWidget *parent):QDoubleValidator(parent){} virtual void fixup (QString& text) const { bool ok = 1; double v = text.toDouble(&ok); if(!ok){ text = QString::number(0); fixup(text); } int nd = this->decimals(); //ndigest behind zero if(vtop()){ v = floor(top()*pow(10,nd))/pow(10,nd); text = QString::number(v,'g'); }else{ v = round(v*pow(10,nd))/pow(10,nd); text = QString::number(v,'g'); } } } }; #endif