1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "QDS_SpinBox.h"
24 #include <QtxIntSpinBox.h>
28 \brief Datum with control corresponding to spin box.
30 This control used for integer numbers. User can input data directly in the spin box
31 or can modify current value by clicking arrow (+/-) buttons.
37 Create spin box datum object with datum identifier \a id and parent widget \a parent.
39 Parameter \a flags defines behaviour of datum and set of created
40 subwidgets. Default value of this parameter is QDS::All.
42 Parameter \a comp specifies the component name which will be used
43 when searching the dictionary item.
45 \param id datum identifier
46 \param parent parent widget
47 \param flags datum flags
50 QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
51 : QDS_Datum( id, parent, flags, comp )
58 QDS_SpinBox::~QDS_SpinBox()
63 \brief Get string from the spin box.
66 QString QDS_SpinBox::getString() const
69 QtxIntSpinBox* aSpinBox = spinBox();
70 if ( aSpinBox && !aSpinBox->isCleared() )
72 res = aSpinBox->text();
73 if ( !aSpinBox->suffix().isEmpty() )
74 res.remove( res.indexOf( aSpinBox->suffix() ), aSpinBox->suffix().length() );
75 if ( !aSpinBox->prefix().isEmpty() )
76 res.remove( res.indexOf( aSpinBox->prefix() ), aSpinBox->prefix().length() );
82 \brief Set the string value to the spin box widget.
83 \param txt string value
85 void QDS_SpinBox::setString( const QString& txt )
90 spinBox()->setCleared( txt.isEmpty() );
92 spinBox()->setValue( txt.toInt() );
96 \brief Get spin box widget.
97 \return internal spin box widget.
99 QtxIntSpinBox* QDS_SpinBox::spinBox() const
101 return ::qobject_cast<QtxIntSpinBox*>( controlWidget() );
105 \brief Create internal spin box as control widget.
106 \param parent parent widget
107 \return created spin box widget
109 QWidget* QDS_SpinBox::createControl( QWidget* parent )
111 QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent );
112 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
113 connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
118 \brief Called when value in the spin box is changed.
120 Emit signals to notify about value changing in the spin box.
122 \param val current spin box value
124 void QDS_SpinBox::onValueChanged( int val )
127 QString str = QString::number( val );
129 emit paramChanged( str );
133 \brief Set the spin box increment value.
134 \param step new increment value
136 void QDS_SpinBox::setStep( const int step )
139 spinBox()->setSingleStep( step );
143 \brief Get the spin box increment value.
144 \return current increment value
146 int QDS_SpinBox::step() const
150 s = spinBox()->singleStep();
155 \brief Process notification about active units system changing.
157 Update spin box contents according to the data dictionary item properties: suffix, prefix, minimum, maximum
159 \param system new active units system
161 void QDS_SpinBox::unitSystemChanged( const QString& system )
163 QDS_Datum::unitSystemChanged( system );
165 QSpinBox* sb = spinBox();
168 // not porting this code to qt4, only commented, since from the task context
169 // the new setted validator accepts all integers
170 //delete sb->validator();
171 //QValidator* valid = validator();
172 //sb->setValidator( valid );
174 sb->setSuffix( suffix() );
175 sb->setPrefix( prefix() );
176 sb->setMinimum( minValue().isEmpty() ? -INT_MAX : minValue().toInt() );
177 sb->setMaximum( maxValue().isEmpty() ? INT_MAX : maxValue().toInt() );