All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LayerExplorer.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 TerraView - A GIS Application.
4 
5  TerraView is free software: you can redistribute it and/or modify
6  it under the terms of the GNU 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  TerraView 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 General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with TerraLib Code Editor. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@dpi.inpe.br>.
18  */
19 
20 // TerraLib
21 #include "../../../se/ColorMap.h"
22 #include "../../../se/RasterSymbolizer.h"
23 #include "../../../se/Utils.h"
24 #include "../../widgets/layer/explorer/AbstractTreeItem.h"
25 #include "../../widgets/layer/explorer/LayerExplorer.h"
26 #include "../../widgets/layer/explorer/LayerTreeModel.h"
27 #include "../../widgets/layer/explorer/LayerTreeView.h"
28 #include "../../widgets/layer/explorer/LegendItem.h"
29 #include "../events/Event.h"
30 #include "../events/ProjectEvents.h"
31 #include "../events/LayerEvents.h"
32 #include "../ApplicationController.h"
33 #include "../Project.h"
34 #include "LayerExplorer.h"
35 
37  : QObject(parent),
38  m_explorer(explorer)
39 {
40  assert(m_explorer);
41 
42  connect(m_explorer, SIGNAL(selectedLayersChanged(std::list<te::map::AbstractLayerPtr>)), SLOT(onSelectedLayersChanged(std::list<te::map::AbstractLayerPtr>)));
44  connect(m_explorer, SIGNAL(layerOrderChanged()), SLOT(onLayerOrderChanged()));
46 }
47 
49 {
50 }
51 
53 {
54  return m_explorer;
55 }
56 
58 {
59  switch(evt->m_id)
60  {
62  {
63  assert(m_explorer);
64 
65  te::qt::af::evt::ProjectAdded* projectAdded = static_cast<te::qt::af::evt::ProjectAdded*>(evt);
66 
67  if(projectAdded == 0 || projectAdded->m_proj == 0)
68  return;
69 
70  m_explorer->set(projectAdded->m_proj->getTopLayers());
71  }
72  break;
73 
75  {
77 
78  // Update the project
80 
82 
83  // Add the layer in the layer explorer
84  te::qt::widgets::AbstractTreeItem* parentItem = m_explorer->getLayerItem(parentLayer);
85 
86  m_explorer->add(e->m_layer, parentItem);
87 
88  if(parentItem)
89  m_explorer->expand(parentItem);
90 
91  te::qt::af::evt::ProjectUnsaved projectUnsavedEvent;
92  ApplicationController::getInstance().broadcast(&projectUnsavedEvent);
93  }
94  break;
95 
97  {
99 
101 
102  // Remove the item from the layer explorer
103  te::qt::widgets::AbstractTreeItem* layerItem = m_explorer->getLayerItem(layer);
104  m_explorer->remove(layerItem);
105 
107 
108  te::qt::af::evt::ProjectUnsaved projectUnsavedEvent;
109  ApplicationController::getInstance().broadcast(&projectUnsavedEvent);
110  }
111  break;
112 
114  {
116 
118 
119  te::map::AbstractLayerPtr layer = item->getLayer();
120 
121  te::qt::widgets::AbstractTreeItem* parentItem = static_cast<te::qt::widgets::AbstractTreeItem*>(item->parent());
122 
123  m_explorer->collapse(parentItem);
124 
125  te::map::AbstractLayerPtr parentLayer = parentItem->getLayer();
126 
127  if(item->getItemType() == "CHART_ITEM")
128  {
129  // If the item is a chart item, remove the chart from the layer associated to the parent of this chart item.
130  parentLayer->setChart(0);
131  }
132  else if(item->getItemType() == "GROUPING_ITEM")
133  {
134  // If the item is a chart item, remove the chart from the layer associated to the parent of this chart item.
135  parentLayer->setGrouping(0);
136  }
137  else if(item->getItemType() == "COLORMAP_ITEM")
138  {
139  // If the item is a color map item, remove the all style from the layer associated to the parent of this color map item.
140  //parentLayer->setStyle(0);
141 
142  te::se::RasterSymbolizer* rs = te::se::GetRasterSymbolizer(parentLayer->getStyle());
143 
144  rs->setColorMap(0);
145  }
146 
147  // Remove the item from the layer explorer
148  m_explorer->remove(item);
149 
150  te::qt::af::evt::ProjectUnsaved projectUnsavedEvent;
151  ApplicationController::getInstance().broadcast(&projectUnsavedEvent);
152  }
153  break;
154 
156  {
158 
159  QAction* action = e->m_action;
160 
161  m_explorer->add(action, "", e->m_itemType.c_str(), m_explorer->getMenuSelectionType(e->m_menuSelectionType));
162  }
163  break;
164 
166  {
168 
169  m_explorer->getTreeView()->remove(e->m_action);
170  }
171  break;
172 
174  {
176 
177  std::list<te::map::AbstractLayerPtr> list = m_explorer->getSelectedSingleLayers();
178 
179  if(list.empty() == false)
180  e->m_layer = list.front();
181  }
182  break;
183 
184  default:
185  break;
186  }
187 }
188 
189 void te::qt::af::LayerExplorer::onSelectedLayersChanged(const std::list<te::map::AbstractLayerPtr>& selectedLayers)
190 {
191  if(selectedLayers.empty())
192  return;
193 
195 
196  std::list<te::map::AbstractLayerPtr>::const_iterator it;
197  for(it = selectedLayers.begin(); it != selectedLayers.end(); ++it)
198  {
201  }
202 }
203 
205 {
206  te::qt::af::evt::LayerVisibilityChanged layerVisibilityChangedEvent(layer, layer->getVisibility());
207  ApplicationController::getInstance().broadcast(&layerVisibilityChangedEvent);
208 
209  te::qt::af::evt::ProjectUnsaved projectUnsavedEvent;
210  ApplicationController::getInstance().broadcast(&projectUnsavedEvent);
211 }
212 
214 {
215  ApplicationController::getInstance().getProject()->setTopLayers(m_explorer->getTopLayers());
216 
217  te::qt::af::evt::ProjectUnsaved projectUnsavedEvent;
218  ApplicationController::getInstance().broadcast(&projectUnsavedEvent);
219 }
220 
222 {
223  te::qt::widgets::LegendItem* legendItem = dynamic_cast<te::qt::widgets::LegendItem*>(item);
224  if(legendItem == 0)
225  return;
226 
227  te::qt::widgets::AbstractTreeItem* layerItem = dynamic_cast<te::qt::widgets::AbstractTreeItem*>(item->parent());
228  assert(layerItem);
229 
230  te::map::AbstractLayer* layer = layerItem->getLayer().get();
231  assert(layer);
232 
233  te::qt::af::evt::LayerStyleSelected layerStyleSelected(layer);
234  ApplicationController::getInstance().broadcast(&layerStyleSelected);
235 }
LayerExplorer(te::qt::widgets::LayerExplorer *explorer, QObject *parent=0)
Constructor.
A connector for the te::qt::widgets::LayerExplorer class to the Application Framework.
This event signals that a new layer was created.
Definition: LayerEvents.h:66
te::map::AbstractLayerPtr m_layer
Layer selected.
Definition: LayerEvents.h:308
This event is used to get a single layer selected in layer tree.
Definition: LayerEvents.h:297
This event is used to add a action in a layer tree pop up.
Definition: LayerEvents.h:249
void onLayerVisibilityChanged(te::map::AbstractLayerPtr layer)
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
It indicates that a new project was created.
Definition: ProjectEvents.h:47
Project * m_proj
Pointer to the new project.
Definition: ProjectEvents.h:60
A base class for application events.
Definition: Event.h:59
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:371
The class that represents an item in a LayerTreeModel.
QAction * m_action
Action to be removed in the pop up menu.
Definition: LayerEvents.h:289
This event indicates that the layer style was selected on the layer explorer.
Definition: LayerEvents.h:228
virtual const std::string getItemType() const =0
It returns the item type.
virtual te::map::AbstractLayerPtr getLayer() const =0
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
This event indicates that the layer has been selected.
Definition: LayerEvents.h:157
This event is used to remove a action in a layer tree pop up.
Definition: LayerEvents.h:276
te::map::AbstractLayerPtr m_parentLayer
The parent layer where the layer will be added.
Definition: LayerEvents.h:82
QAction * m_action
The action to be added in pop up menu.
Definition: LayerEvents.h:266
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
A widget designed to explore the layers of an application.
Definition: LayerExplorer.h:59
int m_id
Identifier.
Definition: Event.h:70
This event signals that the layer visibility has changed.
Definition: LayerEvents.h:132
void setTopLayers(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the top layers of the project.
Definition: Project.cpp:151
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
int m_menuSelectionType
The selection type of the context menu.
Definition: LayerEvents.h:268
void onTreeItemDoubleClicked(te::qt::widgets::AbstractTreeItem *item)
This event signals that a item belonging to a layer will be removed from the layer explorer...
Definition: LayerEvents.h:90
void onApplicationTriggered(te::qt::af::evt::Event *evt)
Listener to the application framewrork events.
It indicates that the project has unsaved changes.
Definition: ProjectEvents.h:68
void broadcast(te::qt::af::evt::Event *evt)
Send events in broadcast for all registered components.
te::qt::widgets::LayerExplorer * getExplorer() const
te::qt::af::Project * getProject()
Get the current project.
void setSelectedLayers(const std::list< te::map::AbstractLayerPtr > &selectedLayers)
It sets all the layers that are selected.
Definition: Project.cpp:181
te::map::AbstractLayerPtr m_layer
Layer removed.
Definition: LayerEvents.h:124
void setColorMap(ColorMap *c)
This event signals that a layer is to be removed from the layer explorer.
Definition: LayerEvents.h:111
te::map::AbstractLayerPtr m_layer
Tha layer to be added.
Definition: LayerEvents.h:81
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
te::qt::widgets::AbstractTreeItem * m_item
Item of the layer to be removed.
Definition: LayerEvents.h:103
std::string m_itemType
The type of the selected item.
Definition: LayerEvents.h:267
void onSelectedLayersChanged(const std::list< te::map::AbstractLayerPtr > &selectedLayers)
It indicates whenever there are changes in the selection of layers in the layer explorer.
te::qt::widgets::LayerExplorer * m_explorer
Pointer to a component te::qt::widgets::LayerExplorer.
void remove(const te::map::AbstractLayerPtr &layer)
It removes the specified layer from the project.
Definition: Project.cpp:198