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;
67 * Implementation of Data Tree object for Object Browser
69 class XGUI_DataTree : public QTreeView
74 /// \param theParent a parent widget
75 XGUI_DataTree(QWidget* theParent);
77 virtual ~XGUI_DataTree();
79 /// Returns current data model
80 XGUI_DataModel* dataModel() const;
83 //! Emited on context menu request
84 void contextMenuRequested(QContextMenuEvent* theEvent);
87 /// Clear content of data tree
91 /// Commit modified data (used for renaming of objects)
92 virtual void commitData(QWidget* theEditor);
94 /// A slot which is called on mouse double click
95 void onDoubleClick(const QModelIndex&);
98 /// Redefinition of virtual method
99 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
101 /// Redefinition of virtual method
102 virtual void resizeEvent(QResizeEvent* theEvent);
105 /**\class XGUI_ObjectsBrowser
107 * \brief Object browser window object. Represents data tree of current data structure
109 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
114 /// \param theParent a parent widget
115 XGUI_ObjectsBrowser(QWidget* theParent);
116 virtual ~XGUI_ObjectsBrowser();
118 //! Returns Model which provides access to data objects
119 XGUI_DataModel* dataModel() const
124 //! Returns list of currently selected objects
125 //! \param theIndexes - output list of corresponded indexes (can be NULL)
126 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
128 /// Set selected list of objects
129 /// \param theObjects list of objects to select
130 void setObjectsSelected(const QObjectPtrList& theObjects);
132 //! Returns currently selected indexes
133 QModelIndexList selectedIndexes() const
135 return myTreeView->selectionModel()->selectedIndexes();
138 //! Returns TreeView widget
139 XGUI_DataTree* treeView() const
144 /// Returns active doc label object
145 QLabel* activeDocLabel() const { return myActiveDocLbl; }
147 /// Rebuild data tree
148 void rebuildDataTree();
150 /// Resets the object browser into initial state
153 /// Set XML reader object for data model
154 /// \param theReader the reader object
155 void setXMLReader(Config_DataModelReader* theReader);
157 /// Returns list of folders opened state for the given document
158 /// \param theDoc the document
159 /// \return list of booleans with state expanded or not
160 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
162 /// Set folders opened state for the given document
163 /// \param theDoc the document
164 /// \param theStates list of booleans with state expanded or not
165 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
168 //! Called on Edit command request
172 //! Emited when selection is changed
173 void selectionChanged();
175 //! Emited on context menu request
176 void contextMenuRequested(QContextMenuEvent* theEvent);
178 //! Segnal is emitted when user cliks by mouse in header label of object browser
179 void headerMouseDblClicked(const QModelIndex&);
182 /// Show context menu
183 /// \param theEvent a context menu event
184 void onContextMenuRequested(QContextMenuEvent* theEvent);
186 /// Show context menu on upper label
187 /// \param thePnt a position of context menu
188 void onLabelContextMenuRequested(const QPoint& thePnt);
190 //! Called when selection in Data Tree is changed
191 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
193 void onBeforeReset();
195 void onAfterModelReset();
198 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
201 XGUI_DataModel* myDocModel;
202 XGUI_ActiveDocLbl* myActiveDocLbl;
203 XGUI_DataTree* myTreeView;
205 /// A field to store expanded items before model reset
206 QModelIndexList myExpandedItems;