All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LayerTreeModel.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 terralib/vp/qt/LayerTreeModel.h
22 
23  \brief The class that defines the model used in the Qt Model/View architecture
24 */
25 
26 #ifndef __TERRALIB_VP_QT_INTERNAL_LAYERTREEMODEL_H
27 #define __TERRALIB_VP_QT_INTERNAL_LAYERTREEMODEL_H
28 
29 // TerraLib
30 #include "../../maptools/AbstractLayer.h"
31 #include "../../qt/widgets/layer/explorer/AbstractTreeItem.h"
32 #include "../Config.h"
33 
34 // STL
35 #include <vector>
36 
37 //Qt
38 #include <QtCore/QAbstractItemModel>
39 
40 namespace te
41 {
42  namespace vp
43  {
44  class TEVPEXPORT LayerTreeModel : public QAbstractItemModel
45  {
46  Q_OBJECT
47 
48  public:
49 
50  /*!
51  \brief It constructs an item model with the given parent.
52 
53  \param layers The layers which will be associated to the model indexes.
54  \param parent The parent object.
55  */
56  LayerTreeModel(const std::list<te::map::AbstractLayerPtr>& layers, bool singleSelection = false, QObject * parent = 0);
57 
58  /*! Destructor */
59  ~LayerTreeModel();
60 
61  /*!
62  \brief It fetches more data for parent.
63 
64  \param parent The object used to fetch more data.
65 
66  \return It returns true if there is more data available for parent.
67  */
68  bool canFetchMore(const QModelIndex& parent) const;
69 
70  /*!
71  \brief It returns the number of columns for the children of the given parent.
72 
73  \param parent The parent index.
74 
75  \return The number of columns for the children of the given parent.
76  */
77  int columnCount(const QModelIndex& parent = QModelIndex()) const;
78 
79  /*!
80  \brief It returns the data stored under the given role for the item referred to by the index.
81 
82  \param index The item index.
83  \param role The role that is used by the view to indicate to the model which type of data it needs.
84 
85  \return The data stored under the given role for the item referred to by the index.
86  */
87  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
88 
89  /*!
90  \brief It fetches any available data for the items with the parent specified by the parent index.
91 
92  \param parent The object used to fetch available data.
93  */
94  void fetchMore(const QModelIndex& parent);
95 
96  /*!
97  \brief It returns the item flags for the given index.
98 
99  \param index The item index.
100 
101  \return The item flags for the given index.
102  */
103  Qt::ItemFlags flags(const QModelIndex& index) const;
104 
105  /*!
106  \brief It checks if the given index has children.
107 
108  \param parent The item index.
109 
110  \return It returns true if the given index has children.
111  */
112  bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
113 
114  /*!
115  \brief It returns the index of the item in the model specified by the given row, column and parent index.
116 
117  It will call createIndex() to generate model indexes that other components
118  can use to refer to items in the model.
119 
120  \param row The item row.
121  \param column The item column.
122  \param parent The parent index of the item.
123 
124  \return The item index.
125  */
126  QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
127 
128  /*!
129  \brief It returns the item parent of the given index, or QModelIndex(), if it has no parent.
130 
131  \param index The item index.
132 
133  \return The parent index of the item with the given index, or QModelIndex(), if it has no parent.
134  */
135  QModelIndex parent(const QModelIndex & index) const;
136 
137  /*!
138  \brief It returns the number of rows of the given parent.
139 
140  \param parent The parent index.
141 
142  \return The number of rows of the given parent.
143  */
144  int rowCount(const QModelIndex & parent = QModelIndex()) const;
145 
146  /*!
147  \brief It sets the role data for the item at index to value.
148 
149  \param index The item index.
150  \param value The value to be assigned to the item.
151  \param role The role used.
152 
153  \return It returns true if successful; otherwise, it returns false.
154 
155  \note The dataChanged() signal is emitted if the data was successfully set.
156  */
157  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
158 
159  /*!
160  \brief Returns the data for the given role and section in the header with the specified orientation.
161 
162  \param section The section number corresponds to the column number.
163  \param orientation This type is used to signify an object's orientation.
164  \param role The role used.
165 
166  \return The data for the given role and section in the header with the specified orientation.
167  */
168  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
169 
170  /*!
171  \brief It get the Layer selected and the Properties selected of the Layer
172 
173  \return It returns a map of Layers end Properties selected.
174  */
175  std::map<te::map::AbstractLayerPtr, std::vector<te::dt::Property*> > getSelected();
176 
177  void setLayerList(const std::list<te::map::AbstractLayerPtr>& layers);
178 
179  private:
180 
181  std::vector<te::qt::widgets::AbstractTreeItem*> m_items;
182  bool m_singleSelection; //!< If is single selection or multiselection
183  };
184  } // end namespace vp
185 } // end namespace te
186 
187 
188 #endif // __TERRALIB_VP_QT_INTERNAL_LAYERTREEMODEL_H
189 
#define TEVPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:64
std::vector< te::qt::widgets::AbstractTreeItem * > m_items
bool m_singleSelection
If is single selection or multiselection.