All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DrawLayerThread.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 DrawLayerThread.h
22 
23  \brief This class represents a thread responsible to draw a given layer. Basically, this class receives draw layer requests and generates a QImage as result.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_INTERNAL_DRAWLAYERTHREAD_H
27 #define __TERRALIB_QT_WIDGETS_INTERNAL_DRAWLAYERTHREAD_H
28 
29 // TerraLib
30 #include "../../../geometry/Envelope.h"
31 #include "../Config.h"
32 
33 // Qt
34 #include <QtCore/QMutex>
35 #include <QtCore/QString>
36 #include <QtCore/QTimer>
37 #include <QtCore/QThread>
38 #include <QImage>
39 
40 namespace te
41 {
42 // Forward declarations
43  namespace map { class AbstractLayer; }
44 
45  namespace qt
46  {
47  namespace widgets
48  {
49  /*!
50  \class DrawLayerThread
51 
52  \brief This class represents a thread responsible to draw a given layer.
53  Basically, this class receives draw layer requests and generates a QImage as result.
54  */
55  class TEQTWIDGETSEXPORT DrawLayerThread : public QThread
56  {
57  Q_OBJECT
58 
59  public:
60 
61  /** @name Initializer Methods
62  * Methods related to instantiation and destruction.
63  */
64  //@{
65 
66  /*!
67  \brief It constructs a new thread responsible to draw a given layer.
68 
69  \param parent The thread's parent.
70  */
71  DrawLayerThread(QObject* parent = 0);
72 
73  /*! \brief Destructor. */
74  ~DrawLayerThread();
75 
76  //@}
77 
78  /*!
79  \brief This method is used to request the draw of the given layer.
80 
81  \param layer The layer that will be draw.
82  \param box The interest area to draw the layer.
83  \param srid The SRS to be used to draw the layer objects.
84  \param size The result size, in pixels; e.g. (800 x 600).
85  \param index An optional index that can be provided by the caller to keep the draw order.
86  */
87  void draw(te::map::AbstractLayer* layer, const te::gm::Envelope& box, int srid, const QSize& size, const int& index);
88 
89  /*! \brief This method tells if the thread finished with success. */
90  bool finishedWithSuccess() const;
91 
92  /*! \brief This method returns an error message if the thread has not finished with success. Otherwise, the error message is empty. */
93  QString getErrorMessage() const;
94 
95  /*! \brief This method returns the layer handled by this thread. */
96  te::map::AbstractLayer* getLayer() const;
97 
98  protected:
99 
100  /* \brief Starts the thread. i.e. performs the layer draw. */
101  void run();
102 
103  protected slots:
104 
105  /* \brief Called right before thread start execution. */
106  void onStarted();
107 
108  /* \brief Used to send a draw feedback. */
109  void sendFeedback();
110 
111  /* \brief Called right after thread stop execution. */
112  void onFinished();
113 
114  signals:
115 
116  /*!
117  \brief This signal is emitted during the draw process.
118 
119  \param image The partial result of draw process.
120  */
121  void feedback(const QImage& image);
122 
123  /*!
124  \brief This signal is emitted when the draw process ends.
125 
126  \param index The thread index.
127  \param image The final result of draw process.
128  */
129  void drawLayerFinished(const int& index, const QImage& image);
130 
131  protected:
132 
133  te::map::AbstractLayer* m_layer; //!< The layer that will be drawn.
134  te::gm::Envelope m_env; //!< The interest area to draw the layer.
135  int m_srid; //!< The SRS to be used to draw the layer objects.
136  int m_index; //!< An optional index that can be provided by the caller to keep the draw order.
137  QImage m_image; //!< The image that will be generated during the draw process.
138  QMutex m_mutex; //!< Controls the serialization between threads.
139  QTimer m_feedback; //!< Timer used to send feedback. The feedback will be sent right after timeout() QTimer's signal.
140  int m_interval; //!< Interval used to send feedbacks.
141  bool m_finishedWithSuccess; //!< A flag that indicates if the layer could be drawn.
142  QString m_errorMessage; //!< A string that contains an error message.
143  };
144 
145  } // end namespace widgets
146  } // end namespace qt
147 } // end namespace te
148 
149 #endif // __TERRALIB_QT_WIDGETS_INTERNAL_DRAWLAYERTHREAD_H
This is the base class for layers.
Definition: AbstractLayer.h:76
te::map::AbstractLayer * m_layer
The layer that will be drawn.
int m_srid
The SRS to be used to draw the layer objects.
int m_interval
Interval used to send feedbacks.
te::gm::Envelope m_env
The interest area to draw the layer.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
QImage m_image
The image that will be generated during the draw process.
This class represents a thread responsible to draw a given layer. Basically, this class receives draw...
bool m_finishedWithSuccess
A flag that indicates if the layer could be drawn.
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:66
int m_index
An optional index that can be provided by the caller to keep the draw order.
QTimer m_feedback
Timer used to send feedback. The feedback will be sent right after timeout() QTimer's signal...
QMutex m_mutex
Controls the serialization between threads.
QString m_errorMessage
A string that contains an error message.