Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.h
1
2 #ifndef XGUI_ObjectsBrowser_H
3 #define XGUI_ObjectsBrowser_H
4
5 #include "XGUI.h"
6 #include <ModuleBase_Definitions.h>
7 #include <ModelAPI_Object.h>
8
9 #include <QWidget>
10 #include <QTreeView>
11
12 class XGUI_DocumentDataModel;
13 class QLineEdit;
14
15
16 class XGUI_DataTree: public QTreeView
17 {
18   Q_OBJECT
19 public:
20   XGUI_DataTree(QWidget* theParent);
21   virtual ~XGUI_DataTree();
22
23   //! Returns list of currently selected features
24   QList<ObjectPtr> selectedFeatures() const { return mySelectedData; }
25
26   XGUI_DocumentDataModel* dataModel() const;
27
28 signals:
29   //! Emited when selection is changed
30   void selectionChanged();
31   void activePartChanged(FeaturePtr thePart); 
32  
33   //! Emited on context menu request
34   void contextMenuRequested(QContextMenuEvent* theEvent);
35
36 protected slots:
37   virtual void commitData(QWidget* theEditor);
38
39 protected:
40   virtual void mouseDoubleClickEvent(QMouseEvent* theEvent);
41   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
42
43 private slots:
44   //! Called when selection in Data Tree is changed
45   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
46
47 private:
48   //! List of currently selected data
49   QList<ObjectPtr> mySelectedData;
50 };
51
52
53 /**\class XGUI_ObjectsBrowser
54  * \ingroup GUI
55  * \brief Object browser window object. Represents data tree of current data structure
56  */
57  class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
58 {
59   Q_OBJECT
60 public:
61   XGUI_ObjectsBrowser(QWidget* theParent);
62   virtual ~XGUI_ObjectsBrowser();
63
64   //! Returns Model which provides access to data objects
65   XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
66
67   //! Returns list of currently selected features
68   QList<ObjectPtr> selectedObjects() const { return myObjectsList; }
69
70   void setFeaturesSelected(const QFeatureList& theFeatures);
71
72   //! Returns currently selected indexes
73   QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
74
75   //! Returns TreeView widget
76   XGUI_DataTree* treeView() const { return myTreeView; }
77
78   //! Activates currently selected part. Signal activePartChanged will not be sent
79   void activatePart(const FeaturePtr& thePart);
80
81   void rebuildDataTree();
82
83 signals:
84   //! Emited when selection is changed
85   void selectionChanged();
86
87   //! Emited when current active document is changed
88   void activePartChanged(FeaturePtr thePart); 
89  
90   //! Emited on context menu request
91   void contextMenuRequested(QContextMenuEvent* theEvent);
92
93 protected:
94   virtual bool eventFilter(QObject* obj, QEvent* theEvent);
95
96 private slots:
97   void onActivePartChanged(FeaturePtr thePart);
98   void onContextMenuRequested(QContextMenuEvent* theEvent);
99   void onLabelContextMenuRequested(const QPoint& thePnt);
100
101   //! Called on Edit command request
102   void onEditItem();
103
104   void onSelectionChanged();
105
106 private:
107   void closeDocNameEditing(bool toSave);
108
109   //! Internal model
110   XGUI_DocumentDataModel* myDocModel;
111
112   QLineEdit* myActiveDocLbl;
113   XGUI_DataTree* myTreeView;
114
115   QList<ObjectPtr> myObjectsList;
116 };
117
118 #endif