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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_ObjectsBrowser_H
22 #define XGUI_ObjectsBrowser_H
25 #include <ModuleBase_Definitions.h>
26 #include <ModelAPI_Object.h>
27 #include <ModelAPI_ResultPart.h>
28 #include <ModelAPI_Events.h>
34 class ModuleBase_IDocumentDataModel;
36 class Config_DataModelReader;
40 * Implementation of root label in Object Browser
42 class XGUI_ActiveDocLbl: public QLabel
47 /// \param theText a text
48 /// \param theParent a parent widget
49 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
52 /// \param theView a view
53 void setTreeView(QTreeView* theView);
56 QTreeView* treePalette() const { return myTreeView;}
58 #if (!defined HAVE_SALOME) && (defined WIN32)
59 virtual bool event(QEvent* theEvent);
68 virtual void mouseReleaseEvent( QMouseEvent* e);
71 bool eventFilter(QObject* theObj, QEvent* theEvent);
74 QString myPreSelectionStyle;
75 QString myNeutralStyle;
76 QString mySelectionStyle;
78 QTreeView* myTreeView;
85 * Implementation of Data Tree object for Object Browser
87 class XGUI_DataTree : public QTreeView
92 /// \param theParent a parent widget
93 XGUI_DataTree(QWidget* theParent);
95 virtual ~XGUI_DataTree();
97 /// Returns current data model
98 XGUI_DataModel* dataModel() const;
101 //! Emited on context menu request
102 void contextMenuRequested(QContextMenuEvent* theEvent);
105 /// Clear content of data tree
106 virtual void clear();
109 /// Commit modified data (used for renaming of objects)
110 virtual void commitData(QWidget* theEditor);
112 /// A slot which is called on mouse double click
113 void onDoubleClick(const QModelIndex&);
116 /// Redefinition of virtual method
117 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
119 /// Redefinition of virtual method
120 virtual void resizeEvent(QResizeEvent* theEvent);
123 /**\class XGUI_ObjectsBrowser
125 * \brief Object browser window object. Represents data tree of current data structure
127 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
132 /// \param theParent a parent widget
133 XGUI_ObjectsBrowser(QWidget* theParent);
134 virtual ~XGUI_ObjectsBrowser();
136 //! Returns Model which provides access to data objects
137 XGUI_DataModel* dataModel() const
142 //! Returns list of currently selected objects
143 //! \param theIndexes - output list of corresponded indexes (can be NULL)
144 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
146 /// Set selected list of objects
147 /// \param theObjects list of objects to select
148 void setObjectsSelected(const QObjectPtrList& theObjects);
150 //! Returns currently selected indexes
151 QModelIndexList selectedIndexes() const
153 return myTreeView->selectionModel()->selectedIndexes();
156 //! Returns TreeView widget
157 XGUI_DataTree* treeView() const
162 /// Returns active doc label object
163 QLabel* activeDocLabel() const { return myActiveDocLbl; }
165 /// Rebuild data tree
166 void rebuildDataTree();
168 /// Resets the object browser into initial state
171 /// Set XML reader object for data model
172 /// \param theReader the reader object
173 void setXMLReader(Config_DataModelReader* theReader);
175 /// Returns list of folders opened state for the given document
176 /// \param theDoc the document
177 /// \return list of booleans with state expanded or not
178 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
180 /// Set folders opened state for the given document
181 /// \param theDoc the document
182 /// \param theStates list of booleans with state expanded or not
183 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
186 //! Called on Edit command request
190 //! Emited when selection is changed
191 void selectionChanged();
193 //! Emited on context menu request
194 void contextMenuRequested(QContextMenuEvent* theEvent);
196 //! Segnal is emitted when user cliks by mouse in header label of object browser
197 void headerMouseDblClicked(const QModelIndex&);
200 /// Show context menu
201 /// \param theEvent a context menu event
202 void onContextMenuRequested(QContextMenuEvent* theEvent);
204 /// Show context menu on upper label
205 /// \param thePnt a position of context menu
206 void onLabelContextMenuRequested(const QPoint& thePnt);
208 //! Called when selection in Data Tree is changed
209 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
211 void onBeforeReset();
213 void onAfterModelReset();
216 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
219 XGUI_DataModel* myDocModel;
220 XGUI_ActiveDocLbl* myActiveDocLbl;
221 XGUI_DataTree* myTreeView;
223 /// A field to store expanded items before model reset
224 QModelIndexList myExpandedItems;