Loading...
Searching...
No Matches
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
43namespace 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
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
141
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
Abstract tool concept.
LineString is a curve with linear interpolation between points.
Definition: LineString.h:65
A point with x and y coordinate values.
Definition: Point.h:51
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:51
This class defines an interface for objects that can receive application events and respond to them,...
Definition: AbstractTool.h:64
A canvas built on top of Qt.
Definition: Canvas.h:55
A widget to control the display of a set of layers.
Definition: MapDisplay.h:72
This class implements a concrete tool to measure operation (distance, area, and angle).
Definition: Measure.h:67
MeasureType
Defines the measure type measured by this tool.
Definition: Measure.h:78
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
te::gm::Coord2D m_lastPos
The last position captured on mouse move event.
Definition: Measure.h:151
std::vector< te::gm::Coord2D > m_coords
The coord list managed by the measure tool.
Definition: Measure.h:150
QPen m_pen
The pen used to draw the path.
Definition: Measure.h:153
double calculateAngle(te::gm::LineString *line) const
std::string m_unit
The unit symbol for the measure.
Definition: Measure.h:156
double calculateLength(te::gm::LineString *line) const
QBrush m_brush
The brush used to draw the path.
Definition: Measure.h:154
virtual bool eventFilter(QObject *watched, QEvent *e)
Sets the SRID to be used in the area calcuation.
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
void drawPolygon(Canvas &canvas)
bool m_isFinished
A flag that indicates if the operations was finished.
Definition: Measure.h:155
bool keyPressEvent(QKeyEvent *e)
This event handler can be reimplemented in a concrete tool class to receive key press events for the ...
MeasureType m_measureType
The measure type.
Definition: Measure.h:152
void drawText(Canvas &canvas, const std::string &text, te::gm::Point *p)
void setSRID(int srid)
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Measure(MapDisplay *display, const MeasureType &measureType, const QCursor &cursor, QObject *parent=0)
It constructs a measure tool associated with the given map display.
bool mouseDoubleClickEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse double click events...
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
void drawLine(Canvas &canvas)
double calculateArea(te::gm::Polygon *polygon) const
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
TerraLib.
#define slots
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:41
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63