QGIS API Documentation 4.5.0-Master (3b5d115045b)
Loading...
Searching...
No Matches
qgswebenginepage.h
Go to the documentation of this file.
1/***************************************************************************
2 qgswebenginepage.h
3 -------------------
4 begin : December 2023
5 copyright : (C) 2023 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 QGSWEBENGINEPAGE_H
19#define QGSWEBENGINEPAGE_H
20
21#include <memory>
22
23#include "qgis_core.h"
24#include "qgis_sip.h"
26
27#include <QObject>
28#include <QPageLayout>
29#include <QSize>
30#include <QUrl>
31
32SIP_IF_MODULE( HAVE_WEBENGINE_SIP )
33
34class QWebEnginePage;
35class QPainter;
36class QgsFeedback;
37class QgsPdfRenderer;
38
47class CORE_EXPORT QgsWebEnginePage : public QObject
48{
49 Q_OBJECT
50
51 public:
55 QgsWebEnginePage( QObject *parent SIP_TRANSFERTHIS = nullptr );
57
63 QWebEnginePage *page() SIP_SKIP;
64
76 bool setContent( const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl(), bool blocking = false );
77
91 bool setHtml( const QString &html, const QUrl &baseUrl = QUrl(), bool blocking = false );
92
104 bool setUrl( const QUrl &url, bool blocking = false );
105
111 QSize documentSize() const;
112
125 bool render( QPainter *painter, const QRectF &painterRect ) SIP_THROW( QgsNotSupportedException );
126
144 static bool printToPdfBlocking(
145 const QString &html, const QString &pdfFileName, QString &errorMessage SIP_OUT, int width, const QgsHtmlRenderSettings &settings = QgsHtmlRenderSettings(), QgsFeedback *feedback = nullptr
146 );
147
165 static bool printToPdfBlocking(
166 const QUrl &url, const QString &pdfFileName, QString &errorMessage SIP_OUT, int width, const QgsHtmlRenderSettings &settings = QgsHtmlRenderSettings(), QgsFeedback *feedback = nullptr
167 );
168
191 static bool renderBlocking(
192 const QString &html,
193 QPainter *painter,
194 const QRectF &painterRect,
195 QString &errorMessage SIP_OUT,
196 QSizeF &renderedSize SIP_OUT,
198 QgsFeedback *feedback = nullptr
200
223 static bool renderBlocking(
224 const QUrl &url,
225 QPainter *painter,
226 const QRectF &painterRect,
227 QString &errorMessage SIP_OUT,
228 QSizeF &renderedSize SIP_OUT,
230 QgsFeedback *feedback = nullptr
232
233 signals:
234
239
246 void loadProgress( int progress );
247
255 void loadFinished( bool ok );
256
257 private:
258 void handlePostBlockingLoadOperations();
259
260 static QString htmlToPdfExecutable();
261
262 static QString htmlToPdfReturnCodeToString( int code );
263 static bool doPrintToPdf( const QStringList &args, const QgsHtmlRenderSettings &settings, QString &errorMessage, QgsFeedback *feedback );
264 static bool renderBlockingInternal( QPainter *painter, QgsPdfRenderer &renderer, QString &errorMessage, const QRectF &painterRect, QSizeF &renderedSize );
265
266 std::unique_ptr< QWebEnginePage > mPage;
267 mutable QSize mCachedSize;
268};
269
270#endif // QGSWEBENGINEPAGE_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Encapsulates settings for rendering HTML content.
Custom exception class which is raised when an operation is not supported.
Utility class for rendering PDF documents.
bool setContent(const QByteArray &data, const QString &mimeType=QString(), const QUrl &baseUrl=QUrl(), bool blocking=false)
Sets the content of the web page to data.
static bool renderBlocking(const QString &html, QPainter *painter, const QRectF &painterRect, QString &errorMessage, QSizeF &renderedSize, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
Renders HTML content to a painter asynchronously.
void loadStarted()
This signal is emitted when the page starts loading content.
bool setHtml(const QString &html, const QUrl &baseUrl=QUrl(), bool blocking=false)
Sets the content of this page to html.
bool setUrl(const QUrl &url, bool blocking=false)
Sets the url of the web page to be displayed.
void loadFinished(bool ok)
This signal is emitted when the page finishes loading content.
QgsWebEnginePage(QObject *parent=nullptr)
Constructor for QgsWebEnginePage, with the specified parent widget.
bool render(QPainter *painter, const QRectF &painterRect)
Renders the web page contents to a painter.
void loadProgress(int progress)
This signal is emitted when the global progress status changes.
~QgsWebEnginePage() override
QWebEnginePage * page()
Returns a reference to the QWebEnginePage.
QSize documentSize() const
Returns the size of the page document, in pixels.
static bool printToPdfBlocking(const QString &html, const QString &pdfFileName, QString &errorMessage, int width, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
Renders HTML content to a PDF file asynchronously.
#define SIP_IF_MODULE(condition)
Definition qgis_sip.h:27
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_THROW(name,...)
Definition qgis_sip.h:215