Back to index

salome-gui  6.5.0
QDS_SpinBoxDbl.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "QDS_SpinBoxDbl.h"
00024 
00025 #include <QtxDoubleSpinBox.h>
00026 
00027 /*
00028   \class QDS_SpinBoxDbl
00029   \brief Datum with control corresponding to spin box.
00030   
00031   This control is suitable for double numbers. User can input data directly in the spin box
00032   or can modify current value by clicking arrow (+/-) buttons.
00033 */
00034 
00051 QDS_SpinBoxDbl::QDS_SpinBoxDbl( const QString& id, QWidget* parent, const int flags, const QString& comp )
00052 : QDS_Datum( id, parent, flags, comp )
00053 {
00054 }
00055 
00059 QDS_SpinBoxDbl::~QDS_SpinBoxDbl()
00060 {
00061 }
00062 
00067 QString QDS_SpinBoxDbl::getString() const
00068 {
00069   QString res;
00070   QtxDoubleSpinBox* sb = spinBox();
00071   if ( sb && !sb->isCleared() )
00072   {
00073     /*bool hasFocus = sb->hasFocus();
00074     if ( hasFocus )
00075       sb->clearFocus();*/
00076     
00077     res = sb->text();
00078     if ( !sb->suffix().isEmpty() )
00079       res.remove( res.indexOf( sb->suffix() ), sb->suffix().length() );
00080     if ( !sb->prefix().isEmpty() )
00081       res.remove( res.indexOf( sb->prefix() ), sb->prefix().length() );
00082     
00083     /*if ( hasFocus )
00084       sb->setFocus();*/
00085   }
00086 
00087   return res;
00088 }
00089 
00094 void QDS_SpinBoxDbl::setString( const QString& txt )
00095 {
00096   if ( !spinBox() )
00097     return;
00098 
00099   spinBox()->setCleared( txt.isEmpty() );
00100   if ( !txt.isEmpty() )
00101     spinBox()->setValue( txt.toDouble() );
00102 }
00103 
00108 QtxDoubleSpinBox* QDS_SpinBoxDbl::spinBox() const
00109 {
00110   return ::qobject_cast<QtxDoubleSpinBox*>( controlWidget() );
00111 }
00112 
00118 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
00119 {
00120   QtxDoubleSpinBox* aSpinBox = new QtxDoubleSpinBox( parent );
00121   aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00122   connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
00123   return aSpinBox;
00124 }
00125 
00133 void QDS_SpinBoxDbl::onValueChanged( double )
00134 {
00135   onParamChanged();
00136   QString str = getString();
00137 
00138   emit paramChanged();
00139   emit paramChanged( str );
00140 }
00141 
00146 double QDS_SpinBoxDbl::step() const
00147 {
00148   double s = 0;
00149   if ( spinBox() )
00150     s = spinBox()->singleStep();
00151   return s;
00152 }
00153 
00158 void QDS_SpinBoxDbl::setStep( const double step )
00159 {
00160   if ( spinBox() )
00161     spinBox()->setSingleStep( step );
00162 }
00163 
00171 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
00172 {
00173   QDS_Datum::unitSystemChanged( system );
00174 
00175   QtxDoubleSpinBox* sb = spinBox();
00176   if ( !sb )
00177     return;
00178 
00179   // not porting this code to qt4, only commented, since from the task context
00180   // the new setted validator accepts any double
00181   //delete sb->validator();
00182   //QValidator* valid = validator();
00183   //sb->setValidator( valid );
00184 
00185   sb->setSuffix( suffix() );
00186   sb->setPrefix( prefix() );
00187 
00188   Standard_Integer aPreci = 1;
00189   Handle(DDS_DicItem) aDicItem = dicItem();
00190   if ( !aDicItem.IsNull() )
00191     aPreci = aDicItem->GetPrecision();
00192 
00193   sb->setDecimals( aPreci );
00194 
00195   sb->setSingleStep( .1 );
00196   sb->setMinimum( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() );
00197   sb->setMaximum( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() );
00198 }