1 // Copyright (C) 2007-2008 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.
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
22 #include "QDS_CheckBox.h"
28 \brief Datum with control corresponding to check box.
30 This control can have only two states:
34 QDS_CheckBox don't take into account standard parameter properties
35 (minimum, maximum, filter, etc).
37 QDS_CheckBox can set and get following values for access methods (setStringValue(),
38 setIntegerValue(), setDoubleValue(), stringValue(), integerValue(), doubleValue()):
39 - "1" - check box state is switched on.
40 - "0" - check box state is switched off.
41 - "-1" - check box state is "PartiallyChecked" (undefined).
43 User can set and test "PartiallyChecked" check using methods clear()
44 and isEmpty() correspondingly.
50 Create check box datum object with datum identifier \a id
51 and parent widget \a parent.
53 Parameter \a flags defines behaviour of datum and set of created
54 subwidgets. Default value of this parameter is QDS::All.
56 Parameter \a comp specifies the component name which will be used
57 when searching the dictionary item.
59 \param id datum identifier
60 \param parent parent widget
61 \param flags datum flags
64 QDS_CheckBox::QDS_CheckBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
65 : QDS_Datum( id, parent, flags, comp )
72 QDS_CheckBox::~QDS_CheckBox()
77 \brief Set the state "PartiallyChecked" (undefined) for checkbox.
79 void QDS_CheckBox::clear()
81 setStringValue( "-1" );
85 \brief Get string value from the widget.
86 \return "1" if check box is checked on and "0" otherwise
88 QString QDS_CheckBox::getString() const
91 if ( checkBox() && checkBox()->checkState() != Qt::PartiallyChecked )
92 val = checkBox()->isChecked() ? "1" : "0";
97 \brief Set the string value into the widget.
99 If string \a txt contains "1", then check box state is switched on.
100 If string \a txt contains "0", then check box state is switched on.
101 If string \a txt contains "-1", then check box is reset to
102 "PartiallyChecked" (undefined) state.
104 \param txt string value
106 void QDS_CheckBox::setString( const QString& txt )
112 int val = (int)txt.toDouble( &isOk );
113 if ( isOk && val < 0 )
115 checkBox()->setTristate();
116 checkBox()->setCheckState(Qt::PartiallyChecked);
119 checkBox()->setChecked( isOk && val != 0 );
123 \brief Get internal check box.
124 \return pointer to QCheckBox widget
126 QCheckBox* QDS_CheckBox::checkBox() const
128 return ::qobject_cast<QCheckBox*>( controlWidget() );
132 \brief Create internal check box as control widget.
133 \param parent parent widget
134 \return created check box widget
136 QWidget* QDS_CheckBox::createControl( QWidget* parent )
138 QCheckBox* cb = new QCheckBox( parent );
139 connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) );
140 connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) );
141 connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) );
146 \brief Called when check box is switched.
148 Emits signal paramChanged() to notify about changing of the control state.
150 void QDS_CheckBox::onParamChanged()
156 \brief Called when check box is switched.
158 Switch off check box property "tristate" when state is changed by the user.
160 \param state new check box state
162 void QDS_CheckBox::onStateChanged( int state )
164 if ( state != Qt::PartiallyChecked && checkBox() )
165 checkBox()->setTristate( false );
169 \brief Set the check box state to \a theState.
170 \param theState new check box state
172 void QDS_CheckBox::setChecked( const bool theState )
175 checkBox()->setChecked( theState );
179 \brief Get current check box state.
180 \return check box state
182 bool QDS_CheckBox::isChecked() const
184 return checkBox() ? checkBox()->isChecked() : false;
188 \fn void QDS_CheckBox::toggled( bool on );
189 \brief Emitted when the check box state is toggled.
190 \param on new check box state