AbstractTool.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/AbstractTool.h
22 
23  \brief Abstract tool concept.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_ABSTRACTTOOL_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_ABSTRACTTOOL_H
28 
29 // TerraLib
30 #include "../Config.h"
31 
32 // Boost
33 #include <boost/noncopyable.hpp>
34 
35 // Qt
36 #include <QtCore/QObject>
37 #include <QCursor>
38 
39 // Forward declarations
40 class QKeyEvent;
41 class QMouseEvent;
42 
43 namespace te
44 {
45  namespace qt
46  {
47  namespace widgets
48  {
49 // Forward declarations
50  class MapDisplay;
51 
52  /*!
53  \class AbstractTool
54 
55  \brief This class defines an interface for objects that can receive application events and respond to
56  them, according to specific tool behavior. Tools, in general, receives map display interaction events, like
57  MouseClick, MouseMove, etc. Tools are created to do some GIS operation using the user interactions.
58 
59  \ingroup widgets
60 
61  \sa CoordTracking, Info, Measure, Pan, RubberBand, Selection, Zoom, ZoomArea, ZoomClick, ZoomKeyboard, ZoomWheel
62  */
63  class TEQTWIDGETSEXPORT AbstractTool : public QObject, public boost::noncopyable
64  {
65  public:
66 
67  /** @name Initializer Methods
68  * Methods related to instantiation and destruction.
69  */
70  //@{
71 
72  /*!
73  \brief It constructs a tool associated with the given map display and with the specified cursor.
74 
75  \param display The map display associated with the tool.
76  \param parent The tool's parent.
77 
78  \note The tool will NOT take the ownership of the given pointers.
79  \note If the given cursor is different of Qt::BlankCursor, it will be setted on map display.
80  */
81  AbstractTool(MapDisplay* display, QObject* parent = 0);
82 
83  /*! \brief Destructor. */
84  virtual ~AbstractTool();
85 
86  //@}
87 
88  /** @name AbstractTool Methods
89  * Methods related with tool behavior.
90  */
91  //@{
92 
93  /*!
94  \brief Filters events if this object has been installed as an event filter for the watched object.
95 
96  \param watched The watched object.
97  \param event The last event sent to watched object.
98 
99  \note In your reimplementation of this function, if you want to filter the event out,
100  i.e. stop it being handled further, return true; otherwise return false.
101 
102  \note Here, the default implementation looks for QMouseEvents and call the pure virutal methods
103  defined on AbstractTool class, e.g. mousePressEvent().
104  */
105  virtual bool eventFilter(QObject* watched, QEvent* e);
106 
107  /*!
108  \brief This event handler can be reimplemented in a concrete tool class
109  to receive mouse press events for the watched object.
110 
111  \param e The mouse event.
112 
113  \return If you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
114  */
115  virtual bool mousePressEvent(QMouseEvent* e);
116 
117  /*!
118  \brief This event handler can be reimplemented in a concrete tool class
119  to receive mouse move events for the watched object.
120 
121  \param e The mouse event.
122 
123  \return If you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
124  */
125  virtual bool mouseMoveEvent(QMouseEvent* e);
126 
127  /*!
128  \brief This event handler can be reimplemented in a concrete tool class
129  to receive mouse release events for the watched object.
130 
131  \param e The mouse event.
132 
133  \return If you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
134  */
135  virtual bool mouseReleaseEvent(QMouseEvent* e);
136 
137  /*!
138  \brief This event handler can be reimplemented in a concrete tool class
139  to receive mouse double click events for the watched object.
140 
141  \param e The mouse event.
142 
143  \return If you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
144 
145  \note The AbstractTool will also receive mouse press and mouse release events in addition to the double click event.
146  It is up to the developer to ensure that the application interprets these events correctly.
147  */
148  virtual bool mouseDoubleClickEvent(QMouseEvent* e);
149 
150  /*!
151  \brief This event handler can be reimplemented in a concrete tool class
152  to receive key press events for the watched object.
153 
154  \param e The key event.
155 
156  \return If you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
157  */
158  virtual bool keyPressEvent(QKeyEvent* e);
159 
160  //@}
161 
162  /*!
163  \brief It sets the tool cursor.
164 
165  \param cursor The cursor that will be used during the tool operation.
166  */
167  virtual void setCursor(const QCursor& cursor);
168 
169  protected:
170 
171  MapDisplay* m_display; //!< The map display associated with the tool.
172  QCursor m_cursor; //!< The default tool cursor.
173  QCursor m_curCursor; //!< The current mapdisplay cursor.
174  };
175 
176  } // end namespace widgets
177  } // end namespace qt
178 } // end namespace te
179 
180 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_ABSTRACTTOOL_H
A widget to control the display of a set of layers.
Definition: MapDisplay.h:71
QCursor m_cursor
The default tool cursor.
Definition: AbstractTool.h:172
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:63
TerraLib.
QCursor m_curCursor
The current mapdisplay cursor.
Definition: AbstractTool.h:173
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171