QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 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 void setUserStyleSheetUrl( const QUrl & ) {}
82
83 void setAttribute( WebAttribute, bool ) {}
85};
86
92class CORE_EXPORT QWebPage : public QObject
93{
95 Q_OBJECT
96
97 public:
98 enum LinkDelegationPolicy
99 {
100 DontDelegateLinks,
101 DelegateExternalLinks,
102 DelegateAllLinks
103 };
104
105 enum WebWindowType
106 {
107 WebBrowserWindow,
108 WebModalDialog
109 };
110
111 explicit QWebPage( QObject *parent = nullptr )
112 : QObject( parent )
113 , mSettings( new QWebSettings() )
114 , mFrame( new QWebFrame() )
115 {
116 connect( mFrame, &QWebFrame::loadFinished, this, &QWebPage::loadFinished );
117 }
118
119 ~QWebPage() override
120 {
121 delete mFrame;
122 delete mSettings;
123 }
124
125 QPalette palette() const { return QPalette(); }
126
127 void setPalette( const QPalette &palette ) { Q_UNUSED( palette ) }
128
129 void setViewportSize( const QSize &size ) const { Q_UNUSED( size ) }
130
131 void setLinkDelegationPolicy( LinkDelegationPolicy linkDelegationPolicy )
132 {
133 if ( !parent() )
134 return;
135
136 QTextBrowser *tb = qobject_cast<QTextBrowser *>( parent() );
137 if ( !tb )
138 return;
139
140 tb->setOpenExternalLinks( linkDelegationPolicy != DontDelegateLinks );
141 }
142
143 void setNetworkAccessManager( QNetworkAccessManager *networkAccessManager ) { Q_UNUSED( networkAccessManager ) }
144
145 QWebFrame *mainFrame() const { return mFrame; }
146
147 QWebSettings *settings() const { return mSettings; }
148
149 QSize viewportSize() const { return QSize(); }
150
151 QMenu *createStandardContextMenu() { return new QMenu(); }
152
153 signals:
154
155 void loadFinished( bool ok );
156
157 void downloadRequested( const QNetworkRequest &request );
158
159 void unsupportedContent( QNetworkReply *reply );
160
161 public slots:
162
163 protected:
164 virtual void javaScriptConsoleMessage( const QString &, int, const QString & ) {}
165
166 private:
167 QWebSettings *mSettings = nullptr;
168 QWebFrame *mFrame = nullptr;
170};
171
178class CORE_EXPORT QgsWebPage : public QWebPage
179{
180 Q_OBJECT
181
182 public:
187 explicit QgsWebPage( QObject *parent = nullptr )
188 : QWebPage( parent )
189 {}
190
198 void setIdentifier( const QString &identifier ) { mIdentifier = identifier; }
199
205 QString identifier() const { return mIdentifier; }
206
207 protected:
208 void javaScriptConsoleMessage( const QString &message, int lineNumber, const QString & ) override
209 {
210 if ( mIdentifier.isEmpty() )
211 QgsMessageLog::logMessage( tr( "Line %1: %2" ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
212 else
213 QgsMessageLog::logMessage( tr( "%1 (line %2): %3" ).arg( mIdentifier ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
214 }
215
216 private:
217 QString mIdentifier;
218};
219
220#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:93
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:187
void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &) override
Definition qgswebpage.h:208
void setIdentifier(const QString &identifier)
Sets an identifier for the QgsWebPage.
Definition qgswebpage.h:198
QString identifier() const
Returns the QgsWebPage's identifier.
Definition qgswebpage.h:205