Salome HOME
[Bug PAL7444] display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.
[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 #include "QAD_Tools.h"
30 #include "QAD_Desktop.h"
31 #include "QAD_Application.h"
32
33 #include "SMESHGUI_aParameterDlg.h"
34 #include "SMESHGUI_aParameter.h"
35 #include "SMESHGUI.h"
36 #include "SMESHGUI_SpinBox.h"
37
38 // QT Includes
39 #include <qgroupbox.h>
40 #include <qlabel.h>
41 #include <qpushbutton.h>
42 #include <qlayout.h>
43 #include <qspinbox.h>
44 #include <qvalidator.h>
45 #include <qtextedit.h>
46
47 using namespace std;
48
49 //====================================================================================== 
50 // function : SMESHGUI_aParameterDlg()
51 //
52 //  The dialog will by default be modal, unless you set 'modal' to
53 //  false when constructing dialog
54 // 
55 //====================================================================================== 
56 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg
57                                         (std::list<SMESHGUI_aParameterPtr> params,
58                                          QWidget*                          parent,
59                                          QString                           title,
60                                          bool                              modal ) 
61 : QDialog( parent, "MyParameterDialog", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
62   myParamList( params )
63 {
64   /* creating widgets */
65   init();
66   /* title */
67   setCaption( title );
68
69   /* Move widget on the botton right corner of main widget */
70   QAD_Tools::centerWidget( this, parent );
71 }
72
73 //====================================================================================== 
74 // function : SMESHGUI_aParameterDlg::init()
75 // purpose  : creates dialog's layout
76 //====================================================================================== 
77 void SMESHGUI_aParameterDlg::init()
78 {
79   setSizeGripEnabled( TRUE );
80   
81   QGridLayout* topLayout = new QGridLayout( this );
82   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
83
84   /***************************************************************/
85   QGroupBox* GroupC1 = new QGroupBox( this, "GroupC1" );
86   GroupC1->setColumnLayout(0, Qt::Vertical );
87   GroupC1->layout()->setSpacing( 0 );
88   GroupC1->layout()->setMargin( 0 );
89   QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
90   GroupC1Layout->setAlignment( Qt::AlignTop );
91   GroupC1Layout->setSpacing( 6 );
92   GroupC1Layout->setMargin( 11 );
93   /* Spin boxes with labels */
94   list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
95   for ( int row = 0; paramIt != myParamList.end(); paramIt++ , row++ )
96   {
97     SMESHGUI_aParameterPtr param = (*paramIt);
98     QLabel * label = new QLabel( GroupC1, "TextLabel" );
99     GroupC1Layout->addWidget( label, row, 0 );
100     label->setText( param->Label() );
101     QWidget* aSpinWidget = 0;
102     switch ( param->GetType() ) {
103     case SMESHGUI_aParameter::DOUBLE: {
104       SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox( GroupC1 );
105       aSpinWidget = spin;
106       spin->setPrecision( 12 );
107       break;
108     }
109     case SMESHGUI_aParameter::INT: {
110       QSpinBox* spin = new QSpinBox( GroupC1 );
111       aSpinWidget = spin;
112       break;
113     }
114     case SMESHGUI_aParameter::TEXT: {
115       QTextEdit* edit = new QTextEdit( GroupC1 );
116       edit->setWordWrap( QTextEdit::NoWrap );
117       edit->setTextFormat( Qt::PlainText );
118       aSpinWidget = edit;
119       break;
120     }
121     default:;
122     }
123     if ( aSpinWidget ) {
124       GroupC1Layout->addWidget( aSpinWidget, row, 1 );
125       aSpinWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
126       aSpinWidget->setMinimumSize( 150, 0 );
127       param->InitializeWidget( aSpinWidget );
128       mySpinList.push_back( aSpinWidget );
129     }
130   }
131   
132   /***************************************************************/
133   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
134   GroupButtons->setColumnLayout(0, Qt::Vertical );
135   GroupButtons->layout()->setSpacing( 0 );
136   GroupButtons->layout()->setMargin( 0 );
137   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
138   GroupButtonsLayout->setAlignment( Qt::AlignTop );
139   GroupButtonsLayout->setSpacing( 6 );
140   GroupButtonsLayout->setMargin( 11 );
141   /* Ok button */
142   myButtonOk = new QPushButton( GroupButtons, "buttonOk" );
143   myButtonOk->setText( tr("SMESH_BUT_OK") );
144   myButtonOk->setAutoDefault( TRUE );
145   myButtonOk->setDefault( TRUE );
146   GroupButtonsLayout->addWidget( myButtonOk, 0, 0 );
147   /* add spacer between buttons */
148   GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
149   /* Cancel button */
150   myButtonCancel = new QPushButton( GroupButtons, "buttonCancel" );
151   myButtonCancel->setText( tr("SMESH_BUT_CANCEL") );
152   myButtonCancel->setAutoDefault( TRUE );
153   GroupButtonsLayout->addWidget( myButtonCancel, 0, 2 );
154   
155   /***************************************************************/
156   topLayout->addWidget( GroupC1,      0, 0);
157   topLayout->addWidget( GroupButtons, 1, 0);
158
159   /* signals and slots connections */
160   connect( myButtonOk,     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
161   connect( myButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
162
163   /* Retrieve SMESHGUI */
164   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
165 }
166
167
168 //====================================================================================== 
169 // function : ~SMESHGUI_aParameterDlg()
170 // purpose  : Destructor
171 //====================================================================================== 
172 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg() 
173 {
174 }
175
176 //=======================================================================
177 //function : ClickOnOk
178 //purpose  : 
179 //=======================================================================
180
181 void SMESHGUI_aParameterDlg::ClickOnOk()
182 {
183   if ( !mySMESHGUI->ActiveStudyLocked() ) {
184     list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
185     list<QWidget*>::iterator              widgetIt = mySpinList.begin();
186     for ( ;
187          paramIt != myParamList.end() && widgetIt != mySpinList.end();
188          paramIt++ , widgetIt++ )
189       (*paramIt)->TakeValue( *widgetIt );
190
191     accept();
192   }
193 }
194
195
196 //=======================================================================
197 // function : Parameters()
198 // purpose  : return a list of parameters from a dialog box
199 //=======================================================================
200 bool SMESHGUI_aParameterDlg::Parameters( list<SMESHGUI_aParameterPtr> params, const char *aTitle)
201 {
202   if ( !params.empty() ) {
203     SMESHGUI_aParameterDlg *Dialog =
204       new SMESHGUI_aParameterDlg(params,
205                                  QAD_Application::getDesktop(),
206                                  aTitle,
207                                  TRUE);
208     return (Dialog->exec() == QDialog::Accepted);
209   }
210   return false;
211 }