1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "QDS_SpinBox.h"
21 #include <QtxIntSpinBox.h>
23 #include <qvalidator.h>
28 QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
29 : QDS_Datum( id, parent, flags, comp )
36 QDS_SpinBox::~QDS_SpinBox()
41 Returns string from QSpinBox widget.
43 QString QDS_SpinBox::getString() const
46 QtxIntSpinBox* aSpinBox = spinBox();
47 if ( aSpinBox && !aSpinBox->isCleared() )
49 res = aSpinBox->text();
50 if ( !aSpinBox->suffix().isEmpty() )
51 res.remove( res.find( aSpinBox->suffix() ), aSpinBox->suffix().length() );
52 if ( !aSpinBox->prefix().isEmpty() )
53 res.remove( res.find( aSpinBox->prefix() ), aSpinBox->prefix().length() );
59 Sets the string into QSpinBox widget.
61 void QDS_SpinBox::setString( const QString& txt )
66 spinBox()->setCleared( txt.isEmpty() );
68 spinBox()->setValue( txt.toInt() );
72 Returns pointer to QSpinBox widget.
74 QtxIntSpinBox* QDS_SpinBox::spinBox() const
76 return ::qt_cast<QtxIntSpinBox*>( controlWidget() );
80 Create QSpinBox widget as control subwidget.
82 QWidget* QDS_SpinBox::createControl( QWidget* parent )
84 QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent );
85 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
86 connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
91 Notify about text changing in spin box.
93 void QDS_SpinBox::onValueChanged( int val )
96 QString str = QString::number( val );
98 emit paramChanged( str );
102 Sets the increment step.
104 void QDS_SpinBox::setStep( const int step )
107 spinBox()->setLineStep( step );
111 Returns the increment step.
113 int QDS_SpinBox::step() const
117 s = spinBox()->lineStep();
122 This method is redefined from ancestor class to perform own initialization ( suffix, prefix, etc ).
124 void QDS_SpinBox::unitSystemChanged( const QString& system )
126 QDS_Datum::unitSystemChanged( system );
128 QSpinBox* sb = spinBox();
131 delete sb->validator();
132 QValidator* valid = validator();
133 sb->setValidator( valid );
135 sb->setSuffix( suffix() );
136 sb->setPrefix( prefix() );
137 sb->setMinValue( minValue().toInt() );
138 sb->setMaxValue( maxValue().toInt() );