X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_aParameterDlg.cxx;h=7e824a7b9031c2875a6b1014d40788468617a394;hb=f87e54ae3a450f6adeee75d1b42c3b17e9c6250c;hp=07c1ce1f9452378fe1b8bb2b1b45eb0dca2f5439;hpb=c38c10811a065cf5b13e8807ed71864d92ca7d80;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx index 07c1ce1f9..7e824a7b9 100644 --- a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx @@ -30,6 +30,7 @@ #include "SMESHGUI_aParameter.h" #include "SMESHGUI.h" #include "SMESHGUI_SpinBox.h" +#include "SMESHGUI_Utils.h" #include "SUIT_Tools.h" #include "SUIT_Desktop.h" @@ -41,7 +42,7 @@ #include #include #include -#include +#include using namespace std; @@ -53,13 +54,14 @@ using namespace std; // //====================================================================================== SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg - (std::list params, - QWidget* parent, + ( SMESHGUI* theModule, + std::list params, QString title, bool modal) -: QDialog(parent, "MyParameterDialog", modal, WStyle_Customize | - WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), - myParamList(params) +: QDialog( SMESH::GetDesktop( theModule ), "MyParameterDialog", modal, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myParamList(params), + mySMESHGUI(theModule) { /* creating widgets */ init(); @@ -67,7 +69,7 @@ SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg setCaption(title); /* Move widget on the botton right corner of main widget */ - SUIT_Tools::centerWidget(this, parent); + SUIT_Tools::centerWidget(this, SMESH::GetDesktop( theModule ) ); } //====================================================================================== @@ -78,7 +80,7 @@ void SMESHGUI_aParameterDlg::init() { setSizeGripEnabled(TRUE); - QGridLayout* topLayout = new QGridLayout(this); + QVBoxLayout* topLayout = new QVBoxLayout(this); topLayout->setMargin(11); topLayout->setSpacing(6); /***************************************************************/ @@ -98,37 +100,28 @@ void SMESHGUI_aParameterDlg::init() QLabel * label = new QLabel(GroupC1, "TextLabel"); GroupC1Layout->addWidget(label, row, 0); label->setText(param->Label()); - QWidget* aSpinWidget = 0; - switch (param->GetType()) { - case SMESHGUI_aParameter::DOUBLE: { - SMESHGUI_SpinBox* spin = new SMESHGUI_SpinBox(GroupC1); - aSpinWidget = spin; - spin->setPrecision(12); - break; - } - case SMESHGUI_aParameter::INT: { - QSpinBox* spin = new QSpinBox(GroupC1); - aSpinWidget = spin; - break; - } - case SMESHGUI_aParameter::TEXT: { - QTextEdit* edit = new QTextEdit(GroupC1); - edit->setWordWrap(QTextEdit::NoWrap); - edit->setTextFormat(Qt::PlainText); - aSpinWidget = edit; - break; - } - default:; - } + QWidget* aSpinWidget = param->CreateWidget( GroupC1 ); if (aSpinWidget) { GroupC1Layout->addWidget(aSpinWidget, row, 1); aSpinWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); aSpinWidget->setMinimumSize(150, 0); + + QString sig = param->sigValueChanged(); + if( !sig.isEmpty() && param->GetType()!=SMESHGUI_aParameter::TABLE ) + connect( aSpinWidget, sig.latin1(), this, SLOT( onValueChanged() ) ); + param->InitializeWidget(aSpinWidget); mySpinList.push_back(aSpinWidget); + myLabelList.push_back(label); } } + paramIt = myParamList.begin(); + std::list::const_iterator anIt = mySpinList.begin(); + for( ; paramIt!=myParamList.end(); paramIt++, anIt++ ) + UpdateShown( *paramIt, *anIt ); + + /***************************************************************/ QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); GroupButtons->setColumnLayout(0, Qt::Vertical); @@ -153,15 +146,12 @@ void SMESHGUI_aParameterDlg::init() GroupButtonsLayout->addWidget(myButtonCancel, 0, 2); /***************************************************************/ - topLayout->addWidget(GroupC1, 0, 0); - topLayout->addWidget(GroupButtons, 1, 0); + topLayout->addWidget(GroupC1, 1 ); + topLayout->addWidget(GroupButtons, 0 ); /* signals and slots connections */ connect(myButtonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); connect(myButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); - - /* Retrieve SMESHGUI */ - mySMESHGUI = SMESHGUI::GetSMESHGUI(); } //====================================================================================== @@ -194,13 +184,72 @@ void SMESHGUI_aParameterDlg::ClickOnOk() // function : Parameters() // purpose : return a list of parameters from a dialog box //======================================================================= -bool SMESHGUI_aParameterDlg::Parameters (list params, +bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule, + list params, const char *aTitle) { if (!params.empty()) { SMESHGUI_aParameterDlg *Dialog = - new SMESHGUI_aParameterDlg(params, SMESHGUI::desktop(), aTitle, TRUE); + new SMESHGUI_aParameterDlg( theModule, params, aTitle, TRUE); return (Dialog->exec() == QDialog::Accepted); } return false; } + +//======================================================================= +// function : onValueChanged +// purpose : +//======================================================================= +void SMESHGUI_aParameterDlg::onValueChanged() +{ + if( sender()->inherits( "QWidget" ) ) + { + QWidget* w = ( QWidget* )sender(); + + SMESHGUI_aParameterPtr param; + + std::list::const_iterator anIt = mySpinList.begin(), + aLast = mySpinList.end(); + std::list::const_iterator aPIt = myParamList.begin(); + for( ; anIt!=aLast; anIt++, aPIt++ ) + if( *anIt == w ) + { + (*aPIt)->TakeValue( w ); + UpdateShown( *aPIt, w ); + break; + } + } +} + +//======================================================================= +// function : onValueChanged +// purpose : +//======================================================================= +void SMESHGUI_aParameterDlg::UpdateShown( const SMESHGUI_aParameterPtr param, QWidget* w ) +{ + SMESHGUI_dependParameter* depPar = dynamic_cast( param.get() ); + if( !depPar ) + depPar = dynamic_cast( param.get() ); + + if( !depPar ) + return; + + SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap(); + if( map.isEmpty() ) + return; + + int val; + depPar->TakeValue( w ); + depPar->GetNewInt( val ); + bool hasValue = map.contains( val ); + + std::list::const_iterator anIt = mySpinList.begin(), + aLast = mySpinList.end(), + aLIt = myLabelList.begin(); + for( int i=0; anIt!=aLast; anIt++, aLIt++, i++ ) + { + bool shown = hasValue && map[ val ].contains( i ); + (*anIt)->setShown( shown ); + (*aLIt)->setShown( shown ); + } +}