]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ObjectsBrowser.h
Salome HOME
ef00a1a525225dd557e6539d9b805bdfb7f35379
[modules/shaper.git] / src / XGUI / XGUI_ObjectsBrowser.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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<mailto: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
29 #include <QWidget>
30 #include <QTreeView>
31 #include <QLabel>
32
33 class ModuleBase_IDocumentDataModel;
34 class XGUI_DataModel;
35 class Config_DataModelReader;
36
37 /**
38 * \ingroup GUI
39 * Implementation of root label in Object Browser
40 */
41 class XGUI_ActiveDocLbl: public QLabel
42 {
43 Q_OBJECT
44  public:
45    /// Constructor
46    /// \param theText a text
47    /// \param theParent a parent widget
48    XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent );
49
50    /// Sets tree view
51    /// \param theView a view
52    void setTreeView(QTreeView* theView);
53
54    /// Returns tree view
55    QTreeView* treePalette() const { return myTreeView;}
56
57 #if (!defined HAVE_SALOME) && (defined WIN32)
58    virtual bool event(QEvent* theEvent);
59 #endif
60
61 public slots:
62   /// On unselect
63   void unselect();
64
65 protected:
66   /// On mouse release
67   virtual void mouseReleaseEvent( QMouseEvent* e);
68
69   /// Filter event
70   bool eventFilter(QObject* theObj, QEvent* theEvent);
71
72 private:
73   QString myPreSelectionStyle;
74   QString myNeutralStyle;
75   QString mySelectionStyle;
76
77   QTreeView* myTreeView;
78   bool myIsSelected;
79 };
80
81
82 /**
83 * \ingroup GUI
84 * Implementation of Data Tree object for Object Browser
85 */
86 class XGUI_DataTree : public QTreeView
87 {
88 Q_OBJECT
89  public:
90    /// Constructor
91    /// \param theParent a parent widget
92   XGUI_DataTree(QWidget* theParent);
93
94   virtual ~XGUI_DataTree();
95
96   /// Returns current data model
97   XGUI_DataModel* dataModel() const;
98
99 signals:
100   //! Emited on context menu request
101   void contextMenuRequested(QContextMenuEvent* theEvent);
102
103 public slots:
104   /// Clear content of data tree
105   virtual void clear();
106
107  protected slots:
108   /// Commit modified data (used for renaming of objects)
109   virtual void commitData(QWidget* theEditor);
110
111   /// A slot which is called on mouse double click
112   void onDoubleClick(const QModelIndex&);
113
114  protected:
115    /// Redefinition of virtual method
116   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
117
118    /// Redefinition of virtual method
119   virtual void resizeEvent(QResizeEvent* theEvent);
120 };
121
122 /**\class XGUI_ObjectsBrowser
123  * \ingroup GUI
124  * \brief Object browser window object. Represents data tree of current data structure
125  */
126 class XGUI_EXPORT XGUI_ObjectsBrowser : public QWidget
127 {
128 Q_OBJECT
129  public:
130    /// Constructor
131    /// \param theParent a parent widget
132   XGUI_ObjectsBrowser(QWidget* theParent);
133   virtual ~XGUI_ObjectsBrowser();
134
135   //! Returns Model which provides access to data objects
136   XGUI_DataModel* dataModel() const
137   {
138     return myDocModel;
139   }
140
141   //! Returns list of currently selected objects
142   //! \param theIndexes - output list of corresponded indexes (can be NULL)
143   QObjectPtrList selectedObjects(QModelIndexList* theIndexes = 0) const;
144
145   /// Set selected list of objects
146   /// \param theObjects list of objects to select
147   void setObjectsSelected(const QObjectPtrList& theObjects);
148
149   //! Returns currently selected indexes
150   QModelIndexList selectedIndexes() const
151   {
152     return myTreeView->selectionModel()->selectedIndexes();
153   }
154
155   //! Returns TreeView widget
156   XGUI_DataTree* treeView() const
157   {
158     return myTreeView;
159   }
160
161   /// Returns active doc label object
162   QLabel* activeDocLabel() const { return myActiveDocLbl; }
163
164   /// Rebuild data tree
165   void rebuildDataTree();
166
167   /// Resets the object browser into initial state
168   void clearContent();
169
170   /// Set XML reader object for data model
171   /// \param theReader the reader object
172   void setXMLReader(Config_DataModelReader* theReader);
173
174   /// Returns list of folders opened state for the given document
175   /// \param theDoc the document
176   /// \return list of booleans with state expanded or not
177   std::list<bool> getStateForDoc(DocumentPtr theDoc) const;
178
179   /// Set folders opened state for the given document
180   /// \param theDoc the document
181   /// \param theStates list of booleans with state expanded or not
182   void setStateForDoc(DocumentPtr theDoc, const std::list<bool>& theStates);
183
184 public slots:
185   //! Called on Edit command request
186   void onEditItem();
187
188 signals:
189   //! Emited when selection is changed
190   void selectionChanged();
191
192   //! Emited on context menu request
193   void contextMenuRequested(QContextMenuEvent* theEvent);
194
195   //! Segnal is emitted when user cliks by mouse in header label of object browser
196   void headerMouseDblClicked(const QModelIndex&);
197
198  private slots:
199   /// Show context menu
200   /// \param theEvent a context menu event
201   void onContextMenuRequested(QContextMenuEvent* theEvent);
202
203   /// Show context menu on upper label
204   /// \param thePnt a position of context menu
205   void onLabelContextMenuRequested(const QPoint& thePnt);
206
207   //! Called when selection in Data Tree is changed
208   void onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected);
209
210   void onBeforeReset();
211
212   void onAfterModelReset();
213
214  private:
215   QModelIndexList expandedItems(const QModelIndex& theParent = QModelIndex()) const;
216
217   //! Internal model
218   XGUI_DataModel* myDocModel;
219   XGUI_ActiveDocLbl* myActiveDocLbl;
220   XGUI_DataTree* myTreeView;
221
222   /// A field to store expanded items before model reset
223   QModelIndexList myExpandedItems;
224 };
225
226 #endif