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