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