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>
29 #include <ModelAPI_Folder.h>
36 class ModuleBase_IDocumentDataModel;
38 class Config_DataModelReader;
40 class ModuleBase_ITreeNode;
42 //#define DEBUG_INDXES
46 * Implementation of root label in Object Browser
48 class XGUI_ActiveDocLbl: public QLabel
53 /// \param theText a text
54 /// \param theParent a parent widget
55 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
58 /// \param theView a view
59 void setTreeView(QTreeView* theView);
62 QTreeView* treePalette() const { return myTreeView;}
64 #if (!defined HAVE_SALOME) && (defined WIN32)
65 virtual bool event(QEvent* theEvent);
74 virtual void mouseReleaseEvent( QMouseEvent* e);
77 bool eventFilter(QObject* theObj, QEvent* theEvent);
80 QString myPreSelectionStyle;
81 QString myNeutralStyle;
82 QString mySelectionStyle;
84 QTreeView* myTreeView;
91 * Implementation of Data Tree object for Object Browser
93 class XGUI_EXPORT XGUI_DataTree : public QTreeView
98 /// \param theParent a parent widget
99 XGUI_DataTree(QWidget* theParent);
101 virtual ~XGUI_DataTree();
103 /// Returns current data model
104 XGUI_DataModel* dataModel() const;
107 //! Emited on context menu request
108 void contextMenuRequested(QContextMenuEvent* theEvent);
111 /// Clear content of data tree
112 virtual void clear();
115 /// Commit modified data (used for renaming of objects)
116 virtual void commitData(QWidget* theEditor);
118 /// A slot which is called on mouse double click
119 void onDoubleClick(const QModelIndex&);
122 /// Redefinition of virtual method
123 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
125 /// Redefinition of virtual method
126 virtual void resizeEvent(QResizeEvent* theEvent);
128 /// Redefinition of virtual method
129 virtual void mouseReleaseEvent(QMouseEvent* theEvent);
132 virtual void mousePressEvent(QMouseEvent* theEvent);
136 /// Process a history change request
137 /// \param theIndex a clicked data index
138 void processHistoryChange(const QModelIndex& theIndex);
140 /// Process a visibility change request
141 /// \param theIndex a clicked data index
142 void processEyeClick(const QModelIndex& theIndex);
145 /**\class XGUI_ObjectsBrowser
147 * \brief Object browser window object. Represents data tree of current data structure
149 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
154 /// \param theParent a parent widget
155 XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop);
156 virtual ~XGUI_ObjectsBrowser();
158 //! Returns Model which provides access to data objects
159 XGUI_DataModel* dataModel() const
164 //! Returns list of currently selected objects
165 //! \param theIndexes - output list of corresponded indexes (can be NULL)
166 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
168 /// Set selected list of objects
169 /// \param theObjects list of objects to select
170 void setObjectsSelected(const QObjectPtrList& theObjects);
172 //! Scroll TreeView to make given object visible
173 //! \param theObject object to make it visible
174 void ensureVisible(const ObjectPtr theObject);
176 //! Returns currently selected indexes
177 QModelIndexList selectedIndexes() const
179 if (myTreeView->selectionModel())
180 return myTreeView->selectionModel()->selectedIndexes();
182 return QModelIndexList();
185 //! Returns TreeView widget
186 XGUI_DataTree* treeView() const
191 /// Returns active doc label object
192 QLabel* activeDocLabel() const { return myActiveDocLbl; }
194 /// Rebuild data tree
195 void rebuildDataTree();
197 /// Resets the object browser into initial state
200 /// Initialize the Object browser
201 void initialize(ModuleBase_ITreeNode* theRoot);
203 /// Returns list of folders opened state for the given document
204 /// \param theDoc the document
205 /// \return list of booleans with state expanded or not
206 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
208 /// Set folders opened state for the given document
209 /// \param theDoc the document
210 /// \param theStates list of booleans with state expanded or not
211 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
213 /// Returns current workshop
214 XGUI_Workshop* workshop() const { return myWorkshop; }
216 void onSelectionChanged();
218 /// Updates all items of object browser
219 /// \param theColumn - column of items
220 /// \param theParent - a parent item (by default from root)
221 void updateAllIndexes(int theColumn = 0, const QModelIndex& theParent = QModelIndex());
223 QMap<ObjectPtr, bool> getFoldersState(DocumentPtr theDoc) const;
225 void setFoldersState(const QMap<ObjectPtr, bool>& theStates);
228 //! Called on Edit command request
232 //! Emited when selection is changed
233 void selectionChanged();
235 //! Emited on context menu request
236 void contextMenuRequested(QContextMenuEvent* theEvent);
238 //! Segnal is emitted when user cliks by mouse in header label of object browser
239 void headerMouseDblClicked(const QModelIndex&);
242 /// Show context menu
243 /// \param theEvent a context menu event
244 void onContextMenuRequested(QContextMenuEvent* theEvent);
246 /// Show context menu on upper label
247 /// \param thePnt a position of context menu
248 void onLabelContextMenuRequested(const QPoint& thePnt);
250 //! Called when selection in Data Tree is changed
251 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
253 void onBeforeReset();
255 void onAfterModelReset();
258 QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
261 XGUI_DataModel* myDocModel;
262 XGUI_ActiveDocLbl* myActiveDocLbl;
263 XGUI_DataTree* myTreeView;
264 XGUI_Workshop* myWorkshop;
266 /// A field to store expanded items before model reset
267 QModelIndexList myExpandedItems;