Salome HOME
1. Mirror/Rotation/Translation constraint: using RefList instead of SelectionList
[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 ModuleBase_IDocumentDataModel;
16 class QLineEdit;
17 class XGUI_DataModel;
18
19 //#define ModuleDataModel
20
21 /**
22 * \ingroup GUI
23 * Implementation of Data Tree object for Object Browser
24 */
25 class XGUI_DataTree : public QTreeView
26 {
27 Q_OBJECT
28  public:
29    /// Constructor
30    /// \param theParent a parent widget
31   XGUI_DataTree(QWidget* theParent);
32
33   virtual ~XGUI_DataTree();
34
35   /// Returns current data model
36   ModuleBase_IDocumentDataModel* dataModel() const;
37
38 signals:
39   //! Emited on context menu request
40   void contextMenuRequested(QContextMenuEvent* theEvent);
41
42 public slots:
43   /// Clear content of data tree
44   virtual void clear();
45
46  protected slots:
47   /// Commit modified data (used for renaming of objects)
48   virtual void commitData(QWidget* theEditor);
49
50   void onDoubleClick(const QModelIndex&);
51
52  protected:
53    /// Redefinition of virtual method
54   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
55
56    /// Redefinition of virtual method
57   virtual void resizeEvent(QResizeEvent* theEvent);
58
59 };
60
61 /**\class XGUI_ObjectsBrowser
62  * \ingroup GUI
63  * \brief Object browser window object. Represents data tree of current data structure
64  */
65 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
66 {
67 Q_OBJECT
68  public:
69    /// Constructor
70    /// \param theParent a parent widget
71   XGUI_ObjectsBrowser(QWidget* theParent);
72   virtual ~XGUI_ObjectsBrowser();
73
74   //! Returns Model which provides access to data objects
75 #ifdef ModuleDataModel
76   ModuleBase_IDocumentDataModel* dataModel() const
77   {
78     return myDocModel;
79   }
80 #else
81   XGUI_DataModel* dataModel() const
82   {
83     return myDocModel;
84   }
85 #endif
86
87   //! Returns list of currently selected objects
88   //! \param theIndexes - output list of corresponded indexes (can be NULL)
89   QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
90
91   /// Set selected list of objects
92   /// \param theObjects list of objects to select
93   void setObjectsSelected(const QObjectPtrList& theObjects);
94
95   //! Returns currently selected indexes
96   QModelIndexList selectedIndexes() const
97   {
98     return myTreeView->selectionModel()->selectedIndexes();
99   }
100
101   //! Returns TreeView widget
102   XGUI_DataTree* treeView() const
103   {
104     return myTreeView;
105   }
106
107   /// Returns active doc label object
108   QLineEdit* activeDocLabel() const { return myActiveDocLbl; }
109
110   /// Rebuild data tree
111   void rebuildDataTree();
112
113   /// Resets the object browser into initial state
114   void clearContent();
115
116   /// Set Data Model for the Object Browser
117   void setDataModel(ModuleBase_IDocumentDataModel* theModel);
118
119 public slots:
120   //! Called on Edit command request
121   void onEditItem();
122
123 signals:
124   //! Emited when selection is changed
125   void selectionChanged();
126
127   //! Emited on context menu request
128   void contextMenuRequested(QContextMenuEvent* theEvent);
129
130   //! Segnal is emitted when user cliks by mouse in header label of object browser
131   void headerMouseDblClicked(const QModelIndex&);
132
133  protected:
134    /// Redefinition of virtual method
135   virtual bool eventFilter(QObject* obj, QEvent* theEvent);
136
137  private slots:
138   /// Show context menu
139   /// \param theEvent a context menu event
140   void onContextMenuRequested(QContextMenuEvent* theEvent);
141
142   /// Show context menu on upper label
143   /// \param thePnt a position of context menu
144   void onLabelContextMenuRequested(const QPoint& thePnt);
145
146   //! Called when selection in Data Tree is changed
147   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
148
149  private:
150   void closeDocNameEditing(bool toSave);
151
152   //! Internal model
153 #ifdef ModuleDataModel
154   ModuleBase_IDocumentDataModel* myDocModel;
155 #else
156   XGUI_DataModel* myDocModel;
157 #endif
158   QLineEdit* myActiveDocLbl;
159   XGUI_DataTree* myTreeView;
160 };
161
162 #endif