LayerItemView.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9 
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21  * \file LayerItemView.h
22  *
23  * \brief Defines a layer item view for Qt5.
24  */
25 #ifndef __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMVIEW_H
26 #define __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMVIEW_H
27 
28 #include "../../Config.h"
29 
30 // TerraLib
31 #include "../../../../maptools/AbstractLayer.h"
32 
33 // Qt
34 #include <QTreeView>
35 
36 // STL
37 #include <list>
38 
39 // Forward declarations
40 class QAction;
41 class QStyledItemDelegate;
42 
43 namespace te
44 {
45  namespace map
46  {
47  class Chart;
48  }
49 
50  namespace qt
51  {
52  namespace widgets
53  {
54  class LayerItemModel;
55  class LayerViewMenuManager;
56  class TreeItem;
57 
58  /*!
59  * \class LayerItemView
60  *
61  * \brief A specialization of QTreeView for manipulate layers.
62  *
63  * This is a component used to manipulate layers in a visual way. You can add, remove, reparent items,
64  * changes its visibility, add folders and some other operations over a set of layers. It can be feeded
65  * by the LayersSelector or projects of TerraLib-5.
66  *
67  * \ingroup widgets
68  *
69  * \sa LayerItemModel, LayerViewDelegate, LayerViewMenuManager
70  */
71  class TEQTWIDGETSEXPORT LayerItemView: public QTreeView
72  {
73  Q_OBJECT
74 
75  public:
76 
77  /** @name Initializer Methods
78  * Methods related to instantiation and destruction.
79  */
80  //@{
81 
82  /*!
83  * \brief Constructor.
84  * \param parent Used by Qt for memory release.
85  */
86  LayerItemView(QWidget* parent = 0);
87 
88  /*!
89  * \brief Destructor.
90  */
91  ~LayerItemView();
92  //@}
93 
94  /** @name Tree manipulation Methods
95  * Methods related insertions and recovery of layers in the tree.
96  */
97  //@{
98 
99  /*!
100  * \brief Add the layers to the model
101  * \param layers The list of layers to be added.
102  * \param idx The index of the parent item wich the must be insert.
103  * \param idxPath Unused.
104  */
105  void addLayers(const std::list<te::map::AbstractLayerPtr>& layers, const QModelIndex& idx, const std::string& idxPath = "./");
106 
107  /*!
108  * \brief Sets the list of layers. Old layers in the tree are then removed.
109  * \param layers The new list of layers.
110  */
111  void setLayers(const std::list<te::map::AbstractLayerPtr>& layers);
112 
113  /*!
114  * \brief Returs all layers in the tree including folders.
115  *
116  * This method must be called when we need to store the list of layers.
117  * \return List of layers in the tree.
118  */
119  std::list<te::map::AbstractLayerPtr> getAllLayers() const;
120 
121  /*!
122  * \brief Returns just the visible layers. No folder layers are returned.
123  * \return List of visible layers.
124  */
125  std::list<te::map::AbstractLayerPtr> getVisibleLayers() const;
126 
127  /*!
128  * \brief Returns a list of TreeItem that are selected.
129  * \return The list of selected TreeItem.
130  */
131  std::list<te::qt::widgets::TreeItem*> getSelectedItems() const;
132 
133  /*!
134  * \brief Adds a folder layer to the model.
135  * \param name Name of the folder.
136  * \param idx Index of the parent, where the new folder must be inserted in.
137  */
138  void addFolder(const std::string& name, const QModelIndex& idx);
139 
140  /*!
141  * \brief Updates the chart item of the element.
142  * \param idx Index of the layer to add chart.
143  * \note idx must contain a Layer or the operation will fail.
144  */
145  void updateChart(const QModelIndex& idx);
146 
147  /*!
148  * \brief Updates the grouping item of the element.
149  * \param idx Index of the layer to add grouping.
150  * \note idx must contain a Layer or the operation will fail.
151  */
152  void updateGrouping(const QModelIndex& idx);
153 
154  /*!
155  * \brief updateLegend
156  * \param l
157  */
158  void updateLegend(te::map::AbstractLayer* l);
159  //@}
160 
161  /** @name Popup Menu manipulation Methods
162  * Methods related to manipulation of the popup menus.
163  */
164  //@{
165 
166  /*!
167  * \brief Adds the action to the popup menu presented when there is no layers selected.
168  * \param act Action to be added.
169  */
170  void addNoLayerAction(QAction* act);
171 
172  /*!
173  * \brief Adds the action to the popup menu presented for all kinds of selected items.
174  * \param act Action to be added.
175  */
176  void addAllLayerAction(QAction* act);
177 
178  /*!
179  * \brief Adds the action to the popup menu presented when the selected layer has vector representation.
180  * \param act Action to be added.
181  */
182  void addVectorLayerAction(QAction* act);
183 
184  /*!
185  * \brief Adds the action to the popup menu presented when the selected layer has raster representation.
186  * \param act Action to be added.
187  */
188  void addRasterLayerAction(QAction* act);
189 
190  /*!
191  * \brief Adds the action to the popup menu presented when the selected item is a folder.
192  * \param act Action to be added.
193  */
194  void addFolderLayerAction(QAction* act);
195 
196  /*!
197  * \brief Adds the action to the popup menu presented when there is multiple items selected.
198  * \param act Action to be added.
199  */
200  void addMultipleSelectionAction(QAction* act);
201 
202  /*!
203  * \brief Adds the action to the popup menu presented when the selected layer is invalid.
204  * \param act Action to be added.
205  */
206  void addInvalidLayerAction(QAction* act);
207  //@}
208 
209  /** @name Remove Methods
210  * Methods related to layers removal.
211  */
212  //@{
213 
214  /*!
215  * \brief Removes the items in the list.
216  * \param idxs List of indexes of items to be removed.
217  */
218  void removeItems(const QModelIndexList& idxs);
219 
220  /*!
221  * \brief Removes the items that are selected.
222  */
223  void removeSelectedItems();
224  //@}
225 
226  /** @name Tree Customization Methods
227  * Methods used to change the tree behavior.
228  *
229  * These methods can be used for change the Tree presentation and popup menus.
230  * You can used delegates to change presentation behavior, and use QObject to handle popup menus.
231  */
232  //@{
233 
234  /*!
235  * \brief Removes the delegate from the tree.
236  * \param d Delegate to be removed.
237  *
238  * \note The tree does NOT TAKE the ownership of the pointer.
239  */
240  void removeDelegate(QStyledItemDelegate* d);
241 
242  /*!
243  * \brief Updates the popup event handler.
244  *
245  * This is used for change the popup menus. If you want to change the popup management try to use
246  * this function. You can change all menu handling or a specific type of item.
247  *
248  * \param obj The new menu event handler.
249  *
250  * \note The tree does NOT TAKE the ownership of the pointer.
251  */
252  void setMenuEventHandler(QObject* obj);
253 
254  /*!
255  * \brief Rerturns the current popup handler being used.
256  * \return Current menu event handler.
257  */
258  QObject* getMenuEventHandler() const;
259 
260  /*!
261  * \brief Removes the menu handler.
262  *
263  * Removes the menu handler from the tree.
264  *
265  * \param handler The handler to be removed.
266  *
267  * \note The tree does NOT TAKE free memory of handler object.
268  */
269  void removeMenuEventHandler(QObject* handler);
270  //@}
271 
272  Q_SIGNALS:
273 
274  /** @name Qt signals
275  *
276  * Signals emitted by LayerItemView
277  */
278  //@{
279 
280  /*!
281  * \brief Emited when user double clicks over an AbstractLayer.
282  * \param layer The layer that receives mouse double click event.
283  */
284  void doubleClicked(te::map::AbstractLayerPtr layer);
285 
286  /*!
287  * \brief Emited when some item changes its visibility.
288  */
289  void visibilityChanged();
290 
291  /*!
292  * \brief Emited when the selection changes.
293  * \param layers The current selected layers.
294  */
295  void selectedLayersChanged(const std::list<te::map::AbstractLayerPtr>& layers);
296 
297  /*!
298  * \brief Emited when the order of the layers has changed.
299  */
300  void layerOrderChanged();
301  //@}
302 
303  protected:
304 
305  /** @name Qt Reimplemented Methods
306  *
307  * Methods that are reimplemented of the QTreeView class.
308  */
309  //@{
310  void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
311 
312  void dropEvent(QDropEvent * event);
313 
314  void mouseDoubleClickEvent(QMouseEvent* event);
315  //@}
316 
317  LayerItemModel* m_model; //!< Model to be used.
318  LayerViewMenuManager* m_mnuMger; //!< Default popup handler.
319  QObject* m_outterFilter; //!< Popup handler defined outside the tree.
320  };
321  }
322  }
323 }
324 
325 #endif //__TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMVIEW_H
This is the base class for layers.
Definition: AbstractLayer.h:76
A wdiget used to customize a chart's style parameters.
LayerItemModel * m_model
Model to be used.
URI C++ Library.
Defines an abstract model based on TreeItem objects.
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:71
QObject * m_outterFilter
Popup handler defined outside the tree.
Class for manage the menus of the LayerViewItem.
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
LayerViewMenuManager * m_mnuMger
Default popup handler.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr