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;
18 class Config_DataModelReader;
22 * Implementation of root label in Object Browser
24 class XGUI_ActiveDocLbl: public QLabel
29 /// \param theText a text
30 /// \param theParent a parent widget
31 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
34 /// \param theView a view
35 void setTreeView(QTreeView* theView);
38 QTreeView* treePalette() const { return myTreeView;}
40 #if (!defined HAVE_SALOME) && (defined WIN32)
41 virtual bool event(QEvent* theEvent);
50 virtual void mouseReleaseEvent( QMouseEvent* e);
53 bool eventFilter(QObject* theObj, QEvent* theEvent);
56 QString myPreSelectionStyle;
57 QString myNeutralStyle;
58 QString mySelectionStyle;
60 QTreeView* myTreeView;
65 #if (!defined HAVE_SALOME) && (defined WIN32)
66 #include <QWindowsVistaStyle>
69 * Implementation of XGUI_DataTree custom style
71 class XGUI_TreeViewStyle : public QWindowsVistaStyle
75 XGUI_TreeViewStyle() : QWindowsVistaStyle() {}
77 void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
78 QPainter* thePainter, const QWidget* theWidget = 0) const;
80 void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
81 QModelIndex index() const { return myIndex; }
90 * Implementation of Data Tree object for Object Browser
92 class XGUI_DataTree : public QTreeView
97 /// \param theParent a parent widget
98 XGUI_DataTree(QWidget* theParent);
100 virtual ~XGUI_DataTree();
102 /// Returns current data model
103 XGUI_DataModel* dataModel() const;
106 //! Emited on context menu request
107 void contextMenuRequested(QContextMenuEvent* theEvent);
110 /// Clear content of data tree
111 virtual void clear();
114 /// Commit modified data (used for renaming of objects)
115 virtual void commitData(QWidget* theEditor);
117 /// A slot which is called on mouse double click
118 void onDoubleClick(const QModelIndex&);
121 /// Redefinition of virtual method
122 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
124 /// Redefinition of virtual method
125 virtual void resizeEvent(QResizeEvent* theEvent);
127 #if (!defined HAVE_SALOME) && (defined WIN32)
128 virtual void drawRow(QPainter* thePainter,
129 const QStyleOptionViewItem& theOptions,
130 const QModelIndex& theIndex) const;
132 XGUI_TreeViewStyle* myStyle;
136 /**\class XGUI_ObjectsBrowser
138 * \brief Object browser window object. Represents data tree of current data structure
140 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
145 /// \param theParent a parent widget
146 XGUI_ObjectsBrowser(QWidget* theParent);
147 virtual ~XGUI_ObjectsBrowser();
149 //! Returns Model which provides access to data objects
150 XGUI_DataModel* dataModel() const
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;
159 /// Set selected list of objects
160 /// \param theObjects list of objects to select
161 void setObjectsSelected(const QObjectPtrList& theObjects);
163 //! Returns currently selected indexes
164 QModelIndexList selectedIndexes() const
166 return myTreeView->selectionModel()->selectedIndexes();
169 //! Returns TreeView widget
170 XGUI_DataTree* treeView() const
175 /// Returns active doc label object
176 QLabel* activeDocLabel() const { return myActiveDocLbl; }
178 /// Rebuild data tree
179 void rebuildDataTree();
181 /// Resets the object browser into initial state
184 void setXMLReader(Config_DataModelReader* theReader);
187 //! Called on Edit command request
191 //! Emited when selection is changed
192 void selectionChanged();
194 //! Emited on context menu request
195 void contextMenuRequested(QContextMenuEvent* theEvent);
197 //! Segnal is emitted when user cliks by mouse in header label of object browser
198 void headerMouseDblClicked(const QModelIndex&);
201 /// Show context menu
202 /// \param theEvent a context menu event
203 void onContextMenuRequested(QContextMenuEvent* theEvent);
205 /// Show context menu on upper label
206 /// \param thePnt a position of context menu
207 void onLabelContextMenuRequested(const QPoint& thePnt);
209 //! Called when selection in Data Tree is changed
210 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
212 void onBeforeReset();
214 void onAfterModelReset();
217 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
220 XGUI_DataModel* myDocModel;
221 XGUI_ActiveDocLbl* myActiveDocLbl;
222 XGUI_DataTree* myTreeView;
224 /// A field to store expanded items before model reset
225 QModelIndexList myExpandedItems;