QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgswebpage.h
Go to the documentation of this file.
1/***************************************************************************
2
3 ----------------------------------------------------
4 date : 19.5.2015
5 copyright : (C) 2015 by Matthias Kuhn
6 email : matthias (at) opengis.ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSWEBPAGE_H
17#define QGSWEBPAGE_H
18
19#define SIP_NO_FILE
20
21#include "qgis_core.h"
22#include "qgsmessagelog.h"
23
24#include <QObject>
25
26#ifdef WITH_QTWEBKIT
27#include <QWebPage>
28#else
29
30#include "qgswebframe.h"
31
32#include <QMenu>
33#include <QNetworkAccessManager>
34#include <QPalette>
35#include <QTextBrowser>
36
37
43class CORE_EXPORT QWebSettings : public QObject
44{
46 Q_OBJECT
47
48 public:
49
50 enum WebAttribute
51 {
52 AutoLoadImages,
53 JavascriptEnabled,
54 JavaEnabled,
55 PluginsEnabled,
56 PrivateBrowsingEnabled,
57 JavascriptCanOpenWindows,
58 JavascriptCanAccessClipboard,
59 DeveloperExtrasEnabled,
60 LinksIncludedInFocusChain,
61 ZoomTextOnly,
62 PrintElementBackgrounds,
63 OfflineStorageDatabaseEnabled,
64 OfflineWebApplicationCacheEnabled,
65 LocalStorageEnabled,
66 LocalContentCanAccessRemoteUrls,
67 DnsPrefetchEnabled,
68 XSSAuditingEnabled,
69 AcceleratedCompositingEnabled,
70 SpatialNavigationEnabled,
71 LocalContentCanAccessFileUrls,
72 TiledBackingStoreEnabled,
73 FrameFlatteningEnabled,
74 SiteSpecificQuirksEnabled,
75 JavascriptCanCloseWindows,
76 WebGLEnabled,
77 CSSRegionsEnabled,
78 HyperlinkAuditingEnabled,
79 CSSGridLayoutEnabled,
80 ScrollAnimatorEnabled,
81 CaretBrowsingEnabled,
82 NotificationsEnabled
83 };
84 explicit QWebSettings( QObject *parent = nullptr )
85 : QObject( parent )
86 {
87 }
88
89 void setUserStyleSheetUrl( const QUrl & )
90 {
91 }
92
93 void setAttribute( WebAttribute, bool )
94 {
95 }
97};
98
104class CORE_EXPORT QWebPage : public QObject
105{
107 Q_OBJECT
108
109 public:
110
111 enum LinkDelegationPolicy
112 {
113 DontDelegateLinks,
114 DelegateExternalLinks,
115 DelegateAllLinks
116 };
117
118 enum WebWindowType
119 {
120 WebBrowserWindow,
121 WebModalDialog
122 };
123
124 explicit QWebPage( QObject *parent = nullptr )
125 : QObject( parent )
126 , mSettings( new QWebSettings() )
127 , mFrame( new QWebFrame() )
128 {
129 connect( mFrame, &QWebFrame::loadFinished, this, &QWebPage::loadFinished );
130 }
131
132 ~QWebPage()
133 {
134 delete mFrame;
135 delete mSettings;
136 }
137
138 QPalette palette() const
139 {
140 return QPalette();
141 }
142
143 void setPalette( const QPalette &palette )
144 {
145 Q_UNUSED( palette )
146 }
147
148 void setViewportSize( const QSize &size ) const
149 {
150 Q_UNUSED( size )
151 }
152
153 void setLinkDelegationPolicy( LinkDelegationPolicy linkDelegationPolicy )
154 {
155 if ( !parent() )
156 return;
157
158 QTextBrowser *tb = qobject_cast<QTextBrowser *>( parent() );
159 if ( !tb )
160 return;
161
162 tb->setOpenExternalLinks( linkDelegationPolicy != DontDelegateLinks );
163 }
164
165 void setNetworkAccessManager( QNetworkAccessManager *networkAccessManager )
166 {
167 Q_UNUSED( networkAccessManager )
168 }
169
170 QWebFrame *mainFrame() const
171 {
172 return mFrame;
173 }
174
175 QWebSettings *settings() const
176 {
177 return mSettings;
178 }
179
180 QSize viewportSize() const
181 {
182 return QSize();
183 }
184
185 QMenu *createStandardContextMenu()
186 {
187 return new QMenu();
188 }
189
190 signals:
191
192 void loadFinished( bool ok );
193
194 void downloadRequested( const QNetworkRequest &request );
195
196 void unsupportedContent( QNetworkReply *reply );
197
198 public slots:
199
200 protected:
201
202 virtual void javaScriptConsoleMessage( const QString &, int, const QString & ) {}
203
204 private:
205 QWebSettings *mSettings = nullptr;
206 QWebFrame *mFrame = nullptr;
208};
209#endif
210
217class CORE_EXPORT QgsWebPage : public QWebPage
218{
219 Q_OBJECT
220
221 public:
222
227 explicit QgsWebPage( QObject *parent = nullptr )
228 : QWebPage( parent )
229 {}
230
238 void setIdentifier( const QString &identifier ) { mIdentifier = identifier; }
239
245 QString identifier() const { return mIdentifier; }
246
247 protected:
248
249 void javaScriptConsoleMessage( const QString &message, int lineNumber, const QString & ) override
250 {
251 if ( mIdentifier.isEmpty() )
252 QgsMessageLog::logMessage( tr( "Line %1: %2" ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
253 else
254 QgsMessageLog::logMessage( tr( "%1 (line %2): %3" ).arg( mIdentifier ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
255 }
256
257 private:
258
259 QString mIdentifier;
260
261};
262
263#endif // QGSWEBPAGE_H
264
A collection of stubs to mimic the API of a QWebFrame on systems where QtWebkit is not available.
Definition qgswebframe.h:38
A collection of stubs to mimic the API of a QWebPage on systems where QtWebkit is not available.
Definition qgswebpage.h:105
A collection of stubs to mimic the API of a QWebSettings on systems where QtWebkit is not available.
Definition qgswebpage.h:44
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
QgsWebPage(QObject *parent=nullptr)
Constructor for QgsWebPage.
Definition qgswebpage.h:227
void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &) override
Definition qgswebpage.h:249
void setIdentifier(const QString &identifier)
Sets an identifier for the QgsWebPage.
Definition qgswebpage.h:238
QString identifier() const
Returns the QgsWebPage's identifier.
Definition qgswebpage.h:245