All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Project.cpp
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/qt/af/Project.cpp
22 
23  \brief This class models the concept of a project for the TerraLib Application Framework.
24 */
25 
26 // TerraLib
27 #include "Project.h"
28 
29 // STL
30 #include <algorithm>
31 
33  : m_title(""),
34  m_author(""),
35  m_topLayers(),
36  m_changed(false)
37 {
38 }
39 
41 {
42 
43 }
44 
45 void te::qt::af::Project::setTitle(const std::string& title)
46 {
47  m_title = title;
48  m_changed = true;
49 }
50 
51 const std::string& te::qt::af::Project::getTitle() const
52 {
53  return m_title;
54 }
55 
56 void te::qt::af::Project::setAuthor(const std::string& author)
57 {
58  m_author = author;
59  m_changed = true;
60 }
61 
62 const std::string& te::qt::af::Project::getAuthor() const
63 {
64  return m_author;
65 }
66 
67 const std::list<te::map::AbstractLayerPtr>& te::qt::af::Project::getTopLayers() const
68 {
69  return m_topLayers;
70 }
71 
72 std::list<te::map::AbstractLayerPtr>& te::qt::af::Project::getTopLayers()
73 {
74  return m_topLayers;
75 }
76 
77 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getAllLayers(bool invalid)
78 {
79  std::list<te::map::AbstractLayerPtr> layers;
80 
81  std::list<te::map::AbstractLayerPtr>::const_iterator it;
82 
83  for(it = m_topLayers.begin(); it != m_topLayers.end(); ++it)
84  {
85  te::map::AbstractLayerPtr topLevelLayer = *it;
86 
87  if(!invalid && !topLevelLayer->isValid())
88  {
89  continue;
90  }
91 
92  layers.push_back(topLevelLayer);
93 
94  if(topLevelLayer->getType() == "FOLDERLAYER")
95  {
96  std::vector<te::map::AbstractLayer*> children = topLevelLayer->getDescendants();
97  for(std::size_t i = 0; i < children.size(); ++i)
98  {
99  if(!invalid && !children[i]->isValid())
100  {
101  continue;
102  }
103 
104  layers.push_back(te::map::AbstractLayerPtr(children[i]));
105  }
106 
107  }
108  }
109 
110  return layers;
111 }
112 
113 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getSingleLayers(bool invalid)
114 {
115  std::list<te::map::AbstractLayerPtr> singleLayers;
116 
117  std::list<te::map::AbstractLayerPtr> allLayers = getAllLayers(invalid);
118 
119  std::list<te::map::AbstractLayerPtr>::const_iterator it;
120 
121  for(it = allLayers.begin(); it != allLayers.end(); ++it)
122  {
123  te::map::AbstractLayerPtr layer = *it;
124  if(layer->getType() == "FOLDERLAYER")
125  continue;
126 
127  singleLayers.push_back(te::map::AbstractLayerPtr(layer));
128  }
129 
130  return singleLayers;
131 }
132 
133 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getVisibleSingleLayers(bool invalid)
134 {
135  std::list<te::map::AbstractLayerPtr> visibleSingleLayers;
136 
137  std::list<te::map::AbstractLayerPtr> singleLayers = getSingleLayers(invalid);
138 
139  std::list<te::map::AbstractLayerPtr>::const_iterator it;
140  for(it = singleLayers.begin(); it != singleLayers.end(); ++it)
141  {
142  te::map::AbstractLayerPtr singleLayer = *it;
143 
144  if(singleLayer->getVisibility() == te::map::VISIBLE)
145  visibleSingleLayers.push_back(singleLayer);
146  }
147 
148  return visibleSingleLayers;
149 }
150 
151 void te::qt::af::Project::setTopLayers(const std::list<te::map::AbstractLayerPtr>& layers)
152 {
153  m_topLayers.clear();
154  m_topLayers = layers;
155 }
156 
157 const std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getSelectedLayers(bool invalid) const
158 {
159  if(!invalid)
160  {
161  std::list<te::map::AbstractLayerPtr>::const_iterator it = m_selectedLayers.begin();
162 
163  std::list<te::map::AbstractLayerPtr> validLayers;
164 
165  while(it != m_selectedLayers.end())
166  {
167  if(it->get()->isValid())
168  validLayers.push_back(it->get());
169 
170  ++it;
171  }
172 
173  return validLayers;
174  }
175  else
176  {
177  return m_selectedLayers;
178  }
179 }
180 
181 void te::qt::af::Project::setSelectedLayers(const std::list<te::map::AbstractLayerPtr>& selectedLayers)
182 {
183  m_selectedLayers.clear();
184 
185  m_selectedLayers = selectedLayers;
186 }
187 
189 {
190  if(!parentLayer)
191  m_topLayers.push_back(layer);
192  else
193  parentLayer->add(layer);
194 
195  m_changed = true;
196 }
197 
199 {
200  te::map::AbstractLayerPtr parentLayer = static_cast<te::map::AbstractLayer*>(layer->getParent());
201 
202  if(!parentLayer)
203  m_topLayers.remove(layer);
204  else
205  parentLayer->remove(layer->getIndex());
206 
207  m_changed = true;
208 }
209 
211 {
212  return m_changed;
213 }
214 
215 void te::qt::af::Project::setFileName(const std::string& fName)
216 {
217  m_fileName = fName;
218  m_changed = true;
219 }
220 
221 const std::string& te::qt::af::Project::getFileName() const
222 {
223  return m_fileName;
224 }
225 
227 {
228  m_changed = changed;
229 }
230 
232 {
233  m_topLayers.clear();
234  m_changed = true;
235 }
bool hasChanged()
It informs if the project has changed.
Definition: Project.cpp:210
const std::string & getTitle() const
It gets the title of the project.
Definition: Project.cpp:51
void add(const te::map::AbstractLayerPtr &layer, const te::map::AbstractLayerPtr &parentLayer=te::map::AbstractLayerPtr())
It adds the specified layer to the list of layers of the parent layer. If the parent layer is not spe...
Definition: Project.cpp:188
This is the base class for layers.
Definition: AbstractLayer.h:76
Project()
Constructor.
Definition: Project.cpp:32
This class models the concept of a project for the TerraLib Application Framework.
const std::list< te::map::AbstractLayerPtr > & getTopLayers() const
It gets all the top layers of the project (folder and single layers).
Definition: Project.cpp:67
const std::list< te::map::AbstractLayerPtr > getSelectedLayers(bool invalid=true) const
It gets all the layers that are selected.
Definition: Project.cpp:157
std::list< te::map::AbstractLayerPtr > getAllLayers(bool invalid=true)
It gets all the layers (single and folder layers) of the project.
Definition: Project.cpp:77
void setProjectAsChanged(const bool &changed)
It sets the project status as changed or not.
Definition: Project.cpp:226
void setTitle(const std::string &title)
It sets the title of the project.
Definition: Project.cpp:45
TreeItemPtr remove(std::size_t i)
It removes the i-th child.
Definition: TreeItem.cpp:116
std::list< te::map::AbstractLayerPtr > getSingleLayers(bool invalid=true)
It gets all the single layers of the project.
Definition: Project.cpp:113
void setAuthor(const std::string &author)
It sets the author of the project.
Definition: Project.cpp:56
void setTopLayers(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the top layers of the project.
Definition: Project.cpp:151
~Project()
Destructor.
Definition: Project.cpp:40
void setFileName(const std::string &fName)
It sets the filename where the project will be saved.
Definition: Project.cpp:215
void setSelectedLayers(const std::list< te::map::AbstractLayerPtr > &selectedLayers)
It sets all the layers that are selected.
Definition: Project.cpp:181
const std::string & getAuthor() const
It gets the author of the project.
Definition: Project.cpp:62
void clear()
It clears the project, setting it as having no layers.
Definition: Project.cpp:231
const std::string & getFileName() const
It gets the filename where the project is saved.
Definition: Project.cpp:221
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::list< te::map::AbstractLayerPtr > getVisibleSingleLayers(bool invalid=true)
It gets all the single layers that are visible.
Definition: Project.cpp:133
void remove(const te::map::AbstractLayerPtr &layer)
It removes the specified layer from the project.
Definition: Project.cpp:198