src/terralib/ws/ogc/wms/qtplugin/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/ws/ogc/wms/qtplugin/Plugin.cpp
22 
23  \brief Plugin implementation for the OGC Web Coverage Service (WMS) data source widget.
24 
25  \author Emerson Moraes
26 */
27 
28 #include "Plugin.h"
29 
30 #include <iostream>
31 
32 #include "../../../../core/translator/Translator.h"
33 #include "../../../../core/logger/Logger.h"
34 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
35 #include "../../../../qt/widgets/datasource/core/DataSourceTypeManager.h"
36 #include "../../../../qt/af/events/ApplicationEvents.h"
37 #include "../../../../qt/af/events/LayerEvents.h"
38 #include "../../../../qt/af/ApplicationController.h"
39 #include "../../../../qt/widgets/layer/explorer/LayerItem.h"
40 #include "../../../../qt/widgets/layer/explorer/LayerItemView.h"
41 #include "../qt/WMSType.h"
42 
43 void GetAllWMSLayers(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  GetAllWMSLayers(view, idx, layersIdx);
58  else if(child->getType() == "LAYER")
59  {
60  if(((te::qt::widgets::LayerItem*)child)->getLayer()->getType() == "OGCWMSLAYER")
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),
82  m_delegate(nullptr)
83 {
84 }
85 
87 
89 {
90  if(m_initialized)
91  return;
92 
94 
95  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Map Service (WMS) widget startup!"));
96 
97  m_initialized = true;
98 
100 
101  updateDelegate(true);
102 }
103 
105 {
106  if(!m_initialized)
107  return;
108 
109  te::da::DataSourceInfoManager::getInstance().removeByType("WMS2");
111 
112  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Map Service (WMS) widget shutdown!"));
113 
114  m_initialized = false;
115 
116  updateDelegate(false);
117 
118  QModelIndexList wls;
119 
121 
122  emit triggered(&e);
123 
124  if(e.m_layerExplorer == nullptr)
125  return;
126 
127  GetAllWMSLayers(e.m_layerExplorer, QModelIndex(), wls);
128 
129  if(!wls.isEmpty())
130  {
131  std::list<te::map::AbstractLayerPtr> lst = GetLayers(wls);
132 
134 
135  te::qt::af::evt::LayerRemoved evt(lst, false);
136 
137  emit triggered(&evt);
138  }
139 
140  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
141 }
142 
144 {
146 
147  emit triggered(&e);
148 
150 
151  if(view == nullptr)
152  return;
153 
154  if(add)
155  {
156  m_delegate = new te::ws::ogc::wms::qt::WMSItemDelegate((QStyledItemDelegate*)view->itemDelegate(), this);
157  view->setItemDelegate(m_delegate);
158  }
159  else
160  {
161  view->removeDelegate(m_delegate);
162  delete m_delegate;
163  m_delegate = nullptr;
164  }
165 }
166 
void triggered(te::qt::af::evt::Event *e)
Plugin implementation for the OGC Web Coverage Service (WMS) data source widget.
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
te::qt::widgets::LayerItemView * m_layerExplorer
Basic information about a plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
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.
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
void shutdown()
This method will be called by applicatons to shutdown plugin&#39;s functionality.
#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...
std::list< te::map::AbstractLayerPtr > GetLayers(const QModelIndexList &lst)
void removeDelegate(QStyledItemDelegate *d)
Removes the delegate from the tree.
void GetAllWMSLayers(te::qt::widgets::LayerItemView *view, const QModelIndex &parent, QModelIndexList &layersIdx)
te::ws::ogc::wms::qt::WMSItemDelegate * m_delegate
#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
void startup()
This method will be called by applications to startup some plugin&#39;s functionality.
std::string getType() const
Returns the type of the item.