src/terralib/qt/plugins/datasource/wfs/Plugin.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/plugins/datasource/wfs/Plugin.cpp
22 
23  \brief Plugin implementation for the OGC Web Feature Service (WFS) data source widget.
24 */
25 
26 // TerraLib
27 #include "../../../../common/Config.h"
28 #include "../../../../core/translator/Translator.h"
29 #include "../../../../core/logger/Logger.h"
30 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
31 #include "../../../../maptools/AbstractLayer.h"
32 #include "../../../af/ApplicationController.h"
33 #include "../../../af/events/ApplicationEvents.h"
34 #include "../../../af/events/LayerEvents.h"
35 #include "../../../widgets/datasource/core/DataSourceTypeManager.h"
36 #include "../../../widgets/layer/explorer/LayerItem.h"
37 #include "../../../widgets/layer/explorer/LayerItemView.h"
38 #include "WFSItemDelegate.h"
39 #include "WFSType.h"
40 #include "Plugin.h"
41 #include "../../../../wfs/Utils.h"
42 
43 void GetAllWFSLayers(te::qt::widgets::LayerItemView* view, const QModelIndex& parent,
44  QModelIndexList& layersIdx)
45 {
46  QAbstractItemModel* model = view->model();
47  int cS = model->rowCount(parent);
48 
49  for(int i = 0; i < cS; i++)
50  {
51  QModelIndex idx = model->index(i, 0, parent);
52 
54  static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer());
55 
56  if(child->getType() == "FOLDER")
57  GetAllWFSLayers(view, idx, layersIdx);
58  else if(child->getType() == "LAYER")
59  {
60  if(te::wfs::IsWFSLayer(*((te::qt::widgets::LayerItem*)child)->getLayer()))
61  layersIdx.push_back(idx);
62  }
63  }
64 }
65 
66 std::list<te::map::AbstractLayerPtr> GetLayers(const QModelIndexList& lst)
67 {
68  std::list<te::map::AbstractLayerPtr> res;
69 
70  for(QModelIndexList::const_iterator it = lst.begin(); it != lst.end(); ++it)
71  {
72  QModelIndex idx = *it;
73  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer());
74  res.push_back(((te::qt::widgets::LayerItem*)item)->getLayer());
75  }
76 
77  return res;
78 }
79 
81  : te::core::CppPlugin(pluginInfo), m_delegate(nullptr)
82 {
83 }
84 
86 
88 {
89  if(m_initialized)
90  return;
91 
93 
94  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Feature Service (WFS) widget startup!"));
95 
96  m_initialized = true;
97 
99 
100  updateDelegate(true);
101 }
102 
104 {
105  if(!m_initialized)
106  return;
107 
108  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Feature Service (WFS) widget shutdown!"));
109 
110  m_initialized = false;
111 
112  updateDelegate(false);
113 
114  QModelIndexList wls;
115 
117 
118  emit triggered(&e);
119 
120  if(e.m_layerExplorer == nullptr)
121  return;
122 
123  GetAllWFSLayers(e.m_layerExplorer, QModelIndex(), wls);
124 
125  if(!wls.isEmpty())
126  {
127  std::list<te::map::AbstractLayerPtr> lst = GetLayers(wls);
128 
130  }
131 
132  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
133 
134  te::da::DataSourceInfoManager::getInstance().removeByType("WFS");
136 }
137 
139 {
141 
142  emit triggered(&e);
143 
145 
146  if(view == nullptr)
147  return;
148 
149  if(add)
150  {
151  m_delegate = new WFSItemDelegate((QStyledItemDelegate*)view->itemDelegate(), this);
152  view->setItemDelegate(m_delegate);
153  }
154  else
155  {
156  view->removeDelegate(m_delegate);
157  delete m_delegate;
158  m_delegate = nullptr;
159  }
160 }
161 
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
te::qt::widgets::LayerItemView * m_layerExplorer
void GetAllWFSLayers(te::qt::widgets::LayerItemView *view, const QModelIndex &parent, QModelIndexList &layersIdx)
Basic information about a plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::list< te::map::AbstractLayerPtr > GetLayers(const QModelIndexList &lst)
Defines a hierarchical structure.
static DataSourceTypeManager & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
void removeItems(const QModelIndexList &idxs)
Removes the items in the list.
void triggered(te::qt::af::evt::Event *e)
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
Plugin implementation for the OGC Web Feature Service (WFS) data source widget.
#define TERRALIB_PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
void startup()
This method will be called by applications to startup some plugin&#39;s functionality.
void removeDelegate(QStyledItemDelegate *d)
Removes the delegate from the tree.
#define TE_LOG_TRACE(message)
Use this tag in order to log a message to the TerraLib default logger with the TRACE level...
Definition: Logger.h:293
WFS data source type.
TEWFSEXPORT bool IsWFSLayer(const te::map::AbstractLayer &layer)
void shutdown()
This method will be called by applicatons to shutdown plugin&#39;s functionality.
std::string getType() const
Returns the type of the item.