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