From: dmv Date: Tue, 26 Aug 2008 07:28:41 +0000 (+0000) Subject: Bug IPAL20206 Qt4 porting: vectors are not displayed in 3D and hangup on edit X-Git-Tag: TG_TRIPOLI_qt4_porting~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f8ba9f5bad0f8f1113bb1fd3d1daf051fc4b82d2;p=modules%2Fgui.git Bug IPAL20206 Qt4 porting: vectors are not displayed in 3D and hangup on edit --- diff --git a/src/Qtx/QtxDoubleSpinBox.cxx b/src/Qtx/QtxDoubleSpinBox.cxx index 53d7822f2..4723f7bfe 100644 --- a/src/Qtx/QtxDoubleSpinBox.cxx +++ b/src/Qtx/QtxDoubleSpinBox.cxx @@ -22,6 +22,7 @@ #include "QtxDoubleSpinBox.h" #include +#include /*! \class QtxDoubleSpinBox @@ -57,12 +58,58 @@ */ QtxDoubleSpinBox::QtxDoubleSpinBox( QWidget* parent ) : QDoubleSpinBox( parent ), - myCleared( false ) + myCleared( false ), + myPrecision(0) { connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); } +QValidator::State QtxDoubleSpinBox::validate( QString& str, int& pos ) const +{ + if (myPrecision >= 0) + return QDoubleSpinBox::validate(str, pos); + + QString pref = this->prefix(); + QString suff = this->suffix(); + uint overhead = pref.length() + suff.length(); + QValidator::State state = QValidator::Invalid; + + QDoubleValidator v (NULL); + + if ( overhead == 0 ) + state = v.validate( str, pos ); + else + { + if ( str.length() >= overhead && str.startsWith( pref ) && + str.right( suff.length() ) == suff ) + { + QString core = str.mid( pref.length(), str.length() - overhead ); + int corePos = pos - pref.length(); + state = v.validate( core, corePos ); + pos = corePos + pref.length(); + str.replace( pref.length(), str.length() - overhead, core ); + } + else + { + state = v.validate( str, pos ); + if ( state == QValidator::Invalid ) + { + QString special = this->specialValueText().trimmed(); + QString candidate = str.trimmed(); + if ( special.startsWith( candidate ) ) + { + if ( candidate.length() == special.length() ) + state = QValidator::Acceptable; + else + state = QValidator::Intermediate; + } + } + } + } + return state; +} + /*! \brief Constructor. @@ -77,7 +124,8 @@ QtxDoubleSpinBox::QtxDoubleSpinBox( QWidget* parent ) */ QtxDoubleSpinBox::QtxDoubleSpinBox( double min, double max, double step, QWidget* parent ) : QDoubleSpinBox( parent ), - myCleared( false ) + myCleared( false ), + myPrecision( 0 ) { setMinimum( min ); setMaximum( max ); @@ -116,14 +164,33 @@ void QtxDoubleSpinBox::setCleared( const bool on ) setSpecialValueText( specialValueText() ); } -/*! - \brief Convert value to the text. - \param val value being converted - \return string containing the converted value -*/ +void QtxDoubleSpinBox::setPrecision( const int prec ) +{ + int newPrec = qMax( prec, 0 ); + int oldPrec = qMax( myPrecision, 0 ); + myPrecision = prec; + if ( newPrec != oldPrec ) + update(); +} + +int QtxDoubleSpinBox::getPrecision() const +{ + return myPrecision; +} + +double QtxDoubleSpinBox::valueFromText(const QString &text) const +{ + if (myPrecision < 0) + return text.toDouble(); + + return QDoubleSpinBox::valueFromText(text); +} + QString QtxDoubleSpinBox::textFromValue( double val ) const { - return removeTrailingZeroes( myCleared ? QString() : QDoubleSpinBox::textFromValue( val ) ); + QString s; + s.setNum( val, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : qAbs( myPrecision ) ); + return removeTrailingZeroes( s ); } /*! diff --git a/src/Qtx/QtxDoubleSpinBox.h b/src/Qtx/QtxDoubleSpinBox.h index fe180c2d2..5a6d58325 100644 --- a/src/Qtx/QtxDoubleSpinBox.h +++ b/src/Qtx/QtxDoubleSpinBox.h @@ -25,6 +25,7 @@ #include "Qtx.h" #include +#include class QTX_EXPORT QtxDoubleSpinBox : public QDoubleSpinBox { @@ -38,8 +39,14 @@ public: bool isCleared() const; virtual void setCleared( const bool ); + int getPrecision() const ; + void setPrecision( const int ); + virtual void stepBy( int ); + virtual double valueFromText(const QString &text) const; + virtual QValidator::State validate( QString& str, int& pos ) const; + private slots: virtual void onTextChanged( const QString& ); @@ -50,6 +57,7 @@ protected: private: bool myCleared; + int myPrecision; }; #endif