1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef XGUI_ObjectsBrowser_H
21 #define XGUI_ObjectsBrowser_H
24 #include <ModuleBase_Definitions.h>
25 #include <ModelAPI_Object.h>
26 #include <ModelAPI_ResultPart.h>
27 #include <ModelAPI_Events.h>
33 class ModuleBase_IDocumentDataModel;
35 class Config_DataModelReader;
39 * Implementation of root label in Object Browser
41 class XGUI_ActiveDocLbl: public QLabel
46 /// \param theText a text
47 /// \param theParent a parent widget
48 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
51 /// \param theView a view
52 void setTreeView(QTreeView* theView);
55 QTreeView* treePalette() const { return myTreeView;}
57 #if (!defined HAVE_SALOME) && (defined WIN32)
58 virtual bool event(QEvent* theEvent);
67 virtual void mouseReleaseEvent( QMouseEvent* e);
70 bool eventFilter(QObject* theObj, QEvent* theEvent);
73 QString myPreSelectionStyle;
74 QString myNeutralStyle;
75 QString mySelectionStyle;
77 QTreeView* myTreeView;
84 * Implementation of Data Tree object for Object Browser
86 class XGUI_DataTree : public QTreeView
91 /// \param theParent a parent widget
92 XGUI_DataTree(QWidget* theParent);
94 virtual ~XGUI_DataTree();
96 /// Returns current data model
97 XGUI_DataModel* dataModel() const;
100 //! Emited on context menu request
101 void contextMenuRequested(QContextMenuEvent* theEvent);
104 /// Clear content of data tree
105 virtual void clear();
108 /// Commit modified data (used for renaming of objects)
109 virtual void commitData(QWidget* theEditor);
111 /// A slot which is called on mouse double click
112 void onDoubleClick(const QModelIndex&);
115 /// Redefinition of virtual method
116 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
118 /// Redefinition of virtual method
119 virtual void resizeEvent(QResizeEvent* theEvent);
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 QLabel* activeDocLabel() const { return myActiveDocLbl; }
164 /// Rebuild data tree
165 void rebuildDataTree();
167 /// Resets the object browser into initial state
170 /// Set XML reader object for data model
171 /// \param theReader the reader object
172 void setXMLReader(Config_DataModelReader* theReader);
174 /// Returns list of folders opened state for the given document
175 /// \param theDoc the document
176 /// \return list of booleans with state expanded or not
177 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
179 /// Set folders opened state for the given document
180 /// \param theDoc the document
181 /// \param theStates list of booleans with state expanded or not
182 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
185 //! Called on Edit command request
189 //! Emited when selection is changed
190 void selectionChanged();
192 //! Emited on context menu request
193 void contextMenuRequested(QContextMenuEvent* theEvent);
195 //! Segnal is emitted when user cliks by mouse in header label of object browser
196 void headerMouseDblClicked(const QModelIndex&);
199 /// Show context menu
200 /// \param theEvent a context menu event
201 void onContextMenuRequested(QContextMenuEvent* theEvent);
203 /// Show context menu on upper label
204 /// \param thePnt a position of context menu
205 void onLabelContextMenuRequested(const QPoint& thePnt);
207 //! Called when selection in Data Tree is changed
208 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
210 void onBeforeReset();
212 void onAfterModelReset();
215 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
218 XGUI_DataModel* myDocModel;
219 XGUI_ActiveDocLbl* myActiveDocLbl;
220 XGUI_DataTree* myTreeView;
222 /// A field to store expanded items before model reset
223 QModelIndexList myExpandedItems;