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/Rule.h"
24 #include "../../../se/Utils.h"
25 #include "../../widgets/layer/explorer/LayerItem.h"
26 #include "../../widgets/layer/explorer/LayerItemView.h"
27 #include "../events/Event.h"
28 #include "../events/ApplicationEvents.h"
29 #include "../events/LayerEvents.h"
30 #include "../ApplicationController.h"
31 #include "LayerExplorer.h"
32 
33 
34 std::list<te::map::AbstractLayerPtr> GetSelectedLayers(QTreeView* view)
35 {
36  std::list<te::map::AbstractLayerPtr> res;
37 
38  QModelIndexList lst = view->selectionModel()->selectedIndexes();
39 
40  for(QModelIndexList::iterator it = lst.begin(); it != lst.end(); ++it)
41  {
42  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>((*it).internalPointer());
43 
44  if(item->getType() == "LAYER")
45  res.push_back(((te::qt::widgets::LayerItem*)item)->getLayer());
46  }
47 
48  return res;
49 }
50 
51 void GetAvailableLayers(const QModelIndex& parent, te::qt::widgets::LayerItemView* view, std::list<te::map::AbstractLayerPtr>& layers)
52 {
53  int s = view->model()->rowCount(parent);
54 
55  for(int i = 0; i < s; i++)
56  {
57  QModelIndex childIdx = view->model()->index(i, 0, parent);
58 
59  if(childIdx.isValid())
60  {
61  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(childIdx.internalPointer());
62 
63  if(item->getType() == "LAYER")
64  layers.push_back(((te::qt::widgets::LayerItem*)item)->getLayer());
65  else if(item->getType() == "FOLDER")
66  GetAvailableLayers(childIdx, view, layers);
67  }
68  }
69 }
70 
72  : QObject(parent),
73  m_explorer(explorer)
74 {
75  assert(m_explorer);
76 
77  connect(m_explorer, SIGNAL(selectedLayersChanged(std::list<te::map::AbstractLayerPtr>)), SLOT(onSelectedLayersChanged(std::list<te::map::AbstractLayerPtr>)));
78  connect(m_explorer, SIGNAL(visibilityChanged()), SLOT(onLayerVisibilityChanged()));
79  connect(m_explorer, SIGNAL(styleVisibilityChanged(te::map::AbstractLayerPtr)), SLOT(onStyleVisibilityChanged(te::map::AbstractLayerPtr)));
80  connect(m_explorer, SIGNAL(layerOrderChanged()), SLOT(onLayerOrderChanged()));
82  connect(m_explorer, SIGNAL(styleDoubleClicked(te::map::AbstractLayerPtr)), SLOT(onStyleItemDoubleClicked(te::map::AbstractLayerPtr)));
84 }
85 
87 
89 {
90  return m_explorer;
91 }
92 
94 {
95  switch(evt->m_id)
96  {
98  {
99  }
100  break;
101 
103  {
105  std::list<te::map::AbstractLayerPtr> layers;
106  QModelIndexList lst = m_explorer->selectionModel()->selectedIndexes();
107 
108  layers.push_back(e->m_layer);
109 
110  QModelIndex par;
111  if(!lst.isEmpty())
112  par = *lst.begin();
113 
114  if(par.isValid())
115  {
116  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(par.internalPointer());
117 
118  if(item->getType() == "FOLDER")
119  {
120  m_explorer->addLayers(layers, par);
121  m_explorer->expand(par);
122  }
123  else
124  m_explorer->addLayers(layers, QModelIndex());
125  }
126  else
127  m_explorer->addLayers(layers, par);
128  }
129  break;
131  {
133  std::list<te::map::AbstractLayerPtr> layers = e->m_layers;
134  QModelIndexList lst = m_explorer->selectionModel()->selectedIndexes();
135 
136  QModelIndex par;
137  if (!lst.isEmpty())
138  par = *lst.begin();
139 
140  if (par.isValid())
141  {
142  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(par.internalPointer());
143 
144  if (item->getType() == "FOLDER")
145  {
146  m_explorer->addLayers(layers, par);
147  m_explorer->expand(par);
148  }
149  else
150  m_explorer->addLayers(layers, QModelIndex());
151  }
152  else
153  m_explorer->addLayers(layers, par);
154  }
155  break;
157  {
158  }
159  break;
160 
162  {
164 
165  QAction* action = e->m_action;
166 
167  if (e->m_itemType == "RASTER_LAYER_ITEM")
168  {
170  }
171  }
172  break;
173 
175  {
177 
178  m_explorer->removeAction(e->m_action);
179  }
180  break;
181 
183  {
185 
186  std::list<te::map::AbstractLayerPtr> list = GetSelectedLayers(m_explorer);
187 
188  if(list.empty() == false)
189  e->m_layer = list.front();
190  }
191  break;
192 
194  {
196  GetAvailableLayers(QModelIndex(), m_explorer, e->m_layers);
197  }
198  break;
199 
201  {
204  }
205 
206  default:
207  break;
208  }
209 }
210 
211 void te::qt::af::LayerExplorer::onSelectedLayersChanged(const std::list<te::map::AbstractLayerPtr>& selectedLayers)
212 {
213  if(selectedLayers.empty())
214  return;
215 
216  std::list<te::map::AbstractLayerPtr>::const_iterator it;
217  for(it = selectedLayers.begin(); it != selectedLayers.end(); ++it)
218  {
220  emit triggered(&ev);
221  }
222 }
223 
225 {
226  te::qt::af::evt::LayerVisibilityChanged layerVisibilityChangedEvent;
227  emit triggered(&layerVisibilityChangedEvent);
228 }
229 
231 {
232  te::qt::af::evt::LayerChanged e2(layer.get(), true);
233  emit triggered(&e2);
234 }
235 
237 {
238  //te::qt::af::evt::ProjectUnsaved projectUnsavedEvent;
239  //emit triggered(&projectUnsavedEvent);
240 }
241 
243  te::map::AbstractLayerPtr /*layer*/)
244 {
245 
246 }
247 
249 {
250  te::qt::af::evt::LayerStyleSelected layerStyleSelected(layer, nullptr);
251  emit triggered(&layerStyleSelected);
252 }
253 
255 {
256  te::qt::af::evt::LayerStyleSelected layerStyleSelected(layer, rule);
257  emit triggered(&layerStyleSelected);
258 }
This event signals that a new layer was created.
Definition: LayerEvents.h:71
te::map::AbstractLayerPtr m_layer
Layer selected.
Definition: LayerEvents.h:336
This event is used to get a single layer selected in layer tree.
Definition: LayerEvents.h:325
void onStyleVisibilityChanged(te::map::AbstractLayerPtr layer)
This event is used to add a action in a layer tree pop up.
Definition: LayerEvents.h:277
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
This event signals that a list of layers have been created.
Definition: LayerEvents.h:95
A base class for application events.
te::qt::widgets::LayerItemView * m_layerExplorer
std::list< te::map::AbstractLayerPtr > GetSelectedLayers(QTreeView *view)
void onRuleItemDoubleClicked(te::map::AbstractLayerPtr layer, te::se::Rule *rule)
void GetAvailableLayers(const QModelIndex &parent, te::qt::widgets::LayerItemView *view, std::list< te::map::AbstractLayerPtr > &layers)
QAction * m_action
Action to be removed in the pop up menu.
Definition: LayerEvents.h:317
This event indicates that the layer style was selected on the layer explorer.
Definition: LayerEvents.h:254
Defines a hierarchical structure.
te::qt::widgets::LayerItemView * getExplorer() const
void addLayers(const std::list< te::map::AbstractLayerPtr > &layers, const QModelIndex &idx, const std::string &idxPath="./")
Add the layers to the model.
void onStyleItemDoubleClicked(te::map::AbstractLayerPtr layer)
This event indicates that the layer has been selected.
Definition: LayerEvents.h:183
This event is used to remove a action in a layer tree pop up.
Definition: LayerEvents.h:304
te::qt::widgets::LayerItemView * m_explorer
Pointer to a component te::qt::widgets::LayerExplorer.
QAction * m_action
The action to be added in pop up menu.
Definition: LayerEvents.h:294
A connector for the te::qt::widgets::LayerExplorer class to the Application Framework.
This event signals that the layer visibility has changed.
Definition: LayerEvents.h:163
std::list< te::map::AbstractLayerPtr > m_layers
The layers to be added.
Definition: LayerEvents.h:110
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
LayerExplorer(te::qt::widgets::LayerItemView *explorer, QObject *parent=0)
Constructor.
void onApplicationTriggered(te::qt::af::evt::Event *evt)
Listener to the application framewrork events.
~LayerExplorer()
Destructor.
std::list< te::map::AbstractLayerPtr > m_layers
Definition: LayerEvents.h:345
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
void addRasterLayerAction(QAction *act)
Adds the action to the popup menu presented when the selected layer has raster representation.
te::map::AbstractLayerPtr m_layer
The layer to be added.
Definition: LayerEvents.h:86
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onTreeItemDoubleClicked(te::map::AbstractLayerPtr layer)
std::string m_itemType
The type of the selected item.
Definition: LayerEvents.h:295
std::string getType() const
Returns the type of the item.
void onSelectedLayersChanged(const std::list< te::map::AbstractLayerPtr > &selectedLayers)
It indicates whenever there are changes in the selection of layers in the layer explorer.
void triggered(te::qt::af::evt::Event *e)