1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "QDS_CheckBox.h"
21 #include <qcheckbox.h>
26 Datum with control corresponding to check box. This control can have only two states:
27 1 (on/true) or 0 (off/false). QDS_CheckBox don't take into account standard parameter
28 properties (minimum, maximum, filter, etc).
30 QDS_CheckBox can set and get following values for access methods (setStringValue(),
31 setIntegerValue(), setDoubleValue(), stringValue(), integerValue(), doubleValue()):
32 \li "1" - check box state is setted as on.
33 \li "0" - check box state is setted as off.
34 \li "-1" - check box state is setted as "NoChage" (undefined).
36 User can set and check a state "NoChange" using methods clear() and isEmpty() accordingly.
40 Constructor. Create check box datum object with datum identifier \aid under widget \aparent.
41 Parameter \aflags define behaviour of datum and set of created subwidgets. Default value of
42 this parameter is QDS::All. Parameter \acomp specify the component name which will be used
43 during search of dictionary item.
45 QDS_CheckBox::QDS_CheckBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
46 : QDS_Datum( id, parent, flags, comp )
53 QDS_CheckBox::~QDS_CheckBox()
58 Sets the state "NoChange" for checkbox.
60 void QDS_CheckBox::clear()
62 setStringValue( "-1" );
66 Returns string from QCheckBox widget. If the check box state is on then 1 returned otherwise 0.
68 QString QDS_CheckBox::getString() const
71 if ( checkBox() && checkBox()->state() != QButton::NoChange )
72 val = checkBox()->isChecked() ? "1" : "0";
77 Sets the string into QCheckBox widget. If argument \atxt is string with number "1" then check box
78 state is setted as on. If argument \atxt is string with number "0" then state is setted as off.
79 If argument \atxt is string with number "-1" then state is setted as "NoChage" (undefined).
81 void QDS_CheckBox::setString( const QString& txt )
87 int val = (int)txt.toDouble( &isOk );
88 if ( isOk && val < 0 )
90 checkBox()->setTristate();
91 checkBox()->setNoChange();
94 checkBox()->setChecked( isOk && val != 0 );
98 Returns pointer to QCheckBox widget.
100 QCheckBox* QDS_CheckBox::checkBox() const
102 return ::qt_cast<QCheckBox*>( controlWidget() );
106 Create QCheckBox widget as control subwidget.
108 QWidget* QDS_CheckBox::createControl( QWidget* parent )
110 QCheckBox* cb = new QCheckBox( parent );
111 connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) );
112 connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) );
113 connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) );
118 Notify about ñhanging of control state
120 void QDS_CheckBox::onParamChanged()
126 Notify about ñhanging of control state. Switch off check box property "tristate" when
127 state changed by user.
129 void QDS_CheckBox::onStateChanged( int state )
131 if ( state != QButton::NoChange && checkBox() )
132 checkBox()->setTristate( false );
136 Sets the check box state \atheState.
138 void QDS_CheckBox::setChecked( const bool theState )
141 checkBox()->setChecked( theState );
145 Returns current check box state.
147 bool QDS_CheckBox::isChecked() const
149 return checkBox() ? checkBox()->isChecked() : false;