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-2013 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  layers.push_back(te::map::AbstractLayerPtr(children[i]));
99  }
100  }
101 
102  return layers;
103 }
104 
105 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getSingleLayers(bool invalid)
106 {
107  std::list<te::map::AbstractLayerPtr> singleLayers;
108 
109  std::list<te::map::AbstractLayerPtr> allLayers = getAllLayers(invalid);
110 
111  std::list<te::map::AbstractLayerPtr>::const_iterator it;
112 
113  for(it = allLayers.begin(); it != allLayers.end(); ++it)
114  {
115  te::map::AbstractLayerPtr layer = *it;
116  if(layer->getType() == "FOLDERLAYER")
117  continue;
118 
119  singleLayers.push_back(te::map::AbstractLayerPtr(layer));
120  }
121 
122  return singleLayers;
123 }
124 
125 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getVisibleSingleLayers(bool invalid)
126 {
127  std::list<te::map::AbstractLayerPtr> visibleSingleLayers;
128 
129  std::list<te::map::AbstractLayerPtr> singleLayers = getSingleLayers(invalid);
130 
131  std::list<te::map::AbstractLayerPtr>::const_iterator it;
132  for(it = singleLayers.begin(); it != singleLayers.end(); ++it)
133  {
134  te::map::AbstractLayerPtr singleLayer = *it;
135 
136  if(singleLayer->getVisibility() == te::map::VISIBLE)
137  visibleSingleLayers.push_back(singleLayer);
138  }
139 
140  return visibleSingleLayers;
141 }
142 
143 void te::qt::af::Project::setTopLayers(const std::list<te::map::AbstractLayerPtr>& layers)
144 {
145  m_topLayers.clear();
146  m_topLayers = layers;
147 }
148 
149 const std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getSelectedLayers(bool invalid) const
150 {
151  if(!invalid)
152  {
153  std::list<te::map::AbstractLayerPtr>::const_iterator it = m_selectedLayers.begin();
154 
155  std::list<te::map::AbstractLayerPtr> validLayers;
156 
157  while(it != m_selectedLayers.end())
158  {
159  if(it->get()->isValid())
160  validLayers.push_back(it->get());
161 
162  ++it;
163  }
164 
165  return validLayers;
166  }
167  else
168  {
169  return m_selectedLayers;
170  }
171 }
172 
173 void te::qt::af::Project::setSelectedLayers(const std::list<te::map::AbstractLayerPtr>& selectedLayers)
174 {
175  m_selectedLayers.clear();
176 
177  m_selectedLayers = selectedLayers;
178 }
179 
181 {
182  if(!parentLayer)
183  m_topLayers.push_back(layer);
184  else
185  parentLayer->add(layer);
186 
187  m_changed = true;
188 }
189 
191 {
192  te::map::AbstractLayerPtr parentLayer = static_cast<te::map::AbstractLayer*>(layer->getParent());
193 
194  if(!parentLayer)
195  m_topLayers.remove(layer);
196  else
197  parentLayer->remove(layer->getIndex());
198 
199  m_changed = true;
200 }
201 
203 {
204  return m_changed;
205 }
206 
207 void te::qt::af::Project::setFileName(const std::string& fName)
208 {
209  m_fileName = fName;
210  m_changed = true;
211 }
212 
213 const std::string& te::qt::af::Project::getFileName() const
214 {
215  return m_fileName;
216 }
217 
219 {
220  m_changed = changed;
221 }
222 
224 {
225  m_topLayers.clear();
226  m_changed = true;
227 }
bool hasChanged()
It informs if the project has changed.
Definition: Project.cpp:202
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:180
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:149
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:218
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:105
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:143
~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:207
void setSelectedLayers(const std::list< te::map::AbstractLayerPtr > &selectedLayers)
It sets all the layers that are selected.
Definition: Project.cpp:173
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:223
const std::string & getFileName() const
It gets the filename where the project is saved.
Definition: Project.cpp:213
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:125
void remove(const te::map::AbstractLayerPtr &layer)
It removes the specified layer from the project.
Definition: Project.cpp:190