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;
39 //#define DEBUG_INDXES
43 * Implementation of root label in Object Browser
45 class XGUI_ActiveDocLbl: public QLabel
50 /// \param theText a text
51 /// \param theParent a parent widget
52 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
55 /// \param theView a view
56 void setTreeView(QTreeView* theView);
59 QTreeView* treePalette() const { return myTreeView;}
61 #if (!defined HAVE_SALOME) && (defined WIN32)
62 virtual bool event(QEvent* theEvent);
71 virtual void mouseReleaseEvent( QMouseEvent* e);
74 bool eventFilter(QObject* theObj, QEvent* theEvent);
77 QString myPreSelectionStyle;
78 QString myNeutralStyle;
79 QString mySelectionStyle;
81 QTreeView* myTreeView;
88 * Implementation of Data Tree object for Object Browser
90 class XGUI_DataTree : public QTreeView
95 /// \param theParent a parent widget
96 XGUI_DataTree(QWidget* theParent);
98 virtual ~XGUI_DataTree();
100 /// Returns current data model
101 XGUI_DataModel* dataModel() const;
104 //! Emited on context menu request
105 void contextMenuRequested(QContextMenuEvent* theEvent);
108 /// Clear content of data tree
109 virtual void clear();
112 /// Commit modified data (used for renaming of objects)
113 virtual void commitData(QWidget* theEditor);
115 /// A slot which is called on mouse double click
116 void onDoubleClick(const QModelIndex&);
119 /// Redefinition of virtual method
120 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
122 /// Redefinition of virtual method
123 virtual void resizeEvent(QResizeEvent* theEvent);
125 /// Redefinition of virtual method
126 virtual void mouseReleaseEvent(QMouseEvent* theEvent);
129 virtual void mousePressEvent(QMouseEvent* theEvent);
133 /// Process a history change request
134 /// \param theIndex a clicked data index
135 void processHistoryChange(const QModelIndex& theIndex);
137 /// Process a visibility change request
138 /// \param theIndex a clicked data index
139 void processEyeClick(const QModelIndex& theIndex);
142 /**\class XGUI_ObjectsBrowser
144 * \brief Object browser window object. Represents data tree of current data structure
146 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
151 /// \param theParent a parent widget
152 XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop);
153 virtual ~XGUI_ObjectsBrowser();
155 //! Returns Model which provides access to data objects
156 XGUI_DataModel* dataModel() const
161 //! Returns list of currently selected objects
162 //! \param theIndexes - output list of corresponded indexes (can be NULL)
163 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
165 /// Set selected list of objects
166 /// \param theObjects list of objects to select
167 void setObjectsSelected(const QObjectPtrList& theObjects);
169 //! Returns currently selected indexes
170 QModelIndexList selectedIndexes() const
172 return myTreeView->selectionModel()->selectedIndexes();
175 //! Returns TreeView widget
176 XGUI_DataTree* treeView() const
181 /// Returns active doc label object
182 QLabel* activeDocLabel() const { return myActiveDocLbl; }
184 /// Rebuild data tree
185 void rebuildDataTree();
187 /// Resets the object browser into initial state
190 /// Set XML reader object for data model
191 /// \param theReader the reader object
192 void setXMLReader(Config_DataModelReader* theReader);
194 /// Returns list of folders opened state for the given document
195 /// \param theDoc the document
196 /// \return list of booleans with state expanded or not
197 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
199 /// Set folders opened state for the given document
200 /// \param theDoc the document
201 /// \param theStates list of booleans with state expanded or not
202 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
204 /// Returns current workshop
205 XGUI_Workshop* workshop() const { return myWorkshop; }
207 void onSelectionChanged();
211 //! Called on Edit command request
215 //! Emited when selection is changed
216 void selectionChanged();
218 //! Emited on context menu request
219 void contextMenuRequested(QContextMenuEvent* theEvent);
221 //! Segnal is emitted when user cliks by mouse in header label of object browser
222 void headerMouseDblClicked(const QModelIndex&);
225 /// Show context menu
226 /// \param theEvent a context menu event
227 void onContextMenuRequested(QContextMenuEvent* theEvent);
229 /// Show context menu on upper label
230 /// \param thePnt a position of context menu
231 void onLabelContextMenuRequested(const QPoint& thePnt);
233 //! Called when selection in Data Tree is changed
234 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
236 void onBeforeReset();
238 void onAfterModelReset();
241 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
244 XGUI_DataModel* myDocModel;
245 XGUI_ActiveDocLbl* myActiveDocLbl;
246 XGUI_DataTree* myTreeView;
247 XGUI_Workshop* myWorkshop;
249 /// A field to store expanded items before model reset
250 QModelIndexList myExpandedItems;