From: asl Date: Wed, 13 Jul 2005 03:28:14 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7a2da1ed67342db32cb4402c5cdf68ddb7d53a4e;p=modules%2Fgui.git *** empty log message *** --- diff --git a/src/SalomeApp/SalomeApp_Dialog.cxx b/src/SalomeApp/SalomeApp_Dialog.cxx index ceaea4a61..a462eafd5 100644 --- a/src/SalomeApp/SalomeApp_Dialog.cxx +++ b/src/SalomeApp/SalomeApp_Dialog.cxx @@ -21,7 +21,7 @@ SalomeApp_Dialog::SalomeApp_Dialog( QWidget* parent, const char* name, bool moda bool allowResize, const int f, WFlags wf ) : QtxDialog( parent, name, modal, allowResize, f, wf ), myIsExclusive( true ), - myIsAutoResumed( false ) + myIsBusy( false ) { setObjectPixmap( "SalomeApp", tr( "ICON_SELECT" ) ); } @@ -133,6 +133,32 @@ bool SalomeApp_Dialog::isObjectShown( const int id ) const return myObjects.contains( id ) && myObjects[ id ].myEdit->isShown(); } +//======================================================================= +// name : setObjectEnabled +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectEnabled( const int id, const bool en ) +{ + if( myObjects.contains( id ) && isObjectEnabled( id )!=en ) + { + Object& obj = myObjects[ id ]; + obj.myEdit->setEnabled( en ); + obj.myBtn->setEnabled( en ); + obj.myLabel->setEnabled( en ); + if( !en ) + ( ( QToolButton* )obj.myBtn )->setOn( false ); + } +} + +//======================================================================= +// name : isObjectEnabled +// Purpose : +//======================================================================= +bool SalomeApp_Dialog::isObjectEnabled( const int id ) const +{ + return myObjects.contains( id ) && myObjects[ id ].myEdit->isEnabled(); +} + //======================================================================= // name : selectObject // Purpose : @@ -157,19 +183,7 @@ void SalomeApp_Dialog::selectObject( const QStringList& _names, aLast = myObjects.end(); for( ; anIt!=aLast; anIt++ ) if( anIt.data().myBtn->isOn() ) - { - QStringList names = _names, ids = _ids; - TypesList types = _types; - - filterTypes( anIt.key(), names, types, ids ); - - anIt.data().myEdit->setText( selectionDescription( names, types, anIt.data().myNI ) ); - anIt.data().myTypes = types; - anIt.data().myIds = ids; - anIt.data().myNames = names; - - emit selectionChanged( anIt.key() ); - } + selectObject( anIt.key(), _names, _types, _ids ); } //======================================================================= @@ -262,6 +276,7 @@ int SalomeApp_Dialog::createObject( const QString& label, QWidget* parent, const QLineEdit* ne = new QLineEdit( parent ); ne->setReadOnly( true ); ne->setMinimumWidth( 150 ); + connect( ne, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); myObjects[ nid ].myEdit = ne; myObjects[ nid ].myNI = OneNameOrCount; @@ -587,6 +602,7 @@ void SalomeApp_Dialog::setNameIndication( const int id, const NameIndication ni for( ; anIt!=aLast; anIt++ ) { anIt.data().myNI = ni; + setReadOnly( anIt.key(), isReadOnly( anIt.key() ) ); aNext = anIt; aNext++; updateObject( anIt.key(), aNext==aLast ); } @@ -594,6 +610,7 @@ void SalomeApp_Dialog::setNameIndication( const int id, const NameIndication ni else if( myObjects.contains( id ) ) { myObjects[ id ].myNI = ni; + setReadOnly( id, isReadOnly( id ) ); updateObject( id, true ); } } @@ -607,6 +624,9 @@ QString SalomeApp_Dialog::selectionDescription( const QStringList& names, const if( names.count()!=types.count() ) return "SalomeApp_Dialog::selectionDescription(): Error!!!"; + if( names.isEmpty() ) + return QString::null; + switch( ni ) { case OneName: @@ -621,7 +641,7 @@ QString SalomeApp_Dialog::selectionDescription( const QStringList& names, const break; case ListOfNames: - return names.join( ", " ); + return names.join( " " ); break; case Count: @@ -688,3 +708,92 @@ void SalomeApp_Dialog::deactivateAll() btn->setOn( false ); } } + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::selectObject( const int id, const QString& name, const int type, const QString& selid ) +{ + QStringList names; names.append( name ); + TypesList types; types.append( type ); + QStringList ids; ids.append( selid ); + selectObject( id, names, types, ids ); +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::selectObject( const int id, const QStringList& _names, const TypesList& _types, + const QStringList& _ids ) +{ + if( !myObjects.contains( id ) ) + return; + + QStringList names = _names, ids = _ids; + TypesList types = _types; + + filterTypes( id, names, types, ids ); + + Object& obj = myObjects[ id ]; + obj.myEdit->setText( selectionDescription( names, types, obj.myNI ) ); + obj.myTypes = types; + obj.myIds = ids; + obj.myNames = names; + + emit selectionChanged( id ); +} + +//======================================================================= +// name : setReadOnly +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setReadOnly( const int id, const bool ro ) +{ + if( myObjects.contains( id ) ) + myObjects[ id ].myEdit->setReadOnly( nameIndication( id )==ListOfNames || nameIndication( id )==OneName ? ro : true ); +} + +//======================================================================= +// name : isReadOnly +// Purpose : +//======================================================================= +bool SalomeApp_Dialog::isReadOnly( const int id ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].myEdit->isReadOnly(); + else + return true; +} + +//======================================================================= +// name : onTextChanged +// Purpose : +//======================================================================= +void SalomeApp_Dialog::onTextChanged( const QString& text ) +{ + if( myIsBusy ) + return; + + myIsBusy = true; + + if( sender() && sender()->inherits( "QLineEdit" ) ) + { + QLineEdit* edit = ( QLineEdit* )sender(); + int id = -1; + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data().myEdit == edit ) + id = anIt.key(); + + if( id>=0 && !isReadOnly( id ) ) + { + QStringList list = QStringList::split( " ", text ); + emit objectChanged( id, list ); + } + } + + myIsBusy = false; +} diff --git a/src/SalomeApp/SalomeApp_Dialog.h b/src/SalomeApp/SalomeApp_Dialog.h index e0e5cfe52..b66215401 100644 --- a/src/SalomeApp/SalomeApp_Dialog.h +++ b/src/SalomeApp/SalomeApp_Dialog.h @@ -69,6 +69,12 @@ public: //! Check the shown state bool isObjectShown( const int ) const; + //! Change the enabled state of widgets corresponding to id + void setObjectEnabled( const int, const bool ); + + //! Check the enabled state + bool isObjectEnabled( const int ) const; + //! Pass to all active widgets name, type and id of selected object void selectObject( const QString&, const int, const QString& ); @@ -78,6 +84,10 @@ public: */ void selectObject( const QStringList&, const TypesList&, const QStringList& ); + //! Select in certain widget avoiding check if there is active widget + void selectObject( const int, const QString&, const int, const QString& ); + void selectObject( const int, const QStringList&, const TypesList&, const QStringList& ); + //! Check if certain widget has selection bool hasSelection( const int ) const; @@ -102,11 +112,17 @@ signals: //! selection in certain widget is off void objectDeactivated( int ); + + /* + text representation of selection is changed + it is emitted only if "read only" state of line edit is false + */ + void objectChanged( int, const QStringList& ); protected: //! Finds and returns resource manager SUIT_ResourceMgr* resMgr() const; - + /*! Create label, button and line edit for object selection * If passed id is negative, then id will be calculated automatically (first free id) * Returns the same id (if id>=0) or calculated @@ -172,10 +188,20 @@ protected: //! Check using name indication if multiple selection in possible bool multipleSelection( const int ) const; + //! Set the "read only" state of object selection line edit + //! The "read only" will be false only if name indication is ListOfNames + void setReadOnly( const int, const bool ); + + //! Check the "read only" state of object selection line edit + bool isReadOnly( const int ) const; + private slots: //! emits if the object selection button changes state void onToggled( bool ); + //! text in some line edit is changed + void onTextChanged( const QString& ); + private: /*! If buttons are exclusive, set to "off" all buttons except one with id @@ -209,7 +235,7 @@ private: private: ObjectMap myObjects; QMap myTypeNames; - bool myIsExclusive, myIsAutoResumed; + bool myIsExclusive, myIsBusy; QPixmap myPixmap; };