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