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 // PORTING_TO_SALOME_8
67 //#include <QWindowsVistaStyle>
68 #include <QCommonStyle>
71 * Implementation of XGUI_DataTree custom style
73 class XGUI_TreeViewStyle : public QCommonStyle // PORTING_TO_SALOME_8 QWindowsVistaStyle
77 XGUI_TreeViewStyle() : QCommonStyle/*QWindowsVistaStyle*/() {}
79 void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
80 QPainter* thePainter, const QWidget* theWidget = 0) const;
82 void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
83 QModelIndex index() const { return myIndex; }
92 * Implementation of Data Tree object for Object Browser
94 class XGUI_DataTree : public QTreeView
99 /// \param theParent a parent widget
100 XGUI_DataTree(QWidget* theParent);
102 virtual ~XGUI_DataTree();
104 /// Returns current data model
105 XGUI_DataModel* dataModel() const;
108 //! Emited on context menu request
109 void contextMenuRequested(QContextMenuEvent* theEvent);
112 /// Clear content of data tree
113 virtual void clear();
116 /// Commit modified data (used for renaming of objects)
117 virtual void commitData(QWidget* theEditor);
119 /// A slot which is called on mouse double click
120 void onDoubleClick(const QModelIndex&);
123 /// Redefinition of virtual method
124 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
126 /// Redefinition of virtual method
127 virtual void resizeEvent(QResizeEvent* theEvent);
129 #if (!defined HAVE_SALOME) && (defined WIN32)
130 virtual void drawRow(QPainter* thePainter,
131 const QStyleOptionViewItem& theOptions,
132 const QModelIndex& theIndex) const;
134 XGUI_TreeViewStyle* myStyle;
138 /**\class XGUI_ObjectsBrowser
140 * \brief Object browser window object. Represents data tree of current data structure
142 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
147 /// \param theParent a parent widget
148 XGUI_ObjectsBrowser(QWidget* theParent);
149 virtual ~XGUI_ObjectsBrowser();
151 //! Returns Model which provides access to data objects
152 XGUI_DataModel* dataModel() const
157 //! Returns list of currently selected objects
158 //! \param theIndexes - output list of corresponded indexes (can be NULL)
159 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
161 /// Set selected list of objects
162 /// \param theObjects list of objects to select
163 void setObjectsSelected(const QObjectPtrList& theObjects);
165 //! Returns currently selected indexes
166 QModelIndexList selectedIndexes() const
168 return myTreeView->selectionModel()->selectedIndexes();
171 //! Returns TreeView widget
172 XGUI_DataTree* treeView() const
177 /// Returns active doc label object
178 QLabel* activeDocLabel() const { return myActiveDocLbl; }
180 /// Rebuild data tree
181 void rebuildDataTree();
183 /// Resets the object browser into initial state
186 /// Set XML reader object for data model
187 /// \param theReader the reader object
188 void setXMLReader(Config_DataModelReader* theReader);
190 /// Returns list of folders opened state for the given document
191 /// \param theDoc the document
192 /// \return list of booleans with state expanded or not
193 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
195 /// Set folders opened state for the given document
196 /// \param theDoc the document
197 /// \param theStates list of booleans with state expanded or not
198 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
201 //! Called on Edit command request
205 //! Emited when selection is changed
206 void selectionChanged();
208 //! Emited on context menu request
209 void contextMenuRequested(QContextMenuEvent* theEvent);
211 //! Segnal is emitted when user cliks by mouse in header label of object browser
212 void headerMouseDblClicked(const QModelIndex&);
215 /// Show context menu
216 /// \param theEvent a context menu event
217 void onContextMenuRequested(QContextMenuEvent* theEvent);
219 /// Show context menu on upper label
220 /// \param thePnt a position of context menu
221 void onLabelContextMenuRequested(const QPoint& thePnt);
223 //! Called when selection in Data Tree is changed
224 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
226 void onBeforeReset();
228 void onAfterModelReset();
231 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
234 XGUI_DataModel* myDocModel;
235 XGUI_ActiveDocLbl* myActiveDocLbl;
236 XGUI_DataTree* myTreeView;
238 /// A field to store expanded items before model reset
239 QModelIndexList myExpandedItems;