1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_aParameterDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_aParameterDlg.h"
30 #include "SMESHGUI_aParameter.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
35 #include "SUIT_Tools.h"
36 #include "SUIT_Desktop.h"
39 #include <qgroupbox.h>
41 #include <qpushbutton.h>
44 #include <qvalidator.h>
45 #include <qlineedit.h>
49 //======================================================================================
50 // function : SMESHGUI_aParameterDlg()
52 // The dialog will by default be modal, unless you set 'modal' to
53 // false when constructing dialog
55 //======================================================================================
56 SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg
57 ( SMESHGUI* theModule,
58 std::list<SMESHGUI_aParameterPtr> params,
61 : QDialog( SMESH::GetDesktop( theModule ), "MyParameterDialog", modal, WStyle_Customize |
62 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
66 /* creating widgets */
71 /* Move widget on the botton right corner of main widget */
72 SUIT_Tools::centerWidget(this, SMESH::GetDesktop( theModule ) );
75 //======================================================================================
76 // function : SMESHGUI_aParameterDlg::init()
77 // purpose : creates dialog's layout
78 //======================================================================================
79 void SMESHGUI_aParameterDlg::init()
81 setSizeGripEnabled(TRUE);
83 QVBoxLayout* topLayout = new QVBoxLayout(this);
84 topLayout->setMargin(11); topLayout->setSpacing(6);
86 /***************************************************************/
87 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
88 GroupC1->setColumnLayout(0, Qt::Vertical);
89 GroupC1->layout()->setSpacing(0);
90 GroupC1->layout()->setMargin(0);
91 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
92 GroupC1Layout->setAlignment(Qt::AlignTop);
93 GroupC1Layout->setSpacing(6);
94 GroupC1Layout->setMargin(11);
95 /* Spin boxes with labels */
96 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
97 for (int row = 0; paramIt != myParamList.end(); paramIt++ , row++)
99 SMESHGUI_aParameterPtr param = (*paramIt);
100 QLabel * label = new QLabel(GroupC1, "TextLabel");
101 GroupC1Layout->addWidget(label, row, 0);
102 label->setText(param->Label());
103 QWidget* aSpinWidget = param->CreateWidget( GroupC1 );
105 GroupC1Layout->addWidget(aSpinWidget, row, 1);
106 aSpinWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
107 aSpinWidget->setMinimumSize(150, 0);
109 QString sig = param->sigValueChanged();
110 if( !sig.isEmpty() && param->GetType()!=SMESHGUI_aParameter::TABLE )
111 connect( aSpinWidget, sig.latin1(), this, SLOT( onValueChanged() ) );
113 param->InitializeWidget(aSpinWidget);
114 mySpinList.push_back(aSpinWidget);
115 myLabelList.push_back(label);
119 paramIt = myParamList.begin();
120 std::list<QWidget*>::const_iterator anIt = mySpinList.begin();
121 for( ; paramIt!=myParamList.end(); paramIt++, anIt++ )
122 UpdateShown( *paramIt, *anIt );
125 /***************************************************************/
126 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
127 GroupButtons->setColumnLayout(0, Qt::Vertical);
128 GroupButtons->layout()->setSpacing(0);
129 GroupButtons->layout()->setMargin(0);
130 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
131 GroupButtonsLayout->setAlignment(Qt::AlignTop);
132 GroupButtonsLayout->setSpacing(6);
133 GroupButtonsLayout->setMargin(11);
135 myButtonOk = new QPushButton(GroupButtons, "buttonOk");
136 myButtonOk->setText(tr("SMESH_BUT_OK"));
137 myButtonOk->setAutoDefault(TRUE);
138 myButtonOk->setDefault(TRUE);
139 GroupButtonsLayout->addWidget(myButtonOk, 0, 0);
140 /* add spacer between buttons */
141 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
143 myButtonCancel = new QPushButton(GroupButtons, "buttonCancel");
144 myButtonCancel->setText(tr("SMESH_BUT_CANCEL"));
145 myButtonCancel->setAutoDefault(TRUE);
146 GroupButtonsLayout->addWidget(myButtonCancel, 0, 2);
148 /***************************************************************/
149 topLayout->addWidget(GroupC1, 1 );
150 topLayout->addWidget(GroupButtons, 0 );
152 /* signals and slots connections */
153 connect(myButtonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
154 connect(myButtonCancel, SIGNAL(clicked()), this, SLOT(reject()));
157 //======================================================================================
158 // function : ~SMESHGUI_aParameterDlg()
159 // purpose : Destructor
160 //======================================================================================
161 SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg()
165 //=======================================================================
166 //function : ClickOnOk
168 //=======================================================================
169 void SMESHGUI_aParameterDlg::ClickOnOk()
171 if (!mySMESHGUI->isActiveStudyLocked()) {
172 list<SMESHGUI_aParameterPtr>::iterator paramIt = myParamList.begin();
173 list<QWidget*>::iterator widgetIt = mySpinList.begin();
175 paramIt != myParamList.end() && widgetIt != mySpinList.end();
176 paramIt++ , widgetIt++)
177 (*paramIt)->TakeValue(*widgetIt);
183 //=======================================================================
184 // function : Parameters()
185 // purpose : return a list of parameters from a dialog box
186 //=======================================================================
187 bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule,
188 list<SMESHGUI_aParameterPtr> params,
191 if (!params.empty()) {
192 SMESHGUI_aParameterDlg *Dialog =
193 new SMESHGUI_aParameterDlg( theModule, params, aTitle, TRUE);
194 return (Dialog->exec() == QDialog::Accepted);
199 //=======================================================================
200 // function : onValueChanged
202 //=======================================================================
203 void SMESHGUI_aParameterDlg::onValueChanged()
205 if( sender()->inherits( "QWidget" ) )
207 QWidget* w = ( QWidget* )sender();
209 SMESHGUI_aParameterPtr param;
211 std::list<QWidget*>::const_iterator anIt = mySpinList.begin(),
212 aLast = mySpinList.end();
213 std::list<SMESHGUI_aParameterPtr>::const_iterator aPIt = myParamList.begin();
214 for( ; anIt!=aLast; anIt++, aPIt++ )
217 (*aPIt)->TakeValue( w );
218 UpdateShown( *aPIt, w );
224 //=======================================================================
225 // function : onValueChanged
227 //=======================================================================
228 void SMESHGUI_aParameterDlg::UpdateShown( const SMESHGUI_aParameterPtr param, QWidget* w )
230 SMESHGUI_dependParameter* depPar = dynamic_cast<SMESHGUI_enumParameter*>( param.get() );
232 depPar = dynamic_cast<SMESHGUI_boolParameter*>( param.get() );
237 SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap();
242 depPar->TakeValue( w );
243 depPar->GetNewInt( val );
244 bool hasValue = map.contains( val );
246 std::list<QWidget*>::const_iterator anIt = mySpinList.begin(),
247 aLast = mySpinList.end(),
248 aLIt = myLabelList.begin();
249 for( int i=0; anIt!=aLast; anIt++, aLIt++, i++ )
251 bool shown = hasValue && map[ val ].contains( i );
252 (*anIt)->setShown( shown );
253 (*aLIt)->setShown( shown );