ExtentAcquire.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/widgets/tools/ExtentAcquire.cpp
22 
23  \brief This class implements a concrete tool to define a boundary rectangle.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Envelope.h"
28 #include "../canvas/MapDisplay.h"
29 #include "ExtentAcquire.h"
30 
31 // Qt
32 #include <QMouseEvent>
33 
35  : RubberBand(display, parent),
36  m_started(false)
37 {
38  setCursor(cursor);
39 }
40 
42 
44 {
45  if(e->button() != Qt::LeftButton)
46  return false;
47 
48  m_started = true;
49  m_rect = QRectF();
50 
52 }
53 
55 {
56  if(!m_started)
57  return false;
58 
60 }
61 
63 {
64  m_started = false;
65 
66  if(e->button() != Qt::LeftButton)
67  return false;
68 
70 
71  if(m_rect.isNull()) // Zoom by click
72  {
73  //QRect displayRect = m_display->rect();
74  m_rect.moveCenter(m_origin);
75  }
76 
77  // Converts zoom boundary to world coordinates
78  QPointF ll(m_rect.left(), m_rect.bottom());
79  QPointF ur(m_rect.right(), m_rect.top());
80  ll = m_display->transform(ll);
81  ur = m_display->transform(ur);
82 
83  if (ll.x() == ur.x() && ll.y() == ur.y())
84  return false;
85 
86  // Updates the map display with the new extent
87  te::gm::Envelope envelope(ll.x(), ll.y(), ur.x(), ur.y());
88 
89  emit extentAcquired(envelope);
90 
91  return true;
92 }
virtual bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Definition: RubberBand.cpp:53
This class implements a concrete tool to define a boundary rectangle.
virtual bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: RubberBand.cpp:70
QPoint m_origin
Origin point on mouse pressed.
Definition: RubberBand.h:92
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
virtual bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: RubberBand.cpp:47
bool m_started
Flag that indicates if operation was started.
ExtentAcquire(MapDisplay *display, const QCursor &cursor, QObject *parent=0)
It constructs a extent acquire tool associated with the given map display and with the specified curs...
A widget to control the display of a set of layers.
void extentAcquired(te::gm::Envelope env)
QRectF m_rect
The boundary rectangle managed by the rubber band.
Definition: RubberBand.h:93
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
An Envelope defines a 2D rectangular region.
virtual void setCursor(const QCursor &cursor)
It sets the tool cursor.
This class provides a rectangle that can indicate a boundary.
Definition: RubberBand.h:52
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...