Salome HOME
Join modifications from branch BR_3_1_0deb
[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
41 class OB_EXPORT OB_Browser : public QFrame, public SUIT_PopupClient
42 {
43         Q_OBJECT
44
45   class ToolTip;
46
47 public:
48   OB_Browser( QWidget* = 0, SUIT_DataObject* theRoot = 0 );
49   virtual ~OB_Browser();
50
51   virtual QString   popupClientType() const { return QString( "ObjectBrowser" ); }
52
53   SUIT_DataObject*  getRootObject() const;
54   virtual void      setRootObject( SUIT_DataObject* theRoot = 0 );
55
56   int               numberOfSelected() const;
57
58   DataObjectList    getSelected() const;
59   void              getSelected( DataObjectList& ) const;
60
61   virtual void      setSelected( const SUIT_DataObject* theObject, const bool = false );
62   virtual void      setSelected( const DataObjectList& theObjLst, const bool = false );
63
64   bool              isOpen( SUIT_DataObject* theObject ) const;
65   virtual void      setOpen( SUIT_DataObject* theObject, const bool theOpen = true );
66
67   bool              isAutoUpdate() const;
68   virtual void      setAutoUpdate( const bool );
69
70   bool              isAutoDeleteObjects() const;
71   virtual void      setAutoDeleteObjects( const bool );
72
73   virtual void      updateTree( SUIT_DataObject* = 0, const bool autoOpen = true );
74   virtual void      replaceTree( SUIT_DataObject*, SUIT_DataObject* );
75
76   bool              isShowToolTips();
77   void              setShowToolTips( const bool theDisplay );
78
79   void              adjustWidth();
80
81   SUIT_DataObject*  dataObjectAt( const QPoint& ) const;
82
83   OB_Filter*        filter() const;
84   void              setFilter( OB_Filter* );
85
86   bool              rootIsDecorated() const;
87   void              setRootIsDecorated( const bool );
88
89   int               autoOpenLevel() const;
90   void              setAutoOpenLevel( const int );
91
92   virtual int       addColumn( const QString&, const int id = -1, const int width = -1 );
93   virtual int       addColumn( const QIconSet&, const QString&, const int id = -1, const int width = -1 );
94   virtual void      removeColumn( const int id );
95
96   void              setNameTitle( const QString& );
97   virtual void      setNameTitle( const QIconSet&, const QString& );
98   void              setColumnTitle( const int id, const QString& );
99   virtual void      setColumnTitle( const int id, const QIconSet&, const QString& );
100
101   QString           nameTitle() const;
102   QString           columnTitle( const int ) const;
103
104   bool              isColumnVisible( const int ) const;
105   virtual void      setColumnShown( const int, const bool );
106
107   virtual void      setWidthMode( QListView::WidthMode );
108
109   QValueList<int>   columns() const;
110
111   bool              appropriateColumn( const int ) const;
112   virtual void      setAppropriateColumn( const int, const bool );
113
114   virtual bool      eventFilter(QObject* watched, QEvent* e);
115
116   QListView*        listView() const;
117
118   virtual void      contextMenuPopup( QPopupMenu* );
119
120 signals:
121   void              selectionChanged();
122   void              doubleClicked( SUIT_DataObject* );
123   void              dropped( DataObjectList, SUIT_DataObject*, int );
124
125 private slots:
126   void              onExpand();
127   void              onColumnVisible( int );
128   void              onDestroyed( SUIT_DataObject* );
129   void              onDoubleClicked ( QListViewItem* );
130   void              onDropped( QPtrList<QListViewItem>, QListViewItem*, int );
131
132 protected:
133   void              adjustWidth( QListViewItem* );
134   virtual void      updateView( const SUIT_DataObject* theStartObj = 0 );
135   virtual void      updateText();
136
137   virtual void      keyPressEvent( QKeyEvent* );
138
139   SUIT_DataObject*  dataObject( const QListViewItem* ) const;
140   QListViewItem*    listViewItem( const SUIT_DataObject* ) const;
141
142 private:
143   typedef QMap<SUIT_DataObject*, QListViewItem*> ItemMap;
144   typedef SUIT_DataObjectKeyHandle               DataObjectKey;
145   typedef QMap<SUIT_DataObject*, int>            DataObjectMap;
146   typedef QMap<DataObjectKey, int>               DataObjectKeyMap;
147
148 private:
149   void              expand( QListViewItem* );
150   bool              hasClosed( QListViewItem* ) const;
151
152   void              autoOpenBranches();
153   void              openBranch( QListViewItem*, const int );
154
155   void              removeReferences( QListViewItem* );
156   void              removeConnections( SUIT_DataObject* );
157   void              createConnections( SUIT_DataObject* );
158   void              removeObject( SUIT_DataObject*, const bool = true );
159
160   void              updateText( QListViewItem* );
161
162   DataObjectKey     objectKey( QListViewItem* ) const;
163   DataObjectKey     objectKey( SUIT_DataObject* ) const;
164
165   QListViewItem*    createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0 );
166   QListViewItem*    createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0 );
167
168   SUIT_DataObject*  storeState( DataObjectMap&, DataObjectMap&,
169                                 DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const;
170   void              restoreState( const DataObjectMap&, const DataObjectMap&, const SUIT_DataObject*,
171                                   const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& );
172
173 private:
174   OB_ListView*      myView;
175   SUIT_DataObject*  myRoot;
176   ItemMap           myItems;
177   QToolTip*         myTooltip;
178   QMap<int, int>    myColumnIds;
179   bool              myAutoUpdate;
180   bool              myAutoDelObjs;
181   bool              myShowToolTips;
182   bool              myRootDecorated;
183   int               myAutoOpenLevel;
184
185   friend class OB_Browser::ToolTip;
186 };
187
188 #endif