Salome HOME
Libraries for several kinds of controls (line edit, spinbox, combobox, ...). These...
[modules/gui.git] / src / QDS / QDS_SpinBoxDbl.cxx
1 #include "QDS_SpinBoxDbl.h"
2
3 #include <DDS_Dictionary.h>
4
5 #include <qvalidator.h>
6
7 #include <QtxDblSpinBox.h>
8
9 /*!
10   Constructor.
11 */
12 QDS_SpinBoxDbl::QDS_SpinBoxDbl( const QString& id, QWidget* parent, const int flags, const QString& comp )
13 : QDS_Datum( id, parent, flags, comp )
14 {
15 }
16
17 /*!
18   Destructor.
19 */
20 QDS_SpinBoxDbl::~QDS_SpinBoxDbl()
21 {
22 }
23
24 /*!
25   Returns string from QSpinBox widget.
26 */
27 QString QDS_SpinBoxDbl::getString() const
28 {
29   QString res;
30   QtxDblSpinBox* sb = spinBox();
31   if ( sb )
32   {
33     bool hasFocus = sb->hasFocus();
34     if ( hasFocus )
35       sb->clearFocus();
36     
37     res = sb->text();
38     if ( !sb->suffix().isEmpty() )
39       res.remove( res.find( sb->suffix() ), sb->suffix().length() );
40     if ( !sb->prefix().isEmpty() )
41       res.remove( res.find( sb->prefix() ), sb->prefix().length() );
42     
43     if ( hasFocus )
44       sb->setFocus();
45   }
46
47   return res;
48 }
49
50 /*!
51   Sets the string into QSpinBox widget.
52 */
53 void QDS_SpinBoxDbl::setString( const QString& txt )
54 {
55   if ( spinBox() )
56     spinBox()->setValue( txt.toDouble() );
57 }
58
59 /*!
60   Returns pointer to XMLGUI_SpinBoxDbl widget.
61 */
62 QtxDblSpinBox* QDS_SpinBoxDbl::spinBox() const
63 {
64   return ::qt_cast<QtxDblSpinBox*>( controlWidget() );
65 }
66
67 /*!
68   Create QSpinBox widget as control subwidget.
69 */
70 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
71 {
72   QtxDblSpinBox* aSpinBox = new QtxDblSpinBox( parent );
73   aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
74   connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
75   return aSpinBox;
76 }
77
78 /*!
79   Notify about text changing in spin box.
80 */
81 void QDS_SpinBoxDbl::onValueChanged( double )
82 {
83   onParamChanged();
84   QString str = getString();
85
86   emit paramChanged();
87   emit paramChanged( str );
88 }
89
90 /*!
91   Returns the increment step.
92 */
93 double QDS_SpinBoxDbl::step() const
94 {
95   double s = 0;
96   if ( spinBox() )
97     s = spinBox()->lineStep();
98   return s;
99 }
100
101 /*!
102   Sets the increment step.
103 */
104 void QDS_SpinBoxDbl::setStep( const double step )
105 {
106   if ( spinBox() )
107     spinBox()->setLineStep( step );
108 }
109
110 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
111 {
112   QDS_Datum::unitSystemChanged( system );
113
114   QtxDblSpinBox* sb = spinBox();
115   if ( !sb )
116     return;
117
118   delete sb->validator();
119   QValidator* valid = validator();
120   sb->setValidator( valid );
121
122   sb->setSuffix( suffix() );
123   sb->setPrefix( prefix() );
124
125   Standard_Integer aPreci = 1;
126   Handle(DDS_DicItem) aDicItem = dicItem();
127   if ( !aDicItem.IsNull() )
128     aPreci = aDicItem->GetPrecision();
129
130   sb->setPrecision( aPreci );
131
132   sb->setLineStep( .1 );
133   sb->setMinValue( minValue().toDouble() );
134   sb->setMaxValue( maxValue().toDouble() );
135 }