Salome HOME
Merge from OCC_development_generic_2006
[modules/gui.git] / src / ObjBrowser / OB_Browser.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 #ifndef OB_BROWSER_H
20 #define OB_BROWSER_H
21
22 #include "OB.h"
23
24 #include <qframe.h>
25
26 #include <qmap.h>
27 #include <qlistview.h>
28
29 #include <SUIT_DataObject.h>
30 #include <SUIT_DataObjectKey.h>
31 #include <SUIT_PopupClient.h>
32
33 #ifdef WNT
34 #pragma warning( disable:4251 )
35 #endif
36
37 class QToolTip;
38 class OB_Filter;
39 class OB_ListView;
40 class OB_ListItem;
41
42 class OB_EXPORT OB_Browser : public QFrame, public SUIT_PopupClient
43 {
44         Q_OBJECT
45
46   class ToolTip;
47
48 public:
49   OB_Browser( QWidget* = 0, SUIT_DataObject* theRoot = 0 );
50   virtual ~OB_Browser();
51
52   virtual QString   popupClientType() const { return QString( "ObjectBrowser" ); }
53
54   SUIT_DataObject*  getRootObject() const;
55   virtual void      setRootObject( SUIT_DataObject* theRoot = 0 );
56
57   int               numberOfSelected() const;
58
59   DataObjectList    getSelected() const;
60   void              getSelected( DataObjectList& ) const;
61
62   virtual void      setSelected( const SUIT_DataObject* theObject, const bool = false );
63   virtual void      setSelected( const DataObjectList& theObjLst, const bool = false );
64
65   bool              isOpen( SUIT_DataObject* theObject ) const;
66   virtual void      setOpen( SUIT_DataObject* theObject, const bool theOpen = true );
67
68   bool              isAutoUpdate() const;
69   virtual void      setAutoUpdate( const bool );
70
71   bool              isAutoDeleteObjects() const;
72   virtual void      setAutoDeleteObjects( const bool );
73
74   virtual void      updateTree( SUIT_DataObject* = 0, const bool autoOpen = true );
75   virtual void      replaceTree( SUIT_DataObject*, SUIT_DataObject* );
76
77   bool              isShowToolTips();
78   void              setShowToolTips( const bool theDisplay );
79
80   void              adjustWidth();
81
82   SUIT_DataObject*  dataObjectAt( const QPoint& ) const;
83
84   OB_Filter*        filter() const;
85   void              setFilter( OB_Filter* );
86
87   bool              rootIsDecorated() const;
88   void              setRootIsDecorated( const bool );
89
90   int               autoOpenLevel() const;
91   void              setAutoOpenLevel( const int );
92
93   virtual int       addColumn( const QString&, const int id = -1, const int width = -1 );
94   virtual int       addColumn( const QIconSet&, const QString&, const int id = -1, const int width = -1 );
95   virtual void      removeColumn( const int id );
96
97   void              setNameTitle( const QString& );
98   virtual void      setNameTitle( const QIconSet&, const QString& );
99   void              setColumnTitle( const int id, const QString& );
100   virtual void      setColumnTitle( const int id, const QIconSet&, const QString& );
101
102   QString           nameTitle() const;
103   QString           columnTitle( const int ) const;
104
105   bool              isColumnVisible( const int ) const;
106   virtual void      setColumnShown( const int, const bool );
107
108   virtual void      setWidthMode( QListView::WidthMode );
109
110   QValueList<int>   columns() const;
111
112   bool              appropriateColumn( const int ) const;
113   virtual void      setAppropriateColumn( const int, const bool );
114
115   virtual bool      eventFilter(QObject* watched, QEvent* e);
116
117   QListView*        listView() const;
118
119   virtual void      contextMenuPopup( QPopupMenu* );
120
121   void              setModified();
122   unsigned long     getModifiedTime() { return myModifiedTime; }
123
124 signals:
125   void              selectionChanged();
126   void              doubleClicked( SUIT_DataObject* );
127   void              dropped( DataObjectList, SUIT_DataObject*, int );
128
129 private slots:
130   void              onExpand();
131   void              onColumnVisible( int );
132   void              onDestroyed( SUIT_DataObject* );
133   void              onDoubleClicked ( QListViewItem* );
134   void              onDropped( QPtrList<QListViewItem>, QListViewItem*, int );
135
136 protected:
137   void              adjustWidth( QListViewItem* );
138   virtual void      updateView( SUIT_DataObject* = 0 );
139   virtual void      updateText();
140
141   virtual void      keyPressEvent( QKeyEvent* );
142
143   SUIT_DataObject*  dataObject( const QListViewItem* ) const;
144   QListViewItem*    listViewItem( const SUIT_DataObject* ) const;
145
146 private:
147   typedef QMap<SUIT_DataObject*, QListViewItem*> ItemMap;
148   typedef SUIT_DataObjectKeyHandle               DataObjectKey;
149   typedef QMap<SUIT_DataObject*, int>            DataObjectMap;
150   typedef QMap<DataObjectKey, int>               DataObjectKeyMap;
151
152 private:
153   void              expand( QListViewItem* );
154   bool              hasClosed( QListViewItem* ) const;
155
156   void              autoOpenBranches();
157   void              openBranch( QListViewItem*, const int );
158
159   void              removeReferences( QListViewItem* );
160   void              removeConnections( SUIT_DataObject* );
161   void              createConnections( SUIT_DataObject* );
162   void              removeObject( SUIT_DataObject*, const bool = true );
163
164   void              updateText( QListViewItem* );
165
166   DataObjectKey     objectKey( QListViewItem* ) const;
167   DataObjectKey     objectKey( SUIT_DataObject* ) const;
168
169   QListViewItem*    createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false );
170   QListViewItem*    createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false );
171
172   SUIT_DataObject*  storeState( DataObjectMap&, DataObjectMap&,
173                                 DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const;
174   void              restoreState( const DataObjectMap&, const DataObjectMap&, const SUIT_DataObject*,
175                                   const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& );
176
177 private:
178   friend class OB_BrowserSync;
179
180   OB_ListView*      myView;
181   SUIT_DataObject*  myRoot;
182   ItemMap           myItems;
183   QToolTip*         myTooltip;
184   QMap<int, int>    myColumnIds;
185   bool              myAutoUpdate;
186   bool              myAutoDelObjs;
187   bool              myShowToolTips;
188   bool              myRootDecorated;
189   int               myAutoOpenLevel;
190
191   friend class OB_Browser::ToolTip;
192
193   unsigned long     myModifiedTime;
194 };
195
196 #endif