IdentityAction.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/vp/IdentityAction.cpp
22 
23  \brief This file defines the Identity class
24 */
25 
26 // Terralib
27 #include "../../../vp/qt/IdentityDialog.h"
28 #include "../../af/ApplicationController.h"
29 #include "../../af/events/LayerEvents.h"
30 #include "IdentityAction.h"
31 
32 // Qt
33 #include <QObject>
34 #include <QMessageBox>
35 
36 // STL
37 #include <cassert>
38 #include <memory>
39 
41  : te::qt::plugins::vp::AbstractAction(menu)
42 {
43  createAction(tr("Identity...").toUtf8().data(), "vector-processing-identity");
44  m_action->setObjectName("Processing.Vector Processing.Identity");
45 }
46 
48 
50 {
51  QWidget* parent = te::qt::af::AppCtrlSingleton::getInstance().getMainWindow();
52  te::vp::IdentityDialog dlg(parent);
53 
54  // get the list of layers from current project
55  dlg.setLayers(getLayers());
56 
57  if(dlg.exec() != QDialog::Accepted)
58  return;
59 
60  te::map::AbstractLayerPtr layer = dlg.getLayer();
61 
62  if(!layer)
63  return;
64 
65  int reply;
66 
67  std::vector<std::string> warnings = dlg.getWarnings();
68 
69  if(!warnings.empty())
70  {
71  std::string details;
72  for(std::size_t w = 0; w < warnings.size(); ++w)
73  details += warnings[w] + "\n";
74 
75  QMessageBox question(
76  QMessageBox::Warning, tr("Identity Result"),
77  tr("The operation was concluded successfully. But it has warning(s). "
78  "Would you like to add the layer to the project?"));
79  question.addButton(QMessageBox::No);
80  question.addButton(QMessageBox::Yes);
81  question.setDetailedText(QString(details.c_str()));
82 
83  reply = question.exec();
84  }
85  else
86  {
87  reply = QMessageBox::question(
88  nullptr, tr("Identity Result"),
89  tr("The operation was concluded successfully. Would you like to add "
90  "the layer to the project?"),
91  QMessageBox::No, QMessageBox::Yes);
92  }
93 
94  if(reply == QMessageBox::Yes)
95  addNewLayer(layer);
96 }
A dialog used to execute vector identity.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
void createAction(std::string name, std::string pixmap="")
Create and set the actions parameters.
std::vector< std::string > getWarnings()
te::map::AbstractLayerPtr getLayer()
virtual void onActionActivated(bool checked)
This file defines the Identity class.
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
void addNewLayer(te::map::AbstractLayerPtr layer)
Add a new layer into layer explorer widget.
QAction * m_action
Action used to call the process.
std::list< te::map::AbstractLayerPtr > getLayers()
Get the list of layers from app.
This is an abstract class used to register actions into vp pluging.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr