SHAPER  9.12.0
XGUI_ObjectsBrowser.h
1 // Copyright (C) 2014-2023 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 
141  void processEyeClick(const QModelIndex& theIndex);
142 };
143 
148 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
149 {
150 Q_OBJECT
151  public:
154  XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop);
155  virtual ~XGUI_ObjectsBrowser();
156 
159  {
160  return myDocModel;
161  }
162 
165  QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
166 
169  void setObjectsSelected(const QObjectPtrList& theObjects);
170 
173  void ensureVisible(const ObjectPtr theObject);
174 
176  QModelIndexList selectedIndexes() const
177  {
178  if (myTreeView->selectionModel())
179  return myTreeView->selectionModel()->selectedIndexes();
180  else
181  return QModelIndexList();
182  }
183 
186  {
187  return myTreeView;
188  }
189 
191  QLabel* activeDocLabel() const { return myActiveDocLbl; }
192 
194  void rebuildDataTree();
195 
197  void clearContent();
198 
200  void initialize(ModuleBase_ITreeNode* theRoot);
201 
205  std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
206 
210  void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
211 
213  XGUI_Workshop* workshop() const { return myWorkshop; }
214 
215  void onSelectionChanged();
216 
220  void updateAllIndexes(int theColumn = 0, const QModelIndex& theParent = QModelIndex());
221 
222  QMap<ObjectPtr, bool> getFoldersState(DocumentPtr theDoc) const;
223 
224  void setFoldersState(const QMap<ObjectPtr, bool>& theStates);
225 
226 public slots:
228  void onEditItem();
229 
230 signals:
233 
235  void contextMenuRequested(QContextMenuEvent* theEvent);
236 
238  void headerMouseDblClicked(const QModelIndex&);
239 
241  void sizeChanged();
242 
243 
244 protected:
246  void resizeEvent(QResizeEvent* theEvent);
247 
248 
249  private slots:
252  void onContextMenuRequested(QContextMenuEvent* theEvent);
253 
256  void onLabelContextMenuRequested(const QPoint& thePnt);
257 
259  void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
260 
261  void onBeforeReset();
262 
263  void onAfterModelReset();
264 
265  private:
266  QList<ModuleBase_ITreeNode*> expandedItems(const QModelIndex& theParent = QModelIndex()) const;
267 
269  XGUI_DataModel* myDocModel;
270  XGUI_ActiveDocLbl* myActiveDocLbl;
271  XGUI_DataTree* myTreeView;
272  XGUI_Workshop* myWorkshop;
273 
275  //QModelIndexList myExpandedItems;
276  QList<ModuleBase_ITreeNode*> myExpandedItems;
277 };
278 
279 #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:368
bool eventFilter(QObject *theObj, QEvent *theEvent)
Filter event.
Definition: XGUI_ObjectsBrowser.cpp:346
QTreeView * treePalette() const
Returns tree view.
Definition: XGUI_ObjectsBrowser.h:61
virtual void mouseReleaseEvent(QMouseEvent *e)
On mouse release.
Definition: XGUI_ObjectsBrowser.cpp:356
XGUI_ActiveDocLbl(const QString &theText, QWidget *theParent)
Constructor.
Definition: XGUI_ObjectsBrowser.cpp:285
void setTreeView(QTreeView *theView)
Sets tree view.
Definition: XGUI_ObjectsBrowser.cpp:294
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)
Emited on context menu request.
Object browser window object.
Definition: XGUI_ObjectsBrowser.h:149
void selectionChanged()
Emited when selection is changed.
XGUI_DataModel * dataModel() const
Returns Model which provides access to data objects.
Definition: XGUI_ObjectsBrowser.h:158
QLabel * activeDocLabel() const
Returns active doc label object.
Definition: XGUI_ObjectsBrowser.h:191
void headerMouseDblClicked(const QModelIndex &)
Segnal is emitted when user cliks by mouse in header label of object browser.
QModelIndexList selectedIndexes() const
Returns currently selected indexes.
Definition: XGUI_ObjectsBrowser.h:176
void sizeChanged()
An signal emitted on resize of the Object Browser.
XGUI_Workshop * workshop() const
Returns current workshop.
Definition: XGUI_ObjectsBrowser.h:213
void contextMenuRequested(QContextMenuEvent *theEvent)
Emited on context menu request.
XGUI_DataTree * treeView() const
Returns TreeView widget.
Definition: XGUI_ObjectsBrowser.h:185
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:82