1 // Copyright (C) 2007-2022 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 #if !defined(GLOBAL_DOUBLE_CONVERSION)
65 // VSR 01/07/2010: Disable thousands separator for spin box
66 // (to avoid incosistency of double-2-string and string-2-double conversion)
67 // see issue 14540 (old id 21219)
69 loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
73 setCorrectionMode( QSpinBox::CorrectToNearestValue );
74 connect( lineEdit(), SIGNAL( textChanged( const QString& ) ),
75 this, SLOT( onTextChanged( const QString& ) ) );
81 Constructs a spin box with specified minimum, maximum and step value.
82 The value is initially set to the minimum value.
84 \param min spin box minimum possible value
85 \param max spin box maximum possible value
86 \param step spin box increment/decrement value
87 \param parent parent object
89 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent )
93 #if !defined(GLOBAL_DOUBLE_CONVERSION)
94 // VSR 01/07/2010: Disable thousands separator for spin box
95 // (to avoid incosistency of double-2-string and string-2-double conversion)
96 // see issue 14540 (old id 21219)
98 loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
104 setSingleStep( step );
105 setCorrectionMode( QSpinBox::CorrectToNearestValue );
107 connect( lineEdit(), SIGNAL( textChanged( const QString& ) ),
108 this, SLOT( onTextChanged( const QString& ) ) );
114 QtxIntSpinBox::~QtxIntSpinBox()
119 \brief Check if spin box is in the "cleared" state.
120 \return \c true if spin box is cleared
122 bool QtxIntSpinBox::isCleared() const
128 \brief Change "cleared" status of the spin box.
129 \param on new "cleared" status
131 void QtxIntSpinBox::setCleared( const bool on )
133 if ( myCleared == on )
137 setSpecialValueText( specialValueText() );
141 \brief Convert value to the text.
142 \param val value being converted
143 \return string containing the converted value
145 QString QtxIntSpinBox::textFromValue( int val ) const
147 return myCleared ? QString() : QSpinBox::textFromValue( val );
151 \brief Perform \a steps increment/decrement steps.
153 The \a steps value can be any integer number. If it is > 0,
154 the value incrementing is done, otherwise value is decremented
157 \param steps number of increment/decrement steps
159 void QtxIntSpinBox::stepBy( int steps )
163 QSpinBox::stepBy( steps );
167 \brief Called when user enters the text in the spin box.
168 \param txt current spin box text (not used)
170 void QtxIntSpinBox::onTextChanged( const QString& )