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 AbstractTool;
58  class Canvas;
59  class ScaleWidget;
60  class Grid;
61 
62  /*!
63  \class MapDisplay
64 
65  \brief A widget to control the display of a set of layers.
66 
67  \ingroup widgets
68 
69  \sa te::map::AbstractMapDisplay, te::map::MapDisplay
70  */
71  class TEQTWIDGETSEXPORT MapDisplay : public QWidget, public te::map::MapDisplay
72  {
73  Q_OBJECT
74 
75  public:
76 
77  /*!
78  \enum ResizePolicy
79 
80  \brief Defines the resize policy for map display.
81  */
83  {
84  Fixed, /*!< Document-me! */
85  Cut, /*!< Document-me! */
86  Center /*!< Document-me! */
87  };
88 
89  /** @name Initializer Methods
90  * Methods related to instantiation and destruction.
91  */
92  //@{
93 
94  /*!
95  \brief It constructs an empty map display with the given dimensions which is a child of parent, with widget flags set to f.
96 
97  \param size The map display size.
98  \param parent The widget's parent.
99  \param f Widget window flags.
100  */
101  MapDisplay(const QSize& size, QWidget* parent = 0, Qt::WindowFlags f = 0);
102 
103  MapDisplay(QWidget* parent = 0, Qt::WindowFlags f = 0);
104 
105  /*! \brief Destructor. */
106  virtual ~MapDisplay();
107 
108  //@}
109 
110  /** @name AbstractMapDisplay Methods */
111  //@{
112 
113  virtual void changeData(te::map::AbstractLayerPtr, int nsrid = TE_UNKNOWN_SRS);
114 
115  virtual void setExtent(te::gm::Envelope& e, bool doRefresh = true);
116 
117  virtual void refresh(bool redraw = false);
118 
119  unsigned int getWidth() const;
120 
121  unsigned int getHeight() const;
122 
123  double getWidthMM() const;
124 
125  double getHeightMM() const;
126 
127  virtual void setSRID(const int& srid, bool doRefresh = true);
128 
129  //@}
130 
131  /*!
132  \brief It returns the map display pixmap.
133 
134  \return The map display pixmap.
135 
136  \note The caller of this method will NOT take the ownership of the returned pixmap.
137  */
138  virtual QPixmap* getDisplayPixmap() const;
139 
140  /*!
141  \brief It returns the map display draft pixmap.
142 
143  \return The map display draft pixmap.
144 
145  \note This pixmap can be used to draw some feedback on map display.
146  \note The caller of this method will NOT take the ownership of the returned pixmap.
147  */
148  virtual QPixmap* getDraftPixmap() const;
149 
150  /*!
151  \brief Sets the resize policy to this map display.
152 
153  \param policy The resize policy.
154  */
155  virtual void setResizePolicy(const ResizePolicy& policy);
156 
157  /*!
158  \brief Sets the timeout interval in milliseconds to redraw on resize event.
159 
160  \param msec The timeout interval in milliseconds.
161  */
162  virtual void setResizeInterval(int msec);
163 
164  /*!
165  \brief Transforms the given point, in screen coordinates, to a point in world coordinates.
166 
167  \param p A point in screen coordinates.
168 
169  \return The point in world coordinates.
170 
171  \note This method will return a null point if the transform can not be done.
172  */
173  virtual QPointF transform(const QPointF& p);
174 
175  /*!
176  \brief Gets the map display background color
177 
178  \return The map display background color.
179  */
180  virtual QColor getBackgroundColor();
181 
182  /*!
183  \brief Sets the map display background color
184 
185  \param color The color.
186  */
187  virtual void setBackgroundColor(const QColor& color);
188 
189  /*! \brief Returns if the map display is drawing. */
190  bool isDrawing() const;
191 
192  /*!
193  \brief Calculates and return the current scale
194  */
195  virtual double getScale() const;
196 
197  /*!
198  \brief Defines the scale and calculates envelope based on the requested scale
199  */
200  virtual bool setScale(const double& scale);
201 
202  /*!
203  \brief Returns the current values of the DPI in X-axis and in Y-axis
204  */
205  virtual void getDPI(int& dpiX, int& dpiY) const;
206 
207  /*!
208  \brief Overrides the values of the DPI that had been acquired from the device.
209  This is done in order to make the scale be correctly computed and allows the correct computation of sizes in millimeters.
210  */
211  virtual void setOverrideDPI(int dpiX, int dpiY);
212 
213  /*!
214  \brief Returns the default value of the DPI. In this case, the values from the device will be acquired.
215  */
216  virtual void restoreDPI();
217 
218  virtual void updateLayer(te::map::AbstractLayerPtr layer, bool redraw = true) { }
219 
220  /*!
221  \brief Updates the current tool being used on te::qt::widgets::MapDisplay.
222 
223  \param tool The new te::qt::widgets::AbstractTool.
224 
225  \param delPrevious True for delete the old tool.
226 
227  \note The class will take the ownership of the given pointer.
228  */
229  virtual void setCurrentTool(te::qt::widgets::AbstractTool* tool, const bool& delPrevious = true);
230 
231  /*!
232  \brief Defines the min scale and max scale.
233  */
234  virtual void setLimitScale(double minScale, double maxScale);
235 
236  /*!
237  \brief Gets the digitalization factor.
238  */
239  virtual double getDigitalization() const;
240 
241  /*!
242  \brief Sets the digitalization factor.
243  */
244  virtual void setDigitalization(double digitalization);
245 
246  /*!
247  \brief Returns the pointer for the graphic scale object;
248  \return Pointer for the graphic scale object
249  */
250  ScaleWidget* getGraphicScale() const;
251 
252  Grid* getGrid() const;
253 
254  public slots:
255 
256  /*!
257  \brief Shows / hides the graphic scale
258  \param visible True shows the graphic scale, false hides it.
259  */
260  void showGraphicScale(bool visible);
261 
262  /*!
263  \brief
264  \param
265  */
266  void showGrid(bool visible);
267 
268  protected:
269 
270  /*!
271  \brief It displays the given layer.
272 
273  \param layer The layer that will be drawn.
274  \param painter The painter that will composed the draw result.
275 
276  \note This method is called recursively for each child of the given layer.
277  \note It may need to retrieve data in order top display the layers.
278  */
279  virtual void draw(te::map::AbstractLayer* layer, QPainter& painter);
280 
281  /*!
282  \brief It retrieves an associated canvas to the given layer.
283 
284  \param layer The layer for wich we want to get an associated canvas.
285 
286  \note If there is not a canvas associated to the given layer, one will be created.
287 
288  \return A canvas associated to the layer.
289  */
290  virtual te::qt::widgets::Canvas* getCanvas(te::map::AbstractLayer* layer, int type = QInternal::Pixmap);
291 
292  /*!
293  \brief It resizes all canvas of map display.
294  */
295  virtual void resizeAllCanvas();
296 
297  /*!
298  \brief It adjusts the map display extent based on resize policy.
299 
300  \param oldSize The size before the resize.
301  \param size The size after the resize.
302  */
303  virtual void adjustExtent(const QSize& oldSize, const QSize& size);
304 
305  /*!
306  \brief It assembles the final image and draws the widget.
307 
308  \param e The event received by this widget.
309  */
310  virtual void paintEvent(QPaintEvent* e);
311 
312  /*!
313  \brief This event handler receives widget resize events wich are passed in the event parameter.
314 
315  \param e The resize event.
316  */
317  virtual void resizeEvent(QResizeEvent* e);
318 
319  protected slots:
320 
321  virtual void onResizeTimeout();
322 
323  signals:
324 
325  /*! This signal is emitted when the map display extent changed. */
326  void extentChanged();
327 
328  /*! this signal is issued to others draw on this display. */
329  void displayPaintEvent(QPainter*);
330 
331  /*! This signal is sent to others know that the projection was changed. */
332  void displaySridChanged();
333 
334  ///*! This signal is sent to others know that is drag enter event. */
335  //void displayDragEnterEvent(QDragEnterEvent*);
336  //void displayDragMoveEvent(QDragMoveEvent*);
337  ///*! This signal is sent to others know that is drop event. */
338  //void displayDropEvent(QDropEvent*);
339 
340  private:
341 
342  /** @name Copy Constructor and Assignment Operator
343  * Copy constructor and assignment operator not allowed.
344  */
345  //@{
346 
347  /*!
348  \brief Copy constructor not allowed.
349 
350  \param rhs The right-hand-side copy that would be used to copy from.
351  */
352  MapDisplay(const MapDisplay& rhs);
353 
354  /*!
355  \brief Assignment operator not allowed.
356 
357  \param rhs The right-hand-side copy that would be used to copy from.
358 
359  \return A reference to this object.
360  */
361  MapDisplay& operator=(const MapDisplay& rhs);
362 
363  //@}
364 
365  protected:
366 
367  QPixmap* m_displayPixmap; //!< This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible layers.
368  QPixmap* m_draftPixmap; //!< The draft pixmap can be used to draw some feedback on map display.
369  QColor m_backgroundColor; //!< Background color.
370  ResizePolicy m_resizePolicy; //!< Resize policy for this map display.
371  QSize m_oldSize; //!< Stores the last size of map display on start resize event.
372  QTimer* m_timer; //!< Timer to execute redraw on resize action.
373  int m_interval; //!< Timeout interval in milliseconds to redraw.
374  bool m_isDrawing; //!< A flag that indicates if the map display is drawing.
375 
376  mutable double m_scale; //!< Current calculated scale
377  int m_overridedDpiX; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
378  int m_overridedDpiY; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
379  double m_minScale; //!< The minimun scale.
380  double m_maxScale; //!< The maximum scale.
381  double m_digitalization; //!< Factor used in digitalization.
382 
383  te::qt::widgets::AbstractTool* m_tool; //!< Pointer to the current tool being used.
384 
385  ScaleWidget* m_graphicScale; //!< Graphic scale pointer.
386  Grid* m_grid; //!< Planar grid pointer.
387  };
388  } // end namespace widgets
389  } // end namespace qt
390 } // end namespace te
391 
392 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MAPDISPLAY_H
#define slots
A widget that shows the graphic scale associated with a display.
Definition: ScaleWidget.h:99
This is the base class for layers.
Definition: AbstractLayer.h:77
Grid * m_grid
Planar grid pointer.
Definition: MapDisplay.h:386
bool m_isDrawing
A flag that indicates if the map display is drawing.
Definition: MapDisplay.h:374
A widget to control the display of a set of layers.
Definition: MapDisplay.h:71
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:367
double m_scale
Current calculated scale.
Definition: MapDisplay.h:376
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:63
QSize m_oldSize
Stores the last size of map display on start resize event.
Definition: MapDisplay.h:371
ResizePolicy m_resizePolicy
Resize policy for this map display.
Definition: MapDisplay.h:370
double m_digitalization
Factor used in digitalization.
Definition: MapDisplay.h:381
int m_interval
Timeout interval in milliseconds to redraw.
Definition: MapDisplay.h:373
te::qt::widgets::AbstractTool * m_tool
Pointer to the current tool being used.
Definition: MapDisplay.h:383
int m_overridedDpiX
Overrided value of the DPI in the X-axis, so the scale can be correctly computed. ...
Definition: MapDisplay.h:377
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
TerraLib.
This class controls how a set of layers are displayed.
Definition: MapDisplay.h:45
ScaleWidget * m_graphicScale
Graphic scale pointer.
Definition: MapDisplay.h:385
This class implements the grid, planar or geographic, to be used with the MapDisplay.
Definition: Grid.h:74
int m_overridedDpiY
Overrided value of the DPI in the X-axis, so the scale can be correctly computed. ...
Definition: MapDisplay.h:378
A canvas built on top of Qt.
Definition: Canvas.h:54
ResizePolicy
Defines the resize policy for map display.
Definition: MapDisplay.h:82
virtual void updateLayer(te::map::AbstractLayerPtr layer, bool redraw=true)
Definition: MapDisplay.h:218
double m_maxScale
The maximum scale.
Definition: MapDisplay.h:380
double m_minScale
The minimun scale.
Definition: MapDisplay.h:379
#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:368
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QColor m_backgroundColor
Background color.
Definition: MapDisplay.h:369
QTimer * m_timer
Timer to execute redraw on resize action.
Definition: MapDisplay.h:372