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 
26 // TerraLib
27 #include "../../../../common/Config.h"
28 #include "../../../../common/Translator.h"
29 #include "../../../../common/Logger.h"
30 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
31 #include "../../../../wms/qt/WMSLayerItem.h"
32 #include "../../../widgets/datasource/core/DataSourceTypeManager.h"
33 #include "../../../widgets/layer/explorer/AbstractTreeItemFactory.h"
34 #include "../../../widgets/layer/explorer/LayerExplorer.h"
35 #include "../../../widgets/layer/explorer/LayerTreeModel.h"
36 #include "../../../af/ApplicationController.h"
37 #include "../../../af/BaseApplication.h"
38 #include "../../../af/connectors/LayerExplorer.h"
39 #include "WMSType.h"
40 #include "Plugin.h"
41 
42 // Qt
43 #include <QTreeView>
44 
45 // Boost
46 #include <boost/functional/factory.hpp>
47 #include <boost/bind.hpp>
48 
49 void GetWMSLayers(QAbstractItemModel* model, const QModelIndex& parent, std::list<te::qt::widgets::AbstractTreeItem*>& layers)
50 {
51  int cc = model->rowCount(parent);
52 
53  for(int i = 0; i < cc; i++)
54  {
55  QModelIndex cIdx = model->index(i, 0, parent);
56 
57  te::qt::widgets::AbstractTreeItem* cItem = static_cast<te::qt::widgets::AbstractTreeItem*>(cIdx.internalPointer());
58 
59  if(cItem->getItemType() == "WMS_LAYER_ITEM")
60  layers.push_back(cItem);
61  else if(cItem->getItemType() == "FOLDER_LAYER_ITEM")
62  GetWMSLayers(model, cIdx, layers);
63  }
64 }
65 
66 
68  : te::plugin::Plugin(pluginInfo)
69 {
70 }
71 
73 {
74 }
75 
77 {
78  if(m_initialized)
79  return;
80 
81  te::qt::widgets::AbstractTreeItemFactory::reg("WMSLAYER", boost::bind(boost::factory<te::wms::WMSLayerItem*>(), _1, _2));
82 
84 
85  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Map Service (WMS) widget startup!"));
86 
87  m_initialized = true;
88 }
89 
91 {
92  if(!m_initialized)
93  return;
94 
95  te::da::DataSourceInfoManager::getInstance().removeByType("WMS");
97 
98  TE_LOG_TRACE(TE_TR("TerraLib Qt OGC Web Map Service (WMS) widget shutdown!"));
99 
100  m_initialized = false;
101 
103 
104  if((exp == 0) || (exp->getExplorer() == 0) || exp->getExplorer()->getTreeModel())
105  return;
106 
107  std::list<te::qt::widgets::AbstractTreeItem*> wms;
108 
109  GetWMSLayers(exp->getExplorer()->getTreeModel(), QModelIndex(), wms);
110 
111  exp->removeLayers(wms);
112 }
113 
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
Definition: Logger.h:137
A connector for the te::qt::widgets::LayerExplorer class to the Application Framework.
Definition: LayerExplorer.h:70
The class that represents an item in a LayerTreeModel.
LayerTreeModel * getTreeModel() const
A QMainWindow to be used as the basis for TerraLib applications.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:346
virtual const std::string getItemType() const =0
It returns the item type.
static void reg(const std::string &key, const FactoryFnctType &f)
void removeLayers(const std::list< te::qt::widgets::AbstractTreeItem * > &items)
Plugin(const te::plugin::PluginInfo &pluginInfo)
Definition: Plugin.cpp:67
void GetWMSLayers(QAbstractItemModel *model, const QModelIndex &parent, std::list< te::qt::widgets::AbstractTreeItem * > &layers)
Definition: Plugin.cpp:49
#define PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
Definition: Config.h:54
static DataSourceTypeManager & getInstance()
It returns a reference to the singleton instance.
~Plugin()
Virtual destructor.
Definition: Plugin.cpp:72
URI C++ Library.
te::qt::widgets::LayerExplorer * getExplorer() const
void startup()
Do nothing! Just set plugin as started.
Definition: Plugin.cpp:76
Plugin implementation for the OGC Web Map Service (WMS) data source widget.
The basic information about a plugin.
Definition: PluginInfo.h:61
void shutdown()
Do nothing! Just set plugin as stopped.
Definition: Plugin.cpp:90
WMS data source type.