QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 <QObject>
24 
25 #ifdef WITH_QTWEBKIT
26 #include <QWebPage>
27 #else
28 
29 #include "qgswebframe.h"
30 
31 #include <QMenu>
32 #include <QNetworkAccessManager>
33 #include <QPalette>
34 #include <QTextBrowser>
35 
36 
42 class CORE_EXPORT QWebSettings : public QObject
43 {
45  Q_OBJECT
46 
47  public:
48 
49  enum WebAttribute
50  {
51  AutoLoadImages,
52  JavascriptEnabled,
53  JavaEnabled,
54  PluginsEnabled,
55  PrivateBrowsingEnabled,
56  JavascriptCanOpenWindows,
57  JavascriptCanAccessClipboard,
58  DeveloperExtrasEnabled,
59  LinksIncludedInFocusChain,
60  ZoomTextOnly,
61  PrintElementBackgrounds,
62  OfflineStorageDatabaseEnabled,
63  OfflineWebApplicationCacheEnabled,
64  LocalStorageEnabled,
65  LocalContentCanAccessRemoteUrls,
66  DnsPrefetchEnabled,
67  XSSAuditingEnabled,
68  AcceleratedCompositingEnabled,
69  SpatialNavigationEnabled,
70  LocalContentCanAccessFileUrls,
71  TiledBackingStoreEnabled,
72  FrameFlatteningEnabled,
73  SiteSpecificQuirksEnabled,
74  JavascriptCanCloseWindows,
75  WebGLEnabled,
76  CSSRegionsEnabled,
77  HyperlinkAuditingEnabled,
78  CSSGridLayoutEnabled,
79  ScrollAnimatorEnabled,
80  CaretBrowsingEnabled,
81  NotificationsEnabled
82  };
83  explicit QWebSettings( QObject *parent = nullptr )
84  : QObject( parent )
85  {
86  }
87 
88  void setUserStyleSheetUrl( const QUrl & )
89  {
90  }
91 
92  void setAttribute( WebAttribute, bool )
93  {
94  }
96 };
97 
103 class CORE_EXPORT QWebPage : public QObject
104 {
106  Q_OBJECT
107 
108  public:
109 
110  enum LinkDelegationPolicy
111  {
112  DontDelegateLinks,
113  DelegateExternalLinks,
114  DelegateAllLinks
115  };
116 
117  enum WebWindowType
118  {
119  WebBrowserWindow,
120  WebModalDialog
121  };
122 
123  explicit QWebPage( QObject *parent = nullptr )
124  : QObject( parent )
125  , mSettings( new QWebSettings() )
126  , mFrame( new QWebFrame() )
127  {
128  }
129 
130  ~QWebPage()
131  {
132  delete mFrame;
133  delete mSettings;
134  }
135 
136  QPalette palette() const
137  {
138  return QPalette();
139  }
140 
141  void setPalette( const QPalette &palette )
142  {
143  Q_UNUSED( palette )
144  }
145 
146  void setViewportSize( const QSize &size ) const
147  {
148  Q_UNUSED( size )
149  }
150 
151  void setLinkDelegationPolicy( LinkDelegationPolicy linkDelegationPolicy )
152  {
153  if ( !parent() )
154  return;
155 
156  QTextBrowser *tb = qobject_cast<QTextBrowser *>( parent() );
157  if ( !tb )
158  return;
159 
160  tb->setOpenExternalLinks( linkDelegationPolicy != DontDelegateLinks );
161  }
162 
163  void setNetworkAccessManager( QNetworkAccessManager *networkAccessManager )
164  {
165  Q_UNUSED( networkAccessManager )
166  }
167 
168  QWebFrame *mainFrame() const
169  {
170  return mFrame;
171  }
172 
173  QWebSettings *settings() const
174  {
175  return mSettings;
176  }
177 
178  QSize viewportSize() const
179  {
180  return QSize();
181  }
182 
183  QMenu *createStandardContextMenu()
184  {
185  return new QMenu();
186  }
187 
188  signals:
189 
190  void loadFinished( bool ok );
191 
192  void downloadRequested( const QNetworkRequest &request );
193 
194  void unsupportedContent( QNetworkReply *reply );
195 
196  public slots:
197 
198  protected:
199 
200  virtual void javaScriptConsoleMessage( const QString &, int, const QString & ) {}
201 
202  private:
203  QWebSettings *mSettings = nullptr;
204  QWebFrame *mFrame = nullptr;
206 };
207 #endif
208 
216 class CORE_EXPORT QgsWebPage : public QWebPage
217 {
218  Q_OBJECT
219 
220  public:
221 
226  explicit QgsWebPage( QObject *parent = nullptr )
227  : QWebPage( parent )
228  {}
229 
237  void setIdentifier( const QString &identifier ) { mIdentifier = identifier; }
238 
244  QString identifier() const { return mIdentifier; }
245 
246  protected:
247 
248  void javaScriptConsoleMessage( const QString &message, int lineNumber, const QString & ) override
249  {
250  if ( mIdentifier.isEmpty() )
251  QgsMessageLog::logMessage( tr( "Line %1: %2" ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
252  else
253  QgsMessageLog::logMessage( tr( "%1 (line %2): %3" ).arg( mIdentifier ).arg( lineNumber ).arg( message ), tr( "JavaScript" ) );
254  }
255 
256  private:
257 
258  QString mIdentifier;
259 
260 };
261 
262 #endif // QGSWEBPAGE_H
263 
QString identifier() const
Returns the QgsWebPage&#39;s identifier.
Definition: qgswebpage.h:244
void setIdentifier(const QString &identifier)
Sets an identifier for the QgsWebPage.
Definition: qgswebpage.h:237
The QWebSettings class is a collection of stubs to mimic the API of a QWebSettings on systems where Q...
Definition: qgswebpage.h:42
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &) override
Definition: qgswebpage.h:248
QgsWebPage(QObject *parent=nullptr)
Constructor for QgsWebPage.
Definition: qgswebpage.h:226
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
Definition: qgswebpage.h:103
QWebPage subclass which redirects JavaScript errors and console output to the QGIS message log...
Definition: qgswebpage.h:216
The QWebFrame class is a collection of stubs to mimic the API of a QWebFrame on systems where QtWebki...
Definition: qgswebframe.h:37