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