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