Salome HOME
PAL8536. SMESHGUI_doubleParameter::InitializeWidget() : allow going down to _bottom...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_aParameter.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_aParameter.cxx
25 //  Module : SMESH
26 //  $Header$
27
28 #include "SMESHGUI_aParameter.h"
29   
30 #include <qspinbox.h>
31 #include <qvalidator.h>
32 #include <qtextedit.h>
33
34 #include "QAD_SpinBoxDbl.h"
35
36 SMESHGUI_aParameter::~SMESHGUI_aParameter() {}
37
38 //=================================================================================
39 // class    : SMESHGUI_intParameter
40 // purpose  :
41 //=================================================================================
42 SMESHGUI_intParameter::SMESHGUI_intParameter(const int      theInitValue,
43                                              const QString& theLabel,
44                                              const int      theBottom,   
45                                              const int      theTop)
46      :SMESHGUI_aParameter(theLabel),
47        _top(theTop), _bottom(theBottom), _initValue( theInitValue )
48 {
49 }
50 SMESHGUI_aParameter::Type SMESHGUI_intParameter::GetType() const
51 {
52   return SMESHGUI_aParameter::INT;
53 }
54 bool SMESHGUI_intParameter::GetNewInt( int & theValue ) const
55 {
56   theValue = _newValue;
57   return _newValue != _initValue;
58 }
59 bool SMESHGUI_intParameter::GetNewDouble( double & Value ) const
60 {
61   return false;
62 }
63 bool SMESHGUI_intParameter::GetNewText( QString & Value ) const
64 {
65   return false;
66 }
67 void SMESHGUI_intParameter::InitializeWidget( QWidget* theQWidget) const
68 {
69   QSpinBox * aSpin = dynamic_cast< QSpinBox *>( theQWidget );
70   if ( aSpin ) {
71     aSpin->setMinValue( _bottom );
72     aSpin->setMaxValue( _top );
73     aSpin->setValue( _initValue );
74   }
75 }
76 void SMESHGUI_intParameter::TakeValue( QWidget* theQWidget)
77 {
78   QSpinBox * aSpin = dynamic_cast< QSpinBox *>( theQWidget );
79   if ( aSpin )
80     _newValue = aSpin->value();
81 }
82 //=================================================================================
83 // class    : SMESHGUI_doubleParameter
84 // purpose  :
85 //=================================================================================
86 SMESHGUI_doubleParameter::SMESHGUI_doubleParameter(const double   theInitValue,
87                                                    const QString& theLabel,
88                                                    const double   theBottom,   
89                                                    const double   theTop,
90                                                    const double   theStep,
91                                                    const int      theDecimals)
92      :SMESHGUI_aParameter( theLabel ),
93        _top( theTop ), _bottom( theBottom ), _step( theStep ),
94        _initValue( theInitValue ), _decimals( theDecimals )
95 {
96 }
97 SMESHGUI_aParameter::Type SMESHGUI_doubleParameter::GetType() const
98 {
99   return SMESHGUI_aParameter::DOUBLE;
100 }
101 bool SMESHGUI_doubleParameter::GetNewInt( int & theValue ) const
102 {
103   return false;
104 }
105 bool SMESHGUI_doubleParameter::GetNewDouble( double & Value ) const
106 {
107   Value = _newValue;
108   return _newValue != _initValue;
109 }
110 bool SMESHGUI_doubleParameter::GetNewText( QString & Value ) const
111 {
112   return false;
113 }
114 void SMESHGUI_doubleParameter::InitializeWidget( QWidget* theQWidget) const
115 {
116   QAD_SpinBoxDbl * aSpin = dynamic_cast< QAD_SpinBoxDbl *>( theQWidget );
117   if ( aSpin ) {
118     aSpin->setPrecision( _decimals );
119     aSpin->setDblPrecision( _bottom );
120     aSpin->setRange( _bottom, _top );
121     aSpin->setValue( _initValue );
122     aSpin->setLineStep( _step );
123   }
124 }
125 void SMESHGUI_doubleParameter::TakeValue( QWidget* theQWidget)
126 {
127   QAD_SpinBoxDbl * aSpin = dynamic_cast< QAD_SpinBoxDbl *>( theQWidget );
128   if ( aSpin )
129     _newValue = aSpin->value();
130 }
131
132 //=================================================================================
133 // class    : SMESHGUI_strParameter
134 // purpose  :
135 //=================================================================================
136 SMESHGUI_strParameter::SMESHGUI_strParameter(const QString& theInitValue,
137                                              const QString& theLabel)
138      :SMESHGUI_aParameter(theLabel),
139       _initValue( theInitValue )
140 {
141 }
142 SMESHGUI_aParameter::Type SMESHGUI_strParameter::GetType() const
143 {
144   return SMESHGUI_aParameter::TEXT;
145 }
146 bool SMESHGUI_strParameter::GetNewInt( int & theValue ) const
147 {
148   return false;
149 }
150 bool SMESHGUI_strParameter::GetNewDouble( double & Value ) const
151 {
152   return false;
153 }
154 bool SMESHGUI_strParameter::GetNewText( QString & theValue ) const
155 {
156   theValue = _newValue;
157   return _newValue != _initValue;
158 }
159 void SMESHGUI_strParameter::InitializeWidget( QWidget* theQWidget) const
160 {
161   QTextEdit * anEdit = dynamic_cast< QTextEdit *>( theQWidget );
162   if ( anEdit ) {
163     anEdit->setText( _initValue );
164   }
165 }
166 void SMESHGUI_strParameter::TakeValue( QWidget* theQWidget)
167 {
168   QTextEdit * anEdit = dynamic_cast< QTextEdit *>( theQWidget );
169   if ( anEdit )
170     _newValue = anEdit->text();
171 }