QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include "qgsmessagelog.h"
20 #include <QObject>
21 
22 #ifdef WITH_QTWEBKIT
23 #include <QWebPage>
24 #else
25 
26 #include "qgswebframe.h"
27 
28 #include <QMenu>
29 #include <QNetworkAccessManager>
30 #include <QPalette>
31 #include <QTextBrowser>
32 
33 
38 class CORE_EXPORT QWebSettings : public QObject
39 {
41  Q_OBJECT
42 
43  public:
44 
45  enum WebAttribute
46  {
47  AutoLoadImages,
48  JavascriptEnabled,
49  JavaEnabled,
50  PluginsEnabled,
51  PrivateBrowsingEnabled,
52  JavascriptCanOpenWindows,
53  JavascriptCanAccessClipboard,
54  DeveloperExtrasEnabled,
55  LinksIncludedInFocusChain,
56  ZoomTextOnly,
57  PrintElementBackgrounds,
58  OfflineStorageDatabaseEnabled,
59  OfflineWebApplicationCacheEnabled,
60  LocalStorageEnabled,
61  LocalContentCanAccessRemoteUrls,
62  DnsPrefetchEnabled,
63  XSSAuditingEnabled,
64  AcceleratedCompositingEnabled,
65  SpatialNavigationEnabled,
66  LocalContentCanAccessFileUrls,
67  TiledBackingStoreEnabled,
68  FrameFlatteningEnabled,
69  SiteSpecificQuirksEnabled,
70  JavascriptCanCloseWindows,
71  WebGLEnabled,
72  CSSRegionsEnabled,
73  HyperlinkAuditingEnabled,
74  CSSGridLayoutEnabled,
75  ScrollAnimatorEnabled,
76  CaretBrowsingEnabled,
77  NotificationsEnabled
78  };
79  explicit QWebSettings( QObject* parent = 0 )
80  : QObject( parent )
81  {
82  }
83 
84  void setUserStyleSheetUrl( const QUrl& )
85  {
86  }
87 
88  void setAttribute( WebAttribute, bool )
89  {
90  }
92 };
93 
99 class CORE_EXPORT QWebPage : public QObject
100 {
102  Q_OBJECT
103 
104  public:
105 
106  enum LinkDelegationPolicy
107  {
108  DontDelegateLinks,
109  DelegateExternalLinks,
110  DelegateAllLinks
111  };
112 
113  enum WebWindowType
114  {
115  WebBrowserWindow,
116  WebModalDialog
117  };
118 
119  explicit QWebPage( QObject* parent = 0 )
120  : QObject( parent )
121  , mSettings( new QWebSettings() )
122  , mFrame( new QWebFrame() )
123  {
124  }
125 
126  ~QWebPage()
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  void setForwardUnsupportedContent( bool )
185  {
186  }
187 
188  signals:
189 
190  void loadFinished( bool ok );
191 
192  public slots:
193 
194  protected:
195 
196  virtual void javaScriptConsoleMessage( const QString& , int, const QString& ) {}
197 
198  private:
199  QWebSettings* mSettings;
200  QWebFrame* mFrame;
202 };
203 #endif
204 
211 class CORE_EXPORT QgsWebPage : public QWebPage
212 {
213  Q_OBJECT
214 
215  public:
216 
220  explicit QgsWebPage( QObject* parent = 0 )
221  : QWebPage( parent )
222  {}
223 
230  void setIdentifier( const QString& identifier ) { mIdentifier = identifier; }
231 
236  QString identifier() const { return mIdentifier; }
237 
238  protected:
239 
240  virtual void javaScriptConsoleMessage( const QString& message, int lineNumber, const QString& ) override
241  {
242  if ( mIdentifier.isEmpty() )
243  QgsMessageLog::logMessage( tr( "Line %1: %2" ).arg( lineNumber ).arg( message ), tr( "Javascript" ) );
244  else
245  QgsMessageLog::logMessage( tr( "%1 (line %2): %3" ).arg( mIdentifier ).arg( lineNumber ).arg( message ), tr( "Javascript" ) );
246  }
247 
248  private:
249 
250  QString mIdentifier;
251 
252 };
253 
254 #endif // QGSWEBPAGE_H
255 
The QWebFrame class is a collection of stubs to mimic the API of a QWebFrame on systems where QtWebki...
Definition: qgswebframe.h:32
QString identifier() const
Returns the QgsWebPage&#39;s identifier.
Definition: qgswebpage.h:236
void setIdentifier(const QString &identifier)
Sets an identifier for the QgsWebPage.
Definition: qgswebpage.h:230
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsWebPage(QObject *parent=0)
Constructor for QgsWebPage.
Definition: qgswebpage.h:220
virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &) override
Definition: qgswebpage.h:240
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
Definition: qgswebpage.h:99
QObject * parent() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QWebPage subclass which redirects JavaScript errors and console output to the QGIS message log...
Definition: qgswebpage.h:211
The QWebSettings class is a collection of stubs to mimic the API of a QWebSettings on systems where Q...
Definition: qgswebpage.h:38