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>
15 #include <QWindowsVistaStyle>
17 class ModuleBase_IDocumentDataModel;
22 * Implementation of root label in Object Browser
24 class XGUI_ActiveDocLbl: public QLineEdit
29 /// \param theParent a parent widget
30 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
32 void setTreeView(QTreeView* theView);
34 QTreeView* treePalette() const { return myTreeView;}
36 virtual bool event(QEvent* theEvent);
42 virtual void mouseReleaseEvent( QMouseEvent* e);
44 bool eventFilter(QObject* theObj, QEvent* theEvent);
47 QString myPreSelectionStyle;
48 QString myNeutralStyle;
49 QString mySelectionStyle;
51 QTreeView* myTreeView;
57 * Implementation of XGUI_DataTree custom style
59 class XGUI_TreeViewStyle : public QWindowsVistaStyle
63 XGUI_TreeViewStyle() : QWindowsVistaStyle() {}
65 void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
66 QPainter* thePainter, const QWidget* theWidget = 0) const;
68 void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
69 QModelIndex index() const { return myIndex; }
78 * Implementation of Data Tree object for Object Browser
80 class XGUI_DataTree : public QTreeView
85 /// \param theParent a parent widget
86 XGUI_DataTree(QWidget* theParent);
88 virtual ~XGUI_DataTree();
90 /// Returns current data model
91 XGUI_DataModel* dataModel() const;
94 //! Emited on context menu request
95 void contextMenuRequested(QContextMenuEvent* theEvent);
98 /// Clear content of data tree
102 /// Commit modified data (used for renaming of objects)
103 virtual void commitData(QWidget* theEditor);
105 /// A slot which is called on mouse double click
106 void onDoubleClick(const QModelIndex&);
109 /// Redefinition of virtual method
110 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
112 /// Redefinition of virtual method
113 virtual void resizeEvent(QResizeEvent* theEvent);
115 virtual void drawRow(QPainter* thePainter,
116 const QStyleOptionViewItem& theOptions,
117 const QModelIndex& theIndex) const;
119 XGUI_TreeViewStyle* myStyle;
122 /**\class XGUI_ObjectsBrowser
124 * \brief Object browser window object. Represents data tree of current data structure
126 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
131 /// \param theParent a parent widget
132 XGUI_ObjectsBrowser(QWidget* theParent);
133 virtual ~XGUI_ObjectsBrowser();
135 //! Returns Model which provides access to data objects
136 XGUI_DataModel* dataModel() const
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;
145 /// Set selected list of objects
146 /// \param theObjects list of objects to select
147 void setObjectsSelected(const QObjectPtrList& theObjects);
149 //! Returns currently selected indexes
150 QModelIndexList selectedIndexes() const
152 return myTreeView->selectionModel()->selectedIndexes();
155 //! Returns TreeView widget
156 XGUI_DataTree* treeView() const
161 /// Returns active doc label object
162 QLineEdit* activeDocLabel() const { return myActiveDocLbl; }
164 /// Rebuild data tree
165 void rebuildDataTree();
167 /// Resets the object browser into initial state
171 //! Called on Edit command request
175 //! Emited when selection is changed
176 void selectionChanged();
178 //! Emited on context menu request
179 void contextMenuRequested(QContextMenuEvent* theEvent);
181 //! Segnal is emitted when user cliks by mouse in header label of object browser
182 void headerMouseDblClicked(const QModelIndex&);
185 /// Show context menu
186 /// \param theEvent a context menu event
187 void onContextMenuRequested(QContextMenuEvent* theEvent);
189 /// Show context menu on upper label
190 /// \param thePnt a position of context menu
191 void onLabelContextMenuRequested(const QPoint& thePnt);
193 //! Called when selection in Data Tree is changed
194 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
199 XGUI_DataModel* myDocModel;
200 XGUI_ActiveDocLbl* myActiveDocLbl;
201 XGUI_DataTree* myTreeView;