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