Loading...
Searching...
No Matches
LayerItemModel.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5TerraLib is free software: you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation, either version 3 of the License,
8or (at your option) any later version.
9
10TerraLib is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License
16along with TerraLib. See COPYING. If not, write to
17TerraLib Team at <terralib-team@terralib.org>.
18*/
19
20/*!
21 * \file LayerItemModel.h
22 *
23 * \brief Defines a layer item model for Qt5.
24 */
25#ifndef __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMMODEL_H
26#define __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMMODEL_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 <QAbstractItemModel>
37#include <QVariant>
38
39// STL
40#include <list>
41#include <memory>
42
43#ifndef Q_DECL_OVERRIDE
44 #define Q_DECL_OVERRIDE
45#endif
46
47
48// Forward declarations
49namespace te
50{
51 namespace qt
52 {
53 namespace widgets
54 {
55 class TreeItem;
56
57 /*!
58 * \class LayerItemModel
59 *
60 * \brief Defines an abstract model based on TreeItem objects.
61 *
62 * Models are used by the item views of the Qt5 that represents some data structure. Its used for manipulate models
63 * using a view. This is part of the Model / View framework of the Qt5.
64 *
65 * \sa TreeItem, te::map::AbstractLayer
66 *
67 * \ingroup widgets
68 */
69 class TEQTWIDGETSEXPORT LayerItemModel: public QAbstractItemModel
70 {
71 Q_OBJECT
72
73 public:
74 /*!
75 * \name Instantiation Methods
76 *
77 * Methods related to creation and destruction of the object.
78 */
79 //@{
80
81 /*!
82 * \brief Constructor.
83 *
84 * \param parent Model parent (Used by Qt5).
85 */
86 explicit LayerItemModel(QObject *parent = 0);
87
88 /*!
89 * \brief Destructor.
90 */
92 //@}
93
94 /*!
95 * \name Update Methods
96 *
97 * Methods used for feed the model.
98 */
99 //@{
100
101 /*!
102 * \brief Adds a layer to the model at the end of children list.
103 *
104 * \param layer The layer to be added.
105 *
106 * \param idxPath Unused.
107 */
108 void addLayer(te::map::AbstractLayerPtr layer, const std::string& idxPath = "./");
109
110 /*!
111 * \brief Adds the layer to the model.
112 *
113 * \param layer Layer to be added.
114 *
115 * \param parent Parent of the new LayerItem.
116 *
117 * \param idxPath Unused.
118 */
119 void addLayer(te::map::AbstractLayerPtr layer, const QModelIndex& parent, const std::string& idxPath = "./");
120
121 /*!
122 * \brief Adds a list of layers to the model at the end of children list.
123 *
124 * \param layers The layer list to be added.
125 *
126 * \param idxPath Unused.
127 */
128 void addLayers(const std::list<te::map::AbstractLayerPtr>& layers, const std::string& idxPath = "./");
129
130 /*!
131 * \brief Adds a list of layers to the model.
132 *
133 * \param layers The layer list to be added.
134 *
135 * \param parent The parent of the new LayerItems.
136 *
137 * \param idxPath Unused.
138 */
139 void addLayers(const std::list<te::map::AbstractLayerPtr>& layers, const QModelIndex& parent, const std::string& idxPath = "./");
140
141 /*!
142 * \brief Updates the list of layers in the model.
143 *
144 * \param layers The new set of layers to be set to the model.
145 *
146 * \note Older items are removed from the model.
147 */
148 void setLayers(const std::list<te::map::AbstractLayerPtr>& layers);
149
150 /*!
151 * \brief Adds the set of items to the \a parent at the position \a pos.
152 *
153 * These methods is used when you needs to reparent some items. It is a common operation on the view,
154 * like a drag and drop operation, for example. The \a items are removed from its parents and added
155 * in the \a parent, as children.
156 *
157 * \param items The items to be reparent.
158 *
159 * \param parent The new parent, where the items must be inserted.
160 *
161 * \param pos The position where the items must be inserted.
162 *
163 * \note If \a pos is greater than the size of the list of children, items are, then, added to end of the
164 * list of children.
165 *
166 * \note If you want to add items to the root, try to pass "0" as value for \a parent argument.
167 */
168 void addItems(const std::vector<TreeItem*> items, TreeItem* parent, const int& pos = 0);
169
170 /*!
171 * \brief Adds a new folder item to the model.
172 *
173 * \param name Label of the folder.
174 *
175 * \param parent Parent item. If this value is "0" the folder is added to the root of the model.
176 */
177 void addFolder(const std::string& name, TreeItem* parent = 0);
178
179 /*!
180 * \brief Adds a new folder item to the model.
181 *
182 * \param name Label of the folder.
183 *
184 * \param idx The parent of the new FolderItem.
185 */
186 void addFolder(const std::string& name, const QModelIndex& idx);
187 //@}
188
189 /*!
190 * \name Getter Methods
191 *
192 * Methods used for get items from the model.
193 */
194 //@{
195
196 /*!
197 * \brief Get all layers contained in the model. Commonly used for persistent pourposes.
198 *
199 * \return A list with all layers containded in the model.
200 */
201 std::list<te::map::AbstractLayerPtr> getAllLayers();
202
203 /*!
204 * \brief Returns a list with layers that are visible.
205 *
206 * \return List of visible layers.
207 *
208 * \note Folder layers are not contained in the returned list.
209 */
210 std::list<te::map::AbstractLayerPtr> getVisibleLayers();
211 //@}
212
213 /*!
214 * \name Reimplementation of QAbstractItemModel
215 *
216 * Methods reimplemented of the QAbstractItemModel class.
217 */
218 //@{
219 QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
220
221 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
222
223 QVariant headerData(int section, Qt::Orientation orientation,
224 int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
225
226 QModelIndex index(int row, int column,
227 const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
228
229 QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
230
231 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
232
233 int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
234
235 bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) Q_DECL_OVERRIDE;
236
237 bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()) Q_DECL_OVERRIDE;
238
239 bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) Q_DECL_OVERRIDE;
240
241 Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
242
243 QStringList mimeTypes() const Q_DECL_OVERRIDE;
244
245 QMimeData* mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
246
247 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
248
249 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
250 //@}
251
252 /*!
253 * \brief Removes the items in \a lst from the model.
254 *
255 * \param lst List of indexes of the items to be removed.
256 */
257 void removeItems(const QModelIndexList& lst);
258
259 Q_SIGNALS:
260
261 /*!
262 * \name Qt signals
263 *
264 * Signals emitted by LayerItemModel
265 */
266 //@{
267
268 /*!
269 * \brief Signal emited when an item visibility has changed.
270 */
271 void visibilityChanged();
272
273 void styleVisibilityChanged(te::map::AbstractLayerPtr layer);
274 //@}
275
276 protected:
277
278 std::unique_ptr<TreeItem> m_root; //!< The root item of the model.
279 };
280 }
281 }
282}
283
284#endif // __TERRALIB_QT_WIDGETS_LAYER_INTERNAL_LAYERITEMMODEL_H
#define Q_DECL_OVERRIDE
Defines an abstract model based on TreeItem objects.
void addFolder(const std::string &name, TreeItem *parent=0)
Adds a new folder item to the model.
std::list< te::map::AbstractLayerPtr > getVisibleLayers()
Returns a list with layers that are visible.
void addFolder(const std::string &name, const QModelIndex &idx)
Adds a new folder item to the model.
void addItems(const std::vector< TreeItem * > items, TreeItem *parent, const int &pos=0)
Adds the set of items to the parent at the position pos.
Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE
std::list< te::map::AbstractLayerPtr > getAllLayers()
Get all layers contained in the model. Commonly used for persistent pourposes.
void addLayers(const std::list< te::map::AbstractLayerPtr > &layers, const std::string &idxPath="./")
Adds a list of layers to the model at the end of children list.
void addLayers(const std::list< te::map::AbstractLayerPtr > &layers, const QModelIndex &parent, const std::string &idxPath="./")
Adds a list of layers to the model.
void addLayer(te::map::AbstractLayerPtr layer, const std::string &idxPath="./")
Adds a layer to the model at the end of children list.
LayerItemModel(QObject *parent=0)
Constructor.
void addLayer(te::map::AbstractLayerPtr layer, const QModelIndex &parent, const std::string &idxPath="./")
Adds the layer to the model.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE
void setLayers(const std::list< te::map::AbstractLayerPtr > &layers)
Updates the list of layers in the model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const Q_DECL_OVERRIDE
Defines a hierarchical structure.
Definition: TreeItem.h:73
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TerraLib.
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63