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/
19 #include "QDS_CheckBox.h"
21 #include <qcheckbox.h>
24 Constructor. This method is protected. Object can't be directly constructed.
25 Use static method QDS_CheckBox::Create instead.
27 QDS_CheckBox::QDS_CheckBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
28 : QDS_Datum( id, parent, flags, comp )
35 QDS_CheckBox::~QDS_CheckBox()
40 Sets the state "NoChange" for checkbox.
42 void QDS_CheckBox::clear()
44 setStringValue( "-1" );
48 Returns string from QCheckBox widget.
50 QString QDS_CheckBox::getString() const
53 if ( checkBox() && checkBox()->state() != QButton::NoChange )
54 val = checkBox()->isChecked() ? "1" : "0";
59 Sets the string into QCheckBox widget.
61 void QDS_CheckBox::setString( const QString& txt )
67 int val = (int)txt.toDouble( &isOk );
68 if ( isOk && val < 0 )
70 checkBox()->setTristate();
71 checkBox()->setNoChange();
74 checkBox()->setChecked( isOk && val != 0 );
78 Returns pointer to QCheckBox widget.
80 QCheckBox* QDS_CheckBox::checkBox() const
82 return ::qt_cast<QCheckBox*>( controlWidget() );
86 Create QCheckBox widget as control subwidget.
88 QWidget* QDS_CheckBox::createControl( QWidget* parent )
90 QCheckBox* cb = new QCheckBox( parent );
91 connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) );
92 connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) );
93 connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) );
98 Notify about shanging of control state
100 void QDS_CheckBox::onParamChanged()
105 void QDS_CheckBox::onStateChanged( int state )
107 if ( state != QButton::NoChange && checkBox() )
108 checkBox()->setTristate( false );
111 void QDS_CheckBox::setChecked( const bool theState )
114 checkBox()->setChecked( theState );
117 bool QDS_CheckBox::isChecked() const
119 return checkBox() ? checkBox()->isChecked() : false;