From: vsr Date: Thu, 17 Sep 2009 11:56:45 +0000 (+0000) Subject: IPAL21367: Fix problems with the Fixed Points widget: addition of same values should... X-Git-Tag: V5_1_3rc1~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b7cae6675fbeee96b633ed06131b565d5b19f720;p=modules%2Fsmesh.git IPAL21367: Fix problems with the Fixed Points widget: addition of same values should be disabled --- diff --git a/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.cxx index 51685c370..0069a7b4e 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.cxx @@ -25,6 +25,9 @@ // #include "StdMeshersGUI_FixedPointsParamWdg.h" +#include +#include + // Qt includes #include #include @@ -36,7 +39,6 @@ #include #include #include -#include #include #include @@ -44,8 +46,11 @@ #define MARGIN 0 #define SAME_TEXT "-/-" +#define TOLERANCE 1e-7 +#define EQUAL_DBL(a,b) (fabs(a-b)setFrame( false ); sb->setRange( 1, 999); w = sb; @@ -87,8 +92,8 @@ void StdMeshersGUI_FixedPointsParamWdg::LineDelegate::setModelData( QWidget* edi QAbstractItemModel* model, const QModelIndex& index ) const { - model->setData( index, qobject_cast( editor )->value(), Qt::EditRole ); - model->setData( index, qobject_cast( editor )->value(), Qt::UserRole ); + model->setData( index, qobject_cast( editor )->value(), Qt::EditRole ); + model->setData( index, qobject_cast( editor )->value(), Qt::UserRole ); } //================================================================================ @@ -107,7 +112,7 @@ StdMeshersGUI_FixedPointsParamWdg myListWidget = new QListWidget( this ); myTreeWidget = new QTreeWidget( this ); - mySpinBox = new QDoubleSpinBox( this ); + mySpinBox = new QtxDoubleSpinBox( this ); myAddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), this ); myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this ); mySameValues = new QCheckBox( tr("SMESH_SAME_NB_SEGMENTS"), this); @@ -136,10 +141,15 @@ StdMeshersGUI_FixedPointsParamWdg mySpinBox->setRange( 0, 1 ); mySpinBox->setSingleStep( 0.1 ); - - connect( myAddButton, SIGNAL(clicked()), SLOT(onAdd())); - connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove())); - connect( mySameValues, SIGNAL(stateChanged(int)), SLOT(onCheckBoxChanged())); + mySpinBox->setDecimals( 4 ); + mySpinBox->setPrecision( 4 ); + myListWidget->setMinimumWidth( 70 ); + + connect( myAddButton, SIGNAL( clicked() ), SLOT( onAdd() ) ); + connect( myRemoveButton, SIGNAL( clicked() ), SLOT( onRemove() ) ); + connect( mySameValues, SIGNAL( stateChanged( int ) ), SLOT( onCheckBoxChanged() ) ); + connect( mySpinBox, SIGNAL( valueChanged( double ) ), SLOT( updateState() ) ); + connect( myListWidget, SIGNAL( itemSelectionChanged() ), SLOT( updateState() ) ); myListWidget->installEventFilter( this ); clear(); @@ -182,6 +192,7 @@ void StdMeshersGUI_FixedPointsParamWdg::clear() myTreeWidget->addTopLevelItem( newTreeItem( 0, 1 ) ); mySpinBox->setValue( 0. ); onCheckBoxChanged(); + updateState(); } //================================================================================= @@ -249,7 +260,7 @@ void StdMeshersGUI_FixedPointsParamWdg::addPoint( double v) int idx = myTreeWidget->topLevelItemCount()-1; for ( int i = 0 ; i < myListWidget->count(); i++ ) { double lv = point( i ); - if ( lv == v ) { toInsert = false; break; } + if ( EQUAL_DBL(lv,v) ) { toInsert = false; break; } else if ( lv > v ) { idx = i; break; } @@ -263,6 +274,7 @@ void StdMeshersGUI_FixedPointsParamWdg::addPoint( double v) onCheckBoxChanged(); } } + updateState(); } //================================================================================= @@ -281,6 +293,7 @@ void StdMeshersGUI_FixedPointsParamWdg::removePoints() idx > myListWidget->count()-1 ? 1 : point( idx ) ) ); } onCheckBoxChanged(); + updateState(); } double StdMeshersGUI_FixedPointsParamWdg::point( int idx ) const @@ -314,6 +327,16 @@ void StdMeshersGUI_FixedPointsParamWdg::onCheckBoxChanged() } } +//================================================================================= +// function : updateState() +// purpose : Update widgets state +//================================================================================= +void StdMeshersGUI_FixedPointsParamWdg::updateState() +{ + myAddButton->setEnabled( mySpinBox->value() > 0 && mySpinBox->value() < 1 ); + myRemoveButton->setEnabled( myListWidget->selectedItems().count() > 0 ); +} + //================================================================================= // function : GetListOfPoints // purpose : Called to get the list of Edges IDs @@ -325,7 +348,6 @@ SMESH::double_array_var StdMeshersGUI_FixedPointsParamWdg::GetListOfPoints() anArray->length( size ); for (int i = 0; i < size; i++) { anArray[i] = point(i); - // printf ("Point %f \n", anArray[i]); } return anArray; } @@ -339,7 +361,6 @@ void StdMeshersGUI_FixedPointsParamWdg::SetListOfPoints( SMESH::double_array_var clear(); for ( int i = 0; i < thePoints->length(); i++ ) { addPoint( thePoints[ i ] ); - // printf ("Add Point %f \n", thePoints[ i ]); } } @@ -354,7 +375,6 @@ SMESH::long_array_var StdMeshersGUI_FixedPointsParamWdg::GetListOfSegments() anArray->length( size ); for (int i = 0; i < size; i++) { anArray[i] = nbSegments( i ); - // printf ("Segments %d \n", anArray[i] ); } return anArray; } @@ -369,6 +389,5 @@ void StdMeshersGUI_FixedPointsParamWdg::SetListOfSegments( SMESH::long_array_var mySameValues->setChecked(true); for ( int i = 0; i < theSegments->length(); i++ ) { setNbSegments( i, theSegments[i] ); - // printf ("\nadd Segment = %d\n", theSegments[i]); } } diff --git a/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.h b/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.h index b96806de4..273781d34 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.h +++ b/src/StdMeshersGUI/StdMeshersGUI_FixedPointsParamWdg.h @@ -34,10 +34,10 @@ #include class SMESHGUI; +class QtxDoubleSpinBox; class QPushButton; class QLineEdit; class QCheckBox; -class QDoubleSpinBox; class QListWidget; class QListWidgetItem; class QTreeWidget; @@ -67,6 +67,7 @@ private slots: void onAdd(); void onRemove(); void onCheckBoxChanged(); + void updateState(); private: void clear(); @@ -83,7 +84,7 @@ private: private: QListWidget* myListWidget; QTreeWidget* myTreeWidget; - QDoubleSpinBox* mySpinBox; + QtxDoubleSpinBox* mySpinBox; QPushButton* myAddButton; QPushButton* myRemoveButton; QCheckBox* mySameValues;