Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[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
15 class XGUI_DocumentDataModel;
16 class QLineEdit;
17
18 /**
19 * \ingroup GUI
20 * Implementation of Data Tree object for Object Browser
21 */
22 class XGUI_DataTree : public QTreeView
23 {
24 Q_OBJECT
25  public:
26    /// Constructor
27    /// \param theParent a parent widget
28   XGUI_DataTree(QWidget* theParent);
29   virtual ~XGUI_DataTree();
30
31   //! Returns list of currently selected objects
32   QObjectPtrList selectedObjects() const
33   {
34     return mySelectedData;
35   }
36
37   /// Returns current data model
38   XGUI_DocumentDataModel* dataModel() const;
39
40 signals:
41   //! Emited when selection is changed
42   void selectionChanged();
43
44   //! Emited when active part changed
45   void activePartChanged(ObjectPtr thePart);
46
47   //! Emited on context menu request
48   void contextMenuRequested(QContextMenuEvent* theEvent);
49
50 public slots:
51   /// Clear content of data tree
52   virtual void clear();
53
54  protected slots:
55    /// Commit modified data (used for renaming of objects)
56   virtual void commitData(QWidget* theEditor);
57
58  protected:
59    /// Redefinition of virtual method
60   virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
61
62    /// Redefinition of virtual method
63   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
64
65  private slots:
66   //! Called when selection in Data Tree is changed
67   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
68
69  private:
70   //! List of currently selected data
71   QObjectPtrList mySelectedData;
72 };
73
74 /**\class XGUI_ObjectsBrowser
75  * \ingroup GUI
76  * \brief Object browser window object. Represents data tree of current data structure
77  */
78 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
79 {
80 Q_OBJECT
81  public:
82    /// Constructor
83    /// \param theParent a parent widget
84   XGUI_ObjectsBrowser(QWidget* theParent);
85   virtual ~XGUI_ObjectsBrowser();
86
87   //! Returns Model which provides access to data objects
88   XGUI_DocumentDataModel* dataModel() const
89   {
90     return myDocModel;
91   }
92
93   //! Returns list of currently selected objects
94   QObjectPtrList selectedObjects() const
95   {
96     return myObjectsList;
97   }
98
99   /// Set selected list of objects
100   /// \param theObjects list of objects to select
101   void setObjectsSelected(const QObjectPtrList& theObjects);
102
103   //! Returns currently selected indexes
104   QModelIndexList selectedIndexes() const
105   {
106     return myTreeView->selectionModel()->selectedIndexes();
107   }
108
109   //! Returns TreeView widget
110   XGUI_DataTree* treeView() const
111   {
112     return myTreeView;
113   }
114
115   //! Activates currently selected part. Signal activePartChanged will not be sent
116   void activatePart(const ResultPartPtr& thePart);
117
118   /// Rebuild data tree
119   void rebuildDataTree();
120
121   /// Process application event
122   /// \param theMessage an event message
123   void processEvent(const std::shared_ptr<Events_Message>& theMessage);
124
125   /// Resets the object browser into initial state
126   void clearContent();
127
128 signals:
129   //! Emited when selection is changed
130   void selectionChanged();
131
132   //! Emited when current active document is changed
133   void activePartChanged(ObjectPtr thePart);
134
135   //! Emited on context menu request
136   void contextMenuRequested(QContextMenuEvent* theEvent);
137
138  protected:
139    /// Redefinition of virtual method
140   virtual bool eventFilter(QObject* obj, QEvent* theEvent);
141
142  private slots:
143    /// Activate part
144    /// \param thePart a part to activate
145   void onActivePartChanged(ObjectPtr thePart);
146
147   /// Show context menu
148   /// \param theEvent a context menu event
149   void onContextMenuRequested(QContextMenuEvent* theEvent);
150
151   /// Show context menu on upper label
152   /// \param thePnt a position of context menu
153   void onLabelContextMenuRequested(const QPoint& thePnt);
154
155   //! Called on Edit command request
156   void onEditItem();
157
158   /// Process selection changed event
159   void onSelectionChanged();
160
161  private:
162   void closeDocNameEditing(bool toSave);
163
164   //! Internal model
165   XGUI_DocumentDataModel* myDocModel;
166
167   QLineEdit* myActiveDocLbl;
168   XGUI_DataTree* myTreeView;
169
170   QObjectPtrList myObjectsList;
171 };
172
173 #endif