SHAPER  9.15.0
XGUI_ObjectsBrowser.h
1 // Copyright (C) 2014-2025 CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef XGUI_ObjectsBrowser_H
21 #define XGUI_ObjectsBrowser_H
22 
23 #include "XGUI.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>
29 
30 #include <QWidget>
31 #include <QTreeView>
32 #include <QLabel>
33 #include <QMap>
34 
35 class ModuleBase_IDocumentDataModel;
36 class XGUI_DataModel;
38 class XGUI_Workshop;
40 
41 //#define DEBUG_INDXES
42 
48 {
49 Q_OBJECT
50  public:
54  XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
55 
58  void setTreeView(QTreeView* theView);
59 
61  QTreeView* treePalette() const { return myTreeView;}
62 
63 #if (!defined HAVE_SALOME) && (defined WIN32)
64  virtual bool event(QEvent* theEvent);
65 #endif
66 
67 public slots:
69  void unselect();
70 
71 protected:
73  virtual void mouseReleaseEvent( QMouseEvent* e);
74 
76  bool eventFilter(QObject* theObj, QEvent* theEvent);
77 
78 private:
79  QString myPreSelectionStyle;
80  QString myNeutralStyle;
81  QString mySelectionStyle;
82 
83  QTreeView* myTreeView;
84  bool myIsSelected;
85 };
86 
87 
92 class XGUI_EXPORT XGUI_DataTree : public QTreeView
93 {
94 Q_OBJECT
95  public:
98  XGUI_DataTree(QWidget* theParent);
99 
100  virtual ~XGUI_DataTree();
101 
103  XGUI_DataModel* dataModel() const;
104 
105 signals:
107  void contextMenuRequested(QContextMenuEvent* theEvent);
108 
109 public slots:
111  virtual void clear();
112 
113  protected slots:
115  virtual void commitData(QWidget* theEditor);
116 
118  void onDoubleClick(const QModelIndex&);
119 
120  protected:
122  virtual void contextMenuEvent(QContextMenuEvent* theEvent);
123 
125  virtual void resizeEvent(QResizeEvent* theEvent);
126 
128  virtual void mouseReleaseEvent(QMouseEvent* theEvent);
129 
130 #ifdef DEBUG_INDXES
131  virtual void mousePressEvent(QMouseEvent* theEvent);
132 #endif
133 
134 private:
137  void processHistoryChange(const QModelIndex& theIndex);
138 
142  void highlightDependencies(const QModelIndex& theIndex);
143 
146  void processEyeClick(const QModelIndex& theIndex);
147 };
148 
153 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
154 {
155 Q_OBJECT
156  public:
159  XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop);
160  virtual ~XGUI_ObjectsBrowser();
161 
164  {
165  return myDocModel;
166  }
167 
170  QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
171 
174  void setObjectsSelected(const QObjectPtrList& theObjects);
175 
178  void ensureVisible(const ObjectPtr theObject);
179 
181  QModelIndexList selectedIndexes() const
182  {
183  if (myTreeView->selectionModel())
184  return myTreeView->selectionModel()->selectedIndexes();
185  else
186  return QModelIndexList();
187  }
188 
191  {
192  return myTreeView;
193  }
194 
196  QLabel* activeDocLabel() const { return myActiveDocLbl; }
197 
199  void rebuildDataTree();
200 
202  void clearContent();
203 
205  void initialize(ModuleBase_ITreeNode* theRoot);
206 
210  std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
211 
215  void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
216 
218  XGUI_Workshop* workshop() const { return myWorkshop; }
219 
220  void onSelectionChanged();
221 
225  void updateAllIndexes(int theColumn = 0, const QModelIndex& theParent = QModelIndex());
226 
227  QMap<ObjectPtr, bool> getFoldersState(DocumentPtr theDoc) const;
228 
229  void setFoldersState(const QMap<ObjectPtr, bool>& theStates);
230 
231 public slots:
233  void onEditItem();
234 
235 signals:
238 
240  void contextMenuRequested(QContextMenuEvent* theEvent);
241 
243  void headerMouseDblClicked(const QModelIndex&);
244 
246  void sizeChanged();
247 
248 
249 protected:
251  void resizeEvent(QResizeEvent* theEvent);
252 
253 
254  private slots:
257  void onContextMenuRequested(QContextMenuEvent* theEvent);
258 
261  void onLabelContextMenuRequested(const QPoint& thePnt);
262 
264  void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
265 
266  void onBeforeReset();
267 
268  void onAfterModelReset();
269 
270  private:
271  QList<ModuleBase_ITreeNode*> expandedItems(const QModelIndex& theParent = QModelIndex()) const;
272 
274  XGUI_DataModel* myDocModel;
275  XGUI_ActiveDocLbl* myActiveDocLbl;
276  XGUI_DataTree* myTreeView;
277  XGUI_Workshop* myWorkshop;
278 
280  //QModelIndexList myExpandedItems;
281  QList<ModuleBase_ITreeNode*> myExpandedItems;
282 };
283 
284 #endif
Class that reads data model definition XML for further processing in the XGUI_DataModel.
Definition: Config_DataModelReader.h:36
Definition: ModuleBase_ITreeNode.h:44
Implementation of root label in Object Browser.
Definition: XGUI_ObjectsBrowser.h:48
void unselect()
On unselect.
Definition: XGUI_ObjectsBrowser.cpp:402
bool eventFilter(QObject *theObj, QEvent *theEvent)
Filter event.
Definition: XGUI_ObjectsBrowser.cpp:380
QTreeView * treePalette() const
Returns tree view.
Definition: XGUI_ObjectsBrowser.h:61
virtual void mouseReleaseEvent(QMouseEvent *e)
On mouse release.
Definition: XGUI_ObjectsBrowser.cpp:390
XGUI_ActiveDocLbl(const QString &theText, QWidget *theParent)
Constructor.
Definition: XGUI_ObjectsBrowser.cpp:319
void setTreeView(QTreeView *theView)
Sets tree view.
Definition: XGUI_ObjectsBrowser.cpp:328
This is a data model for Object Browser (QTreeView).
Definition: XGUI_DataModel.h:46
Implementation of Data Tree object for Object Browser.
Definition: XGUI_ObjectsBrowser.h:93
void contextMenuRequested(QContextMenuEvent *theEvent)
Emitted on context menu request.
Object browser window object.
Definition: XGUI_ObjectsBrowser.h:154
void selectionChanged()
Emitted when selection is changed.
XGUI_DataModel * dataModel() const
Returns Model which provides access to data objects.
Definition: XGUI_ObjectsBrowser.h:163
QLabel * activeDocLabel() const
Returns active doc label object.
Definition: XGUI_ObjectsBrowser.h:196
void headerMouseDblClicked(const QModelIndex &)
Signal is emitted when user clicks with mouse in header label of object browser.
QModelIndexList selectedIndexes() const
Returns currently selected indexes.
Definition: XGUI_ObjectsBrowser.h:181
void sizeChanged()
An signal emitted on resize of the Object Browser.
XGUI_Workshop * workshop() const
Returns current workshop.
Definition: XGUI_ObjectsBrowser.h:218
void contextMenuRequested(QContextMenuEvent *theEvent)
Emitted on context menu request.
XGUI_DataTree * treeView() const
Returns TreeView widget.
Definition: XGUI_ObjectsBrowser.h:190
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:83