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