if ( !parentWidget() || !myBrowser || !myBrowser->isShowToolTips() )
return;
- QListView* lv = myBrowser->getListView();
+ QListView* lv = myBrowser->listView();
QListViewItem* item = lv->itemAt( pos );
SUIT_DataObject* obj = myBrowser->dataObject( item );
myAutoDelObjs( false ),
myRootDecorated( true )
{
- myView = new OB_ListView( this );
- myView->addColumn( "Data" );
+ myView = new OB_ListView( QtxListView::HeaderAuto, this );
+ myView->setAppropriate( myView->addColumn( "Data" ), false );
myView->setSorting( -1 );
myView->setRootIsDecorated( true );
myView->setSelectionMode( QListView::Extended );
if ( myRoot )
updateView( myRoot );
- else if ( getListView() )
+ else if ( listView() )
{
myItems.clear();
- getListView()->clear();
+ listView()->clear();
}
restoreState( selObjs, openObjs, curObj, selKeys, openKeys, curKey );
int OB_Browser::numberOfSelected() const
{
int count = 0;
- if ( getListView() )
+ if ( listView() )
{
- for ( QListViewItemIterator it( getListView() ); it.current(); ++it )
+ for ( QListViewItemIterator it( listView() ); it.current(); ++it )
if ( it.current()->isSelected() )
count++;
}
{
theObjList.clear();
- if ( !getListView() )
+ if ( !listView() )
return;
- for ( QListViewItemIterator it( getListView() ); it.current(); ++it )
+ for ( QListViewItemIterator it( listView() ); it.current(); ++it )
{
if ( it.current()->isSelected() )
{
SUIT_DataObject* obj = dataObject( it.current() );
if ( obj )
- theObjList.append( obj );
+ theObjList.append( obj );
}
}
}
void OB_Browser::setSelected( const DataObjectList& theObjLst, const bool append )
{
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( !lv )
return;
bool OB_Browser::isOpen( SUIT_DataObject* theObject ) const
{
bool res = false;
- if ( getListView() )
- res = getListView()->isOpen( listViewItem( theObject ) );
+ if ( listView() )
+ res = listView()->isOpen( listViewItem( theObject ) );
return res;
}
void OB_Browser::setOpen( SUIT_DataObject* theObject, const bool theOpen )
{
- if ( getListView() )
- getListView()->setOpen( listViewItem( theObject ), theOpen );
+ if ( listView() )
+ listView()->setOpen( listViewItem( theObject ), theOpen );
}
SUIT_DataObject* OB_Browser::dataObjectAt( const QPoint& pos ) const
{
SUIT_DataObject* obj = 0;
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( lv )
obj = dataObject( lv->itemAt( pos ) );
myView->setFilter( f );
}
-int OB_Browser::addColumn( const QString & label, int width, int index )
+int OB_Browser::addColumn( const QString& label, const int id, const int width )
{
- int id = -1;
- if ( !myView )
- return id;
- if ( index != -1 && myColumnIds.contains( index ) )
- return id; // can not reuse index
-
- int trueId = index;
- id = myView->addColumn( label, width );
- if ( trueId == -1 )
- trueId = id;
- myColumnIds.insert( trueId, id );
- updateText();
-
- return trueId;
+ return addColumn( QIconSet(), label, id, width );
}
-int OB_Browser::addColumn( const QIconSet & iconset, const QString & label, int width, int index )
+int OB_Browser::addColumn( const QIconSet& icon, const QString& label, const int id, const int width )
{
- int id = -1;
- if ( !myView )
- return id;
- if ( index != -1 && myColumnIds.contains( index ) )
- return id; // can not reuse index
+ QListView* lv = listView();
+ if ( !lv )
+ return -1;
+
+ int theId = id;
+ if ( theId < 0 )
+ {
+ while ( myColumnIds.contains( theId ) )
+ theId++;
+ }
+
+ if ( myColumnIds.contains( theId ) )
+ return -1; // can not reuse id
- int trueId = index;
- id = myView->addColumn( iconset, label, width );
- if ( trueId == -1 )
- trueId = id;
- myColumnIds.insert( trueId, id );
+ int sec = -1;
+ if ( icon.isNull() )
+ sec = lv->addColumn( label, width );
+ else
+ sec = lv->addColumn( icon, label, width );
+
+ if ( sec == -1 )
+ return -1;
+
+ myColumnIds.insert( theId, sec );
updateText();
- return trueId;
+ return theId;
}
-void OB_Browser::removeColumn( int index )
+void OB_Browser::removeColumn( const int id )
{
- if ( !myView || !myColumnIds.contains( index ) )
+ QListView* lv = listView();
+ if ( !lv || !myColumnIds.contains( id ) )
return;
- int id = myColumnIds[ index ];
- myView->removeColumn( id );
+ int sec = myColumnIds[id];
+ lv->removeColumn( sec );
// update map of column indeces
- myColumnIds.remove( index );
+ myColumnIds.remove( id );
for ( QMap<int, int>::iterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
{
- if ( it.key() > index )
+ if ( it.key() > id )
it.data()--;
}
updateText();
}
+void OB_Browser::setNameTitle( const QString& label )
+{
+ setNameTitle( QIconSet(), label );
+}
+
+void OB_Browser::setNameTitle( const QIconSet& icon, const QString& label )
+{
+ QListView* lv = listView();
+ if ( !lv )
+ return;
+
+ if ( icon.isNull() )
+ lv->setColumnText( 0, label );
+ else
+ lv->setColumnText( 0, icon, label );
+}
+
+void OB_Browser::setColumnTitle( const int id, const QString& label )
+{
+ setColumnTitle( id, QIconSet(), label );
+}
+
+void OB_Browser::setColumnTitle( const int id, const QIconSet& icon, const QString& label )
+{
+ QListView* lv = listView();
+ if ( !lv || !myColumnIds.contains( id ) )
+ return;
+
+ if ( icon.isNull() )
+ lv->setColumnText( myColumnIds[id], label );
+ else
+ lv->setColumnText( myColumnIds[id], icon, label );
+}
+
+bool OB_Browser::isColumnVisible( const int id ) const
+{
+ myColumnIds.contains( id ) && myView->isShown( myColumnIds[id] );
+}
+
+void OB_Browser::setColumnShown( const int id, const bool on )
+{
+ if ( !myColumnIds.contains( id ) )
+ return;
+
+ myView->setShown( myColumnIds[id], on );
+}
+
void OB_Browser::updateTree( SUIT_DataObject* o )
{
- SUIT_DataObject* obj = o ? o : getRootObject();
+ updateTree( o ? o : getRootObject(), false );
+}
+
+void OB_Browser::updateTree( SUIT_DataObject* obj, const bool notify )
+{
if ( !obj )
return;
SUIT_DataObject* curObj = storeState( selObjs, openObjs, selKeys, openKeys, curKey );
+ if ( notify )
+ emit aboutRefresh();
+
createConnections( obj );
updateView( obj );
void OB_Browser::updateView( const SUIT_DataObject* theStartObj )
{
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( !lv )
return;
}
QListViewItem* OB_Browser::createTree( const SUIT_DataObject* obj,
- QListViewItem* parent, QListViewItem* after )
+ QListViewItem* parent, QListViewItem* after )
{
if ( !obj )
return 0;
QListViewItem* OB_Browser::createItem( const SUIT_DataObject* o,
QListViewItem* parent, QListViewItem* after )
{
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( !lv || !o )
return 0;
myItems.insert( obj, item );
+ updateText( item );
+
return item;
}
void OB_Browser::adjustWidth()
{
- if ( !getListView() )
+ if ( !listView() )
return;
- getListView()->setColumnWidth( 0, 0 );
- if ( getListView()->firstChild() )
- adjustWidth( getListView()->firstChild() );
+ listView()->setColumnWidth( 0, 0 );
+ if ( listView()->firstChild() )
+ adjustWidth( listView()->firstChild() );
}
void OB_Browser::adjustWidth( QListViewItem* item )
return item;
}
-QListView* OB_Browser::getListView() const
+QListView* OB_Browser::listView() const
{
return myView;
}
DataObjectKeyMap& selKeys, DataObjectKeyMap& openKeys,
DataObjectKey& curKey ) const
{
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( !lv )
return 0;
const SUIT_DataObject* curObj, const DataObjectKeyMap& selKeys,
const DataObjectKeyMap& openKeys, const DataObjectKey& curKey )
{
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( !lv )
return;
void OB_Browser::onRefresh()
{
- updateTree();
+ updateTree( 0, true );
}
void OB_Browser::onDestroyed( SUIT_DataObject* obj )
void OB_Browser::updateText()
{
- if ( !myView )
+ if ( myColumnIds.isEmpty() )
return;
-
- if ( myColumnIds.size() )
+
+ QListView* lv = listView();
+ if ( !lv )
+ return;
+
+ for ( QListViewItemIterator it( lv ); it.current(); ++it )
{
- QListViewItemIterator it( myView );
- for ( ; it.current() != 0; ++it )
- {
- QListViewItem* item = it.current();
- SUIT_DataObject* obj = dataObject( item );
- if ( !item || !obj )
- continue;
- QMap<int, int>::iterator it = myColumnIds.begin();
- for( ; it != myColumnIds.end(); ++it )
- item->setText( it.data(), obj->text( it.key() ) );
- }
+ SUIT_DataObject* obj = dataObject( it.current() );
+ if ( !obj )
+ continue;
+
+ for( QMap<int, int>::iterator itr = myColumnIds.begin(); itr != myColumnIds.end(); ++itr )
+ it.current()->setText( itr.data(), obj->text( itr.key() ) );
}
- updateView();
+}
+
+void OB_Browser::updateText( QListViewItem* item )
+{
+ SUIT_DataObject* obj = dataObject( item );
+ if ( !obj )
+ return;
+
+ for( QMap<int, int>::iterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
+ item->setText( it.data(), obj->text( it.key() ) );
}
bool OB_Browser::eventFilter(QObject* watched, QEvent* e)
void OB_Browser::autoOpenBranches()
{
int level = autoOpenLevel();
- QListView* lv = getListView();
+ QListView* lv = listView();
if ( !lv || level < 1 )
return;
class ToolTip;
public:
- OB_Browser( QWidget* = 0, SUIT_DataObject* theRoot = 0 );
- virtual ~OB_Browser();
+ OB_Browser( QWidget* = 0, SUIT_DataObject* theRoot = 0 );
+ virtual ~OB_Browser();
virtual QString popupClientType() const { return QString( "ObjectBrowser" ); }
int autoOpenLevel() const;
void setAutoOpenLevel( const int );
- virtual int addColumn( const QString & label, int width = -1, int index = -1 );
- virtual int addColumn( const QIconSet & iconset, const QString & label, int width = -1, int index = -1 );
- virtual void removeColumn( int index );
+ virtual int addColumn( const QString&, const int id = -1, const int width = -1 );
+ virtual int addColumn( const QIconSet&, const QString&, const int id = -1, const int width = -1 );
+ virtual void removeColumn( const int id );
+
+ void setNameTitle( const QString& );
+ virtual void setNameTitle( const QIconSet&, const QString& );
+ void setColumnTitle( const int id, const QString& );
+ virtual void setColumnTitle( const int id, const QIconSet&, const QString& );
+
+ bool isColumnVisible( const int ) const;
+ virtual void setColumnShown( const int, const bool );
virtual bool eventFilter(QObject* watched, QEvent* e);
- QListView* getListView() const;
-
+ QListView* listView() const;
+
virtual void contextMenuPopup( QPopupMenu* );
signals:
+ void aboutRefresh();
void selectionChanged();
void dropped( DataObjectList, SUIT_DataObject*, int );
void createConnections( SUIT_DataObject* );
void removeObject( SUIT_DataObject*, const bool = true );
+ void updateText( QListViewItem* );
+ void updateTree( SUIT_DataObject*, const bool );
+
DataObjectKey objectKey( QListViewItem* ) const;
DataObjectKey objectKey( SUIT_DataObject* ) const;
colorGrp.setColor( QColorGroup::Background, myObject->color( SUIT_DataObject::Background ) );
if ( myObject->color( SUIT_DataObject::Highlight ).isValid() )
colorGrp.setColor( QColorGroup::Highlight, myObject->color( SUIT_DataObject::Highlight ) );
+ if ( myObject->color( SUIT_DataObject::HighlightedText ).isValid() )
+ colorGrp.setColor( QColorGroup::HighlightedText, myObject->color( SUIT_DataObject::HighlightedText ) );
}
void QtxListView::setColumnWidth( int c, int w )
{
+ if ( myColumns.contains( c ) )
+ myColumns[c].width = w;
+
QListView::setColumnWidth( c, !myColumns.contains( c ) ? w : 0 );
}
class Signal;
typedef enum { None, RadioButton, CheckBox } CheckType;
- typedef enum { Text, Base, Foreground, Background, Highlight } ColorRole;
+ typedef enum { Text, Base, Foreground, Background, Highlight, HighlightedText } ColorRole;
SUIT_DataObject( SUIT_DataObject* = 0 );
virtual ~SUIT_DataObject();
void reparentChildren( const SUIT_DataObject* );
- QString text() const { return text( 0 ); }
- QColor color() const { return color( Foreground ); }
- virtual QString name() const;
- virtual QPixmap icon() const;
virtual QString text( const int ) const;
virtual QColor color( const ColorRole ) const;
+
+ virtual QString name() const;
+ virtual QPixmap icon() const;
virtual QString toolTip() const;
virtual SUIT_DataObject* parent() const;
#include "SalomeApp_Study.h"
#include "SalomeApp_Module.h"
#include "SalomeApp_OBFilter.h"
+#include "SalomeApp_DataObject.h"
#include "SalomeApp_EventFilter.h"
#include "SalomeApp_WidgetContainer.h"
ob->resize( OBJECT_BROWSER_WIDTH, ob->height() );
ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) );
+ ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) );
+ for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
+ ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
+
// Create OBSelector
new SalomeApp_OBSelector( ob, mySelMgr );
logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
}
-
+
return wid;
}
#include "SalomeApp_DataObject.h"
-#include "SalomeApp_RootObject.h"
+
#include "SalomeApp_Study.h"
+#include "SalomeApp_RootObject.h"
-#include <SUIT_DataObjectKey.h>
#include <SUIT_Application.h>
#include <SUIT_ResourceMgr.h>
+#include <SUIT_DataObjectKey.h>
#include <qobject.h>
+#include <SALOMEDSClient_AttributeReal.hxx>
+#include <SALOMEDSClient_AttributeInteger.hxx>
+#include <SALOMEDSClient_AttributeComment.hxx>
+#include <SALOMEDSClient_AttributeTableOfReal.hxx>
+#include <SALOMEDSClient_AttributeTableOfInteger.hxx>
+
/*!
Class: SalomeApp_DataObject::Key
Level: Internal
QString SalomeApp_DataObject::name() const
{
+ QString str;
+
if ( myObject )
- return myObject->GetName().c_str();
- return QString::null;
- //return QString( "%1 [%2]" ).arg( myName ).arg( myEntry ); // for debug
+ str = myObject->GetName().c_str();
+
+ if ( isReference() )
+ str = QString( "* " ) + str;
+
+ return str;
}
QPixmap SalomeApp_DataObject::icon() const
QColor SalomeApp_DataObject::color() const
{
_PTR(GenericAttribute) anAttr;
- if ( myObject && myObject->FindAttribute( anAttr, "AttributeTextColor" ) ){
- _PTR(AttributeTextColor) aColAttr ( anAttr );
+ if ( myObject && myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
+ {
+ _PTR(AttributeTextColor) aColAttr( anAttr );
QColor color( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
return color;
}
return QColor();
}
+QString SalomeApp_DataObject::text( const int id ) const
+{
+ QString txt;
+ switch ( id )
+ {
+ case CT_Value:
+ if ( componentObject() != this )
+ txt = value( referencedObject() );
+ break;
+ case CT_Entry:
+ txt = entry( referencedObject() );
+ break;
+ case CT_IOR:
+ txt = ior( referencedObject() );
+ break;
+ case CT_RefEntry:
+ if ( isReference() )
+ txt = entry( object() );
+ break;
+ }
+ return txt;
+}
+
+QColor SalomeApp_DataObject::color( const ColorRole cr ) const
+{
+ QColor clr;
+ switch ( cr )
+ {
+ case Foreground:
+ {
+ _PTR(GenericAttribute) anAttr;
+ if ( myObject && myObject->FindAttribute( anAttr, "AttributeTextColor" ) )
+ {
+ _PTR(AttributeTextColor) aColAttr( anAttr );
+ clr = QColor( (int)aColAttr->TextColor().R, (int)aColAttr->TextColor().G, (int)aColAttr->TextColor().B );
+ }
+ }
+ break;
+ case Highlight:
+ if ( isReference() )
+ clr = QColor( 255, 0, 0 );
+ break;
+ case HighlightedText:
+ if ( isReference() )
+ clr = QColor( 255, 255, 255 );
+ break;
+ }
+ return clr;
+}
+
QString SalomeApp_DataObject::toolTip() const
{
//return object()->Name();
const SalomeApp_DataObject* compObj = dynamic_cast<SalomeApp_DataObject*>( componentObject() );
if ( compObj && compObj->object() )
{
- _PTR(SComponent) aComp ( compObj->object() );
+ _PTR(SComponent) aComp( compObj->object() );
if ( aComp )
return aComp->ComponentDataType().c_str();
}
return myObject;
}
+bool SalomeApp_DataObject::isReference() const
+{
+ bool isRef = false;
+ if ( myObject )
+ {
+ _PTR(SObject) refObj;
+ isRef = myObject->ReferencedObject( refObj );
+ }
+ return isRef;
+}
+
+_PTR(SObject) SalomeApp_DataObject::referencedObject() const
+{
+ _PTR(SObject) refObj;
+ _PTR(SObject) obj = myObject;
+ while ( obj && obj->ReferencedObject( refObj ) )
+ obj = refObj;
+
+ return obj;
+}
+
+QString SalomeApp_DataObject::ior( const _PTR(SObject)& obj ) const
+{
+ QString txt;
+ if ( obj )
+ {
+ _PTR(GenericAttribute) attr;
+ if ( obj->FindAttribute( attr, "AttributeIOR" ) )
+ {
+ _PTR(AttributeIOR) iorAttr = attr;
+ if ( iorAttr )
+ {
+ std::string str = iorAttr->Value();
+ txt = QString( str.c_str() );
+ }
+ }
+ }
+ return txt;
+}
+
+QString SalomeApp_DataObject::entry( const _PTR(SObject)& obj ) const
+{
+ QString txt;
+ if ( obj )
+ {
+ std::string str = obj->GetID();
+ txt = QString( str.c_str() );
+ }
+ return txt;
+}
+
+QString SalomeApp_DataObject::value( const _PTR(SObject)& obj ) const
+{
+ if ( !obj )
+ return QString::null;
+
+ QString val;
+ _PTR(GenericAttribute) attr;
+
+ if ( obj->FindAttribute( attr, "AttributeInteger" ) )
+ {
+ _PTR(AttributeInteger) intAttr = attr;
+ if ( intAttr )
+ val = QString::number( intAttr->Value() );
+ }
+ else if ( obj->FindAttribute( attr, "AttributeReal" ) )
+ {
+ _PTR(AttributeReal) realAttr = attr;
+ if ( realAttr )
+ val = QString::number( realAttr->Value() );
+ }
+ else if ( obj->FindAttribute( attr, "AttributeTableOfInteger" ) )
+ {
+ _PTR(AttributeTableOfInteger) tableAttr = attr;
+ std::string title = tableAttr->GetTitle();
+ val = QString( title.c_str() );
+ if ( !val.isEmpty() )
+ val += QString( " " );
+ val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
+ }
+ else if ( obj->FindAttribute( attr, "AttributeTableOfReal" ) )
+ {
+ _PTR(AttributeTableOfReal) tableAttr = attr;
+ std::string title = tableAttr->GetTitle();
+ val = QString( title.c_str() );
+ if ( !val.isEmpty() )
+ val += QString( " " );
+ val += QString( "[%1,%2]" ).arg( tableAttr->GetNbRows() ).arg( tableAttr->GetNbColumns() );
+ }
+ else if ( obj->FindAttribute( attr, "AttributeComment") )
+ {
+ _PTR(AttributeComment) comm = attr;
+ std::string str = comm->Value();
+ val = QString( str.c_str() );
+ }
+
+ return val;
+}
/*!
Class: SalomeApp_ModuleObject
{
class Key;
+public:
+ enum { CT_Value, CT_Entry, CT_IOR, CT_RefEntry };
+
public:
SalomeApp_DataObject( SUIT_DataObject* = 0 );
SalomeApp_DataObject( const _PTR(SObject)&, SUIT_DataObject* = 0 );
virtual QColor color() const;
virtual QString toolTip() const;
+ virtual QString text( const int ) const;
+ virtual QColor color( const ColorRole ) const;
+
virtual SUIT_DataObjectKey* key() const;
virtual QString entry() const;
virtual _PTR(SObject) object() const; // location of corresponding SALOMEDS::SObject
+ bool isReference() const;
+ _PTR(SObject) referencedObject() const;
+
SUIT_DataObject* componentObject() const;
QString componentDataType() const; // GEOM, SMESH, VISU, etc.
+private:
+ QString ior( const _PTR(SObject)& ) const;
+ QString entry( const _PTR(SObject)& ) const;
+ QString value( const _PTR(SObject)& ) const;
+
private:
_PTR(SObject) myObject;
};
//=======================================================================================
+msgid "SalomeApp_Application::OBJ_BROWSER_NAME"
+msgstr "Object"
+
+msgid "SalomeApp_Application::OBJ_BROWSER_COLUMN_0"
+msgstr "Value"
+
+msgid "SalomeApp_Application::OBJ_BROWSER_COLUMN_1"
+msgstr "Entry"
+
+msgid "SalomeApp_Application::OBJ_BROWSER_COLUMN_2"
+msgstr "IOR"
+
+msgid "SalomeApp_Application::OBJ_BROWSER_COLUMN_3"
+msgstr "Reference entry"
+
+//=======================================================================================
+
msgid "SalomeApp_ModuleDlg::CAPTION"
msgstr "Activate module"
msgid "SalomeApp_ModuleDlg::ActivateComponent_DESCRIPTION"
msgstr "Create, open or load study."
-//=======================================================================================
\ No newline at end of file
+//=======================================================================================