MapDisplay.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/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 <QWidget>
36 
37 // STL
38 #include <map>
39 
40 // Forward declarations
41 class QTimer;
42 class QGraphicsView;
43 
44 namespace te
45 {
46 // Forward declarations
47  namespace gm { class Envelope; }
48  namespace map { class AbstractLayer; }
49 
50  namespace qt
51  {
52  namespace widgets
53  {
54 // Forward declarations
55  class Canvas;
56 
57  /*!
58  \class MapDisplay
59 
60  \brief A widget to control the display of a set of layers.
61 
62  \ingroup widgets
63 
64  \sa te::map::AbstractMapDisplay, te::map::MapDisplay
65  */
66  class TEQTWIDGETSEXPORT MapDisplay : public QWidget, public te::map::MapDisplay
67  {
68  Q_OBJECT
69 
70  public:
71 
72  /*!
73  \enum ResizePolicy
74 
75  \brief Defines the resize policy for map display.
76  */
78  {
79  Fixed, /*!< Document-me! */
80  Cut, /*!< Document-me! */
81  Center /*!< Document-me! */
82  };
83 
84  /** @name Initializer Methods
85  * Methods related to instantiation and destruction.
86  */
87  //@{
88 
89  /*!
90  \brief It constructs an empty map display with the given dimensions which is a child of parent, with widget flags set to f.
91 
92  \param size The map display size.
93  \param parent The widget's parent.
94  \param f Widget window flags.
95  */
96  MapDisplay(const QSize& size, QWidget* parent = 0, Qt::WindowFlags f = 0);
97 
98  MapDisplay(QWidget* parent = 0, Qt::WindowFlags f = 0);
99 
100  /*! \brief Destructor. */
101  virtual ~MapDisplay();
102 
103  //@}
104 
105  /** @name AbstractMapDisplay Methods */
106  //@{
107 
108  virtual void changeData(te::map::AbstractLayerPtr, int nsrid = TE_UNKNOWN_SRS);
109 
110  virtual void setExtent(te::gm::Envelope& e, bool doRefresh = true);
111 
112  virtual void refresh();
113 
114  unsigned int getWidth() const;
115 
116  unsigned int getHeight() const;
117 
118  double getWidthMM() const;
119 
120  double getHeightMM() const;
121 
122  virtual void setSRID(const int& srid, bool doRefresh = true);
123 
124  //@}
125 
126  /*!
127  \brief It returns the map display pixmap.
128 
129  \return The map display pixmap.
130 
131  \note The caller of this method will NOT take the ownership of the returned pixmap.
132  */
133  virtual QPixmap* getDisplayPixmap() const;
134 
135  /*!
136  \brief It returns the map display draft pixmap.
137 
138  \return The map display draft pixmap.
139 
140  \note This pixmap can be used to draw some feedback on map display.
141  \note The caller of this method will NOT take the ownership of the returned pixmap.
142  */
143  virtual QPixmap* getDraftPixmap() const;
144 
145  /*!
146  \brief Sets the resize policy to this map display.
147 
148  \param policy The resize policy.
149  */
150  virtual void setResizePolicy(const ResizePolicy& policy);
151 
152  /*!
153  \brief Sets the timeout interval in milliseconds to redraw on resize event.
154 
155  \param msec The timeout interval in milliseconds.
156  */
157  virtual void setResizeInterval(int msec);
158 
159  /*!
160  \brief Transforms the given point, in screen coordinates, to a point in world coordinates.
161 
162  \param p A point in screen coordinates.
163 
164  \return The point in world coordinates.
165 
166  \note This method will return a null point if the transform can not be done.
167  */
168  virtual QPointF transform(const QPointF& p);
169 
170  /*!
171  \brief Gets the map display background color
172 
173  \return The map display background color.
174  */
175  virtual QColor getBackgroundColor();
176 
177  /*!
178  \brief Sets the map display background color
179 
180  \param color The color.
181  */
182  virtual void setBackgroundColor(const QColor& color);
183 
184  /*! \brief Returns if the map display is drawing. */
185  bool isDrawing() const;
186 
187  /*!
188  \brief Calculates and return the current scale
189  */
190  virtual double getScale() const;
191 
192  /*!
193  \brief Defines the scale and calculates envelope based on the requested scale
194  */
195  virtual bool setScale(const double& scale);
196 
197  /*!
198  \brief Returns the current values of the DPI in X-axis and in Y-axis
199  */
200  virtual void getDPI(int& dpiX, int& dpiY) const;
201 
202  /*!
203  \brief Overrides the values of the DPI that had been acquired from the device.
204  This is done in order to make the scale be correctly computed and allows the correct computation of sizes in millimeters.
205  */
206  virtual void setOverrideDPI(int dpiX, int dpiY);
207 
208  /*!
209  \brief Returns the default value of the DPI. In this case, the values from the device will be acquired.
210  */
211  virtual void restoreDPI();
212 
213  protected:
214 
215  /*!
216  \brief It displays the given layer.
217 
218  \param layer The layer that will be drawn.
219  \param painter The painter that will composed the draw result.
220 
221  \note This method is called recursively for each child of the given layer.
222  \note It may need to retrieve data in order top display the layers.
223  */
224  virtual void draw(te::map::AbstractLayer* layer, QPainter& painter);
225 
226  /*!
227  \brief It retrieves an associated canvas to the given layer.
228 
229  \param layer The layer for wich we want to get an associated canvas.
230 
231  \note If there is not a canvas associated to the given layer, one will be created.
232 
233  \return A canvas associated to the layer.
234  */
235  virtual te::qt::widgets::Canvas* getCanvas(te::map::AbstractLayer* layer, int type = QInternal::Pixmap);
236 
237  /*!
238  \brief It resizes all canvas of map display.
239  */
240  virtual void resizeAllCanvas();
241 
242  /*!
243  \brief It adjusts the map display extent based on resize policy.
244 
245  \param oldSize The size before the resize.
246  \param size The size after the resize.
247  */
248  virtual void adjustExtent(const QSize& oldSize, const QSize& size);
249 
250  /*!
251  \brief It assembles the final image and draws the widget.
252 
253  \param e The event received by this widget.
254  */
255  virtual void paintEvent(QPaintEvent* e);
256 
257  /*!
258  \brief This event handler receives widget resize events wich are passed in the event parameter.
259 
260  \param e The resize event.
261  */
262  virtual void resizeEvent(QResizeEvent* e);
263 
264  protected slots:
265 
266  virtual void onResizeTimeout();
267 
268  signals:
269 
270  /*! This signal is emitted when the map display extent changed. */
271  void extentChanged();
272 
273  /*! this signal is issued to others draw on this display. */
274  void displayPaintEvent(QPainter*);
275 
276  /*! This signal is sent to others know that the projection was changed. */
277  void displaySridChanged();
278 
279  ///*! This signal is sent to others know that is drag enter event. */
280  //void displayDragEnterEvent(QDragEnterEvent*);
281  //void displayDragMoveEvent(QDragMoveEvent*);
282  ///*! This signal is sent to others know that is drop event. */
283  //void displayDropEvent(QDropEvent*);
284 
285  private:
286 
287  /** @name Copy Constructor and Assignment Operator
288  * Copy constructor and assignment operator not allowed.
289  */
290  //@{
291 
292  /*!
293  \brief Copy constructor not allowed.
294 
295  \param rhs The right-hand-side copy that would be used to copy from.
296  */
297  MapDisplay(const MapDisplay& rhs);
298 
299  /*!
300  \brief Assignment operator not allowed.
301 
302  \param rhs The right-hand-side copy that would be used to copy from.
303 
304  \return A reference to this object.
305  */
306  MapDisplay& operator=(const MapDisplay& rhs);
307 
308  //@}
309 
310  protected:
311 
312  QPixmap* m_displayPixmap; //!< This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible layers.
313  QPixmap* m_draftPixmap; //!< The draft pixmap can be used to draw some feedback on map display.
314  QColor m_backgroundColor; //!< Background color.
315  ResizePolicy m_resizePolicy; //!< Resize policy for this map display.
316  QSize m_oldSize; //!< Stores the last size of map display on start resize event.
317  QTimer* m_timer; //!< Timer to execute redraw on resize action.
318  int m_interval; //!< Timeout interval in milliseconds to redraw.
319  bool m_isDrawing; //!< A flag that indicates if the map display is drawing.
320  std::map<te::map::AbstractLayer*, te::qt::widgets::Canvas*> m_layerCanvasMap; //!< A map that associates a layer to a canvas.
321  mutable double m_scale; //!< Current calculated scale
322  int m_overridedDpiX; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
323  int m_overridedDpiY; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
324  };
325 
326  } // end namespace widgets
327  } // end namespace qt
328 } // end namespace te
329 
330 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MAPDISPLAY_H
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:319
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
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:312
double m_scale
Current calculated scale.
Definition: MapDisplay.h:321
QSize m_oldSize
Stores the last size of map display on start resize event.
Definition: MapDisplay.h:316
ResizePolicy m_resizePolicy
Resize policy for this map display.
Definition: MapDisplay.h:315
int m_interval
Timeout interval in milliseconds to redraw.
Definition: MapDisplay.h:318
int m_overridedDpiX
Overrided value of the DPI in the X-axis, so the scale can be correctly computed. ...
Definition: MapDisplay.h:322
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:41
URI C++ Library.
This class controls how a set of layers are displayed.
Definition: MapDisplay.h:45
std::map< te::map::AbstractLayer *, te::qt::widgets::Canvas * > m_layerCanvasMap
A map that associates a layer to a canvas.
Definition: MapDisplay.h:320
int m_overridedDpiY
Overrided value of the DPI in the X-axis, so the scale can be correctly computed. ...
Definition: MapDisplay.h:323
A canvas built on top of Qt.
Definition: Canvas.h:54
ResizePolicy
Defines the resize policy for map display.
Definition: MapDisplay.h:77
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
QPixmap * m_draftPixmap
The draft pixmap can be used to draw some feedback on map display.
Definition: MapDisplay.h:313
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QColor m_backgroundColor
Background color.
Definition: MapDisplay.h:314
QTimer * m_timer
Timer to execute redraw on resize action.
Definition: MapDisplay.h:317