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_SpinBoxDbl.h"
21 #include <DDS_Dictionary.h>
23 #include <qvalidator.h>
25 #include <QtxDblSpinBox.h>
30 Datum with control corresponding to spin box. This control used for double numbers.
31 User can input data directly in spin box or can modify current value with given
36 Constructor. Create spin box datum object with datum identifier \aid under widget \aparent. Parameter \aflags
37 define behaviour of datum and set of created subwidgets. Default value of this parameter is QDS::All.
38 Parameter \acomp specify the component name which will be used during search of dictionary item.
40 QDS_SpinBoxDbl::QDS_SpinBoxDbl( const QString& id, QWidget* parent, const int flags, const QString& comp )
41 : QDS_Datum( id, parent, flags, comp )
48 QDS_SpinBoxDbl::~QDS_SpinBoxDbl()
53 Returns string from QSpinBox widget. Reimplemented.
55 QString QDS_SpinBoxDbl::getString() const
58 QtxDblSpinBox* sb = spinBox();
59 if ( sb && !sb->isCleared() )
61 bool hasFocus = sb->hasFocus();
66 if ( !sb->suffix().isEmpty() )
67 res.remove( res.find( sb->suffix() ), sb->suffix().length() );
68 if ( !sb->prefix().isEmpty() )
69 res.remove( res.find( sb->prefix() ), sb->prefix().length() );
79 Sets the string into QSpinBox widget. Reimplemented.
81 void QDS_SpinBoxDbl::setString( const QString& txt )
86 spinBox()->setCleared( txt.isEmpty() );
88 spinBox()->setValue( txt.toDouble() );
92 Returns pointer to QtxDblSpinBox widget.
94 QtxDblSpinBox* QDS_SpinBoxDbl::spinBox() const
96 return ::qt_cast<QtxDblSpinBox*>( controlWidget() );
100 Create QSpinBox widget as control subwidget. Reimplemented.
102 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
104 QtxDblSpinBox* aSpinBox = new QtxDblSpinBox( parent );
105 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106 connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
111 Notify about value changing in spin box.
113 void QDS_SpinBoxDbl::onValueChanged( double )
116 QString str = getString();
119 emit paramChanged( str );
123 Returns the increment step.
125 double QDS_SpinBoxDbl::step() const
129 s = spinBox()->lineStep();
134 Sets the increment step.
136 void QDS_SpinBoxDbl::setStep( const double step )
139 spinBox()->setLineStep( step );
143 Notification about active unit system changing. Reimplemented from QDS_Datum.
144 Update validator and spin box parameters: suffix, prefix, minimum, maximum.
146 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
148 QDS_Datum::unitSystemChanged( system );
150 QtxDblSpinBox* sb = spinBox();
154 delete sb->validator();
155 QValidator* valid = validator();
156 sb->setValidator( valid );
158 sb->setSuffix( suffix() );
159 sb->setPrefix( prefix() );
161 Standard_Integer aPreci = 1;
162 Handle(DDS_DicItem) aDicItem = dicItem();
163 if ( !aDicItem.IsNull() )
164 aPreci = aDicItem->GetPrecision();
166 sb->setPrecision( aPreci );
168 sb->setLineStep( .1 );
169 sb->setMinValue( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() );
170 sb->setMaxValue( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() );