From de9b867670a1014d5409a1d1cddd93f13ff46d2d Mon Sep 17 00:00:00 2001 From: ouv Date: Sat, 1 Nov 2008 14:40:51 +0000 Subject: [PATCH] Dump Python Extension --- src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 57 +++++++++++++++++++---- src/SalomeApp/SalomeApp_DoubleSpinBox.h | 11 +++-- src/SalomeApp/SalomeApp_IntSpinBox.cxx | 19 ++++++-- src/SalomeApp/SalomeApp_IntSpinBox.h | 7 +-- 4 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index 6d5360156..8ff2b5e03 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -42,7 +42,10 @@ \param parent parent object */ SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( QWidget* parent ) -: QtxDoubleSpinBox( parent ) +: QtxDoubleSpinBox( parent ), + myDefaultValue( 0.0 ), + myMinimum( 0.0 ), + myMaximum( 99.99 ) { } @@ -59,7 +62,10 @@ SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( QWidget* parent ) \param parent parent object */ SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( double min, double max, double step, QWidget* parent ) -: QtxDoubleSpinBox( min, max, step, parent ) +: QtxDoubleSpinBox( min, max, step, parent ), + myDefaultValue( 0.0 ), + myMinimum( min ), + myMaximum( max ) { } @@ -76,7 +82,10 @@ SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( double min, double max, double \param parent parent object */ SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( double min, double max, double step, int prec, int dec, QWidget* parent ) -: QtxDoubleSpinBox( min, max, step, prec, dec, parent ) +: QtxDoubleSpinBox( min, max, step, prec, dec, parent ), + myDefaultValue( 0.0 ), + myMinimum( min ), + myMaximum( max ) { } @@ -102,7 +111,7 @@ double SalomeApp_DoubleSpinBox::valueFromText( const QString& text ) const str = QString::number( value ); int pos = 0; - if( QtxDoubleSpinBox::validate( str, pos ) == QValidator::Acceptable ) + if( checkRange( str ) && QtxDoubleSpinBox::validate( str, pos ) == QValidator::Acceptable ) value = QtxDoubleSpinBox::valueFromText( str ); else value = defaultValue(); @@ -147,7 +156,28 @@ bool SalomeApp_DoubleSpinBox::isValid() const str = QString::number( value ); int pos = 0; - return QtxDoubleSpinBox::validate( str, pos ) == QValidator::Acceptable; + return checkRange( str ) && QtxDoubleSpinBox::validate( str, pos ) == QValidator::Acceptable; +} + +/*! + \brief This function is used to set minimum and maximum values for this spinbox. + \param value default value +*/ +void SalomeApp_DoubleSpinBox::setRange( const double min, const double max ) +{ + QtxDoubleSpinBox::setRange( min, max ); + + myMinimum = min; + myMaximum = max; +} + +/*! + \brief This function is used to set a default value for this spinbox. + \param value default value +*/ +void SalomeApp_DoubleSpinBox::setDefaultValue( const double value ) +{ + myDefaultValue = value; } /*! @@ -156,10 +186,21 @@ bool SalomeApp_DoubleSpinBox::isValid() const */ double SalomeApp_DoubleSpinBox::defaultValue() const { - if( minimum() > 0 || maximum() < 0 ) - return minimum(); + if( myMinimum > myDefaultValue || myMaximum < myDefaultValue ) + return myMinimum; + + return myDefaultValue; +} - return 0.0; +/*! + \brief This function is used to check that string value lies within predefined range. + \return check status +*/ +bool SalomeApp_DoubleSpinBox::checkRange( const QString& str ) const +{ + bool ok = false; + double value = str.toDouble( &ok ); + return ok && value >= myMinimum && value <= myMaximum; } /*! diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.h b/src/SalomeApp/SalomeApp_DoubleSpinBox.h index 254370631..9f815ac3f 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.h +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.h @@ -43,15 +43,20 @@ public: virtual QValidator::State validate( QString&, int& ) const; - bool isValid() const; + virtual bool isValid() const; + + virtual void setDefaultValue( const double ); + virtual void setRange( double, double ); protected: double defaultValue() const; + bool checkRange( const QString& ) const; bool findVariable( const QString&, double& ) const; -private slots: - private: + double myMinimum; + double myMaximum; + double myDefaultValue; }; #endif diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.cxx b/src/SalomeApp/SalomeApp_IntSpinBox.cxx index f9614ef45..8b631dce1 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_IntSpinBox.cxx @@ -41,7 +41,8 @@ \param parent parent object */ SalomeApp_IntSpinBox::SalomeApp_IntSpinBox( QWidget* parent ) -: QtxIntSpinBox( parent ) +: QtxIntSpinBox( parent ), + myDefaultValue( 0 ) { } @@ -57,7 +58,8 @@ SalomeApp_IntSpinBox::SalomeApp_IntSpinBox( QWidget* parent ) \param parent parent object */ SalomeApp_IntSpinBox::SalomeApp_IntSpinBox( int min, int max, int step, QWidget* parent ) -: QtxIntSpinBox( min, max, step, parent ) +: QtxIntSpinBox( min, max, step, parent ), + myDefaultValue( 0 ) { } @@ -131,16 +133,25 @@ bool SalomeApp_IntSpinBox::isValid() const return QtxIntSpinBox::validate( str, pos ) == QValidator::Acceptable; } +/*! + \brief This function is used to set a default value for this spinbox. + \param value default value +*/ +void SalomeApp_IntSpinBox::setDefaultValue( const int value ) +{ + myDefaultValue = value; +} + /*! \brief This function return a default acceptable value (commonly, 0). \return default acceptable value */ int SalomeApp_IntSpinBox::defaultValue() const { - if( minimum() > 0 || maximum() < 0 ) + if( minimum() > myDefaultValue || maximum() < myDefaultValue ) return minimum(); - return 0; + return myDefaultValue; } /*! diff --git a/src/SalomeApp/SalomeApp_IntSpinBox.h b/src/SalomeApp/SalomeApp_IntSpinBox.h index 5c88a6e69..7ade2ced3 100644 --- a/src/SalomeApp/SalomeApp_IntSpinBox.h +++ b/src/SalomeApp/SalomeApp_IntSpinBox.h @@ -42,15 +42,16 @@ public: virtual QValidator::State validate( QString&, int& ) const; - bool isValid() const; + virtual bool isValid() const; + + virtual void setDefaultValue( const int ); protected: int defaultValue() const; bool findVariable( const QString&, int& ) const; -private slots: - private: + int myDefaultValue; }; #endif -- 2.39.2