QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include "qgswebframe.h"
24
25#include <QMenu>
26#include <QNetworkAccessManager>
27#include <QObject>
28#include <QPalette>
29#include <QTextBrowser>
30
36class CORE_EXPORT QWebSettings : public QObject
37{
39 Q_OBJECT
40
41 public:
42
43 enum WebAttribute
44 {
45 AutoLoadImages,
46 JavascriptEnabled,
47 JavaEnabled,
48 PluginsEnabled,
49 PrivateBrowsingEnabled,
50 JavascriptCanOpenWindows,
51 JavascriptCanAccessClipboard,
52 DeveloperExtrasEnabled,
53 LinksIncludedInFocusChain,
54 ZoomTextOnly,
55 PrintElementBackgrounds,
56 OfflineStorageDatabaseEnabled,
57 OfflineWebApplicationCacheEnabled,
58 LocalStorageEnabled,
59 LocalContentCanAccessRemoteUrls,
60 DnsPrefetchEnabled,
61 XSSAuditingEnabled,
62 AcceleratedCompositingEnabled,
63 SpatialNavigationEnabled,
64 LocalContentCanAccessFileUrls,
65 TiledBackingStoreEnabled,
66 FrameFlatteningEnabled,
67 SiteSpecificQuirksEnabled,
68 JavascriptCanCloseWindows,
69 WebGLEnabled,
70 CSSRegionsEnabled,
71 HyperlinkAuditingEnabled,
72 CSSGridLayoutEnabled,
73 ScrollAnimatorEnabled,
74 CaretBrowsingEnabled,
75 NotificationsEnabled
76 };
77 explicit QWebSettings( QObject *parent = nullptr )
78 : QObject( parent )
79 {
80 }
81
82 void setUserStyleSheetUrl( const QUrl & )
83 {
84 }
85
86 void setAttribute( WebAttribute, bool )
87 {
88 }
90};
91
97class CORE_EXPORT QWebPage : public QObject
98{
100 Q_OBJECT
101
102 public:
103
104 enum LinkDelegationPolicy
105 {
106 DontDelegateLinks,
107 DelegateExternalLinks,
108 DelegateAllLinks
109 };
110
111 enum WebWindowType
112 {
113 WebBrowserWindow,
114 WebModalDialog
115 };
116
117 explicit QWebPage( QObject *parent = nullptr )
118 : QObject( parent )
119 , mSettings( new QWebSettings() )
120 , mFrame( new QWebFrame() )
121 {
122 connect( mFrame, &QWebFrame::loadFinished, this, &QWebPage::loadFinished );
123 }
124
125 ~QWebPage() override
126 {
127 delete mFrame;
128 delete mSettings;
129 }
130
131 QPalette palette() const
132 {
133 return QPalette();
134 }
135
136 void setPalette( const QPalette &palette )
137 {
138 Q_UNUSED( palette )
139 }
140
141 void setViewportSize( const QSize &size ) const
142 {
143 Q_UNUSED( size )
144 }
145
146 void setLinkDelegationPolicy( LinkDelegationPolicy linkDelegationPolicy )
147 {
148 if ( !parent() )
149 return;
150
151 QTextBrowser *tb = qobject_cast<QTextBrowser *>( parent() );
152 if ( !tb )
153 return;
154
155 tb->setOpenExternalLinks( linkDelegationPolicy != DontDelegateLinks );
156 }
157
158 void setNetworkAccessManager( QNetworkAccessManager *networkAccessManager )
159 {
160 Q_UNUSED( networkAccessManager )
161 }
162
163 QWebFrame *mainFrame() const
164 {
165 return mFrame;
166 }
167
168 QWebSettings *settings() const
169 {
170 return mSettings;
171 }
172
173 QSize viewportSize() const
174 {
175 return QSize();
176 }
177
178 QMenu *createStandardContextMenu()
179 {
180 return new QMenu();
181 }
182
183 signals:
184
185 void loadFinished( bool ok );
186
187 void downloadRequested( const QNetworkRequest &request );
188
189 void unsupportedContent( QNetworkReply *reply );
190
191 public slots:
192
193 protected:
194
195 virtual void javaScriptConsoleMessage( const QString &, int, const QString & ) {}
196
197 private:
198 QWebSettings *mSettings = nullptr;
199 QWebFrame *mFrame = nullptr;
201};
202
209class CORE_EXPORT QgsWebPage : public QWebPage
210{
211 Q_OBJECT
212
213 public:
214
219 explicit QgsWebPage( QObject *parent = nullptr )
220 : QWebPage( parent )
221 {}
222
230 void setIdentifier( const QString &identifier ) { mIdentifier = identifier; }
231
237 QString identifier() const { return mIdentifier; }
238
239 protected:
240
241 void javaScriptConsoleMessage( const QString &message, int lineNumber, const QString & ) override
242 {
243 if ( mIdentifier.isEmpty() )
244 QgsMessageLog::logMessage( tr( "Line %1: %2" ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
245 else
246 QgsMessageLog::logMessage( tr( "%1 (line %2): %3" ).arg( mIdentifier ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
247 }
248
249 private:
250
251 QString mIdentifier;
252
253};
254
255#endif // QGSWEBPAGE_H
A collection of stubs to mimic the API of a QWebFrame on systems where QtWebkit is not available.
Definition qgswebframe.h:34
A collection of stubs to mimic the API of a QWebPage on systems where QtWebkit is not available.
Definition qgswebpage.h:98
A collection of stubs to mimic the API of a QWebSettings on systems where QtWebkit is not available.
Definition qgswebpage.h:37
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:219
void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &) override
Definition qgswebpage.h:241
void setIdentifier(const QString &identifier)
Sets an identifier for the QgsWebPage.
Definition qgswebpage.h:230
QString identifier() const
Returns the QgsWebPage's identifier.
Definition qgswebpage.h:237