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/
19 #include "QDS_SpinBoxDbl.h"
21 #include <DDS_Dictionary.h>
23 #include <qvalidator.h>
25 #include <QtxDblSpinBox.h>
30 QDS_SpinBoxDbl::QDS_SpinBoxDbl( const QString& id, QWidget* parent, const int flags, const QString& comp )
31 : QDS_Datum( id, parent, flags, comp )
38 QDS_SpinBoxDbl::~QDS_SpinBoxDbl()
43 Returns string from QSpinBox widget.
45 QString QDS_SpinBoxDbl::getString() const
48 QtxDblSpinBox* sb = spinBox();
49 if ( sb && !sb->isCleared() )
51 bool hasFocus = sb->hasFocus();
56 if ( !sb->suffix().isEmpty() )
57 res.remove( res.find( sb->suffix() ), sb->suffix().length() );
58 if ( !sb->prefix().isEmpty() )
59 res.remove( res.find( sb->prefix() ), sb->prefix().length() );
69 Sets the string into QSpinBox widget.
71 void QDS_SpinBoxDbl::setString( const QString& txt )
76 spinBox()->setCleared( txt.isEmpty() );
78 spinBox()->setValue( txt.toDouble() );
82 Returns pointer to QtxDblSpinBox widget.
84 QtxDblSpinBox* QDS_SpinBoxDbl::spinBox() const
86 return ::qt_cast<QtxDblSpinBox*>( controlWidget() );
90 Create QSpinBox widget as control subwidget.
92 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
94 QtxDblSpinBox* aSpinBox = new QtxDblSpinBox( parent );
95 aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
96 connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
101 Notify about text changing in spin box.
103 void QDS_SpinBoxDbl::onValueChanged( double )
106 QString str = getString();
109 emit paramChanged( str );
113 Returns the increment step.
115 double QDS_SpinBoxDbl::step() const
119 s = spinBox()->lineStep();
124 Sets the increment step.
126 void QDS_SpinBoxDbl::setStep( const double step )
129 spinBox()->setLineStep( step );
132 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
134 QDS_Datum::unitSystemChanged( system );
136 QtxDblSpinBox* sb = spinBox();
140 delete sb->validator();
141 QValidator* valid = validator();
142 sb->setValidator( valid );
144 sb->setSuffix( suffix() );
145 sb->setPrefix( prefix() );
147 Standard_Integer aPreci = 1;
148 Handle(DDS_DicItem) aDicItem = dicItem();
149 if ( !aDicItem.IsNull() )
150 aPreci = aDicItem->GetPrecision();
152 sb->setPrecision( aPreci );
154 sb->setLineStep( .1 );
155 sb->setMinValue( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() );
156 sb->setMaxValue( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() );