IPAL21367: Fix problems with the Fixed Points widget: addition of same values should be disabled

This commit is contained in:
vsr 2009-09-17 11:56:45 +00:00
parent 0aa24a2835
commit b7cae6675f
2 changed files with 36 additions and 16 deletions

View File

@ -25,6 +25,9 @@
// //
#include "StdMeshersGUI_FixedPointsParamWdg.h" #include "StdMeshersGUI_FixedPointsParamWdg.h"
#include <QtxIntSpinBox.h>
#include <QtxDoubleSpinBox.h>
// Qt includes // Qt includes
#include <QPushButton> #include <QPushButton>
#include <QIntValidator> #include <QIntValidator>
@ -36,7 +39,6 @@
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QCheckBox> #include <QCheckBox>
#include <QLineEdit> #include <QLineEdit>
#include <QDoubleSpinBox>
#include <QItemDelegate> #include <QItemDelegate>
#include <QKeyEvent> #include <QKeyEvent>
@ -44,8 +46,11 @@
#define MARGIN 0 #define MARGIN 0
#define SAME_TEXT "-/-" #define SAME_TEXT "-/-"
#define TOLERANCE 1e-7
#define EQUAL_DBL(a,b) (fabs(a-b)<TOLERANCE)
/* /*
* function : Tree Widget Item Delegate * class : Tree Widget Item Delegate
* purpose : Custom item delegate * purpose : Custom item delegate
*/ */
@ -74,7 +79,7 @@ QWidget* StdMeshersGUI_FixedPointsParamWdg::LineDelegate::createEditor( QWidget*
{ {
QWidget* w = 0; QWidget* w = 0;
if ( (index.column() == 1 ) ) { if ( (index.column() == 1 ) ) {
QSpinBox* sb = new QSpinBox( parent ); QtxIntSpinBox* sb = new QtxIntSpinBox( parent );
sb->setFrame( false ); sb->setFrame( false );
sb->setRange( 1, 999); sb->setRange( 1, 999);
w = sb; w = sb;
@ -87,8 +92,8 @@ void StdMeshersGUI_FixedPointsParamWdg::LineDelegate::setModelData( QWidget* edi
QAbstractItemModel* model, QAbstractItemModel* model,
const QModelIndex& index ) const const QModelIndex& index ) const
{ {
model->setData( index, qobject_cast<QSpinBox*>( editor )->value(), Qt::EditRole ); model->setData( index, qobject_cast<QtxIntSpinBox*>( editor )->value(), Qt::EditRole );
model->setData( index, qobject_cast<QSpinBox*>( editor )->value(), Qt::UserRole ); model->setData( index, qobject_cast<QtxIntSpinBox*>( editor )->value(), Qt::UserRole );
} }
//================================================================================ //================================================================================
@ -107,7 +112,7 @@ StdMeshersGUI_FixedPointsParamWdg
myListWidget = new QListWidget( this ); myListWidget = new QListWidget( this );
myTreeWidget = new QTreeWidget( this ); myTreeWidget = new QTreeWidget( this );
mySpinBox = new QDoubleSpinBox( this ); mySpinBox = new QtxDoubleSpinBox( this );
myAddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), this ); myAddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), this );
myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this ); myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this );
mySameValues = new QCheckBox( tr("SMESH_SAME_NB_SEGMENTS"), this); mySameValues = new QCheckBox( tr("SMESH_SAME_NB_SEGMENTS"), this);
@ -136,10 +141,15 @@ StdMeshersGUI_FixedPointsParamWdg
mySpinBox->setRange( 0, 1 ); mySpinBox->setRange( 0, 1 );
mySpinBox->setSingleStep( 0.1 ); mySpinBox->setSingleStep( 0.1 );
mySpinBox->setDecimals( 4 );
mySpinBox->setPrecision( 4 );
myListWidget->setMinimumWidth( 70 );
connect( myAddButton, SIGNAL( clicked() ), SLOT( onAdd() ) ); connect( myAddButton, SIGNAL( clicked() ), SLOT( onAdd() ) );
connect( myRemoveButton, SIGNAL( clicked() ), SLOT( onRemove() ) ); connect( myRemoveButton, SIGNAL( clicked() ), SLOT( onRemove() ) );
connect( mySameValues, SIGNAL( stateChanged( int ) ), SLOT( onCheckBoxChanged() ) ); connect( mySameValues, SIGNAL( stateChanged( int ) ), SLOT( onCheckBoxChanged() ) );
connect( mySpinBox, SIGNAL( valueChanged( double ) ), SLOT( updateState() ) );
connect( myListWidget, SIGNAL( itemSelectionChanged() ), SLOT( updateState() ) );
myListWidget->installEventFilter( this ); myListWidget->installEventFilter( this );
clear(); clear();
@ -182,6 +192,7 @@ void StdMeshersGUI_FixedPointsParamWdg::clear()
myTreeWidget->addTopLevelItem( newTreeItem( 0, 1 ) ); myTreeWidget->addTopLevelItem( newTreeItem( 0, 1 ) );
mySpinBox->setValue( 0. ); mySpinBox->setValue( 0. );
onCheckBoxChanged(); onCheckBoxChanged();
updateState();
} }
//================================================================================= //=================================================================================
@ -249,7 +260,7 @@ void StdMeshersGUI_FixedPointsParamWdg::addPoint( double v)
int idx = myTreeWidget->topLevelItemCount()-1; int idx = myTreeWidget->topLevelItemCount()-1;
for ( int i = 0 ; i < myListWidget->count(); i++ ) { for ( int i = 0 ; i < myListWidget->count(); i++ ) {
double lv = point( i ); double lv = point( i );
if ( lv == v ) { toInsert = false; break; } if ( EQUAL_DBL(lv,v) ) { toInsert = false; break; }
else if ( lv > v ) { else if ( lv > v ) {
idx = i; break; idx = i; break;
} }
@ -263,6 +274,7 @@ void StdMeshersGUI_FixedPointsParamWdg::addPoint( double v)
onCheckBoxChanged(); onCheckBoxChanged();
} }
} }
updateState();
} }
//================================================================================= //=================================================================================
@ -281,6 +293,7 @@ void StdMeshersGUI_FixedPointsParamWdg::removePoints()
idx > myListWidget->count()-1 ? 1 : point( idx ) ) ); idx > myListWidget->count()-1 ? 1 : point( idx ) ) );
} }
onCheckBoxChanged(); onCheckBoxChanged();
updateState();
} }
double StdMeshersGUI_FixedPointsParamWdg::point( int idx ) const 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 // function : GetListOfPoints
// purpose : Called to get the list of Edges IDs // purpose : Called to get the list of Edges IDs
@ -325,7 +348,6 @@ SMESH::double_array_var StdMeshersGUI_FixedPointsParamWdg::GetListOfPoints()
anArray->length( size ); anArray->length( size );
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
anArray[i] = point(i); anArray[i] = point(i);
// printf ("Point %f \n", anArray[i]);
} }
return anArray; return anArray;
} }
@ -339,7 +361,6 @@ void StdMeshersGUI_FixedPointsParamWdg::SetListOfPoints( SMESH::double_array_var
clear(); clear();
for ( int i = 0; i < thePoints->length(); i++ ) { for ( int i = 0; i < thePoints->length(); i++ ) {
addPoint( thePoints[ 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 ); anArray->length( size );
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
anArray[i] = nbSegments( i ); anArray[i] = nbSegments( i );
// printf ("Segments %d \n", anArray[i] );
} }
return anArray; return anArray;
} }
@ -369,6 +389,5 @@ void StdMeshersGUI_FixedPointsParamWdg::SetListOfSegments( SMESH::long_array_var
mySameValues->setChecked(true); mySameValues->setChecked(true);
for ( int i = 0; i < theSegments->length(); i++ ) { for ( int i = 0; i < theSegments->length(); i++ ) {
setNbSegments( i, theSegments[i] ); setNbSegments( i, theSegments[i] );
// printf ("\nadd Segment = %d\n", theSegments[i]);
} }
} }

View File

@ -34,10 +34,10 @@
#include <QStringList> #include <QStringList>
class SMESHGUI; class SMESHGUI;
class QtxDoubleSpinBox;
class QPushButton; class QPushButton;
class QLineEdit; class QLineEdit;
class QCheckBox; class QCheckBox;
class QDoubleSpinBox;
class QListWidget; class QListWidget;
class QListWidgetItem; class QListWidgetItem;
class QTreeWidget; class QTreeWidget;
@ -67,6 +67,7 @@ private slots:
void onAdd(); void onAdd();
void onRemove(); void onRemove();
void onCheckBoxChanged(); void onCheckBoxChanged();
void updateState();
private: private:
void clear(); void clear();
@ -83,7 +84,7 @@ private:
private: private:
QListWidget* myListWidget; QListWidget* myListWidget;
QTreeWidget* myTreeWidget; QTreeWidget* myTreeWidget;
QDoubleSpinBox* mySpinBox; QtxDoubleSpinBox* mySpinBox;
QPushButton* myAddButton; QPushButton* myAddButton;
QPushButton* myRemoveButton; QPushButton* myRemoveButton;
QCheckBox* mySameValues; QCheckBox* mySameValues;