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_SpinBoxDbl.h"
24 #include <QtxDoubleSpinBox.h>
28 \brief Datum with control corresponding to spin box.
30 This control is suitable for double 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_SpinBoxDbl::QDS_SpinBoxDbl( const QString& id, QWidget* parent, const int flags, const QString& comp )
51 : QDS_Datum( id, parent, flags, comp )
58 QDS_SpinBoxDbl::~QDS_SpinBoxDbl()
63 \brief Get string from the spin box.
66 QString QDS_SpinBoxDbl::getString() const
69 QtxDoubleSpinBox* sb = spinBox();
70 if ( sb && !sb->isCleared() )
72 bool hasFocus = sb->hasFocus();
77 if ( !sb->suffix().isEmpty() )
78 res.remove( res.indexOf( sb->suffix() ), sb->suffix().length() );
79 if ( !sb->prefix().isEmpty() )
80 res.remove( res.indexOf( sb->prefix() ), sb->prefix().length() );
90 \brief Set the string value to the spin box widget.
91 \param txt string value
93 void QDS_SpinBoxDbl::setString( const QString& txt )
98 spinBox()->setCleared( txt.isEmpty() );
100 spinBox()->setValue( txt.toDouble() );
104 \brief Get spin box widget.
105 \return internal spin box widget.
107 QtxDoubleSpinBox* QDS_SpinBoxDbl::spinBox() const
109 return ::qobject_cast<QtxDoubleSpinBox*>( controlWidget() );
113 \brief Create internal spin box as control widget.
114 \param parent parent widget
115 \return created spin box widget
117 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
119 QtxDoubleSpinBox* aSpinBox = new QtxDoubleSpinBox( parent );
120 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
121 connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
126 \brief Called when value in the spin box is changed.
128 Emit signals to notify about value changing in the spin box.
130 \param val current spin box value
132 void QDS_SpinBoxDbl::onValueChanged( double )
135 QString str = getString();
138 emit paramChanged( str );
142 \brief Get the spin box increment value.
143 \return current increment value
145 double QDS_SpinBoxDbl::step() const
149 s = spinBox()->singleStep();
154 \brief Set the spin box increment value.
155 \param step new increment value
157 void QDS_SpinBoxDbl::setStep( const double step )
160 spinBox()->setSingleStep( step );
164 \brief Process notification about active units system changing.
166 Update spin box contents according to the data dictionary item properties: suffix, prefix, minimum, maximum
168 \param system new active units system
170 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
172 QDS_Datum::unitSystemChanged( system );
174 QtxDoubleSpinBox* sb = spinBox();
178 // not porting this code to qt4, only commented, since from the task context
179 // the new setted validator accepts any double
180 //delete sb->validator();
181 //QValidator* valid = validator();
182 //sb->setValidator( valid );
184 sb->setSuffix( suffix() );
185 sb->setPrefix( prefix() );
187 Standard_Integer aPreci = 1;
188 Handle(DDS_DicItem) aDicItem = dicItem();
189 if ( !aDicItem.IsNull() )
190 aPreci = aDicItem->GetPrecision();
192 sb->setDecimals( aPreci );
194 sb->setSingleStep( .1 );
195 sb->setMinimum( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() );
196 sb->setMaximum( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() );