1 // Copyright (C) 2014-2024 CEA, EDF
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
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>
28 #include <ModelAPI_Folder.h>
35 class ModuleBase_IDocumentDataModel;
37 class Config_DataModelReader;
39 class ModuleBase_ITreeNode;
41 //#define DEBUG_INDXES
45 * Implementation of root label in Object Browser
47 class XGUI_ActiveDocLbl: public QLabel
52 /// \param theText a text
53 /// \param theParent a parent widget
54 XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
57 /// \param theView a view
58 void setTreeView(QTreeView* theView);
61 QTreeView* treePalette() const { return myTreeView;}
63 #if (!defined HAVE_SALOME) && (defined WIN32)
64 virtual bool event(QEvent* theEvent);
73 virtual void mouseReleaseEvent( QMouseEvent* e);
76 bool eventFilter(QObject* theObj, QEvent* theEvent);
79 QString myPreSelectionStyle;
80 QString myNeutralStyle;
81 QString mySelectionStyle;
83 QTreeView* myTreeView;
90 * Implementation of Data Tree object for Object Browser
92 class XGUI_EXPORT XGUI_DataTree : public QTreeView
97 /// \param theParent a parent widget
98 XGUI_DataTree(QWidget* theParent);
100 virtual ~XGUI_DataTree();
102 /// Returns current data model
103 XGUI_DataModel* dataModel() const;
106 //! Emited on context menu request
107 void contextMenuRequested(QContextMenuEvent* theEvent);
110 /// Clear content of data tree
111 virtual void clear();
114 /// Commit modified data (used for renaming of objects)
115 virtual void commitData(QWidget* theEditor);
117 /// A slot which is called on mouse double click
118 void onDoubleClick(const QModelIndex&);
121 /// Redefinition of virtual method
122 virtual void contextMenuEvent(QContextMenuEvent* theEvent);
124 /// Redefinition of virtual method
125 virtual void resizeEvent(QResizeEvent* theEvent);
127 /// Redefinition of virtual method
128 virtual void mouseReleaseEvent(QMouseEvent* theEvent);
131 virtual void mousePressEvent(QMouseEvent* theEvent);
135 /// Process a history change request
136 /// \param theIndex a clicked data index
137 void processHistoryChange(const QModelIndex& theIndex);
139 /// Highlight parent feature for chosen result or highlight
140 /// result for chosen feature
141 /// \param theIndex a clicked data index
142 void highlightDependencies(const QModelIndex& theIndex);
144 /// Process a visibility change request
145 /// \param theIndex a clicked data index
146 void processEyeClick(const QModelIndex& theIndex);
149 /**\class XGUI_ObjectsBrowser
151 * \brief Object browser window object. Represents data tree of current data structure
153 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
158 /// \param theParent a parent widget
159 XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop);
160 virtual ~XGUI_ObjectsBrowser();
162 //! Returns Model which provides access to data objects
163 XGUI_DataModel* dataModel() const
168 //! Returns list of currently selected objects
169 //! \param theIndexes - output list of corresponded indexes (can be NULL)
170 QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
172 /// Set selected list of objects
173 /// \param theObjects list of objects to select
174 void setObjectsSelected(const QObjectPtrList& theObjects);
176 //! Scroll TreeView to make given object visible
177 //! \param theObject object to make it visible
178 void ensureVisible(const ObjectPtr theObject);
180 //! Returns currently selected indexes
181 QModelIndexList selectedIndexes() const
183 if (myTreeView->selectionModel())
184 return myTreeView->selectionModel()->selectedIndexes();
186 return QModelIndexList();
189 //! Returns TreeView widget
190 XGUI_DataTree* treeView() const
195 /// Returns active doc label object
196 QLabel* activeDocLabel() const { return myActiveDocLbl; }
198 /// Rebuild data tree
199 void rebuildDataTree();
201 /// Resets the object browser into initial state
204 /// Initialize the Object browser
205 void initialize(ModuleBase_ITreeNode* theRoot);
207 /// Returns list of folders opened state for the given document
208 /// \param theDoc the document
209 /// \return list of booleans with state expanded or not
210 std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
212 /// Set folders opened state for the given document
213 /// \param theDoc the document
214 /// \param theStates list of booleans with state expanded or not
215 void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
217 /// Returns current workshop
218 XGUI_Workshop* workshop() const { return myWorkshop; }
220 void onSelectionChanged();
222 /// Updates all items of object browser
223 /// \param theColumn - column of items
224 /// \param theParent - a parent item (by default from root)
225 void updateAllIndexes(int theColumn = 0, const QModelIndex& theParent = QModelIndex());
227 QMap<ObjectPtr, bool> getFoldersState(DocumentPtr theDoc) const;
229 void setFoldersState(const QMap<ObjectPtr, bool>& theStates);
232 //! Called on Edit command request
236 //! Emited when selection is changed
237 void selectionChanged();
239 //! Emited on context menu request
240 void contextMenuRequested(QContextMenuEvent* theEvent);
242 //! Segnal is emitted when user cliks by mouse in header label of object browser
243 void headerMouseDblClicked(const QModelIndex&);
245 //! An signal emitted on resize of the Object Browser
250 //! redefinition of a virtual method
251 void resizeEvent(QResizeEvent* theEvent);
255 /// Show context menu
256 /// \param theEvent a context menu event
257 void onContextMenuRequested(QContextMenuEvent* theEvent);
259 /// Show context menu on upper label
260 /// \param thePnt a position of context menu
261 void onLabelContextMenuRequested(const QPoint& thePnt);
263 //! Called when selection in Data Tree is changed
264 void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
266 void onBeforeReset();
268 void onAfterModelReset();
271 QList<ModuleBase_ITreeNode*> expandedItems(const QModelIndex& theParent = QModelIndex()) const;
274 XGUI_DataModel* myDocModel;
275 XGUI_ActiveDocLbl* myActiveDocLbl;
276 XGUI_DataTree* myTreeView;
277 XGUI_Workshop* myWorkshop;
279 /// A field to store expanded items before model reset
280 //QModelIndexList myExpandedItems;
281 QList<ModuleBase_ITreeNode*> myExpandedItems;