Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / QDS / QDS_CheckBox.cxx
1 // Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "QDS_CheckBox.h"
20
21 #include <qcheckbox.h>
22
23 /*!
24   Constructor. This method is protected. Object can't be directly constructed.
25   Use static method QDS_CheckBox::Create instead.
26 */
27 QDS_CheckBox::QDS_CheckBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
28 : QDS_Datum( id, parent, flags, comp )
29 {
30 }
31
32 /*!
33   Destructor.
34 */
35 QDS_CheckBox::~QDS_CheckBox()
36 {
37 }
38
39 /*!
40   Sets the state "NoChange" for checkbox.
41 */
42 void QDS_CheckBox::clear()
43 {
44   setStringValue( "-1" );
45 }
46
47 /*!
48   Returns string from QCheckBox widget.
49 */
50 QString QDS_CheckBox::getString() const
51 {
52   QString val;
53   if ( checkBox() && checkBox()->state() != QButton::NoChange )
54     val = checkBox()->isChecked() ? "1" : "0";
55   return val;
56 }
57
58 /*!
59   Sets the string into QCheckBox widget.
60 */
61 void QDS_CheckBox::setString( const QString& txt )
62 {
63   if ( !checkBox() )
64     return;
65
66   bool isOk;
67   int val = (int)txt.toDouble( &isOk );
68   if ( isOk && val < 0 )
69   {
70     checkBox()->setTristate();
71     checkBox()->setNoChange();
72   }
73   else
74     checkBox()->setChecked( isOk && val != 0 );
75 }
76
77 /*!
78   Returns pointer to QCheckBox widget.
79 */
80 QCheckBox* QDS_CheckBox::checkBox() const
81 {
82   return ::qt_cast<QCheckBox*>( controlWidget() );
83 }
84
85 /*!
86   Create QCheckBox widget as control subwidget.
87 */
88 QWidget* QDS_CheckBox::createControl( QWidget* parent )
89 {
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 ) ) );
94   return cb;
95 }
96
97 /*!
98   Notify about shanging of control state
99 */
100 void QDS_CheckBox::onParamChanged()
101 {
102   emit paramChanged();
103 }
104
105 void QDS_CheckBox::onStateChanged( int state )
106 {
107   if ( state != QButton::NoChange && checkBox() )
108     checkBox()->setTristate( false );
109 }
110
111 void QDS_CheckBox::setChecked( const bool theState )
112 {
113   if ( checkBox() )
114     checkBox()->setChecked( theState );
115 }
116
117 bool QDS_CheckBox::isChecked() const
118 {
119   return checkBox() ? checkBox()->isChecked() : false;
120 }