src/terralib/qt/plugins/datasource/pgisRaster/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/pgisRaster/Plugin.cpp
22 
23  \brief Plugin implementation for the PostGIS Raster 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 "../../../widgets/datasource/core/DataSourceTypeManager.h"
32 #include "../../../widgets/datasource/selector/DataSourceSelectorDialog.h"
33 #include "../../../widgets/datasource/selector/DataSourceSelectorWidget.h"
34 #include "../../../af/ApplicationController.h"
35 #include "../../../af/events/ApplicationEvents.h"
37 #include "PostGISType.h"
38 #include "Plugin.h"
39 #include "Utils.h"
40 
41 // Qt
42 #include <QAction>
43 #include <QMessageBox>
44 #include <QToolBar>
45 
47  const te::core::PluginInfo& pluginInfo)
48  :
49 
50  te::core::CppPlugin(pluginInfo),
51  m_openPostGISRasterSelector(nullptr)
52 {
54 }
55 
57 
59 {
60  if(m_initialized)
61  return;
62 
63  TE_LOG_TRACE(TE_TR("TerraLib Qt PostGIS widget startup!"));
64 
65  m_initialized = true;
66 
67  //Initializing action
68  m_openPostGISRasterSelector = new QAction(QIcon::fromTheme("datasource-postgis"), tr("PostGIS Raster..."), this);
69  m_openPostGISRasterSelector->setToolTip(tr("Add new PostGIS Raster as a layer."));
70  m_openPostGISRasterSelector->setObjectName("Project.Add Layer.PostGIS Raster");
71 
73  e.m_category = "Dataaccess";
75 
76  emit triggered(&e);
77 
79 
80  //register actions into application tool bar
81  QToolBar* toolBar = te::qt::af::AppCtrlSingleton::getInstance().getToolBar("File Tool Bar");
82 
83  if (toolBar)
84  toolBar->addAction(m_openPostGISRasterSelector);
85 
86 }
87 
89 {
90  if(!m_initialized)
91  return;
92 
93  te::da::DataSourceInfoManager::getInstance().removeByType("POSTGISRASTER");
94  te::da::DataSourceInfoManager::getInstance().removeByType("GDALPOSTGISRASTER");
95 
96  TE_LOG_TRACE(TE_TR("TerraLib Qt PostGIS Raster widget shutdown!"));
97 
98  m_initialized = false;
99 }
100 
102 {
104 
105  std::unique_ptr<te::qt::widgets::DataSourceSelectorDialog> dselector(new te::qt::widgets::DataSourceSelectorDialog(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow()));
106 
107  dselector->getSelectorWidget()->showSpecificDataSource("POSTGISRASTER");
108 
109  if (dselector->exec() == QDialog::Accepted)
110  {
111  std::list<te::da::DataSourceInfoPtr> selectedDatasources = dselector->getSelecteds();
112 
113  if (!selectedDatasources.empty())
114  {
115  te::da::DataSourceInfoPtr dsInfo = selectedDatasources.front();
116 
117  std::unique_ptr<PostGISDataSetSelectorDialog> selector(new PostGISDataSetSelectorDialog(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow()));
118 
119  selector->set(dsInfo);
120 
121  if (selector->exec() == QDialog::Accepted)
122  {
124  selector->getSelecteds(vec);
125 
126  if (vec.empty())
127  {
128  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(),
129  tr("PostGIS Raster"), tr("No PostGIS Raster selected."));
130  }
131  else
132  {
133  CreateLayers(vec);
134  }
135  }
136 
137  }
138  }
139 
140  te::qt::widgets::DataSourceTypeManager::getInstance().remove("POSTGISRASTER");
141 }
142 
void triggered(te::qt::af::evt::Event *e)
Plugin implementation for the PostGIS Raster data source widget.
void startup()
This method will be called by applications to startup some plugin&#39;s functionality.
Basic information about a plugin.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Utility functions for the PgisRaster data source widget plugin.
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void shutdown()
This method will be called by applicatons to shutdown plugin&#39;s functionality.
URI C++ Library.
Definition: Attributes.h:37
#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...
#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
A dialog for selecting a data source.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr