Back to index

salome-gui  6.5.0
QDS_SpinBox.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_SpinBox.h"
00024 
00025 #include <QtxIntSpinBox.h>
00026 
00027 /*
00028   \class QDS_SpinBox
00029   \brief Datum with control corresponding to spin box.
00030 
00031   This control used for integer numbers. User can input data directly in the spin box
00032   or can modify current value by clicking arrow (+/-) buttons.
00033 */
00034 
00051 QDS_SpinBox::QDS_SpinBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
00052 : QDS_Datum( id, parent, flags, comp )
00053 {
00054 }
00055 
00059 QDS_SpinBox::~QDS_SpinBox()
00060 {
00061 }
00062 
00067 QString QDS_SpinBox::getString() const
00068 {
00069   QString res;
00070   QtxIntSpinBox* aSpinBox = spinBox();
00071   if ( aSpinBox && !aSpinBox->isCleared() )
00072   {
00073     res = aSpinBox->text();
00074     if ( !aSpinBox->suffix().isEmpty() )
00075       res.remove( res.indexOf( aSpinBox->suffix() ), aSpinBox->suffix().length() );
00076     if ( !aSpinBox->prefix().isEmpty() )
00077       res.remove( res.indexOf( aSpinBox->prefix() ), aSpinBox->prefix().length() );
00078   }
00079   return res;
00080 }
00081 
00086 void QDS_SpinBox::setString( const QString& txt )
00087 {
00088   if ( !spinBox() )
00089     return;
00090 
00091   spinBox()->setCleared( txt.isEmpty() );
00092   if ( !txt.isEmpty() )
00093     spinBox()->setValue( txt.toInt() );
00094 }
00095 
00100 QtxIntSpinBox* QDS_SpinBox::spinBox() const
00101 {
00102   return ::qobject_cast<QtxIntSpinBox*>( controlWidget() );
00103 }
00104 
00110 QWidget* QDS_SpinBox::createControl( QWidget* parent )
00111 {
00112   QtxIntSpinBox* aSpinBox = new QtxIntSpinBox( parent );
00113   aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00114   connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
00115   return aSpinBox;
00116 }
00117 
00125 void QDS_SpinBox::onValueChanged( int val )
00126 {
00127   onParamChanged();
00128   QString str = QString::number( val );
00129   emit paramChanged();
00130   emit paramChanged( str );
00131 }
00132 
00137 void QDS_SpinBox::setStep( const int step )
00138 {
00139   if ( spinBox() )
00140     spinBox()->setSingleStep( step );
00141 }
00142 
00147 int QDS_SpinBox::step() const
00148 {
00149   int s = 0;
00150   if ( spinBox() )
00151     s = spinBox()->singleStep();
00152   return s;
00153 }
00154 
00162 void QDS_SpinBox::unitSystemChanged( const QString& system )
00163 {
00164   QDS_Datum::unitSystemChanged( system );
00165 
00166   QSpinBox* sb = spinBox();
00167   if ( sb )
00168   {
00169     // not porting this code to qt4, only commented, since from the task context
00170     // the new setted validator accepts all integers
00171     //delete sb->validator();
00172     //QValidator* valid = validator();
00173     //sb->setValidator( valid );
00174 
00175     sb->setSuffix( suffix() );
00176     sb->setPrefix( prefix() );
00177     sb->setMinimum( minValue().isEmpty() ? -INT_MAX : minValue().toInt() );
00178     sb->setMaximum( maxValue().isEmpty() ? INT_MAX : maxValue().toInt() );
00179 
00180   }
00181 }