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. */
100  ~Measure();
101 
102  //@}
103 
104  /** @name AbstractTool Methods
105  * Methods related with tool behavior.
106  */
107  //@{
108 
109  bool mousePressEvent(QMouseEvent* e);
110 
111  bool mouseMoveEvent(QMouseEvent* e);
112 
113  bool mouseReleaseEvent(QMouseEvent* e);
114 
115  bool mouseDoubleClickEvent(QMouseEvent* e);
116 
117  //@}
118 
119  private:
120 
121  void drawGeometry();
122 
123  void drawLine(Canvas& canvas);
124 
125  void drawPolygon(Canvas& canvas);
126 
127  void drawText(Canvas& canvas, const std::string& text, te::gm::Point* p);
128 
129  void clear();
130 
131  double calculateLength(te::gm::LineString* line) const;
132 
133  double calculateAngle(te::gm::LineString* line) const;
134 
135  private slots:
136 
137  void onExtentChanged();
138 
139  protected:
140 
141  std::vector<te::gm::Coord2D> m_coords; //!< The coord list managed by the measure tool.
142  te::gm::Coord2D m_lastPos; //!< The last position captured on mouse move event.
143  MeasureType m_measureType; //!< The measure type.
144  QPen m_pen; //!< The pen used to draw the path.
145  QBrush m_brush; //!< The brush used to draw the path.
146  bool m_isFinished; //!< A flag that indicates if the operations was finished.
147  std::string m_unit; //!< The unit symbol for the measure.
148  };
149 
150  } // end namespace widgets
151  } // end namespace qt
152 } // end namespace te
153 
154 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MEASURE_H
Abstract tool concept.
bool m_isFinished
A flag that indicates if the operations was finished.
Definition: Measure.h:146
te::gm::Coord2D m_lastPos
The last position captured on mouse move event.
Definition: Measure.h:142
QBrush m_brush
The brush used to draw the path.
Definition: Measure.h:145
A widget to control the display of a set of layers.
Definition: MapDisplay.h:69
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:62
MeasureType
Defines the measure type measured by this tool.
Definition: Measure.h:77
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
QPen m_pen
The pen used to draw the path.
Definition: Measure.h:144
std::vector< te::gm::Coord2D > m_coords
The coord list managed by the measure tool.
Definition: Measure.h:141
A point with x and y coordinate values.
Definition: Point.h:50
URI C++ Library.
MeasureType m_measureType
The measure type.
Definition: Measure.h:143
A canvas built on top of Qt.
Definition: Canvas.h:54
MeasureType
Defines the possible types of unit of measurements.
Definition: Enums.h:76
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
This class implements a concrete tool to measure operation (distance, area, and angle).
Definition: Measure.h:66
std::string m_unit
The unit symbol for the measure.
Definition: Measure.h:147