1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef XGUI_ObjectsBrowser_H
4 #define XGUI_ObjectsBrowser_H
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_Object.h>
9 #include <ModelAPI_ResultPart.h>
10 #include <ModelAPI_Events.h>
16 class ModuleBase_IDocumentDataModel;
21 * Implementation of root label in Object Browser
23 class XGUI_ActiveDocLbl: public QLabel
28 /// \param theText a text
29 /// \param theParent a parent widget
30 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
33 /// \param theView a view
34 void setTreeView(QTreeView* theView);
37 QTreeView* treePalette() const { return myTreeView;}
39 #if (!defined HAVE_SALOME) && (defined WIN32)
40 virtual bool event(QEvent* theEvent);
49 virtual void mouseReleaseEvent( QMouseEvent* e);
52 bool eventFilter(QObject* theObj, QEvent* theEvent);
55 QString myPreSelectionStyle;
56 QString myNeutralStyle;
57 QString mySelectionStyle;
59 QTreeView* myTreeView;
64 #if (!defined HAVE_SALOME) && (defined WIN32)
65 #include <QWindowsVistaStyle>
68 * Implementation of XGUI_DataTree custom style
70 class XGUI_TreeViewStyle : public QWindowsVistaStyle
74 XGUI_TreeViewStyle() : QWindowsVistaStyle() {}
76 void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
77 QPainter* thePainter, const QWidget* theWidget = 0) const;
79 void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
80 QModelIndex index() const { return myIndex; }
89 * Implementation of Data Tree object for Object Browser
91 class XGUI_DataTree : public QTreeView
96 /// \param theParent a parent widget
97 XGUI_DataTree(QWidget* theParent);
99 virtual ~XGUI_DataTree();
101 /// Returns current data model
102 XGUI_DataModel* dataModel() const;
105 //! Emited on context menu request
106 void contextMenuRequested(QContextMenuEvent* theEvent);
109 /// Clear content of data tree
110 virtual void clear();
113 /// Commit modified data (used for renaming of objects)
114 virtual void commitData(QWidget* theEditor);
116 /// A slot which is called on mouse double click
117 void onDoubleClick(const QModelIndex&);
120 /// Redefinition of virtual method
121 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
123 /// Redefinition of virtual method
124 virtual void resizeEvent(QResizeEvent* theEvent);
126 #if (!defined HAVE_SALOME) && (defined WIN32)
127 virtual void drawRow(QPainter* thePainter,
128 const QStyleOptionViewItem& theOptions,
129 const QModelIndex& theIndex) const;
131 XGUI_TreeViewStyle* myStyle;
135 /**\class XGUI_ObjectsBrowser
137 * \brief Object browser window object. Represents data tree of current data structure
139 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
144 /// \param theParent a parent widget
145 XGUI_ObjectsBrowser(QWidget* theParent);
146 virtual ~XGUI_ObjectsBrowser();
148 //! Returns Model which provides access to data objects
149 XGUI_DataModel* dataModel() const
154 //! Returns list of currently selected objects
155 //! \param theIndexes - output list of corresponded indexes (can be NULL)
156 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
158 /// Set selected list of objects
159 /// \param theObjects list of objects to select
160 void setObjectsSelected(const QObjectPtrList& theObjects);
162 //! Returns currently selected indexes
163 QModelIndexList selectedIndexes() const
165 return myTreeView->selectionModel()->selectedIndexes();
168 //! Returns TreeView widget
169 XGUI_DataTree* treeView() const
174 /// Returns active doc label object
175 QLabel* activeDocLabel() const { return myActiveDocLbl; }
177 /// Rebuild data tree
178 void rebuildDataTree();
180 /// Resets the object browser into initial state
184 //! Called on Edit command request
188 //! Emited when selection is changed
189 void selectionChanged();
191 //! Emited on context menu request
192 void contextMenuRequested(QContextMenuEvent* theEvent);
194 //! Segnal is emitted when user cliks by mouse in header label of object browser
195 void headerMouseDblClicked(const QModelIndex&);
198 /// Show context menu
199 /// \param theEvent a context menu event
200 void onContextMenuRequested(QContextMenuEvent* theEvent);
202 /// Show context menu on upper label
203 /// \param thePnt a position of context menu
204 void onLabelContextMenuRequested(const QPoint& thePnt);
206 //! Called when selection in Data Tree is changed
207 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
210 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
213 XGUI_DataModel* myDocModel;
214 XGUI_ActiveDocLbl* myActiveDocLbl;
215 XGUI_DataTree* myTreeView;