1 // Copyright (C) 2007-2015 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 #include "QDS_CheckBox.h"
29 \brief Datum with control corresponding to check box.
31 This control can have only two states:
35 QDS_CheckBox don't take into account standard parameter properties
36 (minimum, maximum, filter, etc).
38 QDS_CheckBox can set and get following values for access methods (setStringValue(),
39 setIntegerValue(), setDoubleValue(), stringValue(), integerValue(), doubleValue()):
40 - "1" - check box state is switched on.
41 - "0" - check box state is switched off.
42 - "-1" - check box state is "PartiallyChecked" (undefined).
44 User can set and test "PartiallyChecked" check using methods clear()
45 and isEmpty() correspondingly.
51 Create check box datum object with datum identifier \a id
52 and parent widget \a parent.
54 Parameter \a flags defines behaviour of datum and set of created
55 subwidgets. Default value of this parameter is QDS::All.
57 Parameter \a comp specifies the component name which will be used
58 when searching the dictionary item.
60 \param id datum identifier
61 \param parent parent widget
62 \param flags datum flags
65 QDS_CheckBox::QDS_CheckBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
66 : QDS_Datum( id, parent, flags, comp )
73 QDS_CheckBox::~QDS_CheckBox()
78 \brief Set the state "PartiallyChecked" (undefined) for checkbox.
80 void QDS_CheckBox::clear()
82 setStringValue( "-1" );
86 \brief Get string value from the widget.
87 \return "1" if check box is checked on and "0" otherwise
89 QString QDS_CheckBox::getString() const
92 if ( checkBox() && checkBox()->checkState() != Qt::PartiallyChecked )
93 val = checkBox()->isChecked() ? "1" : "0";
98 \brief Set the string value into the widget.
100 If string \a txt contains "1", then check box state is switched on.
101 If string \a txt contains "0", then check box state is switched on.
102 If string \a txt contains "-1", then check box is reset to
103 "PartiallyChecked" (undefined) state.
105 \param txt string value
107 void QDS_CheckBox::setString( const QString& txt )
113 int val = (int)txt.toDouble( &isOk );
114 if ( isOk && val < 0 )
116 checkBox()->setTristate();
117 checkBox()->setCheckState(Qt::PartiallyChecked);
120 checkBox()->setChecked( isOk && val != 0 );
124 \brief Get internal check box.
125 \return pointer to QCheckBox widget
127 QCheckBox* QDS_CheckBox::checkBox() const
129 return ::qobject_cast<QCheckBox*>( controlWidget() );
133 \brief Create internal check box as control widget.
134 \param parent parent widget
135 \return created check box widget
137 QWidget* QDS_CheckBox::createControl( QWidget* parent )
139 QCheckBox* cb = new QCheckBox( parent );
140 connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) );
141 connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) );
142 connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) );
147 \brief Called when check box is switched.
149 Emits signal paramChanged() to notify about changing of the control state.
151 void QDS_CheckBox::onParamChanged()
157 \brief Called when check box is switched.
159 Switch off check box property "tristate" when state is changed by the user.
161 \param state new check box state
163 void QDS_CheckBox::onStateChanged( int state )
165 if ( state != Qt::PartiallyChecked && checkBox() )
166 checkBox()->setTristate( false );
170 \brief Set the check box state to \a theState.
171 \param theState new check box state
173 void QDS_CheckBox::setChecked( const bool theState )
176 checkBox()->setChecked( theState );
180 \brief Get current check box state.
181 \return check box state
183 bool QDS_CheckBox::isChecked() const
185 return checkBox() ? checkBox()->isChecked() : false;
189 \fn void QDS_CheckBox::toggled( bool on );
190 \brief Emitted when the check box state is toggled.
191 \param on new check box state