From 2ae53d1560ab6b58c95a54404d464f9d55a206d3 Mon Sep 17 00:00:00 2001 From: sln Date: Tue, 23 Aug 2005 08:11:34 +0000 Subject: [PATCH] Base class for all Salome dialogs --- src/SalomeApp/SalomeApp_Dialog.cxx | 860 +++++++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Dialog.h | 266 +++++++++ 2 files changed, 1126 insertions(+) create mode 100644 src/SalomeApp/SalomeApp_Dialog.cxx create mode 100644 src/SalomeApp/SalomeApp_Dialog.h diff --git a/src/SalomeApp/SalomeApp_Dialog.cxx b/src/SalomeApp/SalomeApp_Dialog.cxx new file mode 100644 index 000000000..d708776ee --- /dev/null +++ b/src/SalomeApp/SalomeApp_Dialog.cxx @@ -0,0 +1,860 @@ +// File: SalomeApp_Dialog.cxx +// Author: Alexander SOLOVYOV + +#include +#include + +#include +#include +#include + +/* + Class : SalomeApp_Dialog + Description : Base class for all SALOME dialogs +*/ + +//======================================================================= +// name : SalomeApp_Dialog +// Purpose : Constructor +//======================================================================= +SalomeApp_Dialog::SalomeApp_Dialog( QWidget* parent, const char* name, bool modal, + bool allowResize, const int f, WFlags wf ) +: QtxDialog( parent, name, modal, allowResize, f, wf ), + myIsExclusive( true ), + myIsBusy( false ) +{ + setObjectPixmap( "SalomeApp", tr( "ICON_SELECT" ) ); +} + +//======================================================================= +// name : ~SalomeApp_Dialog +// Purpose : Destructor +//======================================================================= +SalomeApp_Dialog::~SalomeApp_Dialog() +{ +} + +//======================================================================= +// name : show +// Purpose : +//======================================================================= +void SalomeApp_Dialog::show() +{ + QtxDialog::show(); +} + +//======================================================================= +// name : isExclusive +// Purpose : +//======================================================================= +bool SalomeApp_Dialog::isExclusive() const +{ + return myIsExclusive; +} + +//======================================================================= +// name : updateButtons +// Purpose : +//======================================================================= +void SalomeApp_Dialog::updateButtons( const int _id ) +{ + if( !myIsExclusive ) + return; + + int id = _id; + + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QToolButton* but = (QToolButton*)anIt.data().myBtn; + if( but && but->isOn() ) + { + if( id==-1 ) + id = anIt.key(); + + if( anIt.key()!=id ) + but->setOn( false ); + } + } +} + +//======================================================================= +// name : setExclusive +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setExclusive( const bool ex ) +{ + myIsExclusive = ex; + updateButtons(); +} + +//======================================================================= +// name : showObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::showObject( const int id ) +{ + setObjectShown( id, true ); +} + +//======================================================================= +// name : hideObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::hideObject( const int id ) +{ + setObjectShown( id, false ); +} + +//======================================================================= +// name : setObjectShown +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectShown( const int id, const bool shown ) +{ + if( myObjects.contains( id ) && isObjectShown( id )!=shown ) + { + Object& obj = myObjects[ id ]; + obj.myEdit->setShown( shown ); + obj.myBtn->setShown( shown ); + obj.myLabel->setShown( shown ); + if( !shown ) + ( ( QToolButton* )obj.myBtn )->setOn( false ); + } +} + +//======================================================================= +// name : isObjectShown +// Purpose : +//======================================================================= +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 : +//======================================================================= +void SalomeApp_Dialog::selectObject( const QString& name, const int type, const QString& id, const bool update ) +{ + QStringList names; names.append( name ); + TypesList types; types.append( type ); + QStringList ids; ids.append( id ); + selectObject( names, types, ids, update ); +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::selectObject( const QStringList& _names, + const TypesList& _types, + const QStringList& _ids, + const bool update ) +{ + ObjectMap::iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data().myBtn->isOn() ) + selectObject( anIt.key(), _names, _types, _ids, update ); +} + +//======================================================================= +// name : hasSelection +// Purpose : +//======================================================================= +bool SalomeApp_Dialog::hasSelection( const int id ) const +{ + return myObjects.contains( id ) && !myObjects[ id ].myIds.isEmpty(); +} + +//======================================================================= +// name : clearSelection +// Purpose : +//======================================================================= +void SalomeApp_Dialog::clearSelection( const int id ) +{ + if( id==-1 ) + { + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + clearSelection( anIt.key() ); + } + + else if( myObjects.contains( id ) ) + { + myObjects[ id ].myIds.clear(); + myObjects[ id ].myTypes.clear(); + myObjects[ id ].myNames.clear(); + + myObjects[ id ].myEdit->setText( QString::null ); + emit selectionChanged( id ); + } +} + +//======================================================================= +// name : objectWg +// Purpose : +//======================================================================= +QWidget* SalomeApp_Dialog::objectWg( const int theId, const int theWgId ) const +{ + QWidget* aResWg = 0; + if( myObjects.contains( theId ) ) + { + if ( theWgId == Label ) + aResWg = myObjects[ theId ].myLabel; + else if ( theWgId == Btn ) + aResWg = myObjects[ theId ].myBtn; + else if ( theWgId == Control ) + aResWg = myObjects[ theId ].myEdit; + } + return aResWg; +} + +//======================================================================= +// name : objectText +// Purpose : +//======================================================================= +QString SalomeApp_Dialog::objectText( const int theId ) const +{ + return myObjects.contains( theId ) ? myObjects[ theId ].myEdit->text() : ""; +} + +//======================================================================= +// name : setObjectText +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectText( const int theId, const QString& theText ) +{ + if ( myObjects.contains( theId ) ) + myObjects[ theId ].myEdit->setText( theText ); +} + +//======================================================================= +// name : selectedObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::selectedObject( const int id, QStringList& list ) const +{ + if( myObjects.contains( id ) ) + list = myObjects[ id ].myIds; +} + +//======================================================================= +// name : selectedObject +// Purpose : +//======================================================================= +QString SalomeApp_Dialog::selectedObject( const int id ) const +{ + if ( myObjects.contains( id ) && myObjects[ id ].myIds.count() > 0 ) + return myObjects[ id ].myIds.first(); + else + return ""; +} + +//======================================================================= +// name : objectSelection +// Purpose : +//======================================================================= +void SalomeApp_Dialog::objectSelection( SelectedObjects& objs ) const +{ + //objs.clear(); + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QStringList ids; + selectedObject( anIt.key(), ids ); + if( !ids.isEmpty() ) + objs.insert( anIt.key(), ids ); + } +} + +//======================================================================= +// name : createObject +// Purpose : +//======================================================================= +int SalomeApp_Dialog::createObject( const QString& label, QWidget* parent, const int id ) +{ + int nid = id; + if( nid<0 ) + for( nid=0; myObjects.contains( nid ); nid++ ); + + if( !myObjects.contains( nid ) ) + { + QLabel* lab = new QLabel( label, parent ); + myObjects[ nid ].myLabel = lab; + + QToolButton* but = new QToolButton( parent ); + but->setIconSet( QIconSet( myPixmap ) ); + but->setToggleButton( true ); + but->setMaximumWidth( but->height() ); + but->setMinimumWidth( but->height() ); + connect( but, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) ); + myObjects[ nid ].myBtn = but; + + 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; + } + return nid; +} + +//======================================================================= +// name : renameObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::renameObject( const int id, const QString& label ) +{ + if( myObjects.contains( id ) ) + myObjects[ id ].myLabel->setText( label ); +} + +//======================================================================= +// name : setObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectType( const int id, const int type1, ... ) +{ + TypesList types; + + const int* tt = &type1; + while( *tt>=0 ) + { + types.append( *tt ); + tt++; + } + + setObjectType( id, types ); +} + +//======================================================================= +// name : setObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectType( const int id, const TypesList& list ) +{ + if( !myObjects.contains( id ) ) + return; + + TypesList& internal = myObjects[ id ].myPossibleTypes; + + QMap types; + TypesList::const_iterator anIt = list.begin(), + aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + types.insert( *anIt, 0 ); + + + internal.clear(); + QMap::const_iterator aMIt = types.begin(), + aMLast = types.end(); + for( ; aMIt!=aMLast; aMIt++ ) + internal.append( aMIt.key() ); + + updateObject( id ); +} + +//======================================================================= +// name : addObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::addObjectType( const int id, const int type1, const int, ... ) +{ + TypesList types; objectTypes( id, types ); + + const int* tt = &type1; + while( *tt>=0 ) + { + types.append( *tt ); + tt++; + } + + setObjectType( id, types ); +} + +//======================================================================= +// name : addObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::addObjectType( const int id, const TypesList& list ) +{ + TypesList types = list; objectTypes( id, types ); + setObjectType( id, types ); +} + +//======================================================================= +// name : addObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::addObjectType( const int id, const int type ) +{ + TypesList types; objectTypes( id, types ); + types.append( type ); + setObjectType( id, types ); +} + +//======================================================================= +// name : removeObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::removeObjectType( const int id ) +{ + TypesList types; + setObjectType( id, types ); +} + +//======================================================================= +// name : removeObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::removeObjectType( const int id, const TypesList& list ) +{ + if( !myObjects.contains( id ) ) + return; + + TypesList& internal = myObjects[ id ].myPossibleTypes; + + QMap types; + TypesList::const_iterator anIt = internal.begin(), + aLast = internal.end(); + for( ; anIt!=aLast; anIt++ ) + types.insert( *anIt, 0 ); + anIt = list.begin(); aLast = list.end(); + for( ; anIt!=aLast; anIt++ ) + types.remove( *anIt ); + + + internal.clear(); + QMap::const_iterator aMIt = types.begin(), + aMLast = types.end(); + for( ; aMIt!=aMLast; aMIt++ ) + internal.append( aMIt.key() ); + + updateObject( id ); +} + +//======================================================================= +// name : removeObjectType +// Purpose : +//======================================================================= +void SalomeApp_Dialog::removeObjectType( const int id, const int type ) +{ + TypesList list; list.append( type ); + removeObjectType( id, list ); +} + +//======================================================================= +// name : hasObjectType +// Purpose : +//======================================================================= +bool SalomeApp_Dialog::hasObjectType( const int id, const int type ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].myPossibleTypes.contains( type ); + else + return false; +} + +//======================================================================= +// name : objectTypes +// Purpose : +//======================================================================= +void SalomeApp_Dialog::objectTypes( const int id, TypesList& list ) const +{ + if( myObjects.contains( id ) ) + { + TypesList::const_iterator anIt = myObjects[ id ].myPossibleTypes.begin(), + aLast = myObjects[ id ].myPossibleTypes.end(); + for( ; anIt!=aLast; anIt++ ) + list.append( *anIt ); + } +} + +//======================================================================= +// name : onToggled +// Purpose : +//======================================================================= +void SalomeApp_Dialog::onToggled( bool on ) +{ + QButton* but = ( QButton* )sender(); + int id = -1; + + if( !but ) + return; + + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast && id==-1; anIt++ ) + if( anIt.data().myBtn==but ) + id = anIt.key(); + + if( id!=-1 ) + if( on ) + { + emit objectActivated( id ); + updateButtons( id ); + } + else + emit objectDeactivated( id ); +} + +//======================================================================= +// name : updateObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::updateObject( const int id, bool emit_signal ) +{ + if( hasSelection( id ) ) + { + Object& obj = myObjects[ id ]; + filterTypes( id, obj.myNames, obj.myTypes, obj.myIds ); + obj.myEdit->setText( selectionDescription( obj.myNames, obj.myTypes, obj.myNI ) ); + if( emit_signal ) + emit selectionChanged( id ); + } +} + +//======================================================================= +// name : filterTypes +// Purpose : +//======================================================================= +void SalomeApp_Dialog::filterTypes( const int id, QStringList& names, TypesList& types, QStringList& ids ) const +{ + if( !myObjects.contains( id ) ) + return; + + const Object& obj = myObjects[ id ]; + if( obj.myPossibleTypes.isEmpty() ) + return; + + QStringList new_names, new_ids; + TypesList new_types; + + TypesList::const_iterator anIt1 = types.begin(), + aLast = types.end(); + QStringList::const_iterator anIt2 = names.begin(), + anIt3 = ids.begin(); + for( ; anIt1!=aLast; anIt1++, anIt2++, anIt3++ ) + if( obj.myPossibleTypes.contains( *anIt1 ) ) + { + if( new_types.count()==1 && !multipleSelection( id ) ) + break; + + new_names.append( *anIt2 ); + new_types.append( *anIt1 ); + new_ids.append( *anIt3 ); + } + names = new_names; + types = new_types; + ids = new_ids; +} + +//======================================================================= +// name : resMgr +// Purpose : +//======================================================================= +SUIT_ResourceMgr* SalomeApp_Dialog::resMgr() const +{ + return SUIT_Session::session()->resourceMgr(); +} + +//======================================================================= +// name : setObjectPixmap +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectPixmap( const QPixmap& p ) +{ + myPixmap = p; + ObjectMap::const_iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + ( ( QToolButton* )anIt.data().myBtn )->setIconSet( p ); +} + +//======================================================================= +// name : setObjectPixmap +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setObjectPixmap( const QString& section, const QString& file ) +{ + SUIT_ResourceMgr* mgr = resMgr(); + if( mgr ) + setObjectPixmap( mgr->loadPixmap( section, file ) ); +} + +//======================================================================= +// name : multipleSelection +// Purpose : +//======================================================================= +bool SalomeApp_Dialog::multipleSelection( const int id ) const +{ + return nameIndication( id )!=OneName; +} + +//======================================================================= +// name : nameIndication +// Purpose : +//======================================================================= +SalomeApp_Dialog::NameIndication SalomeApp_Dialog::nameIndication( const int id ) const +{ + if( myObjects.contains( id ) ) + return myObjects[ id ].myNI; + else + return OneNameOrCount; +} + +//======================================================================= +// name : setNameIndication +// Purpose : +//======================================================================= +void SalomeApp_Dialog::setNameIndication( const int id, const NameIndication ni ) +{ + if( id==-1 ) + { + ObjectMap::iterator anIt = myObjects.begin(), + aNext, + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + anIt.data().myNI = ni; + setReadOnly( anIt.key(), isReadOnly( anIt.key() ) ); + aNext = anIt; aNext++; + updateObject( anIt.key(), aNext==aLast ); + } + } + else if( myObjects.contains( id ) ) + { + myObjects[ id ].myNI = ni; + setReadOnly( id, isReadOnly( id ) ); + updateObject( id, true ); + } +} + +//======================================================================= +// name : selectionDescription +// Purpose : +//======================================================================= +QString SalomeApp_Dialog::selectionDescription( const QStringList& names, const TypesList& types, const NameIndication ni ) const +{ + if( names.count()!=types.count() ) + return "SalomeApp_Dialog::selectionDescription(): Error!!!"; + + if( names.isEmpty() ) + return QString::null; + + switch( ni ) + { + case OneName: + return names.first(); + break; + + case OneNameOrCount: + if( names.count()==1 ) + return names.first(); + else + return countOfTypes( types ); + break; + + case ListOfNames: + return names.join( " " ); + break; + + case Count: + return countOfTypes( types ); + break; + }; + return QString::null; +} + +//======================================================================= +// name : countOfTypes +// Purpose : +//======================================================================= +QString SalomeApp_Dialog::countOfTypes( const TypesList& types ) const +{ + QMap typesCount; + QStringList typeCount; + + TypesList::const_iterator anIt = types.begin(), + aLast = types.end(); + for( ; anIt!=aLast; anIt++ ) + if( typesCount.contains( *anIt ) ) + typesCount[ *anIt ]++; + else + typesCount[ *anIt ] = 1; + + QMap::const_iterator aMIt = typesCount.begin(), + aMLast = typesCount.end(); + for( ; aMIt!=aMLast; aMIt++ ) + typeCount.append( QString( "%1 %2" ).arg( aMIt.data() ).arg( typeName( aMIt.key() ) ) ); + + return typeCount.join( ", " ); +} + +//======================================================================= +// name : typeName +// Purpose : +//======================================================================= +QString& SalomeApp_Dialog::typeName( const int type ) +{ + return myTypeNames[ type ]; +} + +//======================================================================= +// name : typeName +// Purpose : +//======================================================================= +const QString& SalomeApp_Dialog::typeName( const int type ) const +{ + return myTypeNames[ type ]; +} + + +//======================================================================= +// name : activateObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::activateObject( const int theId ) +{ + if ( myObjects.contains( theId ) && !myObjects[ theId ].myBtn->isOn() ) + myObjects[ theId ].myBtn->toggle(); +} + +//======================================================================= +// name : deactivateAll +// Purpose : +//======================================================================= +void SalomeApp_Dialog::deactivateAll() +{ + ObjectMap::iterator anIt = myObjects.begin(), + aLast = myObjects.end(); + for( ; anIt!=aLast; anIt++ ) + { + QToolButton* btn = ( QToolButton* )anIt.data().myBtn; + btn->setOn( false ); + } +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::selectObject( const int id, const QString& name, const int type, const QString& selid, const bool update ) +{ + QStringList names; names.append( name ); + TypesList types; types.append( type ); + QStringList ids; ids.append( selid ); + selectObject( id, names, types, ids, update ); +} + +//======================================================================= +// name : selectObject +// Purpose : +//======================================================================= +void SalomeApp_Dialog::selectObject( const int id, const QStringList& _names, const TypesList& _types, + const QStringList& _ids, const bool update ) +{ + if( !myObjects.contains( id ) ) + return; + + QStringList names = _names, ids = _ids; + TypesList types = _types; + + filterTypes( id, names, types, ids ); + + Object& obj = myObjects[ id ]; + if( update ) + 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 new file mode 100644 index 000000000..8ffba8309 --- /dev/null +++ b/src/SalomeApp/SalomeApp_Dialog.h @@ -0,0 +1,266 @@ +// File: SalomeApp_Dialog.h +// Author: Alexander SOLOVYOV + +#ifndef SALOMEAPP_DIALOG_H +#define SALOMEAPP_DIALOG_H + +#include + +#include +#include +#include + +class QLineEdit; +class QButton; +class QLabel; + +class SUIT_ResourceMgr; + +/* + Class : SalomeApp_Dialog + Description : Base class for all SALOME dialogs +*/ +class SalomeApp_Dialog : public QtxDialog +{ + Q_OBJECT + +public: + typedef QValueList TypesList; + typedef QMap SelectedObjects; + + enum ObjectWg + { + Label = 0x00000001, + Btn = 0x00000002, + Control = 0x00000004 + }; + + typedef enum + { + OneName, // " is shown + ListOfNames, //! list of all names is shown + Count //! In every case " " is shown + + } NameIndication; + //! The enumeration describing how names of selected objects will be shown in line edit + //! For more details see above + +public: + SalomeApp_Dialog( QWidget* = 0, const char* = 0, bool = false, + bool = false, const int = Standard, WFlags = 0 ); + virtual ~SalomeApp_Dialog(); + + virtual void show(); + + //! Check if buttons is exclusive (as radiobuttons) + bool isExclusive() const; + + //! Set exclusive state + void setExclusive( const bool ); + + //! Check if operation according to dialog will be resumed automatically when mouse enter the dialog + bool isAutoResumed() const; + + //! Set auto resumed state + void setAutoResumed( const bool ); + + //! Show widgets corresponding to id + void showObject( const int ); + + //! Hide widgets corresponding to id + void hideObject( const int ); + + //! Change the shown state of widgets corresponding to id + void setObjectShown( const int, const bool ); + + //! 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; + + //! Get widget of object (see ObjectWg enumeration) + QWidget* objectWg( const int theId, const int theWgId ) const; + + //! Pass to all active widgets name, type and id of selected object + void selectObject( const QString&, const int, const QString&, const bool = true ); + + /*! + Pass to all active widgets list of names, types and ids of selected objects + Every active widget filters list and accept only objects with possible types + */ + void selectObject( const QStringList&, const TypesList&, const QStringList&, const bool = true ); + + //! Get text of object's control + QString objectText( const int ) const; + + //! Set text of object's control + void setObjectText( const int, const QString& ); + + //! Select in certain widget avoiding check if there is active widget + void selectObject( const int, const QString&, const int, const QString&, const bool = true ); + void selectObject( const int, const QStringList&, const TypesList&, const QStringList&, const bool = true ); + + //! Check if certain widget has selection + bool hasSelection( const int ) const; + + //! Clear selection in widgets. If parameter is -1, then selection in all widgets will be cleared + void clearSelection( const int = -1 ); + + //! Get ids list of object selected in certain widget + void selectedObject( const int, QStringList& ) const; + + //! Get ids list of object selected in certain widget + QString selectedObject( const int ) const; + + //! Get map "widget id -> ids list" + void objectSelection( SelectedObjects& ) const; + + //! Activate object selection button + void activateObject( const int ); + + //! Set all object selection buttons to inactive state + void deactivateAll(); + +signals: + //! selection in certain widget is changed + void selectionChanged ( int ); + + //! selection in certain widget is on + void objectActivated ( int ); + + //! 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 + */ + int createObject ( const QString&, QWidget*, const int = -1 ); + + //! Set pixmap as icon for all selection buttons + void setObjectPixmap ( const QPixmap& ); + + //! Load pixmap with section, name using resource manager and set as icon for all selection buttons + void setObjectPixmap ( const QString&, const QString& ); + + //! Change label + void renameObject ( const int, const QString& ); + + //! Set possible types for certain id. The list of arguments must be finished by negative integer + void setObjectType ( const int, const int, ... ); + + //! Set list as possible types for object selection + void setObjectType ( const int, const TypesList& ); + + /*! + Add types to list of possible types + The list of arguments must be finished by negative integer + */ + void addObjectType ( const int, const int, const int, ... ); + + //! Add types to list of possible types + void addObjectType ( const int, const TypesList& ); + + //! Add type to list of possible types + void addObjectType ( const int, const int ); + + //! Clear list of possible types (it means, that all types are welcome) + void removeObjectType( const int ); + + //! Remove types in list from list of possible types + void removeObjectType( const int, const TypesList& ); + + //! Remove a type from list of possible types + void removeObjectType( const int, const int ); + + //! Check if list of possible types contains this one + bool hasObjectType ( const int, const int ) const; + + //! Return list of possible types + void objectTypes ( const int, TypesList& ) const; + + //!Change and get type name for indicating in selection widget + QString& typeName( const int ); + const QString& typeName( const int ) const; + + //! Create string contains selection list by list of names, list of types and current name indication state + virtual QString selectionDescription( const QStringList&, const TypesList&, const NameIndication ) const; + + //! Create string by pattern " " for current list of types + virtual QString countOfTypes( const TypesList& ) const; + + //! Get and set name indication for certain widget + NameIndication nameIndication( const int ) const; + void setNameIndication( const int, const NameIndication ); + + //! 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 + If id=-1, then all buttons, except first with "on" state, will be set to "off" + */ + void updateButtons( const int = -1 ); + + /*! + Filter types and update selection string in line edit + If bool is true, then signal is emitted + */ + void updateObject( const int, bool = true ); + + //! Remove from list not possible types and remove from names and ids lists the corresponding items + void filterTypes( const int, QStringList&, TypesList&, QStringList& ) const; + +private: + typedef struct + { + QLineEdit* myEdit; + QButton* myBtn; + QLabel* myLabel; + QStringList myNames, myIds; + TypesList myTypes, myPossibleTypes; + NameIndication myNI; + + } Object; + + typedef QMap ObjectMap; + +private: + ObjectMap myObjects; + QMap myTypeNames; + bool myIsExclusive, myIsBusy; + QPixmap myPixmap; +}; + +#endif -- 2.39.2