myIsExclusive( true )
{
setObjectPixmap( "SalomeApp", tr( "ICON_SELECT" ) );
+ setNameIndication( OneNameOrCount );
}
SalomeApp_Dialog::~SalomeApp_Dialog()
aLast = myObjects.end();
for( ; anIt!=aLast; anIt++ )
{
- QPushButton* but = anIt.data().btn;
+ QPushButton* but = anIt.data().myBtn;
if( but && but->isOn() )
{
if( id==-1 )
if( myObjects.contains( id ) && isObjectShown( id )!=shown )
{
Object& obj = myObjects[ id ];
- obj.edit->setShown( shown );
- obj.btn->setShown( shown );
- obj.label->setShown( shown );
+ obj.myEdit->setShown( shown );
+ obj.myBtn->setShown( shown );
+ obj.myLabel->setShown( shown );
if( !shown )
- obj.btn->setOn( false );
+ obj.myBtn->setOn( false );
}
}
bool SalomeApp_Dialog::isObjectShown( const int id ) const
{
- return myObjects.contains( id ) && myObjects[ id ].edit->isShown();
+ return myObjects.contains( id ) && myObjects[ id ].myEdit->isShown();
}
void SalomeApp_Dialog::selectObject( const QString& name, const int type, const QString& entry )
+{
+ QStringList names; names.append( name );
+ TypesList types; types.append( type );
+ QStringList entries; entries.append( entry );
+ selectObject( names, types, entries );
+}
+
+void SalomeApp_Dialog::selectObject( const QStringList& _names,
+ const TypesList& _types,
+ const QStringList& _entries )
{
ObjectMap::iterator anIt = myObjects.begin(),
aLast = myObjects.end();
for( ; anIt!=aLast; anIt++ )
- if( anIt.data().btn->isOn() )
+ if( anIt.data().myBtn->isOn() )
{
- if( isCorrectType( anIt.key(), type ) )
- {
- anIt.data().edit->setText( name );
- anIt.data().type = type;
- anIt.data().entry = entry;
- }
- else
- {
- anIt.data().edit->setText( QString::null );
- anIt.data().type = -1;
- anIt.data().entry = QString::null;
- }
+ QStringList names, entries;
+ TypesList types;
+
+ filterTypes( anIt.key(), names, types, entries );
+
+ anIt.data().myEdit->setText( selectionDescription( names, types ) );
+ anIt.data().myTypes = types;
+ anIt.data().myEntries = entries;
+ anIt.data().myNames = names;
+
emit selectionChanged( anIt.key() );
}
}
bool SalomeApp_Dialog::hasSelection( const int id ) const
{
- return myObjects.contains( id ) && !myObjects[ id ].entry.isEmpty();
+ return myObjects.contains( id ) && !myObjects[ id ].myEntries.isEmpty();
}
void SalomeApp_Dialog::clearSelection( const int id )
{
if( myObjects.contains( id ) )
{
- myObjects[ id ].entry = QString::null;
- myObjects[ id ].type = -1;
- myObjects[ id ].edit->setText( QString::null );
+ myObjects[ id ].myEntries.clear();
+ myObjects[ id ].myTypes.clear();
+ myObjects[ id ].myNames.clear();
+
+ myObjects[ id ].myEdit->setText( QString::null );
emit selectionChanged( id );
}
}
-QString SalomeApp_Dialog::selectedObject( const int id ) const
+void SalomeApp_Dialog::selectedObject( const int id, QStringList& list ) const
{
if( myObjects.contains( id ) )
- return myObjects[ id ].entry;
- else
- return QString::null;
+ list = myObjects[ id ].myEntries;
+ //else
+ // list.clear();
}
void SalomeApp_Dialog::objectSelection( SelectedObjects& objs ) const
aLast = myObjects.end();
for( ; anIt!=aLast; anIt++ )
{
- QString entry = selectedObject( anIt.key() );
- if( !entry.isEmpty() )
- objs.insert( anIt.key(), entry );
+ QStringList entries;
+ selectedObject( anIt.key(), entries );
+ if( !entries.isEmpty() )
+ objs.insert( anIt.key(), entries );
}
}
if( !myObjects.contains( nid ) )
{
QLabel* lab = new QLabel( label, parent );
- myObjects[ nid ].label = lab;
+ myObjects[ nid ].myLabel = lab;
QPushButton* but = new QPushButton( parent );
but->setIconSet( QIconSet( myPixmap ) );
but->setToggleButton( true );
connect( but, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
- myObjects[ nid ].btn = but;
+ myObjects[ nid ].myBtn = but;
QLineEdit* ne = new QLineEdit( parent );
ne->setReadOnly( true );
- myObjects[ nid ].edit = ne;
+ myObjects[ nid ].myEdit = ne;
}
return nid;
}
void SalomeApp_Dialog::renameObject( const int id, const QString& label )
{
if( myObjects.contains( id ) )
- myObjects[ id ].label->setText( label );
+ myObjects[ id ].myLabel->setText( label );
}
void SalomeApp_Dialog::setObjectType( const int id, const int type1, ... )
if( !myObjects.contains( id ) )
return;
- TypesList& internal = myObjects[ id ].types;
+ TypesList& internal = myObjects[ id ].myPossibleTypes;
QMap<int,int> types;
TypesList::const_iterator anIt = list.begin(),
if( !myObjects.contains( id ) )
return;
- TypesList& internal = myObjects[ id ].types;
+ TypesList& internal = myObjects[ id ].myPossibleTypes;
QMap<int,int> types;
TypesList::const_iterator anIt = internal.begin(),
bool SalomeApp_Dialog::hasObjectType( const int id, const int type ) const
{
if( myObjects.contains( id ) )
- return myObjects[ id ].types.contains( type );
+ return myObjects[ id ].myPossibleTypes.contains( type );
else
return false;
}
{
if( myObjects.contains( id ) )
{
- TypesList::const_iterator anIt = myObjects[ id ].types.begin(),
- aLast = myObjects[ id ].types.end();
+ TypesList::const_iterator anIt = myObjects[ id ].myPossibleTypes.begin(),
+ aLast = myObjects[ id ].myPossibleTypes.end();
for( ; anIt!=aLast; anIt++ )
list.append( *anIt );
}
ObjectMap::const_iterator anIt = myObjects.begin(),
aLast = myObjects.end();
for( ; anIt!=aLast && id==-1; anIt++ )
- if( anIt.data().btn==but )
+ if( anIt.data().myBtn==but )
id = anIt.key();
if( id!=-1 )
emit objectDeactivated( id );
}
-void SalomeApp_Dialog::updateObject( const int id )
+void SalomeApp_Dialog::updateObject( const int id, bool emit_signal )
{
- if( hasSelection( id ) && !isCorrectType( id, myObjects[ id ].type ) )
- clearSelection( id );
+ if( hasSelection( id ) )
+ {
+ Object& obj = myObjects[ id ];
+ filterTypes( id, obj.myNames, obj.myTypes, obj.myEntries );
+ obj.myEdit->setText( selectionDescription( obj.myNames, obj.myTypes ) );
+ if( emit_signal )
+ emit selectionChanged( id );
+ }
}
-bool SalomeApp_Dialog::isCorrectType( const int id, const int type ) const
+void SalomeApp_Dialog::filterTypes( const int id, QStringList& names, TypesList& types, QStringList& entries ) const
{
- if( myObjects.contains( id ) )
- return hasObjectType( id, type ) || myObjects[ id ].types.isEmpty();
- else
- return false;
+ if( !myObjects.contains( id ) )
+ return;
+
+ const Object& obj = myObjects[ id ];
+ if( obj.myPossibleTypes.isEmpty() )
+ return;
+
+ QStringList new_names, new_entries;
+ TypesList new_types;
+
+ TypesList::const_iterator anIt1 = types.begin(),
+ aLast = types.end();
+ QStringList::const_iterator anIt2 = names.begin(),
+ anIt3 = entries.begin();
+ for( ; anIt1!=aLast; anIt1++, anIt2++, anIt3++ )
+ if( obj.myPossibleTypes.contains( *anIt1 ) )
+ {
+ if( new_types.count()==1 && !multipleSelection() )
+ break;
+
+ new_names.append( *anIt2 );
+ new_types.append( *anIt1 );
+ new_entries.append( *anIt3 );
+ }
+ names = new_names;
+ types = new_types;
+ entries = new_entries;
}
SUIT_ResourceMgr* SalomeApp_Dialog::resMgr() const
ObjectMap::const_iterator anIt = myObjects.begin(),
aLast = myObjects.end();
for( ; anIt!=aLast; anIt++ )
- anIt.data().btn->setIconSet( p );
+ anIt.data().myBtn->setIconSet( p );
}
void SalomeApp_Dialog::setObjectPixmap( const QString& section, const QString& file )
if( mgr )
setObjectPixmap( mgr->loadPixmap( section, file ) );
}
+
+bool SalomeApp_Dialog::multipleSelection() const
+{
+ return nameIndication()==OneName;
+}
+
+SalomeApp_Dialog::NameIndication SalomeApp_Dialog::nameIndication() const
+{
+ return myNI;
+}
+
+void SalomeApp_Dialog::setNameIndication( const NameIndication ni )
+{
+ myNI = ni;
+ ObjectMap::const_iterator anIt = myObjects.begin(),
+ aNext,
+ aLast = myObjects.end();
+ for( ; anIt!=aLast; anIt++ )
+ {
+ aNext = anIt; aNext++;
+ updateObject( anIt.key(), aNext==aLast );
+ }
+}
+
+QString SalomeApp_Dialog::selectionDescription( const QStringList& names, const TypesList& types ) const
+{
+ if( names.count()!=types.count() )
+ return "SalomeApp_Dialog::selectionDescription: Error!!!";
+
+ switch( nameIndication() )
+ {
+ 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;
+}
+
+QString SalomeApp_Dialog::countOfTypes( const TypesList& types ) const
+{
+ QMap<int, int> 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<int,int>::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( ", " );
+}
+
+QString& SalomeApp_Dialog::typeName( const int type )
+{
+ return myTypeNames[ type ];
+}
+
+const QString& SalomeApp_Dialog::typeName( const int type ) const
+{
+ return myTypeNames[ type ];
+}
Q_OBJECT
public:
- typedef QValueList<int> TypesList;
- typedef QMap<int,QString> SelectedObjects;
+ typedef QValueList<int> TypesList;
+ typedef QMap<int,QStringList> SelectedObjects;
+ typedef enum
+ {
+ OneName,
+ OneNameOrCount,
+ ListOfNames,
+ Count
+
+ } NameIndication;
public:
SalomeApp_Dialog( QWidget* = 0, const char* = 0, bool = false,
virtual ~SalomeApp_Dialog();
virtual void show();
- bool isExclusive() const;
- void setExclusive( const bool );
+
+ bool isExclusive() const;
+ void setExclusive( const bool );
- void showObject( const int );
- void hideObject( const int );
- void setObjectShown( const int, const bool );
- bool isObjectShown( const int ) const;
+ void showObject( const int );
+ void hideObject( const int );
+ void setObjectShown( const int, const bool );
+ bool isObjectShown( const int ) const;
- void selectObject( const QString&, const int, const QString& );
- bool hasSelection( const int ) const;
- void clearSelection( const int = -1 );
- QString selectedObject( const int ) const;
- void objectSelection( SelectedObjects& ) const;
+ void selectObject( const QString&, const int, const QString& );
+ void selectObject( const QStringList&, const TypesList&, const QStringList& );
+ bool hasSelection( const int ) const;
+ void clearSelection( const int = -1 );
+ void selectedObject( const int, QStringList& ) const;
+ void objectSelection( SelectedObjects& ) const;
signals:
void selectionChanged ( int );
bool hasObjectType ( const int, const int ) const;
void objectTypes ( const int, TypesList& ) const;
+ QString& typeName( const int );
+ const QString& typeName( const int ) const;
+
+ virtual QString selectionDescription( const QStringList&, const TypesList& ) const;
+ virtual QString countOfTypes( const TypesList& ) const;
+
+ NameIndication nameIndication() const;
+ void setNameIndication( const NameIndication );
+ bool multipleSelection() const;
+
private slots:
void onToggled( bool );
private:
- void updateButtons( const int = -1 );
- void updateObject( const int );
- bool isCorrectType( const int id, const int type ) const;
+ void updateButtons( const int = -1 );
+ void updateObject( const int, bool = true );
+ void filterTypes( const int, QStringList&, TypesList&, QStringList& ) const;
private:
typedef struct
{
- QLineEdit* edit;
- QPushButton* btn;
- QLabel* label;
- QString entry;
- int type;
- TypesList types;
+ QLineEdit* myEdit;
+ QPushButton* myBtn;
+ QLabel* myLabel;
+ QStringList myNames, myEntries;
+ TypesList myTypes, myPossibleTypes;
} Object;
typedef QMap<int, Object> ObjectMap;
private:
- ObjectMap myObjects;
- bool myIsExclusive;
- QPixmap myPixmap;
+ ObjectMap myObjects;
+ QMap<int,QString> myTypeNames;
+ bool myIsExclusive;
+ QPixmap myPixmap;
+ NameIndication myNI;
};
#endif