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