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