All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MapDisplay.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/canvas/MapDisplay.h
22 
23  \brief A Qt4 widget to control the display of a set of layers.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_MAPDISPLAY_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_MAPDISPLAY_H
28 
29 // TerraLib
30 #include "../../../maptools/MapDisplay.h"
31 #include "../../../srs.h"
32 #include "../Config.h"
33 
34 // Qt
35 #include <QtGui/QWidget>
36 
37 // STL
38 #include <map>
39 
40 // Forward declarations
41 class QTimer;
42 
43 namespace te
44 {
45 // Forward declarations
46  namespace gm { class Envelope; }
47  namespace map { class AbstractLayer; }
48 
49  namespace qt
50  {
51  namespace widgets
52  {
53 // Forward declarations
54  class Canvas;
55 
56  /*!
57  \class MapDisplay
58 
59  \brief A widget to control the display of a set of layers.
60 
61  \ingroup widgets
62 
63  \sa te::map::AbstractMapDisplay, te::map::MapDisplay
64  */
65  class TEQTWIDGETSEXPORT MapDisplay : public QWidget, public te::map::MapDisplay
66  {
67  Q_OBJECT
68 
69  public:
70 
71  /*!
72  \enum ResizePolicy
73 
74  \brief Defines the resize policy for map display.
75  */
77  {
78  Fixed, /*!< Document-me! */
79  Cut, /*!< Document-me! */
80  Center, /*!< Document-me! */
81  };
82 
83  /** @name Initializer Methods
84  * Methods related to instantiation and destruction.
85  */
86  //@{
87 
88  /*!
89  \brief It constructs an empty map display with the given dimensions which is a child of parent, with widget flags set to f.
90 
91  \param size The map display size.
92  \param parent The widget's parent.
93  \param f Widget window flags.
94  */
95  MapDisplay(const QSize& size, QWidget* parent = 0, Qt::WindowFlags f = 0);
96 
97  /*! \brief Destructor. */
98  virtual ~MapDisplay();
99 
100  //@}
101 
102  /** @name AbstractMapDisplay Methods */
103  //@{
104 
105  virtual void dragEnterEvent(QDragEnterEvent*);
106 
107  virtual void dropEvent(QDropEvent*);
108 
109  virtual void changeData(te::map::AbstractLayerPtr, int nsrid = TE_UNKNOWN_SRS);
110 
111  virtual void setExtent(te::gm::Envelope& e, bool doRefresh = true);
112 
113  virtual void refresh();
114 
115  unsigned int getWidth() const;
116 
117  unsigned int getHeight() const;
118 
119  double getWidthMM() const;
120 
121  double getHeightMM() const;
122 
123  //@}
124 
125  /*!
126  \brief It returns the map display pixmap.
127 
128  \return The map display pixmap.
129 
130  \note The caller of this method will NOT take the ownership of the returned pixmap.
131  */
132  virtual QPixmap* getDisplayPixmap() const;
133 
134  /*!
135  \brief It returns the map display draft pixmap.
136 
137  \return The map display draft pixmap.
138 
139  \note This pixmap can be used to draw some feedback on map display.
140  \note The caller of this method will NOT take the ownership of the returned pixmap.
141  */
142  virtual QPixmap* getDraftPixmap() const;
143 
144  /*!
145  \brief Sets the resize policy to this map display.
146 
147  \param policy The resize policy.
148  */
149  virtual void setResizePolicy(const ResizePolicy& policy);
150 
151  /*!
152  \brief Sets the timeout interval in milliseconds to redraw on resize event.
153 
154  \param msec The timeout interval in milliseconds.
155  */
156  virtual void setResizeInterval(int msec);
157 
158  /*!
159  \brief Transforms the given point, in screen coordinates, to a point in world coordinates.
160 
161  \param p A point in screen coordinates.
162 
163  \return The point in world coordinates.
164 
165  \note This method will return a null point if the transform can not be done.
166  */
167  virtual QPointF transform(const QPointF& p);
168 
169  /*!
170  \brief Gets the map display background color
171 
172  \return The map display background color.
173  */
174  virtual QColor getBackgroundColor();
175 
176  /*!
177  \brief Sets the map display background color
178 
179  \param color The color.
180  */
181  virtual void setBackgroundColor(const QColor& color);
182 
183  /*! \brief Returns if the map display is drawing. */
184  bool isDrawing() const;
185 
186  protected:
187 
188  /*!
189  \brief It displays the given layer.
190 
191  \param layer The layer that will be drawn.
192  \param painter The painter that will composed the draw result.
193 
194  \note This method is called recursively for each child of the given layer.
195  \note It may need to retrieve data in order top display the layers.
196  */
197  virtual void draw(te::map::AbstractLayer* layer, QPainter& painter);
198 
199  /*!
200  \brief It retrieves an associated canvas to the given layer.
201 
202  \param layer The layer for wich we want to get an associated canvas.
203 
204  \note If there is not a canvas associated to the given layer, one will be created.
205 
206  \return A canvas associated to the layer.
207  */
208  virtual te::qt::widgets::Canvas* getCanvas(te::map::AbstractLayer* layer, int type = QInternal::Pixmap);
209 
210  /*!
211  \brief It resizes all canvas of map display.
212  */
213  virtual void resizeAllCanvas();
214 
215  /*!
216  \brief It adjusts the map display extent based on resize policy.
217 
218  \param oldSize The size before the resize.
219  \param size The size after the resize.
220  */
221  virtual void adjustExtent(const QSize& oldSize, const QSize& size);
222 
223  /*!
224  \brief It assembles the final image and draws the widget.
225 
226  \param e The event received by this widget.
227  */
228  virtual void paintEvent(QPaintEvent* e);
229 
230  /*!
231  \brief This event handler receives widget resize events wich are passed in the event parameter.
232 
233  \param e The resize event.
234  */
235  virtual void resizeEvent(QResizeEvent* e);
236 
237  protected slots:
238 
239  virtual void onResizeTimeout();
240 
241  signals:
242 
243  /*! This signal is emitted when the map display extent changed. */
244  void extentChanged();
245 
246  private:
247 
248  /** @name Copy Constructor and Assignment Operator
249  * Copy constructor and assignment operator not allowed.
250  */
251  //@{
252 
253  /*!
254  \brief Copy constructor not allowed.
255 
256  \param rhs The right-hand-side copy that would be used to copy from.
257  */
258  MapDisplay(const MapDisplay& rhs);
259 
260  /*!
261  \brief Assignment operator not allowed.
262 
263  \param rhs The right-hand-side copy that would be used to copy from.
264 
265  \return A reference to this object.
266  */
267  MapDisplay& operator=(const MapDisplay& rhs);
268 
269  //@}
270 
271  protected:
272 
273  QPixmap* m_displayPixmap; //!< This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible layers.
274  QPixmap* m_draftPixmap; //!< The draft pixmap can be used to draw some feedback on map display.
275  QColor m_backgroundColor; //!< Background color.
276  ResizePolicy m_resizePolicy; //!< Resize policy for this map display.
277  QSize m_oldSize; //!< Stores the last size of map display on start resize event.
278  QTimer* m_timer; //!< Timer to execute redraw on resize action.
279  int m_interval; //!< Timeout interval in milliseconds to redraw.
280  bool m_isDrawing; //!< A flag that indicates if the map display is drawing.
281 
282  std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*> m_layerCanvasMap; //!< A map that associates a layer to a canvas.
283  };
284 
285  } // end namespace widgets
286  } // end namespace qt
287 } // end namespace te
288 
289 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MAPDISPLAY_H
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:101
QTimer * m_timer
Timer to execute redraw on resize action.
Definition: MapDisplay.h:278
This is the base class for layers.
Definition: AbstractLayer.h:76
bool m_isDrawing
A flag that indicates if the map display is drawing.
Definition: MapDisplay.h:280
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:72
ResizePolicy
Defines the resize policy for map display.
Definition: MapDisplay.h:76
QPixmap * m_displayPixmap
This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible...
Definition: MapDisplay.h:273
A canvas built on top of Qt.
Definition: Canvas.h:54
QSize m_oldSize
Stores the last size of map display on start resize event.
Definition: MapDisplay.h:277
A widget to control the display of a set of layers.
Definition: MapDisplay.h:65
QPixmap * m_draftPixmap
The draft pixmap can be used to draw some feedback on map display.
Definition: MapDisplay.h:274
std::map< te::map::AbstractLayer *, te::qt::widgets::Canvas * > m_layerCanvasMap
A map that associates a layer to a canvas.
Definition: MapDisplay.h:282
This class controls how a set of layers are displayed.
Definition: MapDisplay.h:45
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
ResizePolicy m_resizePolicy
Resize policy for this map display.
Definition: MapDisplay.h:276
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
QColor m_backgroundColor
Background color.
Definition: MapDisplay.h:275
int m_interval
Timeout interval in milliseconds to redraw.
Definition: MapDisplay.h:279