src/terralib/qt/plugins/addressgeocoding/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/addressgeocoding/Plugin.cpp
22 
23  \brief Plugin implementation for the Address Geocoding Qt Plugin widget.
24 */
25 
26 // TerraLib
27 #include "../../../addressgeocoding/qt/MainWindowDialog.h"
28 #include "../../../common/Config.h"
29 #include "../../../core/translator/Translator.h"
30 #include "../../../core/logger/Logger.h"
31 #include "../../af/ApplicationController.h"
32 #include "../../af/events/LayerEvents.h"
33 #include "../../af/Utils.h"
34 #include "Plugin.h"
35 
36 // QT
37 #include <QAction>
38 #include <QMenu>
39 #include <QMenuBar>
40 #include <QMessageBox>
41 
43  : QObject(),
44  te::core::CppPlugin(pluginInfo)
45 {
46 }
47 
49 {
50 }
51 
53 {
54  if(m_initialized)
55  return;
56 
57  TE_LOG_TRACE(TE_TR("TerraLib Qt Address Geocoding Plugin startup!"));
58 
59 // add plugin menu
60  QMenu* pluginMenu = te::qt::af::AppCtrlSingleton::getInstance().getMenu("Processing");
61 
62  m_action = new QAction(pluginMenu);
63  m_action->setText("Address Geocoding...");
64  m_action->setIcon(QIcon::fromTheme("addressgeocoding-icon"));
65  m_action->setObjectName("Processing.Address Geocoding");
66 
67  connect(m_action, SIGNAL(triggered(bool)), this, SLOT(onActionActivated(bool)));
68 
69 // Insert action before plugin manager action
70  QAction* pluginsSeparator = te::qt::af::AppCtrlSingleton::getInstance().findAction("ManagePluginsSeparator");
71  pluginMenu->insertAction(pluginsSeparator, m_action);
72 
74 
76 
77  m_initialized = true;
78 }
79 
81 {
82  if(!m_initialized)
83  return;
84 
85 // unregister actions
87 
88  TE_LOG_TRACE(TE_TR("TerraLib Qt Address Geocoding Plugin shutdown!"));
89 
90  m_initialized = false;
91 
92  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
93 }
94 
96 {
97  QWidget* parent = te::qt::af::AppCtrlSingleton::getInstance().getMainWindow();
99 
100  // get the list of layers from current project
102 
103  emit triggered(&e);
104 
105  dlg.setLayers(e.m_layers);
106 
107  if(dlg.exec() != QDialog::Accepted)
108  return;
109 
110  te::map::AbstractLayerPtr layer = dlg.getLayer();
111 
112  if(layer.get() == 0)
113  return;
114 
115  int reply = QMessageBox::question(0, tr("Address Geocoding Result"), tr("The operation was concluded successfully. Would you like to add the layer to the project?"), QMessageBox::No, QMessageBox::Yes);
116 
117  if(reply == QMessageBox::Yes)
118  {
119  te::qt::af::evt::LayerAdded evt(layer);
120 
121  emit triggered(&evt);
122  }
123 }
124 
125 std::list<te::map::AbstractLayerPtr> te::qt::plugins::addressgeocoding::Plugin::getLayers()
126 {
128 
129  emit triggered(&e);
130 
131  return e.m_layers;
132 }
133 
134 
136 {
137  delete m_action;
138 }
139 
This event signals that a new layer was created.
Definition: LayerEvents.h:71
void unRegisterActions()
Function used to unregister all addressgeocoding actions.
std::list< te::map::AbstractLayerPtr > getLayers()
Get the list of layers from app.
TEQTAFEXPORT void AddActionToCustomToolbars(te::qt::af::ApplicationController *appController, QAction *act)
Check QSettings for existance of act and adds it if necessary.
Plugin implementation for the SA Qt Plugin widget.
Basic information about a plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void startup()
This method will be called by applications to startup some plugin&#39;s functionality.
URI C++ Library.
Definition: Attributes.h:37
void onActionActivated(bool checked)
Slot function used when a action was selected.
#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 > m_layers
Definition: LayerEvents.h:345
#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 setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
void shutdown()
This method will be called by applicatons to shutdown plugin&#39;s functionality.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void triggered(te::qt::af::evt::Event *e)