1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include <qlistview.h>
29 #include <SUIT_DataObject.h>
30 #include <SUIT_DataObjectKey.h>
31 #include <SUIT_PopupClient.h>
34 #pragma warning( disable:4251 )
44 Represents object browser. Allows to get/set selection,
45 to drag-n-drop of objects, to determine item by SUIT object and
48 class OB_EXPORT OB_Browser : public QFrame, public SUIT_PopupClient
55 OB_Browser( QWidget* = 0, SUIT_DataObject* theRoot = 0 );
56 virtual ~OB_Browser();
58 virtual QString popupClientType() const { return QString( "ObjectBrowser" ); }
60 SUIT_DataObject* getRootObject() const;
61 virtual void setRootObject( SUIT_DataObject* theRoot = 0 );
63 int numberOfSelected() const;
65 DataObjectList getSelected() const;
66 void getSelected( DataObjectList& ) const;
68 virtual void setSelected( const SUIT_DataObject* theObject, const bool = false );
69 virtual void setSelected( const DataObjectList& theObjLst, const bool = false );
71 bool isOpen( SUIT_DataObject* theObject ) const;
72 virtual void setOpen( SUIT_DataObject* theObject, const bool theOpen = true );
74 bool isAutoUpdate() const;
75 virtual void setAutoUpdate( const bool );
77 bool isAutoDeleteObjects() const;
78 virtual void setAutoDeleteObjects( const bool );
80 virtual void updateTree( SUIT_DataObject* = 0, const bool autoOpen = true );
81 virtual void replaceTree( SUIT_DataObject*, SUIT_DataObject* );
83 bool isShowToolTips();
84 void setShowToolTips( const bool theDisplay );
88 SUIT_DataObject* dataObjectAt( const QPoint& ) const;
90 OB_Filter* filter() const;
91 void setFilter( OB_Filter* );
93 bool rootIsDecorated() const;
94 void setRootIsDecorated( const bool );
96 int autoOpenLevel() const;
97 void setAutoOpenLevel( const int );
99 virtual int addColumn( const QString&, const int id = -1, const int width = -1 );
100 virtual int addColumn( const QIconSet&, const QString&, const int id = -1, const int width = -1 );
101 virtual void removeColumn( const int id );
103 void setNameTitle( const QString& );
104 virtual void setNameTitle( const QIconSet&, const QString& );
105 void setColumnTitle( const int id, const QString& );
106 virtual void setColumnTitle( const int id, const QIconSet&, const QString& );
108 QString nameTitle() const;
109 QString columnTitle( const int ) const;
111 bool isColumnVisible( const int ) const;
112 virtual void setColumnShown( const int, const bool );
114 virtual void setWidthMode( QListView::WidthMode );
116 QValueList<int> columns() const;
118 bool appropriateColumn( const int ) const;
119 virtual void setAppropriateColumn( const int, const bool );
121 virtual bool eventFilter(QObject* watched, QEvent* e);
123 QListView* listView() const;
125 virtual void contextMenuPopup( QPopupMenu* );
128 unsigned long getModifiedTime() { return myModifiedTime; }
131 void selectionChanged();
132 void doubleClicked( SUIT_DataObject* );
133 void dropped( DataObjectList, SUIT_DataObject*, int );
137 void onColumnVisible( int );
138 void onDestroyed( SUIT_DataObject* );
139 void onDoubleClicked ( QListViewItem* );
140 void onDropped( QPtrList<QListViewItem>, QListViewItem*, int );
143 void adjustWidth( QListViewItem* );
144 virtual void updateView( SUIT_DataObject* = 0 );
145 virtual void updateText();
147 virtual void keyPressEvent( QKeyEvent* );
149 SUIT_DataObject* dataObject( const QListViewItem* ) const;
150 QListViewItem* listViewItem( const SUIT_DataObject* ) const;
153 typedef QMap<SUIT_DataObject*, QListViewItem*> ItemMap;
154 typedef SUIT_DataObjectKeyHandle DataObjectKey;
155 typedef QMap<SUIT_DataObject*, int> DataObjectMap;
156 typedef QMap<DataObjectKey, int> DataObjectKeyMap;
159 void expand( QListViewItem* );
160 bool hasClosed( QListViewItem* ) const;
162 void autoOpenBranches();
163 void openBranch( QListViewItem*, const int );
165 void removeReferences( QListViewItem* );
166 void removeConnections( SUIT_DataObject* );
167 void createConnections( SUIT_DataObject* );
168 void removeObject( SUIT_DataObject*, const bool = true );
170 void updateText( QListViewItem* );
171 bool needToUpdateTexts( QListViewItem* ) const;
173 DataObjectKey objectKey( QListViewItem* ) const;
174 DataObjectKey objectKey( SUIT_DataObject* ) const;
176 QListViewItem* createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false );
177 QListViewItem* createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false );
179 SUIT_DataObject* storeState( DataObjectMap&, DataObjectMap&,
180 DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const;
181 void restoreState( const DataObjectMap&, const DataObjectMap&, const SUIT_DataObject*,
182 const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& );
185 friend class OB_BrowserSync;
188 SUIT_DataObject* myRoot;
191 QMap<int, int> myColumnIds;
195 bool myRootDecorated;
198 friend class OB_Browser::ToolTip;
200 unsigned long myModifiedTime;