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 <QCursor>
34 #include <QImage>
35 #include <QMap>
36 #include <QString>
37 
38 // STL
39 #include <vector>
40 
41 class QRunnable;
42 
43 namespace te
44 {
45  namespace qt
46  {
47  namespace widgets
48  {
49  class ThreadManager;
50 // class ScopedCursor;
51 
52  /*!
53  \class MultiThreadMapDisplay
54 
55  \brief A multi thread Qt4 widget to control the display of a set of layers.
56 
57  \ingroup widgets
58 
59  \sa MapDisplay, te::map::AbstractMapDisplay, te::map::MapDisplay
60  */
62  {
63  Q_OBJECT
64 
65  public:
66 
67  /** @name Initializer Methods
68  * Methods related to instantiation and destruction.
69  */
70  //@{
71 
72  /*!
73  \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.
74 
75  \param size The map display size.
76  \param showFeedback A flag that indicates if the map display will show drawing feedback.
77  \param parent The widget's parent.
78  \param f Widget window flags.
79  */
80  MultiThreadMapDisplay(const QSize& size, const bool& showFeedback = true, QWidget* parent = 0, Qt::WindowFlags f = 0);
81 
82  MultiThreadMapDisplay(QWidget* parent = 0, const bool& showFeedback = true, Qt::WindowFlags f = 0);
83 
84  /*! \brief Destructor. */
86 
87  //@}
88 
89  /** @name AbstractMapDisplay Methods
90  */
91  //@{
92 
93  void setExtent(te::gm::Envelope& e, bool doRefresh = true);
94 
95  void refresh(bool redraw = false);
96 
97  //@}
98 
99  /*!
100  \brief Transforms the given point, in screen coordinates, to a point in world coordinates.
101 
102  \param p A point in screen coordinates.
103 
104  \return The point in world coordinates.
105 
106  \note This method will return a null point if the transform can not be done.
107  */
108  virtual QPointF transform(const QPointF& p);
109 
110  void setSynchronous(bool on);
111 
112  void updateLayer(te::map::AbstractLayerPtr layer, bool redraw = true);
113 
114  void updateLayer(std::vector<te::map::AbstractLayerPtr> layers, bool redraw = true);
115 
116  void resizeEvent(QResizeEvent* e);
117 
118  private:
119 
120  void updateTransform();
121 
122  protected slots:
123 
124  void showFeedback(const QImage&) { }
125 
126  void showFeedback();
127 
128  void onDrawLayerFinished(const int& index, const QImage& image);
129 
130  void onRenderingFinished();
131 
132  void onDrawCanceled();
133 
134  signals:
135 
136  /*!
137  \brief This signal is emitted when the draw process ends. i.e. when all layers have been drawn.
138 
139  \param errors A map that indicates the errors that could be occurred during the draw process. i.e layer id -> error message
140 
141  \note The signal parameter maps the layer id (that generated the error) to an error message.
142 
143  \note The signal parameter can be empty. It indicates that no error occurred.
144  */
145  void drawLayersFinished(const QMap<QString, QString>& errors);
146 
147  private:
148 
149  /** @name Copy Constructor and Assignment Operator
150  * Copy constructor and assignment operator not allowed.
151  */
152  //@{
153 
154  /*!
155  \brief Copy constructor not allowed.
156 
157  \param rhs The right-hand-side copy that would be used to copy from.
158  */
160 
161  /*!
162  \brief Assignment operator not allowed.
163 
164  \param rhs The right-hand-side copy that would be used to copy from.
165 
166  \return A reference to this object.
167  */
168  MultiThreadMapDisplay& operator=(const MultiThreadMapDisplay& rhs);
169 
170  //@}
171 
172  protected:
173 
174  std::list<te::map::AbstractLayerPtr> m_visibleLayers; //!< The set of visible layers.
175  std::vector<QRunnable*> m_threads; //!< The set of threads used to draw the layer list.
176  std::map<std::string, 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.
177  bool m_showFeedback; //!< A flag that indicates if the map display will show drawing feedback.
178  QMatrix m_matrix; //!< Used to convert screen coordinates to world coordinates.
179  bool m_synchronous; //!< A flag that indicates if the map display is synchronous or asynchronous.
180 
182  QCursor m_oldCursor;
183 // std::auto_ptr<ScopedCursor> m_cursor;
184  };
185  } // end namespace widgets
186  } // end namespace qt
187 } // end namespace te
188 
189 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MULTITHREAD_MAPDISPLAY_H
A widget to control the display of a set of layers.
Definition: MapDisplay.h:69
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< QRunnable * > m_threads
The set of threads used to draw the layer list.
#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.
std::map< std::string, 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.