src/terralib/qt/plugins/st/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/st/Plugin.cpp
22 
23  \brief Plugin implementation for the st Qt Plugin 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 "../../af/ApplicationController.h"
32 #include "../../af/events/ApplicationEvents.h"
33 #include "../../af/events/LayerEvents.h"
34 #include "../../widgets/layer/explorer/LayerItem.h"
35 #include "../../widgets/layer/explorer/LayerItemView.h"
36 
37 #include "STItemDelegate.h"
38 
39 #ifdef TE_QT_PLUGIN_ST_HAVE_SLIDER
40  #include "TimeSliderWidgetAction.h"
41 #endif
42 
43 #ifdef TE_QT_PLUGIN_ST_HAVE_OBSERVATION
44  #include "ObservationAction.h"
45 #endif
46 
47 #ifdef TE_QT_PLUGIN_ST_HAVE_TIMESERIES
48  #include "TimeSeriesAction.h"
49 #endif
50 
51 #ifdef TE_QT_PLUGIN_ST_HAVE_TRAJECTORY
52  #include "TrajectoryAction.h"
53 #endif
54 
55 // QT
56 #include <QMenu>
57 #include <QMenuBar>
58 
59 
60 
61 void GetAllSTLayers(te::qt::widgets::LayerItemView* view, const QModelIndex& parent, QModelIndexList& layersIdx)
62 {
63  QAbstractItemModel* model = view->model();
64  int cS = model->rowCount(parent);
65 
66  for(int i = 0; i < cS; i++)
67  {
68  QModelIndex idx = model->index(i, 0, parent);
69 
71  static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer());
72 
73  if(child->getType() == "FOLDER")
74  GetAllSTLayers(view, idx, layersIdx);
75  else if(child->getType() == "LAYER")
76  {
77  te::map::AbstractLayerPtr l = ((te::qt::widgets::LayerItem*)child)->getLayer();
78 
79  bool isSTLayer = (l->getType() == "TRAJECTORYDATASETLAYER" ||
80  l->getType() == "OBSERVATIONDATASETLAYER" ||
81  l->getType() == "TIMESERIESDATASETLAYER");
82 
83  if(isSTLayer)
84  layersIdx.push_back(idx);
85  }
86  }
87 
88 }
89 
90 std::list<te::map::AbstractLayerPtr> GetLayers(const QModelIndexList& lst)
91 {
92  std::list<te::map::AbstractLayerPtr> res;
93 
94  for(QModelIndexList::const_iterator it = lst.begin(); it != lst.end(); ++it)
95  {
96  QModelIndex idx = *it;
97  te::qt::widgets::TreeItem* item = static_cast<te::qt::widgets::TreeItem*>(idx.internalPointer());
98  res.push_back(((te::qt::widgets::LayerItem*)item)->getLayer());
99  }
100 
101  return res;
102 }
103 
105  : te::core::CppPlugin(pluginInfo), m_stMenu(0), m_delegate(0)
106 {
107 }
108 
110 
112 {
113  if(m_initialized)
114  return;
115 
116 // it initializes the Translator support for the TerraLib st Qt Plugin
117  //TE_ADD_TEXT_DOMAIN(TE_QT_PLUGIN_ST_TEXT_DOMAIN, TE_QT_PLUGIN_ST_TEXT_DOMAIN_DIR, "UTF-8");
118 
119  TE_LOG_TRACE(TE_TR("TerraLib Qt ST Plugin startup!"));
120 
121 // add plugin menu
122  m_stMenu = new QMenu("Project.Add Layer.Add Temporal Layer");
123 
124  m_stMenu->setTitle(tr("Add Temporal Layer"));
125 
126 // register actions
127  registerActions();
128 
129  m_initialized = true;
130 
132 
133  updateDelegate(true);
134 
136 
137  e.m_category = "Dataaccess";
138  e.m_plgName = "ST";
139  e.m_actions <<m_stMenu->menuAction();
140 
141  emit triggered(&e);
142 }
143 
145 {
146  if(!m_initialized)
147  return;
148 
149 // unregister actions
151 
152 // remove menu
153  delete m_stMenu;
154 
155  TE_LOG_TRACE(TE_TR("TerraLib Qt ST Plugin shutdown!"));
156 
157  m_initialized = false;
158 
159  updateDelegate(false);
160 
161  QModelIndexList stls;
162 
164 
165  emit triggered(&e);
166 
167  if(e.m_layerExplorer == 0)
168  return;
169 
170  GetAllSTLayers(e.m_layerExplorer, QModelIndex(), stls);
171 
172  if(!stls.isEmpty())
173  {
174  std::list<te::map::AbstractLayerPtr> ls = GetLayers(stls);
175 
176  e.m_layerExplorer->removeItems(stls);
178 
179  emit triggered(&evt);
180  }
181 
182  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
183 }
184 
186 {
187 #ifdef TE_QT_PLUGIN_ST_HAVE_SLIDER
190 #endif
191 
192 #ifdef TE_QT_PLUGIN_ST_HAVE_OBSERVATION
195 #endif
196 
197 #ifdef TE_QT_PLUGIN_ST_HAVE_TIMESERIES
200 #endif
201 
202 #ifdef TE_QT_PLUGIN_ST_HAVE_TRAJECTORY
205 #endif
206 }
207 
209 {
210 #ifdef TE_QT_PLUGIN_ST_HAVE_SLIDER
211  delete m_sliderAction;
212 #endif
213 
214 #ifdef TE_QT_PLUGIN_ST_HAVE_OBSERVATION
215  delete m_observactionAction;
216 #endif
217 
218 #ifdef TE_QT_PLUGIN_ST_HAVE_TIMESERIES
219  delete m_timeSeriesAction;
220 #endif
221 
222 #ifdef TE_QT_PLUGIN_ST_HAVE_TRAJECTORY
223  delete m_trajectoryAction;
224 #endif
225 }
226 
228 {
230 
231  emit triggered(&e);
232 
233  if(e.m_layerExplorer == 0)
234  return;
235 
236  if(add)
237  {
238  m_delegate = new STItemDelegate((QStyledItemDelegate*)e.m_layerExplorer->itemDelegate(), this);
239  e.m_layerExplorer->setItemDelegate(m_delegate);
240  }
241  else
242  {
244  delete m_delegate;
245  m_delegate = 0;
246  }
247 }
248 
te::qt::plugins::st::TimeSeriesAction * m_timeSeriesAction
TimeSeries Layer Action.
This file defines the TimeSeriers Action class.
te::qt::plugins::st::TrajectoryAction * m_trajectoryAction
Trajectory Layer Action.
An item that contains a te::map::AbstractLayerPtr.
Definition: LayerItem.h:51
This class register the time series action into the St plugin.
A base class for application events.
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
te::qt::plugins::st::ObservationAction * m_observactionAction
Observation Layer Action.
void startup()
This method will be called by applications to startup some plugin&#39;s functionality.
Plugin implementation for the ST Qt Plugin widget.
Defines a hierarchical structure.
te::qt::plugins::st::TimeSliderWidgetAction * m_sliderAction
Slider Process Action.
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
This class register the time slider widget action into st Plugin.
std::list< te::map::AbstractLayerPtr > GetLayers(const QModelIndexList &lst)
void removeItems(const QModelIndexList &idxs)
Removes the items in the list.
QMenu * m_stMenu
ST Main Menu registered.
A specialization of QTreeView for manipulate layers.
Definition: LayerItemView.h:78
void GetAllSTLayers(te::qt::widgets::LayerItemView *view, const QModelIndex &parent, QModelIndexList &layersIdx)
Plugin(const te::core::PluginInfo &pluginInfo)
#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...
This file defines the TimeSliderWidgetAction class.
This class register the observation action into the St plugin.
void unRegisterActions()
Function used to unregister all raster processing actions.
void triggered(te::qt::af::evt::Event *e)
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
This file defines the Trajectory Action class.
void registerActions()
Function used to register all raster processing actions.
STItemDelegate * m_delegate
Item delegate.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::string getType() const
Returns the type of the item.