Back to index

salome-gui  6.5.0
QtxIntSpinBox.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 // File:      QtxIntSpinBox.cxx
00024 // Author:    Sergey TELKOV
00025 //
00026 #include "QtxIntSpinBox.h"
00027 
00028 #include <QLineEdit>
00060 QtxIntSpinBox::QtxIntSpinBox( QWidget* parent )
00061 : QSpinBox( parent ),
00062   myCleared( false )
00063 {
00064   // VSR 01/07/2010: Disable thousands separator for spin box
00065   // (to avoid incosistency of double-2-string and string-2-double conversion)
00066   QLocale loc;
00067   loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
00068   setLocale(loc);
00069 
00070   setCorrectionMode( QSpinBox::CorrectToNearestValue );
00071   connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), 
00072            this, SLOT( onTextChanged( const QString& ) ) );
00073 }
00074 
00086 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent )
00087 : QSpinBox( parent ),
00088   myCleared( false )
00089 {
00090   // VSR 01/07/2010: Disable thousands separator for spin box
00091   // (to avoid incosistency of double-2-string and string-2-double conversion)
00092   QLocale loc;
00093   loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
00094   setLocale(loc);
00095 
00096   setMinimum( min );
00097   setMaximum( max );
00098   setSingleStep( step );
00099   setCorrectionMode( QSpinBox::CorrectToNearestValue );
00100 
00101   connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), 
00102            this, SLOT( onTextChanged( const QString& ) ) );
00103 }
00104 
00108 QtxIntSpinBox::~QtxIntSpinBox()
00109 {
00110 }
00111 
00116 bool QtxIntSpinBox::isCleared() const
00117 {
00118   return myCleared;
00119 }
00120 
00125 void QtxIntSpinBox::setCleared( const bool on )
00126 {
00127   if ( myCleared == on )
00128     return;
00129   
00130   myCleared = on;
00131   setSpecialValueText( specialValueText() );
00132 }
00133 
00139 QString QtxIntSpinBox::textFromValue( int val ) const
00140 {
00141   return myCleared ? QString() : QSpinBox::textFromValue( val );
00142 }
00143 
00153 void QtxIntSpinBox::stepBy( int steps )
00154 {
00155   myCleared = false;
00156 
00157   QSpinBox::stepBy( steps );
00158 }
00159 
00164 void QtxIntSpinBox::onTextChanged( const QString& )
00165 {
00166   myCleared = false;
00167 }