]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ObjectsBrowser.h
Salome HOME
22b45c08aca2c5ce8fb78ff846d83f4fffdac55c
[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 #if (!defined HAVE_SALOME) && (defined WIN32)
36    virtual bool event(QEvent* theEvent);
37 #endif
38
39 public slots:
40   void unselect();
41
42 protected:
43   virtual void mouseReleaseEvent( QMouseEvent* e);
44
45   bool eventFilter(QObject* theObj, QEvent* theEvent);
46
47 private:
48   QString myPreSelectionStyle;
49   QString myNeutralStyle;
50   QString mySelectionStyle;
51
52   QTreeView* myTreeView;
53   bool myIsSelected;
54 };
55
56
57 #if (!defined HAVE_SALOME) && (defined WIN32)
58 #include <QWindowsVistaStyle>
59 /**
60 * \ingroup GUI
61 * Implementation of XGUI_DataTree custom style
62 */
63 class XGUI_TreeViewStyle : public QWindowsVistaStyle
64 {
65   Q_OBJECT
66 public:
67   XGUI_TreeViewStyle() : QWindowsVistaStyle() {}
68
69   void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
70                      QPainter* thePainter, const QWidget* theWidget = 0) const;
71
72   void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
73   QModelIndex index() const { return myIndex; }
74
75 private:
76   QModelIndex myIndex;
77 };
78 #endif
79
80 /**
81 * \ingroup GUI
82 * Implementation of Data Tree object for Object Browser
83 */
84 class XGUI_DataTree : public QTreeView
85 {
86 Q_OBJECT
87  public:
88    /// Constructor
89    /// \param theParent a parent widget
90   XGUI_DataTree(QWidget* theParent);
91
92   virtual ~XGUI_DataTree();
93
94   /// Returns current data model
95   XGUI_DataModel* dataModel() const;
96
97 signals:
98   //! Emited on context menu request
99   void contextMenuRequested(QContextMenuEvent* theEvent);
100
101 public slots:
102   /// Clear content of data tree
103   virtual void clear();
104
105  protected slots:
106   /// Commit modified data (used for renaming of objects)
107   virtual void commitData(QWidget* theEditor);
108
109   /// A slot which is called on mouse double click
110   void onDoubleClick(const QModelIndex&);
111
112  protected:
113    /// Redefinition of virtual method
114   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
115
116    /// Redefinition of virtual method
117   virtual void resizeEvent(QResizeEvent* theEvent);
118
119 #if (!defined HAVE_SALOME) && (defined WIN32)
120   virtual void drawRow(QPainter* thePainter,
121                         const QStyleOptionViewItem& theOptions,
122                         const QModelIndex& theIndex) const;
123 private:
124   XGUI_TreeViewStyle* myStyle;
125 #endif
126 };
127
128 /**\class XGUI_ObjectsBrowser
129  * \ingroup GUI
130  * \brief Object browser window object. Represents data tree of current data structure
131  */
132 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
133 {
134 Q_OBJECT
135  public:
136    /// Constructor
137    /// \param theParent a parent widget
138   XGUI_ObjectsBrowser(QWidget* theParent);
139   virtual ~XGUI_ObjectsBrowser();
140
141   //! Returns Model which provides access to data objects
142   XGUI_DataModel* dataModel() const
143   {
144     return myDocModel;
145   }
146
147   //! Returns list of currently selected objects
148   //! \param theIndexes - output list of corresponded indexes (can be NULL)
149   QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
150
151   /// Set selected list of objects
152   /// \param theObjects list of objects to select
153   void setObjectsSelected(const QObjectPtrList& theObjects);
154
155   //! Returns currently selected indexes
156   QModelIndexList selectedIndexes() const
157   {
158     return myTreeView->selectionModel()->selectedIndexes();
159   }
160
161   //! Returns TreeView widget
162   XGUI_DataTree* treeView() const
163   {
164     return myTreeView;
165   }
166
167   /// Returns active doc label object
168   QLineEdit* activeDocLabel() const { return myActiveDocLbl; }
169
170   /// Rebuild data tree
171   void rebuildDataTree();
172
173   /// Resets the object browser into initial state
174   void clearContent();
175
176 public slots:
177   //! Called on Edit command request
178   void onEditItem();
179
180 signals:
181   //! Emited when selection is changed
182   void selectionChanged();
183
184   //! Emited on context menu request
185   void contextMenuRequested(QContextMenuEvent* theEvent);
186
187   //! Segnal is emitted when user cliks by mouse in header label of object browser
188   void headerMouseDblClicked(const QModelIndex&);
189
190  private slots:
191   /// Show context menu
192   /// \param theEvent a context menu event
193   void onContextMenuRequested(QContextMenuEvent* theEvent);
194
195   /// Show context menu on upper label
196   /// \param thePnt a position of context menu
197   void onLabelContextMenuRequested(const QPoint& thePnt);
198
199   //! Called when selection in Data Tree is changed
200   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
201
202  private:
203
204   //! Internal model
205   XGUI_DataModel* myDocModel;
206   XGUI_ActiveDocLbl* myActiveDocLbl;
207   XGUI_DataTree* myTreeView;
208 };
209
210 #endif