DissolveAction.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
4  applications.
5 
6  TerraLib is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License,
9  or (at your option) any later version.
10 
11  TerraLib is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with TerraLib. See COPYING. If not, write to
18  TerraLib Team at <terralib-team@terralib.org>.
19  */
20 
21 /*!
22  \file terralib/qt/plugins/vp/DissolveAction.cpp
23 
24  \brief This file defines the Dissolve class
25 */
26 
27 // Terralib
28 #include "../../../vp/qt/DissolveDialog.h"
29 #include "../../af/ApplicationController.h"
30 #include "../../af/events/LayerEvents.h"
31 #include "DissolveAction.h"
32 
33 // Qt
34 #include <QObject>
35 #include <QMessageBox>
36 
37 // STL
38 #include <memory>
39 
41  : te::qt::plugins::vp::AbstractAction(menu)
42 {
43  createAction(tr("Dissolve...").toUtf8().data(),
44  "vector-processing-dissolve");
45  m_action->setObjectName("Processing.Vector Processing.Dissolve");
46 }
47 
49 
51 {
52  QWidget* parent = te::qt::af::AppCtrlSingleton::getInstance().getMainWindow();
53  te::vp::DissolveDialog dlg(parent);
54 
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("Dissolve 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("Dissolve 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 }
void createAction(std::string name, std::string pixmap="")
Create and set the actions parameters.
std::vector< std::string > getWarnings()
Get warning messages.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
virtual void onActionActivated(bool checked)
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 file defines the Dissolve class.
This is an abstract class used to register actions into vp pluging.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
te::map::AbstractLayerPtr getLayer()
Get the generated layer.