QGIS API Documentation 4.3.0-Master (0cef2469b72)
Loading...
Searching...
No Matches
qgspicturerasterizer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspicturerasterizer.h
3 -----------------
4 begin : November 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSPICTURERASTERIZER_H
19#define QGSPICTURERASTERIZER_H
20
21#include "qgis.h"
22#include "qgis_core.h"
23
24#include <QFutureWatcher>
25#include <QImage>
26#include <QObject>
27#include <QPicture>
28
29class QgsFeedback;
30
31#ifndef SIP_RUN
33class QgsPictureRasterizerJob : public QObject
34{
35 Q_OBJECT
36
37 public:
38 QgsPictureRasterizerJob( const QPicture &picture, const QSize &targetSize );
39
40 void cancelWithoutBlocking();
41 void cancelAndWait();
42 bool isCanceled() const;
43 QSize targetSize() const { return mTargetSize; }
44 QImage result() const { return mWatcher.result(); }
45
46 signals:
47 void finished();
48
49 private:
50 QSize mTargetSize;
51 std::unique_ptr< QgsFeedback > mFeedback;
52 QFutureWatcher< QImage > mWatcher;
53};
55#endif
56
69class CORE_EXPORT QgsPictureRasterizer : public QObject
70{
71 Q_OBJECT
72
73 public:
77 explicit QgsPictureRasterizer( QObject *parent SIP_TRANSFERTHIS = nullptr );
78 ~QgsPictureRasterizer() override;
79
85 void setPicture( const QPicture &picture );
86
92 QPicture picture() const { return mPicture; }
93
97 void clear();
98
102 void invalidate();
103
111 QImage image( const QSize &targetSize );
112
116 bool isRendering() const;
117
123 void setMaxCacheSize( int maxSize );
124
130 int maxCacheSize() const { return mMaxCacheSize; }
131
132 signals:
133
137 void rendered();
138
139 private slots:
140 void startRenderJob();
141 void onRenderJobFinished();
142
143 private:
144#ifdef SIP_RUN
146#endif
147
148 void cancelRunningJob( bool block );
149
150 QPicture mPicture;
151
152 QImage mCachedImage;
153 QSize mTargetSize;
154 bool mInvalidated = true;
155
156 int mMaxCacheSize = 5000;
157
158 QTimer *mUpdateTimer = nullptr;
159 std::unique_ptr< QgsPictureRasterizerJob > mJob;
160
161 QgsPictureRasterizer( const QgsPictureRasterizer & ) = delete;
162 QgsPictureRasterizer &operator=( const QgsPictureRasterizer & ) = delete;
163};
164
165#endif //QGSPICTURERASTERIZER_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
void setPicture(const QPicture &picture)
Sets the source picture to cache.
QgsPictureRasterizer(QObject *parent=nullptr)
Constructor for QgsPictureRasterizer, with the specified parent object.
int maxCacheSize() const
Returns the maximum width or height (in pixels) of the cached QImage.
void rendered()
Emitted when a background rasterization finishes and a new cached image is available.
QPicture picture() const
Returns the current source QPicture.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52