From: asl Date: Tue, 16 Aug 2005 12:45:13 +0000 (+0000) Subject: PAL8238 X-Git-Tag: T_3_0_2a1~29 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=61be698c0d2d886ce88ad99c43ede52fd0e4cd2b PAL8238 --- diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index ec0cf92b5..992a108c5 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -150,6 +150,7 @@ LIB_MOC = \ SMESHGUI_SewingDlg.h \ SMESHGUI_PrecisionDlg.h \ SMESHGUI_MergeNodesDlg.h \ + SMESHGUI_aParameter.h \ SMESHGUI_EditMeshDlg.h \ SMESHGUI_CreatePolyhedralVolumeDlg.h diff --git a/src/SMESHGUI/SMESHGUI_aParameter.cxx b/src/SMESHGUI/SMESHGUI_aParameter.cxx index d52b641ba..3e513f04b 100644 --- a/src/SMESHGUI/SMESHGUI_aParameter.cxx +++ b/src/SMESHGUI/SMESHGUI_aParameter.cxx @@ -29,12 +29,24 @@ #include #include +#include #include +#include +#include +#include +#include +#include +#include #include SMESHGUI_aParameter::~SMESHGUI_aParameter() {} +QString SMESHGUI_aParameter::sigValueChanged() const +{ + return QString::null; +} + //================================================================================= // class : SMESHGUI_intParameter // purpose : @@ -44,7 +56,8 @@ SMESHGUI_intParameter::SMESHGUI_intParameter (const int theInitValue, const int theBottom, const int theTop) :SMESHGUI_aParameter(theLabel), - _top(theTop), _bottom(theBottom), _initValue(theInitValue) + _top(theTop), _bottom(theBottom), _initValue(theInitValue), + _newValue( theInitValue ) { } SMESHGUI_aParameter::Type SMESHGUI_intParameter::GetType() const @@ -64,6 +77,12 @@ bool SMESHGUI_intParameter::GetNewText (QString & Value) const { return false; } + +QWidget* SMESHGUI_intParameter::CreateWidget( QWidget* parent ) const +{ + return new QSpinBox( parent ); +} + void SMESHGUI_intParameter::InitializeWidget (QWidget* theQWidget) const { QSpinBox * aSpin = dynamic_cast< QSpinBox *>(theQWidget); @@ -80,6 +99,11 @@ void SMESHGUI_intParameter::TakeValue (QWidget* theQWidget) _newValue = aSpin->value(); } +QString SMESHGUI_intParameter::sigValueChanged() const +{ + return SIGNAL( valueChanged( int ) ); +} + //================================================================================= // class : SMESHGUI_doubleParameter // purpose : @@ -112,6 +136,12 @@ bool SMESHGUI_doubleParameter::GetNewText (QString & Value) const { return false; } + +QWidget* SMESHGUI_doubleParameter::CreateWidget( QWidget* parent ) const +{ + return new QtxDblSpinBox( parent ); +} + void SMESHGUI_doubleParameter::InitializeWidget (QWidget* theQWidget) const { QtxDblSpinBox* aSpin = dynamic_cast(theQWidget); @@ -132,6 +162,11 @@ void SMESHGUI_doubleParameter::TakeValue (QWidget* theQWidget) _newValue = aSpin->value(); } +QString SMESHGUI_doubleParameter::sigValueChanged() const +{ + return SIGNAL( valueChanged( double ) ); +} + //================================================================================= // class : SMESHGUI_strParameter // purpose : @@ -144,7 +179,7 @@ SMESHGUI_strParameter::SMESHGUI_strParameter (const QString& theInitValue, } SMESHGUI_aParameter::Type SMESHGUI_strParameter::GetType() const { - return SMESHGUI_aParameter::TEXT; + return SMESHGUI_aParameter::STRING; } bool SMESHGUI_strParameter::GetNewInt (int & theValue) const { @@ -159,16 +194,748 @@ bool SMESHGUI_strParameter::GetNewText (QString & theValue) const theValue = _newValue; return _newValue != _initValue; } + +QWidget* SMESHGUI_strParameter::CreateWidget( QWidget* parent ) const +{ + return new QLineEdit( parent ); +} + void SMESHGUI_strParameter::InitializeWidget (QWidget* theQWidget) const { - QTextEdit * anEdit = dynamic_cast< QTextEdit *>(theQWidget); + QLineEdit* anEdit = dynamic_cast< QLineEdit* >(theQWidget); if (anEdit) { anEdit->setText(_initValue); } } void SMESHGUI_strParameter::TakeValue (QWidget* theQWidget) { - QTextEdit * anEdit = dynamic_cast< QTextEdit *>(theQWidget); + QLineEdit* anEdit = dynamic_cast< QLineEdit* >(theQWidget); if (anEdit) _newValue = anEdit->text(); } + +QString SMESHGUI_strParameter::sigValueChanged() const +{ + return SIGNAL( textChanged( const QString& ) ); +} + + + +//================================================================================= +// class : SMESHGUI_dependParameter +// purpose : +//================================================================================= +SMESHGUI_dependParameter::SMESHGUI_dependParameter( const QString& label ) +: SMESHGUI_aParameter( label ) +{ +} + +const SMESHGUI_dependParameter::ShownMap& SMESHGUI_dependParameter::shownMap() const +{ + return myShownMap; +} + +SMESHGUI_dependParameter::ShownMap& SMESHGUI_dependParameter::shownMap() +{ + return myShownMap; +} + + + + + +//================================================================================= +// class : SMESHGUI_enumParameter +// purpose : +//================================================================================= +SMESHGUI_enumParameter::SMESHGUI_enumParameter( const QStringList& values, + const int initValue, + const QString& label ) +: SMESHGUI_dependParameter( label ), + myInitValue( initValue ), + myValue( initValue ), + myValues( values ) +{ +} + +SMESHGUI_enumParameter::~SMESHGUI_enumParameter() +{ +} + +SMESHGUI_aParameter::Type SMESHGUI_enumParameter::GetType() const +{ + return SMESHGUI_aParameter::ENUM; +} + +bool SMESHGUI_enumParameter::GetNewInt( int& v ) const +{ + v = myValue; + return myValue!=myInitValue; +} + +bool SMESHGUI_enumParameter::GetNewDouble( double& ) const +{ + return false; +} + +bool SMESHGUI_enumParameter::GetNewText( QString& v ) const +{ + bool res = myValue>=0 && myValueinherits( "QComboBox" ) ) + { + QComboBox* c = ( QComboBox* ) w; + c->clear(); + c->insertStringList( myValues ); + c->setCurrentItem( myInitValue ); + } +} + +void SMESHGUI_enumParameter::TakeValue( QWidget* w ) +{ + if( w && w->inherits( "QComboBox" ) ) + { + QComboBox* c = ( QComboBox* ) w; + myValue = c->currentItem(); + } +} + +int SMESHGUI_enumParameter::Count() const +{ + return myValues.count(); +} + +QString SMESHGUI_enumParameter::sigValueChanged() const +{ + return SIGNAL( activated( int ) ); +} + + +//================================================================================= +// class : SMESHGUI_boolParameter +// purpose : +//================================================================================= +SMESHGUI_boolParameter::SMESHGUI_boolParameter( const bool initValue, + const QString& label ) +: SMESHGUI_dependParameter( label ), + myInitValue( initValue ), + myValue( myInitValue ) +{ +} + +SMESHGUI_boolParameter::~SMESHGUI_boolParameter() +{ +} + +SMESHGUI_aParameter::Type SMESHGUI_boolParameter::GetType() const +{ + return BOOL; +} + +bool SMESHGUI_boolParameter::GetNewInt( int& v ) const +{ + if( myValue ) + v = 1; + else + v = 0; + return v!=myInitValue; +} + +bool SMESHGUI_boolParameter::GetNewDouble( double& ) const +{ + return false; +} + +bool SMESHGUI_boolParameter::GetNewText( QString& ) const +{ + return false; +} + +QWidget* SMESHGUI_boolParameter::CreateWidget( QWidget* parent ) const +{ + return new QCheckBox( parent ); +} + +void SMESHGUI_boolParameter::InitializeWidget( QWidget* w ) const +{ + if( w && w->inherits( "QCheckBox" ) ) + { + QCheckBox* box = ( QCheckBox* )w; + box->setChecked( myInitValue ); + } +} + +void SMESHGUI_boolParameter::TakeValue( QWidget* w ) +{ + if( w && w->inherits( "QCheckBox" ) ) + { + QCheckBox* box = ( QCheckBox* )w; + myValue = box->isChecked(); + } +} + +QString SMESHGUI_boolParameter::sigValueChanged() const +{ + return SIGNAL( stateChanged( int ) ); +} + + + + +//================================================================================= +// class : SMESHGUI_doubleItem +// purpose : Custom table item which contains double and has double validator +//================================================================================= +class SMESHGUI_doubleItem: public QTableItem +{ +public: + SMESHGUI_doubleItem( QTable*, EditType, const double ); + virtual ~SMESHGUI_doubleItem(); + + void setValidator( const double, const double, const int ); + void validator( double&, double&, int& ); + virtual QWidget* createEditor() const; + +private: + QDoubleValidator* myValidator; +}; + +SMESHGUI_doubleItem::SMESHGUI_doubleItem( QTable* t, EditType e, const double num ) +: QTableItem( t, e, QString( "%1" ).arg( num ) ), + myValidator( new QDoubleValidator( 0.0, 1.0, 3, t ) ) +{ +} + +SMESHGUI_doubleItem::~SMESHGUI_doubleItem() +{ +} + +void SMESHGUI_doubleItem::setValidator( const double bot, const double top, const int dec ) +{ + myValidator->setBottom( bot ); + myValidator->setTop( top ); + myValidator->setDecimals( dec ); +} + +void SMESHGUI_doubleItem::validator( double& bot, double& top, int& dec ) +{ + bot = myValidator->bottom(); + top = myValidator->top(); + dec = myValidator->decimals(); +} + +QWidget* SMESHGUI_doubleItem::createEditor() const +{ + QWidget* res = QTableItem::createEditor(); + if( res && res->inherits( "QLineEdit" ) ) + { + QLineEdit* l = ( QLineEdit* )res; + l->setValidator( myValidator ); + } + return res; +} + + +//================================================================================= +// class : SMESHGUI_Table +// purpose : +//================================================================================= +SMESHGUI_Table::SMESHGUI_Table( int numRows, int numCols, QWidget* parent, const char* name ) +: QTable( numRows, numCols, parent, name ) +{ +} + +SMESHGUI_Table::~SMESHGUI_Table() +{ +} + +QSize SMESHGUI_Table::sizeHint() const +{ + if( cachedSizeHint().isValid() ) + return cachedSizeHint(); + + constPolish(); + + QSize sh = QScrollView::sizeHint(); + if( sh.width()<400 ) + sh.setWidth( 400 ); + if( sh.height()<200 ) + sh.setHeight( 200 ); + + setCachedSizeHint( sh ); + return sh; +} + +void SMESHGUI_Table::stopEditing() +{ + endEdit( currEditRow(), currEditCol(), false, false ); +} + +void SMESHGUI_Table::validator( const int row, const int col, double& minV, double& maxV, int& dec ) +{ + SMESHGUI_doubleItem* it = dynamic_cast( item( row, col ) ); + if( it ) + it->validator( minV, maxV, dec ); +} + +void SMESHGUI_Table::setValidator( const double minV, const double maxV, const int dec, + const int rmin, const int rmax, + const int cmin, const int cmax ) +{ + int r1 = rmin>=0 ? rmin : 0, + r2 = rmax>=0 ? rmax : numRows(), + c1 = cmin>=0 ? cmin : 0, + c2 = cmax>=0 ? cmax : numCols(); + + for( int i=r1; i<=r2; i++ ) + for( int j=c1; j<=c2; j++ ) + { + SMESHGUI_doubleItem* it = dynamic_cast( item( i, j ) ); + if( it ) + it->setValidator( minV, maxV, dec ); + } +} + + + +//================================================================================= +// class : SMESHGUI_TableFrame +// purpose : +//================================================================================= +SMESHGUI_TableFrame::SMESHGUI_TableFrame( QWidget* parent ) +: QFrame( parent ) +{ + QVBoxLayout* main = new QVBoxLayout( this, 0, 0 ); + + myTable = new SMESHGUI_Table( 1, 1, this ); + + QFrame* aButFrame = new QFrame( this ); + QHBoxLayout* butLay = new QHBoxLayout( aButFrame, 5, 5 ); + + myAddColumn = new QPushButton( "Add column", aButFrame ); + + myRemoveColumn = new QPushButton( "Remove column", aButFrame ); + + myAddRow = new QPushButton( "Add row", aButFrame ); + + myRemoveRow = new QPushButton( "Remove row", aButFrame ); + + butLay->addWidget( myAddColumn, 0 ); + butLay->addWidget( myRemoveColumn, 0 ); + butLay->addWidget( myAddRow, 0 ); + butLay->addWidget( myRemoveRow, 0 ); + butLay->addStretch( 1 ); + + main->addWidget( myTable, 1 ); + main->addWidget( aButFrame, 0 ); + + connect( myAddColumn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myRemoveColumn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myAddRow, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myRemoveRow, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); +} + +SMESHGUI_TableFrame::~SMESHGUI_TableFrame() +{ +} + +SMESHGUI_Table* SMESHGUI_TableFrame::table() const +{ + return myTable; +} + +void SMESHGUI_TableFrame::setShown( const Button b, const bool sh ) +{ + if( button( b ) ) + button( b )->setShown( sh ); +} + +bool SMESHGUI_TableFrame::isShown( const Button b ) const +{ + bool res = false; + if( button( b ) ) + res = button( b )->isShown(); + return res; +} + +QButton* SMESHGUI_TableFrame::button( const Button b ) const +{ + QButton* res = 0; + switch( b ) + { + case ADD_COLUMN: + res = myAddColumn; + break; + + case REMOVE_COLUMN: + res = myRemoveColumn; + break; + + case ADD_ROW: + res = myAddRow; + break; + + case REMOVE_ROW: + res = myRemoveRow; + break; + } + return res; +} + +void SMESHGUI_TableFrame::onButtonClicked() +{ + if( sender()==button( ADD_COLUMN ) ) + emit toEdit( ADD_COLUMN, table()->currentColumn() ); + + else if( sender()==button( REMOVE_COLUMN ) ) + emit toEdit( REMOVE_COLUMN, table()->currentColumn() ); + + else if( sender()==button( ADD_ROW ) ) + emit toEdit( ADD_ROW, table()->currentRow() ); + + else if( sender()==button( REMOVE_ROW ) ) + emit toEdit( REMOVE_ROW, table()->currentRow() ); +} + + +//================================================================================= +// class : SMESHGUI_tableParameter +// purpose : +//================================================================================= +SMESHGUI_tableParameter::SMESHGUI_tableParameter( const double init, + const QString& label ) +: SMESHGUI_aParameter( label ), + myInitValue( init ), + myColsInt( 1 ), + myRowsInt( 1 ), + myEditCols( false ), + myEditRows( false ) +{ +} + +SMESHGUI_tableParameter::~SMESHGUI_tableParameter() +{ +} + +SMESHGUI_aParameter::Type SMESHGUI_tableParameter::GetType() const +{ + return TABLE; +} + +bool SMESHGUI_tableParameter::GetNewInt( int& ) const +{ + return false; +} + +bool SMESHGUI_tableParameter::GetNewDouble( double& ) const +{ + return false; +} + +bool SMESHGUI_tableParameter::GetNewText( QString& ) const +{ + return false; +} + +QWidget* SMESHGUI_tableParameter::CreateWidget( QWidget* par ) const +{ + SMESHGUI_TableFrame* t = new SMESHGUI_TableFrame( par ); + connect( t, SIGNAL( toEdit( SMESHGUI_TableFrame::Button, int ) ), + this, SLOT ( onEdit( SMESHGUI_TableFrame::Button, int ) ) ); + + update( t ); + return t; +} + +void SMESHGUI_tableParameter::setItems( QWidget* w, + int old_row, int new_row, + int old_col, int new_col ) const +{ + if( w && w->inherits( "SMESHGUI_TableFrame" ) ) + { + QTable* tab = ( ( SMESHGUI_TableFrame* )w )->table(); + + if( old_row<0 ) + old_row = 0; + if( new_row<0 ) + new_row = tab->numRows(); + if( old_col<0 ) + old_col = 0; + if( new_col<0 ) + new_col = tab->numCols(); + + for( int i=old_row, m=new_row; isetItem( i, j, new SMESHGUI_doubleItem( tab, QTableItem::WhenCurrent, myInitValue ) ); + + for( int i=0, m=new_row; isetItem( i, j, new SMESHGUI_doubleItem( tab, QTableItem::WhenCurrent, myInitValue ) ); + + for( int j=old_col; jsetColumnWidth( j, 50 ); + } +} + +void SMESHGUI_tableParameter::InitializeWidget( QWidget* w ) const +{ + setItems( w ); + + if( w && w->inherits( "SMESHGUI_TableFrame" ) ) + { + SMESHGUI_Table* tab = ( ( SMESHGUI_TableFrame* )w )->table(); + tab->stopEditing(); + + int col = tab->numCols(), + row = tab->numRows(); + + for( int i=0, m=row; iitem( i, j )->setText( QString( "%1" ).arg( myData[row*j+i] ) ); + } +} + +void SMESHGUI_tableParameter::TakeValue( QWidget* w ) +{ + if( w && w->inherits( "SMESHGUI_TableFrame" ) ) + { + QTable* tab = ( ( SMESHGUI_TableFrame* )w )->table(); + + int col = tab->numCols(), + row = tab->numRows(); + + myData.length( col*row ); + for( int i=0; itext( i, j ).toDouble(); + } +} + +void SMESHGUI_tableParameter::data( SMESH::double_array& v ) const +{ + v = myData; +} + +void SMESHGUI_tableParameter::setData( const SMESH::double_array& d ) +{ + myData = d; +} + +void SMESHGUI_tableParameter::update( QWidget* w ) const +{ + if( w && w->inherits( "SMESHGUI_TableFrame" ) ) + { + SMESHGUI_TableFrame* tabfr = ( SMESHGUI_TableFrame* ) w; + SMESHGUI_Table* tab = tabfr->table(); + + int old_col = tab->numCols(), + old_row = tab->numRows(); + + int col = myColsInt, row = myRowsInt; + if( myCols.get() ) + myCols->GetNewInt( col ); + + if( myRows.get() ) + myRows->GetNewInt( row ); + + if( col<=0 ) + col = 1; + if( row<=0 ) + row = 1; + + if( col!=tab->numCols() ) + tab->setNumCols( col ); + + if( row!=tab->numRows() ) + tab->setNumRows( row ); + + tabfr->setShown( SMESHGUI_TableFrame::ADD_COLUMN, myEditCols ); + tabfr->setShown( SMESHGUI_TableFrame::REMOVE_COLUMN, myEditCols ); + tabfr->setShown( SMESHGUI_TableFrame::ADD_ROW, myEditRows ); + tabfr->setShown( SMESHGUI_TableFrame::REMOVE_ROW, myEditRows ); + + setItems( w, old_row, row, old_col, col ); + + QMap< int, QString >::const_iterator aNIt = myColNames.begin(), + aNLast = myColNames.end(); + for( ; aNIt!=aNLast; aNIt++ ) + tab->horizontalHeader()->setLabel( aNIt.key(), aNIt.data() ); + + ValidatorsMap::const_iterator anIt = myValidators.begin(), + aLast = myValidators.end(); + for( ; anIt!=aLast; anIt++ ) + { + int row = anIt.key(), dec; + double minV, maxV; + validator( row, minV, maxV, dec ); + tab->setValidator( minV, maxV, dec, -1, -1, col, col ); + } + + QSize s = tab->sizeHint(); + tab->resize( s.width(), s.height() ); + } +} + +void SMESHGUI_tableParameter::setColCount( const int c, QWidget* w ) +{ + myColsInt = c; + update( w ); +} + +void SMESHGUI_tableParameter::setRowCount( const int c, QWidget* w ) +{ + myRowsInt = c; + update( w ); +} + +void SMESHGUI_tableParameter::setColCount( const SMESHGUI_aParameterPtr p, QWidget* w ) +{ + if( p.get() ) + { + myCols = p; + update( w ); + } +} + +void SMESHGUI_tableParameter::setRowCount( const SMESHGUI_aParameterPtr p, QWidget* w ) +{ + if( p.get() ) + { + myRows = p; + update( w ); + } +} + +QString SMESHGUI_tableParameter::sigValueChanged() const +{ + return SIGNAL( valueChanged( int, int ) ); +} + +void SMESHGUI_tableParameter::setValidator( const int ind, const double minV, const double maxV, const int dec ) +{ + ValidatorInfo inf; + inf.myMin = minV; + inf.myMax = maxV; + inf.myDecimals = dec; + myValidators[ ind ] = inf; +} + +void SMESHGUI_tableParameter::validator( const int ind, double& minV, double& maxV, int& dec ) const +{ + if( myValidators.contains( ind ) ) + { + const ValidatorInfo& inf = myValidators[ ind ]; + minV = inf.myMin; + maxV = inf.myMax; + dec = inf.myDecimals; + } +} + +void SMESHGUI_tableParameter::setEditCols( const bool ed ) +{ + myEditCols = ed; +} + +void SMESHGUI_tableParameter::setEditRows( const bool ed ) +{ + myEditRows = ed; +} + +void SMESHGUI_tableParameter::setColName( const int ind, const QString& name ) +{ + myColNames.insert( ind, name ); +} + +QString SMESHGUI_tableParameter::colName( const int ind ) const +{ + if( myColNames.contains( ind ) ) + return myColNames[ ind ]; + else + return QString::null; +} + +void SMESHGUI_tableParameter::onEdit( SMESHGUI_TableFrame::Button b, int n ) +{ + if( sender() && sender()->inherits( "SMESHGUI_TableFrame" ) ) + { + SMESHGUI_TableFrame* fr = ( SMESHGUI_TableFrame* )sender(); + SMESHGUI_Table* tab = fr->table(); + + switch( b ) + { + case SMESHGUI_TableFrame::ADD_COLUMN: + { + if( !myEditCols || myCols.get() ) + return; + + myColsInt++; update( fr ); + if( n>=0 ) + for( int i=0; i=n; j-- ) + if( j==n ) + tab->setText( i, j, QString( "%1" ).arg( myInitValue ) ); + else + tab->setText( i, j, tab->text( i, j-1 ) ); + break; + } + + case SMESHGUI_TableFrame::REMOVE_COLUMN: + { + if( !myEditCols || myCols.get() || myColsInt<=1 ) + return; + + if( n>=0 ) + for( int i=0; isetText( i, j, tab->text( i, j+1 ) ); + myColsInt--; update( fr ); + + break; + } + + case SMESHGUI_TableFrame::ADD_ROW: + { + if( !myEditRows || myRows.get() ) + return; + + myRowsInt++; update( fr ); + if( n>=0 ) + for( int i=myRowsInt-1; i>=n; i-- ) + for( int j=0; jsetText( i, j, QString( "%1" ).arg( myInitValue ) ); + else + tab->setText( i, j, tab->text( i-1, j ) ); + break; + } + + case SMESHGUI_TableFrame::REMOVE_ROW: + { + if( !myEditRows || myRows.get() || myRowsInt<=1 ) + return; + + if( n>=0 ) + for( int i=n; isetText( i, j, tab->text( i+1, j ) ); + myRowsInt--; update( fr ); + + break; + } + } + } +} diff --git a/src/SMESHGUI/SMESHGUI_aParameter.h b/src/SMESHGUI/SMESHGUI_aParameter.h index a4360b5fd..8613b50dd 100644 --- a/src/SMESHGUI/SMESHGUI_aParameter.h +++ b/src/SMESHGUI/SMESHGUI_aParameter.h @@ -29,41 +29,50 @@ #define SMESHGUI_aParameter_H #include -#include +#include +#include +#include + +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) class QWidget; class SMESHGUI_aParameter; typedef boost::shared_ptr SMESHGUI_aParameterPtr; -//================================================================================= -// class : SMESHGUI_aParameter -// purpose : -//================================================================================= +/*! + * \brief This class is the base class of all parameters + */ class SMESHGUI_aParameter { public: SMESHGUI_aParameter(const QString& label):_label(label) {} virtual ~SMESHGUI_aParameter(); - enum Type { INT, DOUBLE, TEXT }; + enum Type { INT, DOUBLE, STRING, ENUM, BOOL, TABLE }; virtual Type GetType() const = 0; virtual bool GetNewInt( int & Value ) const = 0; virtual bool GetNewDouble( double & Value ) const = 0; virtual bool GetNewText( QString & Value ) const = 0; - virtual void InitializeWidget( QWidget* ) const = 0; virtual void TakeValue( QWidget* ) = 0; + virtual QWidget* CreateWidget( QWidget* ) const = 0; + virtual void InitializeWidget( QWidget* ) const = 0; - QString & Label() { return _label; } + /*! + * \brief Returns string representation of signal emitted when value in corrsponding widget is changed + */ + virtual QString sigValueChanged() const; - private: + QString & Label() { return _label; } + +private: QString _label; }; -//================================================================================= -// class : SMESHGUI_intParameter -// purpose : -//================================================================================= +/*! + * \brief This class provides parameter with integer value + */ class SMESHGUI_intParameter: public SMESHGUI_aParameter { public: @@ -78,18 +87,20 @@ public: virtual bool GetNewInt( int & Value ) const; virtual bool GetNewDouble( double & Value ) const; virtual bool GetNewText( QString & Value ) const; - virtual void InitializeWidget( QWidget* ) const; virtual void TakeValue( QWidget* ); + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; - private: + virtual QString sigValueChanged() const; + +private: int _top, _bottom; int _initValue, _newValue; }; -//================================================================================= -// class : SMESHGUI_doubleParameter -// purpose : -//================================================================================= +/*! + * \brief This class provides parameter with double value + */ class SMESHGUI_doubleParameter: public SMESHGUI_aParameter { public: @@ -108,35 +119,324 @@ public: virtual bool GetNewInt( int & Value ) const; virtual bool GetNewDouble( double & Value ) const; virtual bool GetNewText( QString & Value ) const; + virtual QWidget* CreateWidget( QWidget* ) const; virtual void InitializeWidget( QWidget* ) const; virtual void TakeValue( QWidget* ); - private: + virtual QString sigValueChanged() const; + +private: double _top, _bottom, _step; double _initValue, _newValue; int _decimals; }; - -//================================================================================= -// class : SMESHGUI_strParameter -// purpose : -//================================================================================= +/*! + * \brief This class provides parameter with string value + */ class SMESHGUI_strParameter: public SMESHGUI_aParameter { public: - SMESHGUI_strParameter(const QString& initValue = "", - const QString& label = QString::null); - QString InitValue() { return _initValue; } + SMESHGUI_strParameter( const QString& initValue = "", + const QString& label = QString::null); + QString& InitValue() { return _initValue; } virtual Type GetType() const; virtual bool GetNewInt( int & Value ) const; virtual bool GetNewDouble( double & Value ) const; virtual bool GetNewText( QString & Value ) const; + virtual QWidget* CreateWidget( QWidget* ) const; virtual void InitializeWidget( QWidget* ) const; virtual void TakeValue( QWidget* ); - private: + virtual QString sigValueChanged() const; + +private: QString _initValue, _newValue; }; + +/*! + * \brief This class represents the base parameter which contains dependency of + * shown state of other parameters on value of current + */ +class SMESHGUI_dependParameter: public SMESHGUI_aParameter +{ +public: + /*! + * \brief This map describes what parameters must be shown when this parameter has value as key + * The list contains some indices of parameters (for example, order in some list) + * Value is integer based 0. If map is empty, it means that there is no dependencies. + */ + typedef QValueList< int > IntList; + typedef QMap< int, IntList > ShownMap; + +public: + SMESHGUI_dependParameter( const QString& = QString::null ); + + const ShownMap& shownMap() const; + ShownMap& shownMap(); + +private: + ShownMap myShownMap; +}; + +/*! + * \brief This class represents parameter which can have value from fixed set + */ +class SMESHGUI_enumParameter: public SMESHGUI_dependParameter +{ +public: + /*! + * \brief Creates parameter with set of values 'values', default value 'init' and title 'label' + * Every value can be described both by integer based 0 or by string value + */ + SMESHGUI_enumParameter( const QStringList& values, + const int init = 0, + const QString& label = QString::null ); + virtual ~SMESHGUI_enumParameter(); + + /*! + * \brief Returns count of possible values + */ + int Count() const; + + int& InitValue() { return myInitValue; } + virtual Type GetType() const; + virtual bool GetNewInt( int& ) const; + virtual bool GetNewDouble( double& ) const; + virtual bool GetNewText( QString& ) const; + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; + virtual void TakeValue( QWidget* ); + + virtual QString sigValueChanged() const; + +private: + int myInitValue, myValue; + QStringList myValues; +}; + + +/*! + * \brief This class represents parameter which can have value true or false + */ +class SMESHGUI_boolParameter: public SMESHGUI_dependParameter +{ +public: + SMESHGUI_boolParameter( const bool = false, + const QString& = QString::null ); + virtual ~SMESHGUI_boolParameter(); + + bool& InitValue() { return myInitValue; } + virtual Type GetType() const; + virtual bool GetNewInt( int& ) const; + virtual bool GetNewDouble( double& ) const; + virtual bool GetNewText( QString& ) const; + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; + virtual void TakeValue( QWidget* ); + + virtual QString sigValueChanged() const; + +private: + bool myInitValue, myValue; +}; + + +class QButton; + +/*! + * \brief This class represents custom table. It has only double values and + editor for every cell has validator + */ +class SMESHGUI_Table : public QTable +{ + Q_OBJECT + +public: + SMESHGUI_Table( int numRows, int numCols, QWidget* = 0, const char* = 0 ); + virtual ~SMESHGUI_Table(); + +/*! + * \brief Hides current editor of cell + */ + void stopEditing(); + + virtual QSize sizeHint() const; + +/*! + * \brief Returns parameters of double validator corresponding to cell (row,col) + */ + void validator( const int row, const int col, double&, double&, int& ); + +/*! + * \brief Sets the double validator parameters to every cell in row range [rmin,rmax] + * and column range [cmin,cmax]. + * If rmin=-1 then rmin is set to 0, if rmax=-1 then rmax = last row. + * Analogically cmin and cmax are set + */ + void setValidator( const double, const double, const int, + const int rmin = -1, const int rmax = -1, + const int cmin = -1, const int cmax = -1 ); +}; + + +/*! + * \brief This class represents frame for table and buttons + */ +class SMESHGUI_TableFrame : public QFrame +{ + Q_OBJECT + +public: +/*! + * \brief Values corresponding to buttons for table resize + */ + typedef enum { ADD_COLUMN, REMOVE_COLUMN, ADD_ROW, REMOVE_ROW } Button; + +public: + SMESHGUI_TableFrame( QWidget* ); + ~SMESHGUI_TableFrame(); + + SMESHGUI_Table* table() const; + +/*! + * \brief Changes shown state of some button for table resize + */ + void setShown( const Button, const bool ); + +/*! + * \brief Returns shown state of some button for table resize + */ + bool isShown( const Button ) const; + +private: + QButton* button( const Button ) const; + +private slots: + void onButtonClicked(); + +signals: +/*! + * \brief This signal is emitted if some of button for table resize is clicked + * Second parameter is current column for ADD_COLUMN, REMOVE_COLUMN buttons + * and current row for ADD_ROW, REMOVE_ROW buttons. Take into account that + * this object resize table ( returned by table() ) automatically + */ + void toEdit( SMESHGUI_TableFrame::Button, int ); + +private: + QButton *myAddColumn, *myRemoveColumn, *myAddRow, *myRemoveRow; + SMESHGUI_Table* myTable; +}; + + +/*! + * \brief This class represents parameter which can have two-dimensional array of values + */ +class SMESHGUI_tableParameter: public QObject, public SMESHGUI_aParameter +{ + Q_OBJECT + +public: +/*! + * \brief Creates table parameter with default value 'init' and title 'label'. + * The default value means that by default the table is filled with default value + * and if new column or row is added then it is filled with default value + */ + SMESHGUI_tableParameter( const double init = 0.0, + const QString& label = QString::null ); + virtual ~SMESHGUI_tableParameter(); + + virtual Type GetType() const; + virtual bool GetNewInt( int& ) const; + virtual bool GetNewDouble( double& ) const; + virtual bool GetNewText( QString& ) const; + virtual QWidget* CreateWidget( QWidget* ) const; + virtual void InitializeWidget( QWidget* ) const; + virtual void TakeValue( QWidget* ); + +/*! + * \brief Updates look of widget in accordance with all parameters of this object + */ + void update( QWidget* ) const; + +/*! + * \brief Returns data taken from widget. Please don't forget to call TakeValue before. + */ + void data( SMESH::double_array& ) const; + +/*! + * \brief Sets data. The InitializeWidget must be called in order to change values in widget + */ + void setData( const SMESH::double_array& ); + +/*! + * \brief Sets count of columns and updates widget + */ + void setColCount( const int, QWidget* = 0 ); + +/*! + * \brief Sets count of rows and updates widget + */ + void setRowCount( const int, QWidget* = 0 ); + +/*! + * \brief Binds count of columns to some parameter and updates widget. Take into account that + * if this parameter is changed, the update() must be called to resize table + */ + void setColCount( const SMESHGUI_aParameterPtr, QWidget* = 0 ); + +/*! + * \brief Binds count of rows to some parameter and updates widget. Take into account that + * if this parameter is changed, the update() must be called to resize table + */ + void setRowCount( const SMESHGUI_aParameterPtr, QWidget* = 0 ); + +/*! + * \brief Enables or disables to change count of columns by buttons + */ + void setEditCols( const bool ); + +/*! + * \brief Enables or disables to change count of rows by buttons + */ + void setEditRows( const bool ); + + virtual QString sigValueChanged() const; + + void setValidator( const int col, const double, const double, const int ); + void validator( const int col, double&, double&, int& ) const; + +/*! + * \brief These methods allow to read and change name of column + */ + void setColName( const int, const QString& ); + QString colName( const int ) const; + +private slots: + void onEdit( SMESHGUI_TableFrame::Button, int ); + +private: + void setItems( QWidget*, int = -1, int = -1, int = -1, int = -1 ) const; + +private: + typedef struct + { + double myMin, myMax; + int myDecimals; + } ValidatorInfo; + + typedef QMap ValidatorsMap; + +private: + int myColsInt, myRowsInt; + SMESHGUI_aParameterPtr myCols, myRows; + double myInitValue; + SMESH::double_array myData; + ValidatorsMap myValidators; + bool myEditCols, myEditRows; + QMap< int, QString > myColNames; +}; + #endif // SMESHGUI_aParameter.h diff --git a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx index 03145925f..7e824a7b9 100644 --- a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx @@ -42,7 +42,7 @@ #include #include #include -#include +#include using namespace std; @@ -80,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); /***************************************************************/ @@ -100,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); @@ -155,8 +146,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 +195,61 @@ bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule, } 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 ); + } +} diff --git a/src/SMESHGUI/SMESHGUI_aParameterDlg.h b/src/SMESHGUI/SMESHGUI_aParameterDlg.h index 0c53672b2..7fd28a96f 100644 --- a/src/SMESHGUI/SMESHGUI_aParameterDlg.h +++ b/src/SMESHGUI/SMESHGUI_aParameterDlg.h @@ -62,8 +62,12 @@ public: protected: void init(); +protected slots: + virtual void onValueChanged(); + private slots: void ClickOnOk(); + void UpdateShown( const SMESHGUI_aParameterPtr, QWidget* ); private: SMESHGUI* mySMESHGUI; @@ -71,7 +75,7 @@ private: QPushButton* myButtonOk; QPushButton* myButtonCancel; - std::list mySpinList; + std::list mySpinList, myLabelList; std::list myParamList; };