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