Salome HOME
Libraries for several kinds of controls (line edit, spinbox, combobox, ...). These...
[modules/gui.git] / src / QDS / QDS_SpinBox.cxx
1 #include "QDS_SpinBox.h"
2
3 #include <qspinbox.h>
4 #include <qvalidator.h>
5
6 /*!
7   Constructor.
8 */
9 QDS_SpinBox::QDS_SpinBox( 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_SpinBox::~QDS_SpinBox()
18 {
19 }
20
21 /*!
22   Returns string from QSpinBox widget.
23 */
24 QString QDS_SpinBox::getString() const
25 {
26   QString res;
27   QSpinBox* aSpinBox = spinBox();
28   if ( aSpinBox )
29   {
30     res = aSpinBox->text();
31     if ( !aSpinBox->suffix().isEmpty() )
32       res.remove( res.find( aSpinBox->suffix() ), aSpinBox->suffix().length() );
33     if ( !aSpinBox->prefix().isEmpty() )
34       res.remove( res.find( aSpinBox->prefix() ), aSpinBox->prefix().length() );
35   }
36   return res;
37 }
38
39 /*!
40   Sets the string into QSpinBox widget.
41 */
42 void QDS_SpinBox::setString( const QString& txt )
43 {
44   if ( spinBox() )
45     spinBox()->setValue( txt.toInt() );
46 }
47
48 /*!
49   Returns pointer to QSpinBox widget.
50 */
51 QSpinBox* QDS_SpinBox::spinBox() const
52 {
53   return ::qt_cast<QSpinBox*>( controlWidget() );
54 }
55
56 /*!
57   Create QSpinBox widget as control subwidget.
58 */
59 QWidget* QDS_SpinBox::createControl( QWidget* parent )
60 {
61   QSpinBox* aSpinBox = new QSpinBox( parent );
62   aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
63   connect( aSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged( int ) ) );
64   return aSpinBox;
65 }
66
67 /*!
68   Notify about text changing in spin box.
69 */
70 void QDS_SpinBox::onValueChanged( int val )
71 {
72   onParamChanged();
73   QString str = QString::number( val );
74   emit paramChanged();
75   emit paramChanged( str );
76 }
77
78 /*!
79   Sets the increment step.
80 */
81 void QDS_SpinBox::setStep( const int step )
82 {
83   if ( spinBox() )
84     spinBox()->setLineStep( step );
85 }
86
87 /*!
88   Returns the increment step.
89 */
90 int QDS_SpinBox::step() const
91 {
92   int s = 0;
93   if ( spinBox() )
94     s = spinBox()->lineStep();
95   return s;
96 }
97
98 /*!
99   This method is redefined from ancestor class to perform own initialization ( suffix, prefix, etc ).
100 */
101 void QDS_SpinBox::unitSystemChanged( const QString& system )
102 {
103   QDS_Datum::unitSystemChanged( system );
104
105   QSpinBox* sb = spinBox();
106   if ( sb )
107   {
108     delete sb->validator();
109     QValidator* valid = validator();
110     sb->setValidator( valid );
111
112     sb->setSuffix( suffix() );
113     sb->setPrefix( prefix() );
114     sb->setMinValue( minValue().toInt() );
115     sb->setMaxValue( maxValue().toInt() );
116   }
117 }