From: stv Date: Tue, 7 Jun 2005 06:08:21 +0000 (+0000) Subject: On/Off columns added into context popup menu for Objects. X-Git-Tag: T3_0_0_a2~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0ff41c560b2229417e462fbb7f8fcf4407ded6ba;p=modules%2Fgui.git On/Off columns added into context popup menu for Objects. --- diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 419933094..ddd557cd3 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -429,6 +429,19 @@ void OB_Browser::setColumnTitle( const int id, const QIconSet& icon, const QStri lv->setColumnText( myColumnIds[id], icon, label ); } +QString OB_Browser::nameTitle() const +{ + return myView->columnText( 0 ); +} + +QString OB_Browser::columnTitle( const int id ) const +{ + QString txt; + if ( myColumnIds.contains( id ) ) + txt = myView->columnText( myColumnIds[id] ); + return txt; +} + bool OB_Browser::isColumnVisible( const int id ) const { return myColumnIds.contains( id ) && myView->isShown( myColumnIds[id] ); @@ -450,6 +463,22 @@ QValueList OB_Browser::columns() const return lst; } +bool OB_Browser::appropriateColumn( const int id ) const +{ + bool res = false; + if ( myColumnIds.contains( id ) ) + res = myView->appropriate( myColumnIds[id] ); + return res; +} + +void OB_Browser::setAppropriateColumn( const int id, const bool on ) +{ + if ( !myColumnIds.contains( id ) ) + return; + + myView->setAppropriate( myColumnIds[id], on ); +} + void OB_Browser::updateTree( SUIT_DataObject* o ) { updateTree( o ? o : getRootObject(), false ); @@ -848,6 +877,11 @@ void OB_Browser::onRefresh() updateTree( 0, true ); } +void OB_Browser::onColumnVisible( int id ) +{ + setColumnShown( id, !isColumnVisible( id ) ); +} + void OB_Browser::onDestroyed( SUIT_DataObject* obj ) { removeObject( obj ); @@ -926,6 +960,28 @@ bool OB_Browser::eventFilter( QObject* o, QEvent* e ) void OB_Browser::contextMenuPopup( QPopupMenu* menu ) { + QValueList cols; + for ( QMap::ConstIterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it ) + { + if ( appropriateColumn( it.key() ) ) + cols.append( it.key() ); + } + + uint num = menu->count(); + menu->setCheckable( true ); + for ( QValueList::const_iterator iter = cols.begin(); iter != cols.end(); ++iter ) + { + QString name = columnTitle( *iter ); + if ( name.isEmpty() ) + continue; + + int id = menu->insertItem( name, this, SLOT( onColumnVisible( int ) ) ); + menu->setItemChecked( id, isColumnVisible( *iter ) ); + menu->setItemParameter( id, *iter ); + } + if ( menu->count() != num ) + menu->insertSeparator(); + DataObjectList selected; getSelected( selected ); diff --git a/src/ObjBrowser/OB_Browser.h b/src/ObjBrowser/OB_Browser.h index c1cf4ef5f..c62cb2181 100755 --- a/src/ObjBrowser/OB_Browser.h +++ b/src/ObjBrowser/OB_Browser.h @@ -80,11 +80,17 @@ public: void setColumnTitle( const int id, const QString& ); virtual void setColumnTitle( const int id, const QIconSet&, const QString& ); + QString nameTitle() const; + QString columnTitle( const int ) const; + bool isColumnVisible( const int ) const; virtual void setColumnShown( const int, const bool ); QValueList columns() const; + bool appropriateColumn( const int ) const; + virtual void setAppropriateColumn( const int, const bool ); + virtual bool eventFilter(QObject* watched, QEvent* e); QListView* listView() const; @@ -99,6 +105,7 @@ signals: private slots: void onExpand(); void onRefresh(); + void onColumnVisible( int ); void onDestroyed( SUIT_DataObject* ); void onDropped( QPtrList, QListViewItem*, int );