Salome HOME
Correct some memory leaks
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_aParameterDlg.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_aParameterDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_aParameterDlg.h"
31 #include "SMESHGUI.h"
32 #include "QAD_SpinBoxDbl.h"
33 #include "QAD_Tools.h"
34
35 // QT Includes
36 #include <qgroupbox.h>
37 #include <qlabel.h>
38 #include <qpushbutton.h>
39 #include <qlayout.h>
40 #include <qspinbox.h>
41 #include <qvalidator.h>
42
43 //====================================================================================== 
44 // function : SMESHGUI_aParameterDlg()
45 // purpose  : Constructs a SMESHGUI_aParametertDlg for double values
46 //
47 //  parent    : parent widget
48 //  title     : is the title for the user in dialog box
49 //  label     : text label for the value
50 //
51 //  bottom     : the minimal value to be entered
52 //  top        : the maximum value to be entered
53 //  decimals   : number of decimals to be entered
54 //
55 //  The dialog will by default be modal, unless you set 'modal' to
56 //  false when constructing dialog
57 // 
58 //====================================================================================== 
59 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg( QWidget*     parent,
60                                                 QString      title,
61                                                 QString      label,
62                                                 const double bottom,
63                                                 const double top,
64                                                 const int    decimals,
65                                                 bool         modal ) 
66 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
67   myIntSpin( 0 ), myDblSpin( 0 )
68 {
69   /* creating widgets */
70   init( true );
71   /* title */
72   setCaption( title );
73   /* caption */
74   myTextLabel->setText( label );
75   /* range */
76   myDblSpin->setRange( bottom, top );
77   ((QDoubleValidator*)(myDblSpin->validator()))->setRange( bottom, top, decimals );
78
79   /* Move widget on the botton right corner of main widget */
80   QAD_Tools::centerWidget( this, parent );
81 }
82
83 //====================================================================================== 
84 // function : SMESHGUI_aParameterDlg()
85 // purpose  : Constructs a SMESHGUI_aParametertDlg for int values
86 //
87 //  parent    : parent widget
88 //  title     : is the title for the user in dialog box
89 //  label     : text label for the value
90 //
91 //  bottom     : the minimal value to be entered
92 //  top        : the maximum value to be entered
93 //
94 //  The dialog will by default be modal, unless you set 'modal' to
95 //  false when constructing dialog
96 // 
97 //====================================================================================== 
98 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg( QWidget*     parent,
99                                                 QString      title,
100                                                 QString      label,
101                                                 const int    bottom,
102                                                 const int    top,
103                                                 bool         modal ) 
104 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
105   myIntSpin( 0 ), myDblSpin( 0 )
106 {
107   /* creating widgets */
108   init( false );
109   /* title */
110   setCaption( title );
111   /* caption */
112   myTextLabel->setText( label );
113   /* range */
114   myIntSpin->setRange( bottom, top );
115   ((QIntValidator*)(myIntSpin->validator()))->setRange( bottom, top );
116
117   /* Move widget on the botton right corner of main widget */
118   QAD_Tools::centerWidget( this, parent );
119 }
120
121 //====================================================================================== 
122 // function : SMESHGUI_aParameterDlg::init()
123 // purpose  : creates dialog's layout
124 //====================================================================================== 
125 void SMESHGUI_aParameterDlg::init( bool isDouble )
126 {
127   setSizeGripEnabled( TRUE );
128   
129   QGridLayout* topLayout = new QGridLayout( this );
130   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
131
132   /***************************************************************/
133   QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
134   GroupC1->setColumnLayout(0, Qt::Vertical );
135   GroupC1->layout()->setSpacing( 0 );
136   GroupC1->layout()->setMargin( 0 );
137   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
138   GroupC1Layout->setAlignment( Qt::AlignTop );
139   GroupC1Layout->setSpacing( 6 );
140   GroupC1Layout->setMargin( 11 );
141   /* Label */
142   /* aTitle1 : text prompt on left of edit line */
143   myTextLabel = new QLabel( GroupC1, "TextLabel" );
144   GroupC1Layout->addWidget( myTextLabel, 0, 0 );
145   /* Spin box */
146   if ( isDouble ) {
147     myIntSpin = 0;
148     myDblSpin = new QAD_SpinBoxDbl( GroupC1 );
149     myDblSpin->setPrecision( 12 );
150     myDblSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
151     myDblSpin->setMinimumSize( 150, 0 );
152     GroupC1Layout->addWidget( myDblSpin, 0, 1 );
153   }
154   else {
155     myDblSpin = 0;
156     myIntSpin = new QSpinBox( GroupC1 );
157     myIntSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
158     myIntSpin->setMinimumSize( 150, 0 );
159     GroupC1Layout->addWidget( myIntSpin, 0, 1 );
160   }
161   
162   /***************************************************************/
163   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
164   GroupButtons->setColumnLayout(0, Qt::Vertical );
165   GroupButtons->layout()->setSpacing( 0 );
166   GroupButtons->layout()->setMargin( 0 );
167   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
168   GroupButtonsLayout->setAlignment( Qt::AlignTop );
169   GroupButtonsLayout->setSpacing( 6 );
170   GroupButtonsLayout->setMargin( 11 );
171   /* Ok button */
172   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
173   myButtonOk->setText( tr("SMESH_BUT_OK") );
174   myButtonOk->setAutoDefault( TRUE );
175   myButtonOk->setDefault( TRUE );
176   GroupButtonsLayout->addWidget( myButtonOk, 0, 0 );
177   /* add spacer between buttons */
178   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
179   /* Cancel button */
180   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
181   myButtonCancel->setText( tr("SMESH_BUT_CANCEL") );
182   myButtonCancel->setAutoDefault( TRUE );
183   GroupButtonsLayout->addWidget( myButtonCancel, 0, 2 );
184   
185   /***************************************************************/
186   topLayout->addWidget( GroupC1,      0, 0);
187   topLayout->addWidget( GroupButtons, 1, 0);
188
189   /* signals and slots connections */
190   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
191   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
192
193   /* Retrieve SMESHGUI */
194   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
195 }
196
197
198 //====================================================================================== 
199 // function : ~SMESHGUI_aParameterDlg()
200 // purpose  : Destructor
201 //====================================================================================== 
202 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg() 
203 {
204 }
205
206 //====================================================================================== 
207 // function : SMESHGUI_aParameterDlg::setValue
208 // purpose  : sets double value
209 //====================================================================================== 
210 void SMESHGUI_aParameterDlg::setValue( const double val )
211 {
212   if ( myDblSpin )
213     myDblSpin->setValue( val );
214 }
215 //====================================================================================== 
216 // function : SMESHGUI_aParameterDlg::setValue
217 // purpose  : sets int value
218 //====================================================================================== 
219 void SMESHGUI_aParameterDlg::setValue( const int val )
220 {
221   if ( myIntSpin )
222     myIntSpin->setValue( val );
223 }
224 //====================================================================================== 
225 // function : SMESHGUI_aParameterDlg::getDblValue
226 // purpose  : returns double value entered by user
227 //====================================================================================== 
228 double SMESHGUI_aParameterDlg::getDblValue()
229 {
230   if ( myDblSpin )
231     return myDblSpin->value();
232   return 0.0;
233 }
234
235 //====================================================================================== 
236 // function : SMESHGUI_aParameterDlg::getIntValu
237 // purpose  : returns int value entered by user
238 //====================================================================================== 
239 int SMESHGUI_aParameterDlg::getIntValue()
240 {
241   if ( myIntSpin )
242     return myIntSpin->value();
243   return 0;
244 }
245
246
247
248
249
250
251
252
253