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 resizeEvent(QResizeEvent* e);
115 
116  private:
117 
118  void updateTransform();
119 
120  protected slots:
121 
122  void showFeedback(const QImage&) { }
123 
124  void showFeedback();
125 
126  void onDrawLayerFinished(const int& index, const QImage& image);
127 
128  void onRenderingFinished();
129 
130  void onDrawCanceled();
131 
132  signals:
133 
134  /*!
135  \brief This signal is emitted when the draw process ends. i.e. when all layers have been drawn.
136 
137  \param errors A map that indicates the errors that could be occurred during the draw process. i.e layer id -> error message
138 
139  \note The signal parameter maps the layer id (that generated the error) to an error message.
140 
141  \note The signal parameter can be empty. It indicates that no error occurred.
142  */
143  void drawLayersFinished(const QMap<QString, QString>& errors);
144 
145  private:
146 
147  /** @name Copy Constructor and Assignment Operator
148  * Copy constructor and assignment operator not allowed.
149  */
150  //@{
151 
152  /*!
153  \brief Copy constructor not allowed.
154 
155  \param rhs The right-hand-side copy that would be used to copy from.
156  */
158 
159  /*!
160  \brief Assignment operator not allowed.
161 
162  \param rhs The right-hand-side copy that would be used to copy from.
163 
164  \return A reference to this object.
165  */
166  MultiThreadMapDisplay& operator=(const MultiThreadMapDisplay& rhs);
167 
168  //@}
169 
170  protected:
171 
172  std::list<te::map::AbstractLayerPtr> m_visibleLayers; //!< The set of visible layers.
173  std::vector<QRunnable*> m_threads; //!< The set of threads used to draw the layer list.
174  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.
175  bool m_showFeedback; //!< A flag that indicates if the map display will show drawing feedback.
176  QMatrix m_matrix; //!< Used to convert screen coordinates to world coordinates.
177  bool m_synchronous; //!< A flag that indicates if the map display is synchronous or asynchronous.
178 
180  QCursor m_oldCursor;
181 // std::auto_ptr<ScopedCursor> m_cursor;
182  };
183  } // end namespace widgets
184  } // end namespace qt
185 } // end namespace te
186 
187 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_MULTITHREAD_MAPDISPLAY_H
A widget to control the display of a set of layers.
Definition: MapDisplay.h:68
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.