]> SALOME platform Git repositories - modules/gui.git/blob - src/QDS/QDS_SpinBoxDbl.cxx
Salome HOME
8a4160e70108a7fd0192315498af426f2556fd8f
[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 && !sb->isCleared() )
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     return;
57
58   spinBox()->setCleared( txt.isEmpty() );
59   if ( !txt.isEmpty() )
60     spinBox()->setValue( txt.toDouble() );
61 }
62
63 /*!
64   Returns pointer to QtxDblSpinBox widget.
65 */
66 QtxDblSpinBox* QDS_SpinBoxDbl::spinBox() const
67 {
68   return ::qt_cast<QtxDblSpinBox*>( controlWidget() );
69 }
70
71 /*!
72   Create QSpinBox widget as control subwidget.
73 */
74 QWidget* QDS_SpinBoxDbl::createControl( QWidget* parent )
75 {
76   QtxDblSpinBox* aSpinBox = new QtxDblSpinBox( parent );
77   aSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
78   connect( aSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged( double ) ) );
79   return aSpinBox;
80 }
81
82 /*!
83   Notify about text changing in spin box.
84 */
85 void QDS_SpinBoxDbl::onValueChanged( double )
86 {
87   onParamChanged();
88   QString str = getString();
89
90   emit paramChanged();
91   emit paramChanged( str );
92 }
93
94 /*!
95   Returns the increment step.
96 */
97 double QDS_SpinBoxDbl::step() const
98 {
99   double s = 0;
100   if ( spinBox() )
101     s = spinBox()->lineStep();
102   return s;
103 }
104
105 /*!
106   Sets the increment step.
107 */
108 void QDS_SpinBoxDbl::setStep( const double step )
109 {
110   if ( spinBox() )
111     spinBox()->setLineStep( step );
112 }
113
114 void QDS_SpinBoxDbl::unitSystemChanged( const QString& system )
115 {
116   QDS_Datum::unitSystemChanged( system );
117
118   QtxDblSpinBox* sb = spinBox();
119   if ( !sb )
120     return;
121
122   delete sb->validator();
123   QValidator* valid = validator();
124   sb->setValidator( valid );
125
126   sb->setSuffix( suffix() );
127   sb->setPrefix( prefix() );
128
129   Standard_Integer aPreci = 1;
130   Handle(DDS_DicItem) aDicItem = dicItem();
131   if ( !aDicItem.IsNull() )
132     aPreci = aDicItem->GetPrecision();
133
134   sb->setPrecision( aPreci );
135
136   sb->setLineStep( .1 );
137   sb->setMinValue( minValue().isEmpty() ? -DBL_MAX : minValue().toDouble() );
138   sb->setMaxValue( maxValue().isEmpty() ? DBL_MAX : maxValue().toDouble() );
139 }