]> SALOME platform Git repositories - modules/gui.git/blob - src/QDS/QDS_CheckBox.cxx
Salome HOME
ded537716607d10732aa166dbad42ff169a0dac0
[modules/gui.git] / src / QDS / QDS_CheckBox.cxx
1 #include "QDS_CheckBox.h"
2
3 #include <qcheckbox.h>
4
5 /*!
6   Constructor. This method is protected. Object can't be directly constructed.
7   Use static method QDS_CheckBox::Create instead.
8 */
9 QDS_CheckBox::QDS_CheckBox( const QString& id, QWidget* parent, const int flags, const QString& comp )
10 : QDS_Datum( id, parent, flags, comp )
11 {
12 }
13
14 /*!
15   Destructor.
16 */
17 QDS_CheckBox::~QDS_CheckBox()
18 {
19 }
20
21 /*!
22   Sets the state "NoChange" for checkbox.
23 */
24 void QDS_CheckBox::clear()
25 {
26   setStringValue( "-1" );
27 }
28
29 /*!
30   Returns string from QCheckBox widget.
31 */
32 QString QDS_CheckBox::getString() const
33 {
34   QString val;
35   if ( checkBox() && checkBox()->state() != QButton::NoChange )
36     val = checkBox()->isChecked() ? "1" : "0";
37   return val;
38 }
39
40 /*!
41   Sets the string into QCheckBox widget.
42 */
43 void QDS_CheckBox::setString( const QString& txt )
44 {
45   if ( !checkBox() )
46     return;
47
48   bool isOk;
49   int val = (int)txt.toDouble( &isOk );
50   if ( isOk && val < 0 )
51   {
52     checkBox()->setTristate();
53     checkBox()->setNoChange();
54   }
55   else
56     checkBox()->setChecked( isOk && val != 0 );
57 }
58
59 /*!
60   Returns pointer to QCheckBox widget.
61 */
62 QCheckBox* QDS_CheckBox::checkBox() const
63 {
64   return ::qt_cast<QCheckBox*>( controlWidget() );
65 }
66
67 /*!
68   Create QCheckBox widget as control subwidget.
69 */
70 QWidget* QDS_CheckBox::createControl( QWidget* parent )
71 {
72   QCheckBox* cb = new QCheckBox( parent );
73   connect( cb, SIGNAL( stateChanged( int ) ), SLOT( onParamChanged() ) );
74   connect( cb, SIGNAL( toggled( bool ) ), SIGNAL( toggled( bool ) ) );
75   connect( cb, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChanged( int ) ) );
76   return cb;
77 }
78
79 /*!
80   Notify about shanging of control state
81 */
82 void QDS_CheckBox::onParamChanged()
83 {
84   emit paramChanged();
85 }
86
87 void QDS_CheckBox::onStateChanged( int state )
88 {
89   if ( state != QButton::NoChange && checkBox() )
90     checkBox()->setTristate( false );
91 }
92
93 void QDS_CheckBox::setChecked( const bool theState )
94 {
95   if ( checkBox() )
96     checkBox()->setChecked( theState );
97 }
98
99 bool QDS_CheckBox::isChecked() const
100 {
101   return checkBox() ? checkBox()->isChecked() : false;
102 }