1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
23 #include "QDS_SpinBox.h"
25 #include <QtxIntSpinBox.h>
29 \brief Datum with control corresponding to spin box.
31 This control used for integer numbers. User can input data directly in the spin box
32 or can modify current value by clicking arrow (+/-) buttons.
38 Create spin box datum object with datum identifier \a id and parent widget \a parent.
40 Parameter \a flags defines behaviour of datum and set of created
41 subwidgets. Default value of this parameter is QDS::All.
43 Parameter \a comp specifies the component name which will be used
44 when searching the dictionary item.
46 \param id datum identifier
47 \param parent parent widget
48 \param flags datum flags
51 QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
52 : QDS_Datum( id, parent, flags, comp )
59 QDS_SpinBox::~QDS_SpinBox()
64 \brief Get string from the spin box.
67 QString QDS_SpinBox::getString() const
70 QtxIntSpinBox* aSpinBox = spinBox();
71 if ( aSpinBox && !aSpinBox->isCleared() )
73 res = aSpinBox->text();
74 if ( !aSpinBox->suffix().isEmpty() )
75 res.remove( res.indexOf( aSpinBox->suffix() ), aSpinBox->suffix().length() );
76 if ( !aSpinBox->prefix().isEmpty() )
77 res.remove( res.indexOf( aSpinBox->prefix() ), aSpinBox->prefix().length() );
83 \brief Set the string value to the spin box widget.
84 \param txt string value
86 void QDS_SpinBox::setString( const QString& txt )
91 spinBox()->setCleared( txt.isEmpty() );
93 spinBox()->setValue( txt.toInt() );
97 \brief Get spin box widget.
98 \return internal spin box widget.
100 QtxIntSpinBox* QDS_SpinBox::spinBox() const
102 return ::qobject_cast<QtxIntSpinBox*>( controlWidget() );
106 \brief Create internal spin box as control widget.
107 \param parent parent widget
108 \return created spin box widget
110 QWidget* QDS_SpinBox::createControl( QWidget* parent )
112 QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent );
113 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
114 connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
119 \brief Called when value in the spin box is changed.
121 Emit signals to notify about value changing in the spin box.
123 \param val current spin box value
125 void QDS_SpinBox::onValueChanged( int val )
128 QString str = QString::number( val );
130 emit paramChanged( str );
134 \brief Set the spin box increment value.
135 \param step new increment value
137 void QDS_SpinBox::setStep( const int step )
140 spinBox()->setSingleStep( step );
144 \brief Get the spin box increment value.
145 \return current increment value
147 int QDS_SpinBox::step() const
151 s = spinBox()->singleStep();
156 \brief Process notification about active units system changing.
158 Update spin box contents according to the data dictionary item properties: suffix, prefix, minimum, maximum
160 \param system new active units system
162 void QDS_SpinBox::unitSystemChanged( const QString& system )
164 QDS_Datum::unitSystemChanged( system );
166 QSpinBox* sb = spinBox();
169 // not porting this code to qt4, only commented, since from the task context
170 // the new setted validator accepts all integers
171 //delete sb->validator();
172 //QValidator* valid = validator();
173 //sb->setValidator( valid );
175 sb->setSuffix( suffix() );
176 sb->setPrefix( prefix() );
177 sb->setMinimum( minValue().isEmpty() ? -INT_MAX : minValue().toInt() );
178 sb->setMaximum( maxValue().isEmpty() ? INT_MAX : maxValue().toInt() );