\param parent parent object
*/
SalomeApp_DoubleSpinBox::SalomeApp_DoubleSpinBox( QWidget* parent )
-: QtxDoubleSpinBox( parent )
+: QtxDoubleSpinBox( parent ),
+ myDefaultValue( 0.0 ),
+ myMinimum( 0.0 ),
+ myMaximum( 99.99 )
{
}
\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 )
{
}
\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 )
{
}
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();
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;
}
/*!
*/
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;
}
/*!
\param parent parent object
*/
SalomeApp_IntSpinBox::SalomeApp_IntSpinBox( QWidget* parent )
-: QtxIntSpinBox( parent )
+: QtxIntSpinBox( parent ),
+ myDefaultValue( 0 )
{
}
\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 )
{
}
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;
}
/*!