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 /// Set XML reader object for data model
185 /// \param theReader the reader object
186 void setXMLReader(Config_DataModelReader* theReader);
188 /// Returns list of folders opened state for the given document
189 /// \param theDoc the document
190 /// \return list of booleans with state expanded or not
191 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
193 /// Set folders opened state for the given document
194 /// \param theDoc the document
195 /// \param theStates list of booleans with state expanded or not
196 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
199 //! Called on Edit command request
203 //! Emited when selection is changed
204 void selectionChanged();
206 //! Emited on context menu request
207 void contextMenuRequested(QContextMenuEvent* theEvent);
209 //! Segnal is emitted when user cliks by mouse in header label of object browser
210 void headerMouseDblClicked(const QModelIndex&);
213 /// Show context menu
214 /// \param theEvent a context menu event
215 void onContextMenuRequested(QContextMenuEvent* theEvent);
217 /// Show context menu on upper label
218 /// \param thePnt a position of context menu
219 void onLabelContextMenuRequested(const QPoint& thePnt);
221 //! Called when selection in Data Tree is changed
222 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
224 void onBeforeReset();
226 void onAfterModelReset();
229 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
232 XGUI_DataModel* myDocModel;
233 XGUI_ActiveDocLbl* myActiveDocLbl;
234 XGUI_DataTree* myTreeView;
236 /// A field to store expanded items before model reset
237 QModelIndexList myExpandedItems;