MultiThreadMapDisplay.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/MultiThreadMapDisplay.h
22 
23  \brief A multi thread Qt4 widget to control the display of a set of layers.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_MULTITHREAD_MAPDISPLAY_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_MULTITHREAD_MAPDISPLAY_H
28 
29 // TerraLib
30 #include "MapDisplay.h"
31 
32 // Qt
33 #include <QtCore/QMap>
34 #include <QtCore/QString>
35 #include <QImage>
36 
37 // STL
38 #include <vector>
39 
40 namespace te
41 {
42  namespace qt
43  {
44  namespace widgets
45  {
46 // Forward declarations
47  class DrawLayerThread;
48 
49  /*!
50  \class MultiThreadMapDisplay
51 
52  \brief A multi thread Qt4 widget to control the display of a set of layers.
53 
54  \ingroup widgets
55 
56  \sa MapDisplay, te::map::AbstractMapDisplay, te::map::MapDisplay
57  */
59  {
60  Q_OBJECT
61 
62  public:
63 
64  /** @name Initializer Methods
65  * Methods related to instantiation and destruction.
66  */
67  //@{
68 
69  /*!
70  \brief It constructs an empty multi thread map display with the given dimensions which is a child of parent, with widget flags set to f.
71 
72  \param size The map display size.
73  \param showFeedback A flag that indicates if the map display will show drawing feedback.
74  \param parent The widget's parent.
75  \param f Widget window flags.
76  */
77  MultiThreadMapDisplay(const QSize& size, const bool& showFeedback = true, QWidget* parent = 0, Qt::WindowFlags f = 0);
78 
79  MultiThreadMapDisplay(QWidget* parent = 0, const bool& showFeedback = true, Qt::WindowFlags f = 0);
80 
81  /*! \brief Destructor. */
83 
84  //@}
85 
86  /** @name AbstractMapDisplay Methods
87  */
88  //@{
89 
90  void setExtent(te::gm::Envelope& e, bool doRefresh = true);
91 
92  void refresh();
93 
94  //@}
95 
96  /*!
97  \brief Transforms the given point, in screen coordinates, to a point in world coordinates.
98 
99  \param p A point in screen coordinates.
100 
101  \return The point in world coordinates.
102 
103  \note This method will return a null point if the transform can not be done.
104  */
105  virtual QPointF transform(const QPointF& p);
106 
107  void setSynchronous(bool on);
108 
109  void updateLayer(te::map::AbstractLayerPtr layer);
110 
111  private:
112 
113  void updateTransform();
114 
115  protected slots:
116 
117  void showFeedback(const QImage& image);
118 
119  void onDrawLayerFinished(const int& index, const QImage& image);
120 
121  signals:
122 
123  /*!
124  \brief This signal is emitted when the draw process ends. i.e. when all layers have been drawn.
125 
126  \param errors A map that indicates the errors that could be occurred during the draw process. i.e layer id -> error message
127 
128  \note The signal parameter maps the layer id (that generated the error) to an error message.
129 
130  \note The signal parameter can be empty. It indicates that no error occurred.
131  */
132  void drawLayersFinished(const QMap<QString, QString>& errors);
133 
134  private:
135 
136  /** @name Copy Constructor and Assignment Operator
137  * Copy constructor and assignment operator not allowed.
138  */
139  //@{
140 
141  /*!
142  \brief Copy constructor not allowed.
143 
144  \param rhs The right-hand-side copy that would be used to copy from.
145  */
147 
148  /*!
149  \brief Assignment operator not allowed.
150 
151  \param rhs The right-hand-side copy that would be used to copy from.
152 
153  \return A reference to this object.
154  */
155  MultiThreadMapDisplay& operator=(const MultiThreadMapDisplay& rhs);
156 
157  //@}
158 
159  protected:
160 
161  std::list<te::map::AbstractLayerPtr> m_visibleLayers; //!< The set of visible layers.
162  std::vector<DrawLayerThread*> m_threads; //!< The set of threads used to draw the layer list.
163  std::map<int, QImage> m_images; //!< The set of images built by each thread. It will be used to compose the final result, keeping the layer list order.
164  bool m_showFeedback; //!< A flag that indicates if the map display will show drawing feedback.
165  QMatrix m_matrix; //!< Used to convert screen coordinates to world coordinates.
166  bool m_synchronous; //!< A flag that indicates if the map display is synchronous or asynchronous.
167  };
168 
169  } // end namespace widgets
170  } // end namespace qt
171 } // end namespace te
172 
173 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MULTITHREAD_MAPDISPLAY_H
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
A Qt4 widget to control the display of a set of layers.
bool m_showFeedback
A flag that indicates if the map display will show drawing feedback.
bool m_synchronous
A flag that indicates if the map display is synchronous or asynchronous.
QMatrix m_matrix
Used to convert screen coordinates to world coordinates.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
URI C++ Library.
std::vector< DrawLayerThread * > m_threads
The set of threads used to draw the layer list.
std::map< int, QImage > m_images
The set of images built by each thread. It will be used to compose the final result, keeping the layer list order.
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::list< te::map::AbstractLayerPtr > m_visibleLayers
The set of visible layers.
A multi thread Qt4 widget to control the display of a set of layers.