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