1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: QtxIntSpinBox.cxx
24 // Author: Sergey TELKOV
26 #include "QtxIntSpinBox.h"
31 \brief Enhanced version of the Qt's spin box.
33 The QtxIntSpinBox class represents the widget for entering the
34 integer values. In addition to the functionality provided by
35 QSpinBox, this class supports "cleared" state - this is the
36 state corresponding to "None" (or empty) entered value.
38 To set "cleared" state use setCleared() method. To check if the spin
39 box stores "cleared" state, use isCleared() method.
42 if (mySpinBox->isCleared()) {
43 ... // process "None" state
46 int value = mySpinBox->value();
47 ... // process entered value
55 Constructs a spin box with 0 as minimum value and 99 as maximum value,
56 a step value of 1. The value is initially set to 0.
58 \param parent parent object
60 QtxIntSpinBox::QtxIntSpinBox( QWidget* parent )
64 // VSR 01/07/2010: Disable thousands separator for spin box
65 // (to avoid incosistency of double-2-string and string-2-double conversion)
67 loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
70 setCorrectionMode( QSpinBox::CorrectToNearestValue );
71 connect( lineEdit(), SIGNAL( textChanged( const QString& ) ),
72 this, SLOT( onTextChanged( const QString& ) ) );
78 Constructs a spin box with specified minimum, maximum and step value.
79 The value is initially set to the minimum value.
81 \param min spin box minimum possible value
82 \param max spin box maximum possible value
83 \param step spin box increment/decrement value
84 \param parent parent object
86 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent )
90 // VSR 01/07/2010: Disable thousands separator for spin box
91 // (to avoid incosistency of double-2-string and string-2-double conversion)
93 loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
98 setSingleStep( step );
99 setCorrectionMode( QSpinBox::CorrectToNearestValue );
101 connect( lineEdit(), SIGNAL( textChanged( const QString& ) ),
102 this, SLOT( onTextChanged( const QString& ) ) );
108 QtxIntSpinBox::~QtxIntSpinBox()
113 \brief Check if spin box is in the "cleared" state.
114 \return \c true if spin box is cleared
116 bool QtxIntSpinBox::isCleared() const
122 \brief Change "cleared" status of the spin box.
123 \param on new "cleared" status
125 void QtxIntSpinBox::setCleared( const bool on )
127 if ( myCleared == on )
131 setSpecialValueText( specialValueText() );
135 \brief Convert value to the text.
136 \param val value being converted
137 \return string containing the converted value
139 QString QtxIntSpinBox::textFromValue( int val ) const
141 return myCleared ? QString() : QSpinBox::textFromValue( val );
145 \brief Perform \a steps increment/decrement steps.
147 The \a steps value can be any integer number. If it is > 0,
148 the value incrementing is done, otherwise value is decremented
151 \param steps number of increment/decrement steps
153 void QtxIntSpinBox::stepBy( int steps )
157 QSpinBox::stepBy( steps );
161 \brief Called when user enters the text in the spin box.
162 \param txt current spin box text (not used)
164 void QtxIntSpinBox::onTextChanged( const QString& )