DeleteGeometryTool.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/edit/qt/tools/DeleteGeometryTool.cpp
22 
23  \brief This class implements a concrete tool to remove geometries.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/GeometryProperty.h"
28 #include "../../../geometry/MultiPolygon.h"
29 #include "../../../dataaccess/dataset/ObjectIdSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../qt/widgets/canvas/MapDisplay.h"
32 #include "../../../qt/widgets/Utils.h"
33 
34 #include "../../Feature.h"
35 #include "../../RepositoryManager.h"
36 #include "../../Utils.h"
37 #include "../Renderer.h"
38 #include "../Utils.h"
39 #include "DeleteGeometryTool.h"
40 
41 // Qt
42 #include <QMessageBox>
43 #include <QMouseEvent>
44 
45 // STL
46 #include <cassert>
47 #include <memory>
48 
50  : GeometriesUpdateTool(display, layer.get(), parent)
51 {
52  updateCursor();
53 }
54 
56 
58 {
59  if (e->button() != Qt::LeftButton)
60  return false;
61 
63  if (m_feature)
64  storeFeature();
65  else
66  {
67  QMessageBox::critical(m_display, tr("Error"), QString(tr("The geometry cannot be selected from the layer.")));
68  return false;
69  }
70 
71  return true;
72 }
73 
75 {
76  QPointF pixelOffset(4.0, 4.0);
77 
78  QRectF rect(pos - pixelOffset, pos + pixelOffset);
79 
80  // Converts rect boundary to world coordinates
81  QPointF ll(rect.left(), rect.bottom());
82  QPointF ur(rect.right(), rect.top());
83  ll = m_display->transform(ll);
84  ur = m_display->transform(ur);
85 
86  te::gm::Envelope env(ll.x(), ll.y(), ur.x(), ur.y());
87 
88  return env;
89 }
90 
92 {
94 
95  if (oType == DELETE)
96  {
98  }
99  else if (oType == UPDATE)
100  {
102  }
103 
105 
106  emit geometriesEdited();
107 }
108 
110 {
111  setCursor(Qt::ArrowCursor);
112 }
DeleteGeometryTool(te::qt::widgets::MapDisplay *display, const te::map::AbstractLayerPtr &layer, QObject *parent=0)
It constructs a remove geometries tool associated with the given map display.
virtual const std::string & getId() const
It returns the layer id.
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Feature * clone() const
Definition: Feature.cpp:182
A widget to control the display of a set of layers.
te::edit::OperationType getOperationTypeId() const
Definition: Feature.cpp:159
This class implements a concrete tool to remove geometries.
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
void setOperationTypeId(const te::edit::OperationType &currentOperationType)
Definition: Feature.cpp:124
static RepositoryManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
TEEDITEXPORT Feature * PickFeature(const te::map::AbstractLayerPtr &layer, const te::gm::Envelope &env, int srid)
te::map::AbstractLayer * m_layer
te::gm::Envelope buildEnvelope(const QPointF &pos)
~DeleteGeometryTool()
Destructor.
void setCursor(const QCursor &cursor)
It sets the tool cursor.
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr