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 Datum with control corresponding to spin box. This control used for integer numbers.
29 User can input data directly in spin box or can modify current value with given
34 Constructor. Create spin box datum object with datum identifier \aid under widget \aparent. Parameter \aflags
35 define behaviour of datum and set of created subwidgets. Default value of this parameter is QDS::All.
36 Parameter \acomp specify the component name which will be used during search of dictionary item.
38 QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
39 : QDS_Datum( id, parent, flags, comp )
46 QDS_SpinBox::~QDS_SpinBox()
51 Returns string from QSpinBox widget. Reimplemented.
53 QString QDS_SpinBox::getString() const
56 QtxIntSpinBox* aSpinBox = spinBox();
57 if ( aSpinBox && !aSpinBox->isCleared() )
59 res = aSpinBox->text();
60 if ( !aSpinBox->suffix().isEmpty() )
61 res.remove( res.find( aSpinBox->suffix() ), aSpinBox->suffix().length() );
62 if ( !aSpinBox->prefix().isEmpty() )
63 res.remove( res.find( aSpinBox->prefix() ), aSpinBox->prefix().length() );
69 Sets the string into QSpinBox widget. Reimplemented.
71 void QDS_SpinBox::setString( const QString& txt )
76 spinBox()->setCleared( txt.isEmpty() );
78 spinBox()->setValue( txt.toInt() );
82 Returns pointer to QSpinBox widget.
84 QtxIntSpinBox* QDS_SpinBox::spinBox() const
86 return ::qt_cast<QtxIntSpinBox*>( controlWidget() );
90 Create QSpinBox widget as control subwidget. Reimplemented.
92 QWidget* QDS_SpinBox::createControl( QWidget* parent )
94 QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent );
95 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96 connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
101 Notify about value changing in spin box.
103 void QDS_SpinBox::onValueChanged( int val )
106 QString str = QString::number( val );
108 emit paramChanged( str );
112 Sets the increment step.
114 void QDS_SpinBox::setStep( const int step )
117 spinBox()->setLineStep( step );
121 Returns the increment step.
123 int QDS_SpinBox::step() const
127 s = spinBox()->lineStep();
132 Notification about active unit system changing. Reimplemented from QDS_Datum.
133 Update validator and spin box parameters: suffix, prefix, minimum, maximum.
135 void QDS_SpinBox::unitSystemChanged( const QString& system )
137 QDS_Datum::unitSystemChanged( system );
139 QSpinBox* sb = spinBox();
142 delete sb->validator();
143 QValidator* valid = validator();
144 sb->setValidator( valid );
146 sb->setSuffix( suffix() );
147 sb->setPrefix( prefix() );
148 sb->setMinValue( minValue().toInt() );
149 sb->setMaxValue( maxValue().toInt() );