ClippingAction.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/rp/ClippingAction.cpp
22 
23  \brief This file defines the Clipping class
24 */
25 
26 // Terralib
27 #include "../../../qt/widgets/rp/ClippingWizard.h"
28 #include "../../../raster/Raster.h"
29 #include "../../af/ApplicationController.h"
30 #include "../../af/BaseApplication.h"
31 #include "../../af/events/LayerEvents.h"
32 #include "ClippingAction.h"
33 
34 // Qt
35 #include <QObject>
36 #include <QMessageBox>
37 
38 // STL
39 #include <memory>
40 
41 te::qt::plugins::rp::ClippingAction::ClippingAction(QMenu* menu, QMenu* popupMenu):te::qt::plugins::rp::AbstractAction(menu, popupMenu)
42 {
43  createAction(tr("Clipping...").toUtf8().data(), "edit-cut");
44  m_action->setObjectName("Processing.Raster Processing.Clipping");
45 
46  createPopUpAction(tr("Clipping...").toUtf8().data(), "clipping");
47 }
48 
50 
52 {
54 
56 
58  m_clippingWizard->setMapDisplay(ba->getMapDisplay());
59 
60  connect(m_clippingWizard.get(), SIGNAL(addLayer(te::map::AbstractLayerPtr)), this, SLOT(addLayerSlot(te::map::AbstractLayerPtr)));
61 
62  connect(m_clippingWizard.get(), SIGNAL(finished(int)), this, SLOT(onClippingWizardFinished()));
63 
64  QActionGroup* mapEditionTools = te::qt::af::AppCtrlSingleton::getInstance().findActionGroup("Map.ToolsGroup");
65  assert(mapEditionTools);
66 
67  m_clippingWizard->setActionGroup(mapEditionTools);
68 
69  std::list<te::map::AbstractLayerPtr> layersList = getLayers();
70 
71  m_clippingWizard->setAttribute(Qt::WA_DeleteOnClose);
72 
73  m_clippingWizard->setList(layersList);
74 
75  m_clippingWizard->setModal(false);
76 
77  m_clippingWizard->show();
78 }
79 
81 {
82  addNewLayer(layer);
83 }
84 
86 {
87  te::qt::af::AppCtrlSingleton::getInstance().removeListener(this);
88 
89  m_clippingWizard.release();
90 }
91 
93  bool /*checked*/)
94 {
96 
97  if(layer.get())
98  {
100 
101  dlg.setLayer(layer);
102 
103  if(dlg.exec() == QDialog::Accepted)
104  {
105  //add layers
106  std::vector<te::map::AbstractLayerPtr> layersVec = dlg.getOutputLayers();
107  for(std::size_t i = 0; i < layersVec.size(); ++i)
108  addNewLayer(layersVec[i]);
109  }
110  }
111  else
112  {
113  QMessageBox::warning(te::qt::af::AppCtrlSingleton::getInstance().getMainWindow(), tr("Warning"), tr("The layer selected is invalid or does not have an raster representation."));
114  }
115 }
116 
118 {
119  switch(e->m_id)
120  {
122  {
123  m_clippingWizard->onMapDisplayExtentChanged();
124  }
125  break;
126 
127  default:
128  break;
129  }
130 }
std::unique_ptr< te::qt::widgets::ClippingWizard > m_clippingWizard
void addLayerSlot(te::map::AbstractLayerPtr layer)
This is an abstract class used to register actions into rp pluging.
virtual void onActionActivated(bool checked)
void createPopUpAction(std::string name, std::string pixmap="")
Create and set the actions parameters.
A base class for application events.
This file defines the Clipping class.
ClippingAction(QMenu *menu, QMenu *popupMenu)
std::vector< te::map::AbstractLayerPtr > getOutputLayers()
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
void createAction(std::string name, std::string pixmap="")
Create and set the actions parameters.
te::map::AbstractLayerPtr getCurrentLayer()
Get the selected layer from layer explorer in app.
URI C++ Library.
Definition: Attributes.h:37
QAction * m_action
Action used to call the process.
This class is GUI used to define the clipping wizard for the RP constast operation.
void onApplicationTriggered(te::qt::af::evt::Event *e)
void setLayer(te::map::AbstractLayerPtr layer)
te::qt::widgets::MapDisplay * getMapDisplay()
virtual void onPopUpActionActivated(bool checked)
void addNewLayer(te::map::AbstractLayerPtr layer)
Add a new layer into layer explorer widget.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::list< te::map::AbstractLayerPtr > getLayers()
Get the list of layers from app.