1 // Copyright (C) 2007-2015 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_SpinBoxDbl.h"
25 #include <QtxDoubleSpinBox.h>
29 \brief Datum with control corresponding to spin box.
31 This control is suitable for double 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_SpinBoxDbl::QDS_SpinBoxDbl( const QString& id, QWidget* parent, const int flags, const QString& comp )
52 : QDS_Datum( id, parent, flags, comp )
59 QDS_SpinBoxDbl::~QDS_SpinBoxDbl()
64 \brief Get string from the spin box.
67 QString QDS_SpinBoxDbl::getString() const
70 QtxDoubleSpinBox* sb = spinBox();
71 if ( sb && !sb->isCleared() )
73 /*bool hasFocus = sb->hasFocus();
78 if ( !sb->suffix().isEmpty() )
79 res.remove( res.indexOf( sb->suffix() ), sb->suffix().length() );
80 if ( !sb->prefix().isEmpty() )
81 res.remove( res.indexOf( sb->prefix() ), sb->prefix().length() );
91 \brief Set the string value to the spin box widget.
92 \param txt string value
94 void QDS_SpinBoxDbl::setString( const QString& txt )
99 spinBox()->setCleared( txt.isEmpty() );
100 if ( !txt.isEmpty() )
101 spinBox()->setValue( txt.toDouble() );
105 \brief Get spin box widget.
106 \return internal spin box widget.
108 QtxDoubleSpinBox* QDS_SpinBoxDbl::spinBox() const
110 return ::qobject_cast<QtxDoubleSpinBox*>( controlWidget() );
114 \brief Create internal spin box as control widget.
115 \param parent parent widget
116 \return created spin box widget
118 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
120 QtxDoubleSpinBox* aSpinBox = new QtxDoubleSpinBox( parent );
121 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
122 connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
127 \brief Called when value in the spin box is changed.
129 Emit signals to notify about value changing in the spin box.
131 \param val current spin box value
133 void QDS_SpinBoxDbl::onValueChanged( double )
136 QString str = getString();
139 emit paramChanged( str );
143 \brief Get the spin box increment value.
144 \return current increment value
146 double QDS_SpinBoxDbl::step() const
150 s = spinBox()->singleStep();
155 \brief Set the spin box increment value.
156 \param step new increment value
158 void QDS_SpinBoxDbl::setStep( const double step )
161 spinBox()->setSingleStep( step );
165 \brief Process notification about active units system changing.
167 Update spin box contents according to the data dictionary item properties: suffix, prefix, minimum, maximum
169 \param system new active units system
171 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
173 QDS_Datum::unitSystemChanged( system );
175 QtxDoubleSpinBox* sb = spinBox();
179 // not porting this code to qt4, only commented, since from the task context
180 // the new setted validator accepts any double
181 //delete sb->validator();
182 //QValidator* valid = validator();
183 //sb->setValidator( valid );
185 sb->setSuffix( suffix() );
186 sb->setPrefix( prefix() );
188 Standard_Integer aPreci = 1;
189 Handle(DDS_DicItem) aDicItem = dicItem();
190 if ( !aDicItem.IsNull() )
191 aPreci = aDicItem->GetPrecision();
193 sb->setDecimals( aPreci );
195 sb->setSingleStep( .1 );
196 sb->setMinimum( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() );
197 sb->setMaximum( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() );