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 se
53  {
54  class Rule;
55  }
56 
57  namespace qt
58  {
59  namespace widgets
60  {
61  class LayerItemModel;
62  class LayerViewMenuManager;
63  class TreeItem;
64 
65  /*!
66  * \class LayerItemView
67  *
68  * \brief A specialization of QTreeView for manipulate layers.
69  *
70  * This is a component used to manipulate layers in a visual way. You can add, remove, reparent items,
71  * changes its visibility, add folders and some other operations over a set of layers. It can be feeded
72  * by the LayersSelector or projects of TerraLib-5.
73  *
74  * \ingroup widgets
75  *
76  * \sa LayerItemModel, LayerViewDelegate, LayerViewMenuManager
77  */
78  class TEQTWIDGETSEXPORT LayerItemView: public QTreeView
79  {
80  Q_OBJECT
81 
82  public:
83 
84  /** @name Initializer Methods
85  * Methods related to instantiation and destruction.
86  */
87  //@{
88 
89  /*!
90  * \brief Constructor.
91  * \param parent Used by Qt for memory release.
92  */
93  LayerItemView(QWidget* parent = 0);
94 
95  /*!
96  * \brief Destructor.
97  */
98  ~LayerItemView();
99  //@}
100 
101  /** @name Tree manipulation Methods
102  * Methods related insertions and recovery of layers in the tree.
103  */
104  //@{
105 
106  /*!
107  * \brief Add the layers to the model
108  * \param layers The list of layers to be added.
109  * \param idx The index of the parent item wich the must be insert.
110  * \param idxPath Unused.
111  */
112  void addLayers(const std::list<te::map::AbstractLayerPtr>& layers, const QModelIndex& idx, const std::string& idxPath = "./");
113 
114  /*!
115  * \brief Sets the list of layers. Old layers in the tree are then removed.
116  * \param layers The new list of layers.
117  */
118  void setLayers(const std::list<te::map::AbstractLayerPtr>& layers);
119 
120  /*!
121  * \brief Returs all layers in the tree including folders.
122  *
123  * This method must be called when we need to store the list of layers.
124  * \return List of layers in the tree.
125  */
126  std::list<te::map::AbstractLayerPtr> getAllLayers() const;
127 
128  /*!
129  * \brief Returns just the visible layers. No folder layers are returned.
130  * \return List of visible layers.
131  */
132  std::list<te::map::AbstractLayerPtr> getVisibleLayers() const;
133 
134  /*!
135  * \brief Returns a list of TreeItem that are selected.
136  * \return The list of selected TreeItem.
137  */
138  std::list<te::qt::widgets::TreeItem*> getSelectedItems() const;
139 
140  /*!
141  * \brief Adds a folder layer to the model.
142  * \param name Name of the folder.
143  * \param idx Index of the parent, where the new folder must be inserted in.
144  */
145  void addFolder(const std::string& name, const QModelIndex& idx);
146 
147  /*!
148  * \brief Updates the chart item of the element.
149  * \param idx Index of the layer to add chart.
150  * \note idx must contain a Layer or the operation will fail.
151  */
152  void updateChart(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 layer has tabular representation.
192  * \param act Action to be added.
193  */
194  void addTabularLayerAction(QAction* act);
195 
196  /*!
197  * \brief Adds the action to the popup menu presented when the selected item is a folder.
198  * \param act Action to be added.
199  */
200  void addFolderLayerAction(QAction* act);
201 
202  /*!
203  * \brief Adds the action to the popup menu presented when there is multiple items selected.
204  * \param act Action to be added.
205  */
206  void addMultipleSelectionAction(QAction* act);
207 
208  /*!
209  * \brief Adds the action to the popup menu presented when the selected layer is invalid.
210  * \param act Action to be added.
211  */
212  void addInvalidLayerAction(QAction* act);
213 
214  /*!
215  * \brief Return the QModelIndex of the Layer in the Tree.
216  * \param model The item model.
217  * \param parent The parent of the index.
218  * \param l The layer.
219  */
220  QModelIndex findLayerIndex(QAbstractItemModel* model, const QModelIndex& parent, te::map::AbstractLayer* l);
221  //@}
222 
223  /** @name Remove Methods
224  * Methods related to layers removal.
225  */
226  //@{
227 
228  /*!
229  * \brief Removes the items in the list.
230  * \param idxs List of indexes of items to be removed.
231  */
232  void removeItems(const QModelIndexList& idxs);
233 
234  /*!
235  * \brief Removes the items that are selected.
236  */
237  void removeSelectedItems();
238  //@}
239 
240  /** @name Tree Customization Methods
241  * Methods used to change the tree behavior.
242  *
243  * These methods can be used for change the Tree presentation and popup menus.
244  * You can used delegates to change presentation behavior, and use QObject to handle popup menus.
245  */
246  //@{
247 
248  /*!
249  * \brief Removes the delegate from the tree.
250  * \param d Delegate to be removed.
251  *
252  * \note The tree does NOT TAKE the ownership of the pointer.
253  */
254  void removeDelegate(QStyledItemDelegate* d);
255 
256  /*!
257  * \brief Updates the popup event handler.
258  *
259  * This is used for change the popup menus. If you want to change the popup management try to use
260  * this function. You can change all menu handling or a specific type of item.
261  *
262  * \param obj The new menu event handler.
263  *
264  * \note The tree does NOT TAKE the ownership of the pointer.
265  */
266  void setMenuEventHandler(QObject* obj);
267 
268  /*!
269  * \brief Rerturns the current popup handler being used.
270  * \return Current menu event handler.
271  */
272  QObject* getMenuEventHandler() const;
273 
274  /*!
275  * \brief Removes the menu handler.
276  *
277  * Removes the menu handler from the tree.
278  *
279  * \param handler The handler to be removed.
280  *
281  * \note The tree does NOT TAKE free memory of handler object.
282  */
283  void removeMenuEventHandler(QObject* handler);
284  //@}
285 
286  Q_SIGNALS:
287 
288  /** @name Qt signals
289  *
290  * Signals emitted by LayerItemView
291  */
292  //@{
293 
294  /*!
295  * \brief Emited when user double clicks over an AbstractLayer.
296  * \param layer The layer that receives mouse double click event.
297  */
298  void doubleClicked(te::map::AbstractLayerPtr layer);
299 
300  /*!
301  * \brief Emited when user double clicks over an Style.
302  * \param layer The layer that receives mouse double click event.
303  */
304  void styleDoubleClicked(te::map::AbstractLayerPtr layer);
305 
306  /*!
307  * \brief Emited when user double clicks over an Rule.
308  * \param layer The layer and Rule that receives mouse double click event.
309  */
310  void ruleDoubleClicked(te::map::AbstractLayerPtr layer, te::se::Rule* rule);
311 
312  /*!
313  * \brief Emited when some item changes its visibility.
314  */
315  void visibilityChanged();
316 
317  /*!
318  * \brief Emited when some style item changes its visibility.
319  */
320  void styleVisibilityChanged(te::map::AbstractLayerPtr layer);
321 
322  /*!
323  * \brief Emited when the selection changes.
324  * \param layers The current selected layers.
325  */
326  void selectedLayersChanged(const std::list<te::map::AbstractLayerPtr>& layers);
327 
328  /*!
329  * \brief Emited when the order of the layers has changed.
330  */
331  void layerOrderChanged();
332  //@}
333 
334  protected:
335 
336  /** @name Qt Reimplemented Methods
337  *
338  * Methods that are reimplemented of the QTreeView class.
339  */
340  //@{
341  void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
342 
343  void dropEvent(QDropEvent * event);
344 
345  void mouseDoubleClickEvent(QMouseEvent* event);
346  //@}
347 
348  LayerItemModel* m_model; //!< Model to be used.
349  LayerViewMenuManager* m_mnuMger; //!< Default popup handler.
350  QObject* m_outterFilter; //!< Popup handler defined outside the tree.
351  };
352  }
353  }
354 }
355 
356 #endif //__TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMVIEW_H
This is the base class for layers.
Definition: AbstractLayer.h:77
A wdiget used to customize a chart&#39;s style parameters.
LayerItemModel * m_model
Model to be used.
TerraLib.
Defines an abstract model based on TreeItem objects.
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
QObject * m_outterFilter
Popup handler defined outside the tree.
Class for manage the menus of the LayerViewItem.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
#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