Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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/ or email : webmaster.salome@opencascade.com
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 class OB_ObjSearch;
42 class OB_FindDlg;
43
44 class OB_Updater 
45 {
46 public:
47   OB_Updater(){};
48   virtual ~OB_Updater(){};
49   virtual void update( SUIT_DataObject* theObj, OB_ListItem* theLI ) = 0;
50 };
51
52 /*!
53   \class OB_Browser
54   Represents object browser. Allows to get/set selection, 
55   to drag-n-drop of objects, to determine item by SUIT object and 
56   vice versa
57 */
58 class OB_EXPORT OB_Browser : public QFrame, public SUIT_PopupClient
59 {
60         Q_OBJECT
61
62   class ToolTip;
63
64 public:
65   OB_Browser( QWidget* = 0, SUIT_DataObject* theRoot = 0 );
66   virtual ~OB_Browser();
67
68   virtual QString   popupClientType() const { return QString( "ObjectBrowser" ); }
69
70   SUIT_DataObject*  getRootObject() const;
71   virtual void      setRootObject( SUIT_DataObject* theRoot = 0 );
72
73   int               numberOfSelected() const;
74
75   DataObjectList    getSelected() const;
76   void              getSelected( DataObjectList& ) const;
77
78   virtual void      setSelected( const SUIT_DataObject* theObject, const bool = false );
79   virtual void      setSelected( const DataObjectList& theObjLst, const bool = false );
80
81   bool              isOpen( SUIT_DataObject* theObject ) const;
82   virtual void      setOpen( SUIT_DataObject* theObject, const bool theOpen = true );
83
84   bool              isAutoUpdate() const;
85   virtual void      setAutoUpdate( const bool );
86
87   bool              isAutoDeleteObjects() const;
88   virtual void      setAutoDeleteObjects( const bool );
89
90   virtual void      updateTree( SUIT_DataObject* = 0, const bool = false );
91   virtual void      replaceTree( SUIT_DataObject*, SUIT_DataObject* );
92
93   bool              isShowToolTips();
94   void              setShowToolTips( const bool theDisplay );
95
96   void              adjustWidth();
97
98   SUIT_DataObject*  dataObjectAt( const QPoint& ) const;
99
100   OB_Filter*        filter() const;
101   void              setFilter( OB_Filter* );
102
103   bool              rootIsDecorated() const;
104   void              setRootIsDecorated( const bool );
105
106   int               autoOpenLevel() const;
107   void              setAutoOpenLevel( const int );
108   void              openLevels( const int = -1 );
109
110   virtual int       addColumn( const QString&, const int id = -1, const int width = -1 );
111   virtual int       addColumn( const QIconSet&, const QString&, const int id = -1, const int width = -1 );
112   virtual void      removeColumn( const int id );
113
114   void              setNameTitle( const QString& );
115   virtual void      setNameTitle( const QIconSet&, const QString& );
116   void              setColumnTitle( const int id, const QString& );
117   virtual void      setColumnTitle( const int id, const QIconSet&, const QString& );
118
119   QString           nameTitle() const;
120   QString           columnTitle( const int ) const;
121
122   bool              isColumnVisible( const int ) const;
123   virtual void      setColumnShown( const int, const bool );
124
125   virtual void      setWidthMode( QListView::WidthMode );
126
127   QValueList<int>   columns() const;
128
129   bool              appropriateColumn( const int ) const;
130   virtual void      setAppropriateColumn( const int, const bool );
131
132   virtual bool      eventFilter(QObject* watched, QEvent* e);
133
134   QListView*        listView() const;
135
136   virtual void      contextMenuPopup( QPopupMenu* );
137
138   void              setModified();
139   unsigned long     getModifiedTime() { return myModifiedTime; }
140   
141   OB_Updater*       getUpdater() const;
142   virtual void      setUpdater( OB_Updater* theUpdate = 0 );
143
144   OB_ObjSearch*     getSearch() const;
145   void              setSearch( OB_ObjSearch* );
146   void              enableSearch( const bool );
147
148 signals:
149   void              selectionChanged();
150   void              doubleClicked( SUIT_DataObject* );
151   void              dropped( DataObjectList, SUIT_DataObject*, int );
152
153 private slots:
154   void              onExpand();
155   void              onColumnVisible( int );
156   void              onDestroyed( SUIT_DataObject* );
157   void              onDoubleClicked ( QListViewItem* );
158   void              onDropped( QPtrList<QListViewItem>, QListViewItem*, int );
159
160 protected:
161   void              adjustWidth( QListViewItem* );
162   virtual void      updateView( SUIT_DataObject* = 0 );
163   virtual void      updateText();
164
165   virtual void      keyPressEvent( QKeyEvent* );
166
167   SUIT_DataObject*  dataObject( const QListViewItem* ) const;
168   QListViewItem*    listViewItem( const SUIT_DataObject* ) const;
169
170 private:
171   typedef QMap<SUIT_DataObject*, QListViewItem*> ItemMap;
172   typedef SUIT_DataObjectKeyHandle               DataObjectKey;
173   typedef QMap<SUIT_DataObject*, int>            DataObjectMap;
174   typedef QMap<DataObjectKey, int>               DataObjectKeyMap;
175
176 private:
177   void              expand( QListViewItem* );
178   bool              hasClosed( QListViewItem* ) const;
179
180   void              autoOpenBranches();
181   void              openBranch( QListViewItem*, const int );
182
183   void              removeReferences( QListViewItem* );
184   void              removeConnections( SUIT_DataObject* );
185   void              createConnections( SUIT_DataObject* );
186   void              removeObject( SUIT_DataObject*, const bool = true );
187
188   void              updateText( QListViewItem* );
189   bool              needToUpdateTexts( QListViewItem* ) const;
190
191   DataObjectKey     objectKey( QListViewItem* ) const;
192   DataObjectKey     objectKey( SUIT_DataObject* ) const;
193
194   QListViewItem*    createTree( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false );
195   QListViewItem*    createItem( const SUIT_DataObject*, QListViewItem*, QListViewItem* = 0, const bool = false );
196
197   SUIT_DataObject*  storeState( DataObjectMap&, DataObjectMap&,
198                                 DataObjectKeyMap&, DataObjectKeyMap&, DataObjectKey& ) const;
199   void              restoreState( const DataObjectMap&, const DataObjectMap&, const SUIT_DataObject*,
200                                   const DataObjectKeyMap&, const DataObjectKeyMap&, const DataObjectKey& );
201
202 private:
203   friend class OB_BrowserSync;
204
205   OB_ListView*      myView;
206   SUIT_DataObject*  myRoot;
207   ItemMap           myItems;
208   QToolTip*         myTooltip;
209   OB_Updater*       myUpdater;
210   QMap<int, int>    myColumnIds;
211   bool              myAutoUpdate;
212   bool              myAutoDelObjs;
213   bool              myShowToolTips;
214   bool              myRootDecorated;
215   int               myAutoOpenLevel;
216   OB_FindDlg       *myFindDlg;
217
218   friend class OB_Browser::ToolTip;
219
220   unsigned long     myModifiedTime;
221 };
222
223 #endif