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 Returns the current tool being used.
233  \return The current tool being used.
234  */
235  te::qt::widgets::AbstractTool* getCurrentTool();
236 
237  /*!
238  \brief Defines the min scale and max scale.
239  */
240  virtual void setLimitScale(double minScale, double maxScale);
241 
242  /*!
243  \brief Gets the digitalization factor.
244  */
245  virtual double getDigitalization() const;
246 
247  /*!
248  \brief Sets the digitalization factor.
249  */
250  virtual void setDigitalization(double digitalization);
251 
252  /*!
253  \brief Returns the pointer for the graphic scale object;
254  \return Pointer for the graphic scale object
255  */
256  ScaleWidget* getGraphicScale() const;
257 
258  Grid* getGrid() const;
259 
260 
261  void blockPopUp();
262 
263  void unBlockPopUp();
264 
265  bool isBlockedPopUp();
266 
267  public slots:
268 
269  /*!
270  \brief Shows / hides the graphic scale
271  \param visible True shows the graphic scale, false hides it.
272  */
273  void showGraphicScale(bool visible);
274 
275  /*!
276  \brief
277  \param
278  */
279  void showGrid(bool visible);
280 
281  protected:
282 
283  /*!
284  \brief It displays the given layer.
285 
286  \param layer The layer that will be drawn.
287  \param painter The painter that will composed the draw result.
288 
289  \note This method is called recursively for each child of the given layer.
290  \note It may need to retrieve data in order top display the layers.
291  */
292  virtual void draw(te::map::AbstractLayer* layer, QPainter& painter);
293 
294  /*!
295  \brief It retrieves an associated canvas to the given layer.
296 
297  \param layer The layer for wich we want to get an associated canvas.
298 
299  \note If there is not a canvas associated to the given layer, one will be created.
300 
301  \return A canvas associated to the layer.
302  */
303  virtual te::qt::widgets::Canvas* getCanvas(te::map::AbstractLayer* layer, int type = QInternal::Pixmap);
304 
305  /*!
306  \brief It resizes all canvas of map display.
307  */
308  virtual void resizeAllCanvas();
309 
310  /*!
311  \brief It adjusts the map display extent based on resize policy.
312 
313  \param oldSize The size before the resize.
314  \param size The size after the resize.
315  */
316  virtual void adjustExtent(const QSize& oldSize, const QSize& size);
317 
318  /*!
319  \brief It assembles the final image and draws the widget.
320 
321  \param e The event received by this widget.
322  */
323  virtual void paintEvent(QPaintEvent* e);
324 
325  /*!
326  \brief This event handler receives widget resize events wich are passed in the event parameter.
327 
328  \param e The resize event.
329  */
330  virtual void resizeEvent(QResizeEvent* e);
331 
332  protected slots:
333 
334  virtual void onResizeTimeout();
335 
336  signals:
337 
338  /*! This signal is emitted when the map display extent changed. */
339  void extentChanged();
340 
341  /*! this signal is issued to others draw on this display. */
342  void displayPaintEvent(QPainter*);
343 
344  /*! This signal is sent to others know that the projection was changed. */
345  void displaySridChanged();
346 
347  ///*! This signal is sent to others know that is drag enter event. */
348  //void displayDragEnterEvent(QDragEnterEvent*);
349  //void displayDragMoveEvent(QDragMoveEvent*);
350  ///*! This signal is sent to others know that is drop event. */
351  //void displayDropEvent(QDropEvent*);
352 
353  private:
354 
355  /** @name Copy Constructor and Assignment Operator
356  * Copy constructor and assignment operator not allowed.
357  */
358  //@{
359 
360  /*!
361  \brief Copy constructor not allowed.
362 
363  \param rhs The right-hand-side copy that would be used to copy from.
364  */
365  MapDisplay(const MapDisplay& rhs);
366 
367  /*!
368  \brief Assignment operator not allowed.
369 
370  \param rhs The right-hand-side copy that would be used to copy from.
371 
372  \return A reference to this object.
373  */
374  MapDisplay& operator=(const MapDisplay& rhs);
375 
376  //@}
377 
378  protected:
379 
380  QPixmap* m_displayPixmap; //!< This pixmap will be the result of all canvas pixmap drawing, i. e., the result of drawing all visible layers.
381  QPixmap* m_draftPixmap; //!< The draft pixmap can be used to draw some feedback on map display.
382  QColor m_backgroundColor; //!< Background color.
383  ResizePolicy m_resizePolicy; //!< Resize policy for this map display.
384  QSize m_oldSize; //!< Stores the last size of map display on start resize event.
385  QTimer* m_timer; //!< Timer to execute redraw on resize action.
386  int m_interval; //!< Timeout interval in milliseconds to redraw.
387  bool m_isDrawing; //!< A flag that indicates if the map display is drawing.
388 
389  mutable double m_scale; //!< Current calculated scale
390  int m_overridedDpiX; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
391  int m_overridedDpiY; //!< Overrided value of the DPI in the X-axis, so the scale can be correctly computed.
392  double m_minScale; //!< The minimun scale.
393  double m_maxScale; //!< The maximum scale.
394  double m_digitalization; //!< Factor used in digitalization.
395 
396  te::qt::widgets::AbstractTool* m_tool; //!< Pointer to the current tool being used.
397 
398  ScaleWidget* m_graphicScale; //!< Graphic scale pointer.
399  Grid* m_grid; //!< Planar grid pointer.
400 
401  std::size_t m_blockPopUpCounter; //!< Flag used to block pop up in this component
402  };
403  } // end namespace widgets
404  } // end namespace qt
405 } // end namespace te
406 
407 #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:399
bool m_isDrawing
A flag that indicates if the map display is drawing.
Definition: MapDisplay.h:387
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:380
double m_scale
Current calculated scale.
Definition: MapDisplay.h:389
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:401
QSize m_oldSize
Stores the last size of map display on start resize event.
Definition: MapDisplay.h:384
ResizePolicy m_resizePolicy
Resize policy for this map display.
Definition: MapDisplay.h:383
double m_digitalization
Factor used in digitalization.
Definition: MapDisplay.h:394
int m_interval
Timeout interval in milliseconds to redraw.
Definition: MapDisplay.h:386
te::qt::widgets::AbstractTool * m_tool
Pointer to the current tool being used.
Definition: MapDisplay.h:396
int m_overridedDpiX
Overrided value of the DPI in the X-axis, so the scale can be correctly computed. ...
Definition: MapDisplay.h:390
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:398
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:391
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:393
double m_minScale
The minimun scale.
Definition: MapDisplay.h:392
#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:381
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
QColor m_backgroundColor
Background color.
Definition: MapDisplay.h:382
QTimer * m_timer
Timer to execute redraw on resize action.
Definition: MapDisplay.h:385