Salome HOME
Introduce internal edit operation state in PartSet module in order to have a virtual...
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_ObjectsBrowser_H
4 #define XGUI_ObjectsBrowser_H
5
6 #include "XGUI.h"
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_Object.h>
9 #include <ModelAPI_ResultPart.h>
10 #include <ModelAPI_Events.h>
11
12 #include <QWidget>
13 #include <QTreeView>
14
15 class ModuleBase_IDocumentDataModel;
16 class QLineEdit;
17 class XGUI_DataModel;
18
19 /**
20 * \ingroup GUI
21 * Implementation of Data Tree object for Object Browser
22 */
23 class XGUI_DataTree : public QTreeView
24 {
25 Q_OBJECT
26  public:
27    /// Constructor
28    /// \param theParent a parent widget
29   XGUI_DataTree(QWidget* theParent);
30
31   virtual ~XGUI_DataTree();
32
33   /// Returns current data model
34   XGUI_DataModel* dataModel() const;
35
36 signals:
37   //! Emited on context menu request
38   void contextMenuRequested(QContextMenuEvent* theEvent);
39
40 public slots:
41   /// Clear content of data tree
42   virtual void clear();
43
44  protected slots:
45   /// Commit modified data (used for renaming of objects)
46   virtual void commitData(QWidget* theEditor);
47
48   /// A slot which is called on mouse double click
49   void onDoubleClick(const QModelIndex&);
50
51  protected:
52    /// Redefinition of virtual method
53   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
54
55    /// Redefinition of virtual method
56   virtual void resizeEvent(QResizeEvent* theEvent);
57
58 };
59
60 /**\class XGUI_ObjectsBrowser
61  * \ingroup GUI
62  * \brief Object browser window object. Represents data tree of current data structure
63  */
64 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
65 {
66 Q_OBJECT
67  public:
68    /// Constructor
69    /// \param theParent a parent widget
70   XGUI_ObjectsBrowser(QWidget* theParent);
71   virtual ~XGUI_ObjectsBrowser();
72
73   //! Returns Model which provides access to data objects
74   XGUI_DataModel* dataModel() const
75   {
76     return myDocModel;
77   }
78
79   //! Returns list of currently selected objects
80   //! \param theIndexes - output list of corresponded indexes (can be NULL)
81   QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
82
83   /// Set selected list of objects
84   /// \param theObjects list of objects to select
85   void setObjectsSelected(const QObjectPtrList& theObjects);
86
87   //! Returns currently selected indexes
88   QModelIndexList selectedIndexes() const
89   {
90     return myTreeView->selectionModel()->selectedIndexes();
91   }
92
93   //! Returns TreeView widget
94   XGUI_DataTree* treeView() const
95   {
96     return myTreeView;
97   }
98
99   /// Returns active doc label object
100   QLineEdit* activeDocLabel() const { return myActiveDocLbl; }
101
102   /// Rebuild data tree
103   void rebuildDataTree();
104
105   /// Resets the object browser into initial state
106   void clearContent();
107
108 public slots:
109   //! Called on Edit command request
110   void onEditItem();
111
112 signals:
113   //! Emited when selection is changed
114   void selectionChanged();
115
116   //! Emited on context menu request
117   void contextMenuRequested(QContextMenuEvent* theEvent);
118
119   //! Segnal is emitted when user cliks by mouse in header label of object browser
120   void headerMouseDblClicked(const QModelIndex&);
121
122  protected:
123    /// Redefinition of virtual method
124   virtual bool eventFilter(QObject* obj, QEvent* theEvent);
125
126  private slots:
127   /// Show context menu
128   /// \param theEvent a context menu event
129   void onContextMenuRequested(QContextMenuEvent* theEvent);
130
131   /// Show context menu on upper label
132   /// \param thePnt a position of context menu
133   void onLabelContextMenuRequested(const QPoint& thePnt);
134
135   //! Called when selection in Data Tree is changed
136   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
137
138  private:
139   void closeDocNameEditing(bool toSave);
140
141   //! Internal model
142   XGUI_DataModel* myDocModel;
143   QLineEdit* myActiveDocLbl;
144   XGUI_DataTree* myTreeView;
145 };
146
147 #endif