Measure.h
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/Measure.h
22 
23  \brief This class implements a concrete tool to measure operation (distance, area, and angle).
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_MEASURE_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_MEASURE_H
28 
29 // TerraLib
30 #include "../../../geometry/Coord2D.h"
31 #include "../Config.h"
32 #include "AbstractTool.h"
33 
34 // Qt
35 #include <QFont>
36 #include <QPainterPath>
37 #include <QPen>
38 
39 // STL
40 #include <vector>
41 #include <string>
42 
43 namespace te
44 {
45  namespace gm
46  {
47  class LineString;
48  class Point;
49  }
50 
51  namespace qt
52  {
53  namespace widgets
54  {
55 // Forward declarations
56  class Canvas;
57  class MapDisplay;
58 
59  /*!
60  \class Measure
61 
62  \brief This class implements a concrete tool to measure operation (distance, area, and angle).
63 
64  \ingroup widgets
65  */
67  {
68  Q_OBJECT
69 
70  public:
71 
72  /*!
73  \enum MeasureType
74 
75  \brief Defines the measure type measured by this tool.
76  */
78  {
79  Distance, /*!< Distance. */
80  Area, /*!< Area. */
81  Angle /*!< Angle. */
82  };
83 
84  /** @name Initializer Methods
85  * Methods related to instantiation and destruction.
86  */
87  //@{
88 
89  /*!
90  \brief It constructs a measure tool associated with the given map display.
91 
92  \param display The map display associated with the tool.
93  \param parent The tool's parent.
94 
95  \note The tool will NOT take the ownership of the given pointers.
96  */
97  Measure(MapDisplay* display, const MeasureType& measureType, const QCursor& cursor, QObject* parent = 0);
98 
99  /*! \brief Destructor. */
101 
102  virtual bool eventFilter(QObject* watched, QEvent* e);
103 
104  //!< Sets the SRID to be used in the area calcuation
105  void setSRID(int srid);
106 
107  //@}
108 
109  /** @name AbstractTool Methods
110  * Methods related with tool behavior.
111  */
112  //@{
113 
114  bool mousePressEvent(QMouseEvent* e);
115 
116  bool mouseMoveEvent(QMouseEvent* e);
117 
118  bool mouseReleaseEvent(QMouseEvent* e);
119 
120  bool mouseDoubleClickEvent(QMouseEvent* e);
121 
122  bool keyPressEvent(QKeyEvent* e);
123 
124  //@}
125 
126  private:
127 
128  void drawGeometry();
129 
130  void drawLine(Canvas& canvas);
131 
132  void drawPolygon(Canvas& canvas);
133 
134  void drawText(Canvas& canvas, const std::string& text, te::gm::Point* p);
135 
136  void clear();
137 
138  double calculateArea(te::gm::Polygon* polygon) const;
139 
140  double calculateLength(te::gm::LineString* line) const;
141 
142  double calculateAngle(te::gm::LineString* line) const;
143 
144  private slots:
145 
147 
148  protected:
149 
150  std::vector<te::gm::Coord2D> m_coords; //!< The coord list managed by the measure tool.
151  te::gm::Coord2D m_lastPos; //!< The last position captured on mouse move event.
152  MeasureType m_measureType; //!< The measure type.
153  QPen m_pen; //!< The pen used to draw the path.
154  QBrush m_brush; //!< The brush used to draw the path.
155  bool m_isFinished; //!< A flag that indicates if the operations was finished.
156  std::string m_unit; //!< The unit symbol for the measure.
157  int m_srid; //!< The SRID to be used in the area calculation. If TE_UNKNOWN_SRS is set, the srid will be get from the mapDisplay
158  bool m_useMapDisplaySRID; //!< If TRUE, the srid will be get from the mapDisplay. If FALSE, tool will use the set SRID
159  };
160 
161  } // end namespace widgets
162  } // end namespace qt
163 } // end namespace te
164 
165 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MEASURE_H
te::qt::widgets::Measure::m_measureType
MeasureType m_measureType
The measure type.
Definition: Measure.h:152
te::qt::widgets::Measure::calculateLength
double calculateLength(te::gm::LineString *line) const
te::qt::widgets::Measure::m_useMapDisplaySRID
bool m_useMapDisplaySRID
If TRUE, the srid will be get from the mapDisplay. If FALSE, tool will use the set SRID.
Definition: Measure.h:158
te::qt::widgets::AbstractTool
This class defines an interface for objects that can receive application events and respond to them,...
Definition: AbstractTool.h:64
te::qt::widgets::Measure::m_brush
QBrush m_brush
The brush used to draw the path.
Definition: Measure.h:154
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::qt::widgets::Measure::Measure
Measure(MapDisplay *display, const MeasureType &measureType, const QCursor &cursor, QObject *parent=0)
It constructs a measure tool associated with the given map display.
te::qt::widgets::Measure::calculateAngle
double calculateAngle(te::gm::LineString *line) const
te::qt::widgets::MapDisplay
A widget to control the display of a set of layers.
Definition: MapDisplay.h:72
te::qt::widgets::Measure::Area
@ Area
Definition: Measure.h:80
te::qt::widgets::Canvas
A canvas built on top of Qt.
Definition: Canvas.h:55
te::qt::widgets::Measure::m_srid
int m_srid
The SRID to be used in the area calculation. If TE_UNKNOWN_SRS is set, the srid will be get from the ...
Definition: Measure.h:157
te::qt::widgets::Measure
This class implements a concrete tool to measure operation (distance, area, and angle).
Definition: Measure.h:67
te::qt::widgets::Measure::drawLine
void drawLine(Canvas &canvas)
te::qt::widgets::Measure::m_lastPos
te::gm::Coord2D m_lastPos
The last position captured on mouse move event.
Definition: Measure.h:151
te::qt::widgets::Measure::mousePressEvent
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
te::common::Angle
@ Angle
Definition: Enums.h:81
TEQTWIDGETSEXPORT
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
te::gm::Polygon
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:51
te::qt::widgets::Measure::mouseReleaseEvent
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
te::qt::widgets::Measure::m_unit
std::string m_unit
The unit symbol for the measure.
Definition: Measure.h:156
te::qt::widgets::Measure::keyPressEvent
bool keyPressEvent(QKeyEvent *e)
This event handler can be reimplemented in a concrete tool class to receive key press events for the ...
te::qt::widgets::Measure::onExtentChanged
void onExtentChanged()
te::qt::widgets::Measure::drawText
void drawText(Canvas &canvas, const std::string &text, te::gm::Point *p)
slots
#define slots
Definition: VirtualMachine.h:48
te::gm::LineString
LineString is a curve with linear interpolation between points.
Definition: LineString.h:65
te::qt::widgets::Measure::Distance
@ Distance
Definition: Measure.h:79
te::qt::widgets::Measure::clear
void clear()
te::qt::widgets::Measure::m_pen
QPen m_pen
The pen used to draw the path.
Definition: Measure.h:153
te::gm::Coord2D
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:41
te::qt::widgets::Measure::calculateArea
double calculateArea(te::gm::Polygon *polygon) const
te::qt::widgets::Measure::m_isFinished
bool m_isFinished
A flag that indicates if the operations was finished.
Definition: Measure.h:155
te::qt::widgets::Measure::setSRID
void setSRID(int srid)
te::qt::widgets::Measure::mouseMoveEvent
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
te::qt::widgets::Measure::MeasureType
MeasureType
Defines the measure type measured by this tool.
Definition: Measure.h:78
te::qt::widgets::Measure::mouseDoubleClickEvent
bool mouseDoubleClickEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse double click events...
te::qt::widgets::Measure::drawGeometry
void drawGeometry()
te::qt::widgets::Measure::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *e)
Sets the SRID to be used in the area calcuation.
te::qt::widgets::Measure::drawPolygon
void drawPolygon(Canvas &canvas)
te::qt::widgets::Measure::m_coords
std::vector< te::gm::Coord2D > m_coords
The coord list managed by the measure tool.
Definition: Measure.h:150
te::qt::widgets::Measure::~Measure
~Measure()
Destructor.
te::gm::Point
A point with x and y coordinate values.
Definition: Point.h:51
AbstractTool.h
Abstract tool concept.