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