attic/src/qt/plugins/datasource/wms/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/wms/Plugin.cpp
22 
23  \brief Plugin implementation for the OGC Web Map Service (WMS) data source widget.
24 */
25 #include "Plugin.h"
26 
27 // TerraLib
28 #include "../../../../common/Config.h"
29 #include "../../../../core/translator/Translator.h"
30 #include "../../../../core/logger/Logger.h"
31 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
32 #include "../../../af/ApplicationController.h"
33 #include "../../../af/events/ApplicationEvents.h"
34 #include "../../../af/events/LayerEvents.h"
35 #include "../../../widgets/Utils.h"
36 #include "../../../widgets/datasource/core/DataSourceTypeManager.h"
37 #include "../../../widgets/layer/explorer/LayerItem.h"
38 #include "../../../widgets/layer/explorer/LayerItemView.h"
39 #include "WMSItemDelegate.h"
40 #include "WMSType.h"
41 
42 // Boost
43 #include <boost/functional/factory.hpp>
44 #include <boost/bind.hpp>
45 
46 
47 void GetAllWMSLayers(te::qt::widgets::LayerItemView* view, const QModelIndex& parent,
48  QModelIndexList& layersIdx)
49 {
50  QAbstractItemModel* model = view->model();
51  int cS = model->rowCount(parent);
52 
53  for(int i = 0; i < cS; i++)
54  {
55  QModelIndex idx = model->index(i, 0, parent);
56 
58  static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer());
59 
60  if(child->getType() == "FOLDER")
61  GetAllWMSLayers(view, idx, layersIdx);
62  else if(child->getType() == "LAYER")
63  {
64  if(((te::qt::widgets::LayerItem*)child)->getLayer()->getType() == "WMSLAYER")
65  layersIdx.push_back(idx);
66  }
67  }
68 }
69 
70 std::list<te::map::AbstractLayerPtr> GetLayers(const QModelIndexList& lst)
71 {
72  std::list<te::map::AbstractLayerPtr> res;
73 
74  for(QModelIndexList::const_iterator it = lst.begin(); it != lst.end(); ++it)
75  {
76  QModelIndex idx = *it;
77  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer());
78  res.push_back(((te::qt::widgets::LayerItem*)item)->getLayer());
79  }
80 
81  return res;
82 }
83 
85  : QObject(),
86  te::core::CppPlugin(pluginInfo),
87  m_delegate(0)
88 {
89 }
90 
92 {
93 }
94 
96 {
97  if(m_initialized)
98  return;
99 
101 
102  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Map Service (WMS) widget startup!"));
103 
104  m_initialized = true;
105 
107 
108  updateDelegate(true);
109 }
110 
112 {
113  if(!m_initialized)
114  return;
115 
116  te::da::DataSourceInfoManager::getInstance().removeByType("WMS");
118 
119  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Map Service (WMS) widget shutdown!"));
120 
121  m_initialized = false;
122 
123  updateDelegate(false);
124 
125  QModelIndexList wls;
126 
128 
129  emit triggered(&e);
130 
131  if(e.m_layerExplorer == 0)
132  return;
133 
134  GetAllWMSLayers(e.m_layerExplorer, QModelIndex(), wls);
135 
136  if(!wls.isEmpty())
137  {
138  std::list<te::map::AbstractLayerPtr> lst = GetLayers(wls);
139 
141 
143 
144  emit triggered(&evt);
145  }
146 
147  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
148 }
149 
151 {
153 
154  emit triggered(&e);
155 
157 
158  if(view == 0)
159  return;
160 
161  if(add)
162  {
163  m_delegate = new WMSItemDelegate((QStyledItemDelegate*)view->itemDelegate(), this);
164  view->setItemDelegate(m_delegate);
165  }
166  else
167  {
168  view->removeDelegate(m_delegate);
169  delete m_delegate;
170  m_delegate = 0;
171  }
172 }
173 
174 
void startup()
This method will be called by applications to startup some plugin&#39;s functionality.
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
Plugin(const te::core::PluginInfo &pluginInfo)
void removeItems(const QModelIndexList &idxs)
Removes the items in the list.
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
std::list< te::map::AbstractLayerPtr > GetLayers(const QModelIndexList &lst)
#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 GetAllWMSLayers(te::qt::widgets::LayerItemView *view, const QModelIndex &parent, QModelIndexList &layersIdx)
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
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.
void triggered(te::qt::af::evt::Event *e)