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 It creates a new user own display draft pixmap.
152 
153  \return The own map display draft pixmap index.
154  */
155  std::size_t createMyOwnDraftPixmap();
156 
157  /*!
158  \brief It returns the user own display draft pixmap.
159 
160  \param index The draft pixmap index
161 
162  \return The own map display draft pixmap.
163 
164  \note This pixmap can be used to draw some feedback on map display.
165  \note The caller of this method will NOT take the ownership of the returned pixmap.
166  */
167  QPixmap* getMyOwnDraftPixmap(std::size_t index);
168 
169  /*!
170  \brief It removes the user own display draft pixmap.
171 
172  \param index The draft pixmap index
173  */
174  void removeMyOwnDraftPixmap(std::size_t index);
175 
176  /*!
177  \brief Sets the resize policy to this map display.
178 
179  \param policy The resize policy.
180  */
181  virtual void setResizePolicy(const ResizePolicy& policy);
182 
183  /*!
184  \brief Sets the timeout interval in milliseconds to redraw on resize event.
185 
186  \param msec The timeout interval in milliseconds.
187  */
188  virtual void setResizeInterval(int msec);
189 
190  /*!
191  \brief Transforms the given point, in screen coordinates, to a point in world coordinates.
192 
193  \param p A point in screen coordinates.
194 
195  \return The point in world coordinates.
196 
197  \note This method will return a null point if the transform can not be done.
198  */
199  virtual QPointF transform(const QPointF& p);
200 
201  /*!
202  \brief Gets the map display background color
203 
204  \return The map display background color.
205  */
206  virtual QColor getBackgroundColor();
207 
208  /*!
209  \brief Sets the map display background color
210 
211  \param color The color.
212  */
213  virtual void setBackgroundColor(const QColor& color);
214 
215  /*! \brief Returns if the map display is drawing. */
216  bool isDrawing() const;
217 
218  /*!
219  \brief Calculates and return the current scale
220  */
221  virtual double getScale() const;
222 
223  /*!
224  \brief Defines the scale and calculates envelope based on the requested scale
225  */
226  virtual bool setScale(const double& scale);
227 
228  /*!
229  \brief Returns the current values of the DPI in X-axis and in Y-axis
230  */
231  virtual void getDPI(int& dpiX, int& dpiY) const;
232 
233  /*!
234  \brief Overrides the values of the DPI that had been acquired from the device.
235  This is done in order to make the scale be correctly computed and allows the correct computation of sizes in millimeters.
236  */
237  virtual void setOverrideDPI(int dpiX, int dpiY);
238 
239  /*!
240  \brief Returns the default value of the DPI. In this case, the values from the device will be acquired.
241  */
242  virtual void restoreDPI();
243 
244  virtual void updateLayer(te::map::AbstractLayerPtr layer, bool redraw = true);
245 
246  /*!
247  \brief Updates the current tool being used on te::qt::widgets::MapDisplay.
248 
249  \param tool The new te::qt::widgets::AbstractTool.
250 
251  \param delPrevious True for delete the old tool.
252 
253  \note The class will take the ownership of the given pointer.
254  */
255  virtual void setCurrentTool(te::qt::widgets::AbstractTool* tool, const bool& delPrevious = true);
256 
257  /*!
258  \brief Returns the current tool being used.
259  \return The current tool being used.
260  */
261  te::qt::widgets::AbstractTool* getCurrentTool();
262 
263  /*!
264  \brief Defines the min scale and max scale.
265  */
266  virtual void setLimitScale(double minScale, double maxScale);
267 
268  /*!
269  \brief Gets the digitalization factor.
270  */
271  virtual double getDigitalization() const;
272 
273  /*!
274  \brief Sets the digitalization factor.
275  */
276  virtual void setDigitalization(double digitalization);
277 
278  /*!
279  \brief Returns the pointer for the graphic scale object;
280  \return Pointer for the graphic scale object
281  */
282  ScaleWidget* getGraphicScale() const;
283 
284  Grid* getGrid() const;
285 
286 
287  void blockPopUp();
288 
289  void unBlockPopUp();
290 
291  bool isBlockedPopUp();
292 
293  public slots:
294 
295  /*!
296  \brief Shows / hides the graphic scale
297  \param visible True shows the graphic scale, false hides it.
298  */
299  void showGraphicScale(bool visible);
300 
301  /*!
302  \brief
303  \param
304  */
305  void showGrid(bool visible);
306 
307  protected:
308 
309  /*!
310  \brief It displays the given layer.
311 
312  \param layer The layer that will be drawn.
313  \param painter The painter that will composed the draw result.
314 
315  \note This method is called recursively for each child of the given layer.
316  \note It may need to retrieve data in order top display the layers.
317  */
318  virtual void draw(te::map::AbstractLayer* layer, QPainter& painter);
319 
320  /*!
321  \brief It retrieves an associated canvas to the given layer.
322 
323  \param layer The layer for wich we want to get an associated canvas.
324 
325  \note If there is not a canvas associated to the given layer, one will be created.
326 
327  \return A canvas associated to the layer.
328  */
329  virtual te::qt::widgets::Canvas* getCanvas(te::map::AbstractLayer* layer, int type = QInternal::Pixmap);
330 
331  /*!
332  \brief It resizes all canvas of map display.
333  */
334  virtual void resizeAllCanvas();
335 
336  /*!
337  \brief It adjusts the map display extent based on resize policy.
338 
339  \param oldSize The size before the resize.
340  \param size The size after the resize.
341  */
342  virtual void adjustExtent(const QSize& oldSize, const QSize& size);
343 
344  /*!
345  \brief It assembles the final image and draws the widget.
346 
347  \param e The event received by this widget.
348  */
349  virtual void paintEvent(QPaintEvent* e);
350 
351  /*!
352  \brief This event handler receives widget resize events wich are passed in the event parameter.
353 
354  \param e The resize event.
355  */
356  virtual void resizeEvent(QResizeEvent* e);
357 
358  protected slots:
359 
360  virtual void onResizeTimeout();
361 
362  signals:
363 
364  /*! This signal is emitted when the map display extent changed. */
365  void extentChanged();
366 
367  /*! this signal is issued to others draw on this display. */
368  void displayPaintEvent(QPainter*);
369 
370  /*! This signal is sent to others know that the projection was changed. */
371  void displaySridChanged();
372 
373  ///*! This signal is sent to others know that is drag enter event. */
374  //void displayDragEnterEvent(QDragEnterEvent*);
375  //void displayDragMoveEvent(QDragMoveEvent*);
376  ///*! This signal is sent to others know that is drop event. */
377  //void displayDropEvent(QDropEvent*);
378 
379  private:
380 
381  /** @name Copy Constructor and Assignment Operator
382  * Copy constructor and assignment operator not allowed.
383  */
384  //@{
385 
386  /*!
387  \brief Copy constructor not allowed.
388 
389  \param rhs The right-hand-side copy that would be used to copy from.
390  */
391  MapDisplay(const MapDisplay& rhs);
392 
393  /*!
394  \brief Assignment operator not allowed.
395 
396  \param rhs The right-hand-side copy that would be used to copy from.
397 
398  \return A reference to this object.
399  */
400  MapDisplay& operator=(const MapDisplay& rhs);
401 
402  //@}
403 
404  protected:
405 
406  QPixmap* m_displayPixmap; //!< This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible layers.
407  QPixmap* m_draftPixmap; //!< The draft pixmap can be used to draw some feedback on map display.
408 
409  std::vector<QPixmap*> m_ownPixmapVec; //!< A vector of users own draft pixmap
410 
411  QColor m_backgroundColor; //!< Background color.
412  ResizePolicy m_resizePolicy; //!< Resize policy for this map display.
413  QSize m_oldSize; //!< Stores the last size of map display on start resize event.
414  QTimer* m_timer; //!< Timer to execute redraw on resize action.
415  int m_interval; //!< Timeout interval in milliseconds to redraw.
416  bool m_isDrawing; //!< A flag that indicates if the map display is drawing.
417 
418  mutable double m_scale; //!< Current calculated scale
419  int m_overridedDpiX; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
420  int m_overridedDpiY; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
421  double m_minScale; //!< The minimun scale.
422  double m_maxScale; //!< The maximum scale.
423  double m_digitalization; //!< Factor used in digitalization.
424 
425  te::qt::widgets::AbstractTool* m_tool; //!< Pointer to the current tool being used.
426 
427  ScaleWidget* m_graphicScale; //!< Graphic scale pointer.
428  Grid* m_grid; //!< Planar grid pointer.
429 
430  std::size_t m_blockPopUpCounter; //!< Flag used to block pop up in this component
431  };
432  } // end namespace widgets
433  } // end namespace qt
434 } // end namespace te
435 
436 #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
std::vector< QPixmap * > m_ownPixmapVec
A vector of users own draft pixmap.
Definition: MapDisplay.h:409
Grid * m_grid
Planar grid pointer.
Definition: MapDisplay.h:428
bool m_isDrawing
A flag that indicates if the map display is drawing.
Definition: MapDisplay.h:416
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:406
double m_scale
Current calculated scale.
Definition: MapDisplay.h:418
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:63
std::size_t m_blockPopUpCounter
Flag used to block pop up in this component.
Definition: MapDisplay.h:430
QSize m_oldSize
Stores the last size of map display on start resize event.
Definition: MapDisplay.h:413
ResizePolicy m_resizePolicy
Resize policy for this map display.
Definition: MapDisplay.h:412
double m_digitalization
Factor used in digitalization.
Definition: MapDisplay.h:423
int m_interval
Timeout interval in milliseconds to redraw.
Definition: MapDisplay.h:415
te::qt::widgets::AbstractTool * m_tool
Pointer to the current tool being used.
Definition: MapDisplay.h:425
int m_overridedDpiX
Overrided value of the DPI in the X-axis, so the scale can be correctly computed. ...
Definition: MapDisplay.h:419
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:427
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:420
A canvas built on top of Qt.
Definition: Canvas.h:54
ResizePolicy
Defines the resize policy for map display.
Definition: MapDisplay.h:82
double m_maxScale
The maximum scale.
Definition: MapDisplay.h:422
double m_minScale
The minimun scale.
Definition: MapDisplay.h:421
#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:407
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QColor m_backgroundColor
Background color.
Definition: MapDisplay.h:411
QTimer * m_timer
Timer to execute redraw on resize action.
Definition: MapDisplay.h:414