All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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()
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  layers.push_back(topLevelLayer);
87 
88  if(topLevelLayer->getType() == "FOLDERLAYER")
89  {
90  std::vector<te::map::AbstractLayer*> children = topLevelLayer->getDescendants();
91  for(std::size_t i = 0; i < children.size(); ++i)
92  layers.push_back(te::map::AbstractLayerPtr(children[i]));
93  }
94  }
95 
96  return layers;
97 }
98 
99 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getSingleLayers()
100 {
101  std::list<te::map::AbstractLayerPtr> singleLayers;
102 
103  std::list<te::map::AbstractLayerPtr> allLayers = getAllLayers();
104 
105  std::list<te::map::AbstractLayerPtr>::const_iterator it;
106 
107  for(it = allLayers.begin(); it != allLayers.end(); ++it)
108  {
109  te::map::AbstractLayerPtr layer = *it;
110 
111  if(layer->getType() == "FOLDERLAYER")
112  continue;
113 
114  singleLayers.push_back(te::map::AbstractLayerPtr(layer));
115  }
116 
117  return singleLayers;
118 }
119 
120 std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getVisibleSingleLayers()
121 {
122  std::list<te::map::AbstractLayerPtr> visibleSingleLayers;
123 
124  std::list<te::map::AbstractLayerPtr> singleLayers = getSingleLayers();
125 
126  std::list<te::map::AbstractLayerPtr>::const_iterator it;
127  for(it = singleLayers.begin(); it != singleLayers.end(); ++it)
128  {
129  te::map::AbstractLayerPtr singleLayer = *it;
130 
131  if(singleLayer->getVisibility() == te::map::VISIBLE)
132  visibleSingleLayers.push_back(singleLayer);
133  }
134 
135  return visibleSingleLayers;
136 }
137 
138 void te::qt::af::Project::setTopLayers(const std::list<te::map::AbstractLayerPtr>& layers)
139 {
140  m_topLayers.clear();
141  m_topLayers = layers;
142 }
143 
144 const std::list<te::map::AbstractLayerPtr> te::qt::af::Project::getSelectedLayers() const
145 {
146  return m_selectedLayers;
147 }
148 
149 void te::qt::af::Project::setSelectedLayers(const std::list<te::map::AbstractLayerPtr>& selectedLayers)
150 {
151  m_selectedLayers.clear();
152 
153  m_selectedLayers = selectedLayers;
154 }
155 
157 {
158  if(!parentLayer)
159  m_topLayers.push_back(layer);
160  else
161  parentLayer->add(layer);
162 
163  m_changed = true;
164 }
165 
167 {
168  te::map::AbstractLayerPtr parentLayer = static_cast<te::map::AbstractLayer*>(layer->getParent());
169 
170  if(!parentLayer)
171  m_topLayers.remove(layer);
172  else
173  parentLayer->remove(layer->getIndex());
174 
175  m_changed = true;
176 }
177 
179 {
180  return m_changed;
181 }
182 
183 void te::qt::af::Project::setFileName(const std::string& fName)
184 {
185  m_fileName = fName;
186 }
187 
188 const std::string& te::qt::af::Project::getFileName() const
189 {
190  return m_fileName;
191 }
192 
194 {
195  m_changed = changed;
196 }
197 
199 {
200  m_topLayers.clear();
201  setProjectAsChanged(true);
202 }
const std::string & getFileName() const
It gets the filename where the project is saved.
Definition: Project.cpp:188
bool hasChanged()
It informs if the project has changed.
Definition: Project.cpp:178
void setSelectedLayers(const std::list< te::map::AbstractLayerPtr > &selectedLayers)
It sets all the layers that are selected.
Definition: Project.cpp:149
const std::string & getAuthor() const
It gets the author of the project.
Definition: Project.cpp:62
This is the base class for layers.
Definition: AbstractLayer.h:76
std::list< te::map::AbstractLayerPtr > getAllLayers()
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:193
void clear()
It clears the project, setting it as having no layers.
Definition: Project.cpp:198
std::list< te::map::AbstractLayerPtr > getVisibleSingleLayers()
It gets all the single layers that are visible.
Definition: Project.cpp:120
void setTitle(const std::string &title)
It sets the title of the project.
Definition: Project.cpp:45
void setFileName(const std::string &fName)
It sets the filename where the project will be saved.
Definition: Project.cpp:183
const std::string & getTitle() const
It gets the title of the project.
Definition: Project.cpp:51
TreeItemPtr remove(std::size_t i)
It removes the i-th child.
Definition: TreeItem.cpp:116
~Project()
Destructor.
Definition: Project.cpp:40
std::list< te::map::AbstractLayerPtr > getSingleLayers()
It gets all the single layers of the project.
Definition: Project.cpp:99
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:156
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
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
This class models the concept of a project for the TerraLib Application Framework.
void remove(const te::map::AbstractLayerPtr &layer)
It removes the specified layer from the project.
Definition: Project.cpp:166
Project()
Constructor.
Definition: Project.cpp:32
void setTopLayers(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the top layers of the project.
Definition: Project.cpp:138
void setAuthor(const std::string &author)
It sets the author of the project.
Definition: Project.cpp:56
const std::list< te::map::AbstractLayerPtr > getSelectedLayers() const
It gets all the layers that are selected.
Definition: Project.cpp:144