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 layer has tabular representation.
194  * \param act Action to be added.
195  */
196  void addTabularLayerAction(QAction* act);
197 
198  /*!
199  * \brief Adds the action to the popup menu presented when the selected item is a folder.
200  * \param act Action to be added.
201  */
202  void addFolderLayerAction(QAction* act);
203 
204  /*!
205  * \brief Adds the action to the popup menu presented when there is multiple items selected.
206  * \param act Action to be added.
207  */
208  void addMultipleSelectionAction(QAction* act);
209 
210  /*!
211  * \brief Adds the action to the popup menu presented when the selected layer is invalid.
212  * \param act Action to be added.
213  */
214  void addInvalidLayerAction(QAction* act);
215 
216  /*!
217  * \brief Return the QModelIndex of the Layer in the Tree.
218  * \param model The item model.
219  * \param parent The parent of the index.
220  * \param l The layer.
221  */
222  QModelIndex findLayerIndex(QAbstractItemModel* model, const QModelIndex& parent, te::map::AbstractLayer* l);
223  //@}
224 
225  /** @name Remove Methods
226  * Methods related to layers removal.
227  */
228  //@{
229 
230  /*!
231  * \brief Removes the items in the list.
232  * \param idxs List of indexes of items to be removed.
233  */
234  void removeItems(const QModelIndexList& idxs);
235 
236  /*!
237  * \brief Removes the items that are selected.
238  */
239  void removeSelectedItems();
240  //@}
241 
242  /** @name Tree Customization Methods
243  * Methods used to change the tree behavior.
244  *
245  * These methods can be used for change the Tree presentation and popup menus.
246  * You can used delegates to change presentation behavior, and use QObject to handle popup menus.
247  */
248  //@{
249 
250  /*!
251  * \brief Removes the delegate from the tree.
252  * \param d Delegate to be removed.
253  *
254  * \note The tree does NOT TAKE the ownership of the pointer.
255  */
256  void removeDelegate(QStyledItemDelegate* d);
257 
258  /*!
259  * \brief Updates the popup event handler.
260  *
261  * This is used for change the popup menus. If you want to change the popup management try to use
262  * this function. You can change all menu handling or a specific type of item.
263  *
264  * \param obj The new menu event handler.
265  *
266  * \note The tree does NOT TAKE the ownership of the pointer.
267  */
268  void setMenuEventHandler(QObject* obj);
269 
270  /*!
271  * \brief Rerturns the current popup handler being used.
272  * \return Current menu event handler.
273  */
274  QObject* getMenuEventHandler() const;
275 
276  /*!
277  * \brief Removes the menu handler.
278  *
279  * Removes the menu handler from the tree.
280  *
281  * \param handler The handler to be removed.
282  *
283  * \note The tree does NOT TAKE free memory of handler object.
284  */
285  void removeMenuEventHandler(QObject* handler);
286  //@}
287 
288  Q_SIGNALS:
289 
290  /** @name Qt signals
291  *
292  * Signals emitted by LayerItemView
293  */
294  //@{
295 
296  /*!
297  * \brief Emited when user double clicks over an AbstractLayer.
298  * \param layer The layer that receives mouse double click event.
299  */
300  void doubleClicked(te::map::AbstractLayerPtr layer);
301 
302  /*!
303  * \brief Emited when user double clicks over an Layer Grouping.
304  * \param layer The layer that receives mouse double click event.
305  */
306  void groupingDoubleClicked(te::map::AbstractLayerPtr layer);
307 
308  /*!
309  * \brief Emited when some item changes its visibility.
310  */
311  void visibilityChanged();
312 
313  /*!
314  * \brief Emited when the selection changes.
315  * \param layers The current selected layers.
316  */
317  void selectedLayersChanged(const std::list<te::map::AbstractLayerPtr>& layers);
318 
319  /*!
320  * \brief Emited when the order of the layers has changed.
321  */
322  void layerOrderChanged();
323  //@}
324 
325  protected:
326 
327  /** @name Qt Reimplemented Methods
328  *
329  * Methods that are reimplemented of the QTreeView class.
330  */
331  //@{
332  void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
333 
334  void dropEvent(QDropEvent * event);
335 
336  void mouseDoubleClickEvent(QMouseEvent* event);
337  //@}
338 
339  LayerItemModel* m_model; //!< Model to be used.
340  LayerViewMenuManager* m_mnuMger; //!< Default popup handler.
341  QObject* m_outterFilter; //!< Popup handler defined outside the tree.
342  };
343  }
344  }
345 }
346 
347 #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: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