]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ObjectsBrowser.h
Salome HOME
de53db9130ce27ed041fe9d8b96b9093f47274fd
[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  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 #ifdef ModuleDataModel
74   ModuleBase_IDocumentDataModel* dataModel() const
75   {
76     return myDocModel;
77   }
78 #else
79   XGUI_DataModel* dataModel() const
80   {
81     return myDocModel;
82   }
83 #endif
84
85   //! Returns list of currently selected objects
86   //! \param theIndexes - output list of corresponded indexes (can be NULL)
87   QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
88
89   /// Set selected list of objects
90   /// \param theObjects list of objects to select
91   void setObjectsSelected(const QObjectPtrList& theObjects);
92
93   //! Returns currently selected indexes
94   QModelIndexList selectedIndexes() const
95   {
96     return myTreeView->selectionModel()->selectedIndexes();
97   }
98
99   //! Returns TreeView widget
100   XGUI_DataTree* treeView() const
101   {
102     return myTreeView;
103   }
104
105   /// Returns active doc label object
106   QLineEdit* activeDocLabel() const { return myActiveDocLbl; }
107
108   /// Rebuild data tree
109   void rebuildDataTree();
110
111   /// Resets the object browser into initial state
112   void clearContent();
113
114   /// Set Data Model for the Object Browser
115   void setDataModel(ModuleBase_IDocumentDataModel* theModel);
116
117 signals:
118   //! Emited when selection is changed
119   void selectionChanged();
120
121   //! Emited on context menu request
122   void contextMenuRequested(QContextMenuEvent* theEvent);
123
124   //! Segnal is emitted when user cliks by mouse in header label of object browser
125   void headerMouseDblClicked(const QModelIndex&);
126
127  protected:
128    /// Redefinition of virtual method
129   virtual bool eventFilter(QObject* obj, QEvent* theEvent);
130
131  private slots:
132   /// Show context menu
133   /// \param theEvent a context menu event
134   void onContextMenuRequested(QContextMenuEvent* theEvent);
135
136   /// Show context menu on upper label
137   /// \param thePnt a position of context menu
138   void onLabelContextMenuRequested(const QPoint& thePnt);
139
140   //! Called on Edit command request
141   void onEditItem();
142
143   //! Called when selection in Data Tree is changed
144   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
145
146  private:
147   void closeDocNameEditing(bool toSave);
148
149   //! Internal model
150 #ifdef ModuleDataModel
151   ModuleBase_IDocumentDataModel* myDocModel;
152 #else
153   XGUI_DataModel* myDocModel;
154 #endif
155   QLineEdit* myActiveDocLbl;
156   XGUI_DataTree* myTreeView;
157 };
158
159 #endif