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