X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_aParameterDlg.cxx;h=211b4f0ec28c94aed4b7df4a02d62b4389770804;hb=7d9ae6b54f5ec98fff137636f7ad2a60d10ce6b6;hp=03145925ff81be452f060bfa901cb6b6bcb34c8b;hpb=a2f0f70d5912ea83c868916f06eaefb58a32ec2e;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx index 03145925f..211b4f0ec 100644 --- a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx @@ -31,6 +31,7 @@ #include "SMESHGUI.h" #include "SMESHGUI_SpinBox.h" #include "SMESHGUI_Utils.h" +#include "SMESHGUI_FunctionPreview.h" #include "SUIT_Tools.h" #include "SUIT_Desktop.h" @@ -42,7 +43,7 @@ #include #include #include -#include +#include using namespace std; @@ -80,7 +81,7 @@ void SMESHGUI_aParameterDlg::init() { setSizeGripEnabled(TRUE); - QGridLayout* topLayout = new QGridLayout(this); + QVBoxLayout* topLayout = new QVBoxLayout(this); topLayout->setMargin(11); topLayout->setSpacing(6); /***************************************************************/ @@ -94,43 +95,42 @@ void SMESHGUI_aParameterDlg::init() GroupC1Layout->setMargin(11); /* Spin boxes with labels */ list::iterator paramIt = myParamList.begin(); - for (int row = 0; paramIt != myParamList.end(); paramIt++ , row++) + int row; + for( row = 0; paramIt != myParamList.end(); paramIt++ , row++) { SMESHGUI_aParameterPtr param = (*paramIt); 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); } } + myPreview = new SMESHGUI_FunctionPreview( GroupC1 ); + myPreview->hide(); + GroupC1Layout->addWidget( myPreview, row, 1 ); + + paramIt = myParamList.begin(); + std::list::const_iterator anIt = mySpinList.begin(); + for( ; paramIt!=myParamList.end(); paramIt++, anIt++ ) + { + (*paramIt)->TakeValue( *anIt ); + UpdateShown( *paramIt, *anIt ); + FunctionPreview( *paramIt, *anIt ); + } + /***************************************************************/ QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); GroupButtons->setColumnLayout(0, Qt::Vertical); @@ -155,8 +155,8 @@ 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())); @@ -204,3 +204,102 @@ bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule, } return false; } + +//======================================================================= +// function : FunctionPreview +// purpose : +//======================================================================= +void SMESHGUI_aParameterDlg::FunctionPreview( const SMESHGUI_aParameterPtr p, QWidget* w ) +{ + if( !w || !w->isShown() ) + return; + + SMESHGUI_strParameter* str_param = dynamic_cast( p.operator->() ); + SMESHGUI_tableParameter* tab_param = dynamic_cast( p.operator->() ); + SMESHGUI_boolParameter* bool_param = dynamic_cast( p.operator->() ); + if( str_param && str_param->needPreview() ) + { + QString val; str_param->GetNewText( val ); + if( !val.isNull() ) + myPreview->setParams( val ); + } + else if( tab_param && tab_param->needPreview() ) + { + SMESH::double_array d; + tab_param->data( d ); + myPreview->setParams( d ); + } + else if( bool_param && bool_param->needPreview() ) + { + int exp=0; + bool_param->GetNewInt( exp ); + myPreview->setIsExp( exp ); + } +} + +//======================================================================= +// function : onValueChanged +// purpose : +//======================================================================= +void SMESHGUI_aParameterDlg::onValueChanged() +{ + if( sender()->inherits( "QWidget" ) ) + { + QWidget* w = ( QWidget* )sender(); + + + 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 ); + FunctionPreview( *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(); + std::list::iterator aPIt = myParamList.begin(); + bool preview = false; + for( int i=0; anIt!=aLast; anIt++, aLIt++, i++, aPIt++ ) + { + bool shown = hasValue && map[ val ].contains( i ); + (*anIt)->setShown( shown ); + (*aLIt)->setShown( shown ); + if( shown ) + { + SMESHGUI_strParameter* str_param = dynamic_cast( (*aPIt).operator->() ); + SMESHGUI_tableParameter* tab_param = dynamic_cast( (*aPIt).operator->() ); + preview = preview || ( str_param && str_param->needPreview() ) || ( tab_param && tab_param->needPreview() ); + } + } + myPreview->setShown( preview ); +}