Salome HOME
Porting on new SALOME
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_ObjectsBrowser_H
4 #define XGUI_ObjectsBrowser_H
5
6 #include "XGUI.h"
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_Object.h>
9 #include <ModelAPI_ResultPart.h>
10 #include <ModelAPI_Events.h>
11
12 #include <QWidget>
13 #include <QTreeView>
14 #include <QLabel>
15
16 class ModuleBase_IDocumentDataModel;
17 class XGUI_DataModel;
18 class Config_DataModelReader;
19
20 /**
21 * \ingroup GUI
22 * Implementation of root label in Object Browser
23 */
24 class XGUI_ActiveDocLbl: public QLabel
25 {
26 Q_OBJECT
27  public:
28    /// Constructor
29    /// \param theText a text
30    /// \param theParent a parent widget
31    XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
32
33    /// Sets tree view
34    /// \param theView a view
35    void setTreeView(QTreeView* theView);
36
37    /// Returns tree view
38    QTreeView* treePalette() const { return myTreeView;}
39
40 #if (!defined HAVE_SALOME) && (defined WIN32)
41    virtual bool event(QEvent* theEvent);
42 #endif
43
44 public slots:
45   /// On unselect
46   void unselect();
47
48 protected:
49   /// On mouse release
50   virtual void mouseReleaseEvent( QMouseEvent* e);
51
52   /// Filter event
53   bool eventFilter(QObject* theObj, QEvent* theEvent);
54
55 private:
56   QString myPreSelectionStyle;
57   QString myNeutralStyle;
58   QString mySelectionStyle;
59
60   QTreeView* myTreeView;
61   bool myIsSelected;
62 };
63
64
65 /**
66 * \ingroup GUI
67 * Implementation of Data Tree object for Object Browser
68 */
69 class XGUI_DataTree : public QTreeView
70 {
71 Q_OBJECT
72  public:
73    /// Constructor
74    /// \param theParent a parent widget
75   XGUI_DataTree(QWidget* theParent);
76
77   virtual ~XGUI_DataTree();
78
79   /// Returns current data model
80   XGUI_DataModel* dataModel() const;
81
82 signals:
83   //! Emited on context menu request
84   void contextMenuRequested(QContextMenuEvent* theEvent);
85
86 public slots:
87   /// Clear content of data tree
88   virtual void clear();
89
90  protected slots:
91   /// Commit modified data (used for renaming of objects)
92   virtual void commitData(QWidget* theEditor);
93
94   /// A slot which is called on mouse double click
95   void onDoubleClick(const QModelIndex&);
96
97  protected:
98    /// Redefinition of virtual method
99   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
100
101    /// Redefinition of virtual method
102   virtual void resizeEvent(QResizeEvent* theEvent);
103 };
104
105 /**\class XGUI_ObjectsBrowser
106  * \ingroup GUI
107  * \brief Object browser window object. Represents data tree of current data structure
108  */
109 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
110 {
111 Q_OBJECT
112  public:
113    /// Constructor
114    /// \param theParent a parent widget
115   XGUI_ObjectsBrowser(QWidget* theParent);
116   virtual ~XGUI_ObjectsBrowser();
117
118   //! Returns Model which provides access to data objects
119   XGUI_DataModel* dataModel() const
120   {
121     return myDocModel;
122   }
123
124   //! Returns list of currently selected objects
125   //! \param theIndexes - output list of corresponded indexes (can be NULL)
126   QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
127
128   /// Set selected list of objects
129   /// \param theObjects list of objects to select
130   void setObjectsSelected(const QObjectPtrList& theObjects);
131
132   //! Returns currently selected indexes
133   QModelIndexList selectedIndexes() const
134   {
135     return myTreeView->selectionModel()->selectedIndexes();
136   }
137
138   //! Returns TreeView widget
139   XGUI_DataTree* treeView() const
140   {
141     return myTreeView;
142   }
143
144   /// Returns active doc label object
145   QLabel* activeDocLabel() const { return myActiveDocLbl; }
146
147   /// Rebuild data tree
148   void rebuildDataTree();
149
150   /// Resets the object browser into initial state
151   void clearContent();
152
153   /// Set XML reader object for data model
154   /// \param theReader the reader object
155   void setXMLReader(Config_DataModelReader* theReader);
156
157   /// Returns list of folders opened state for the given document
158   /// \param theDoc the document
159   /// \return list of booleans with state expanded or not
160   std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
161
162   /// Set folders opened state for the given document
163   /// \param theDoc the document
164   /// \param theStates list of booleans with state expanded or not
165   void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
166
167 public slots:
168   //! Called on Edit command request
169   void onEditItem();
170
171 signals:
172   //! Emited when selection is changed
173   void selectionChanged();
174
175   //! Emited on context menu request
176   void contextMenuRequested(QContextMenuEvent* theEvent);
177
178   //! Segnal is emitted when user cliks by mouse in header label of object browser
179   void headerMouseDblClicked(const QModelIndex&);
180
181  private slots:
182   /// Show context menu
183   /// \param theEvent a context menu event
184   void onContextMenuRequested(QContextMenuEvent* theEvent);
185
186   /// Show context menu on upper label
187   /// \param thePnt a position of context menu
188   void onLabelContextMenuRequested(const QPoint& thePnt);
189
190   //! Called when selection in Data Tree is changed
191   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
192
193   void onBeforeReset();
194
195   void onAfterModelReset();
196
197  private:
198   QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
199
200   //! Internal model
201   XGUI_DataModel* myDocModel;
202   XGUI_ActiveDocLbl* myActiveDocLbl;
203   XGUI_DataTree* myTreeView;
204
205   /// A field to store expanded items before model reset
206   QModelIndexList myExpandedItems;
207 };
208
209 #endif