QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgswebview.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 QGSWEBVIEW_H
17#define QGSWEBVIEW_H
18
19
20#include "qgswebpage.h"
21
22#include <QTextBrowser>
23#include <QWidget>
24
25#define SIP_NO_FILE
26
27class QPrinter;
28
38class CORE_EXPORT QgsWebView : public QTextBrowser
39{
41 Q_OBJECT
42 public:
43 explicit QgsWebView( QWidget *parent = nullptr )
44 : QTextBrowser( parent )
45 , mSettings( new QWebSettings() )
46 , mPage( new QWebPage( this ) )
47 {
48 connect( this, &QTextBrowser::anchorClicked, this, &QgsWebView::linkClicked );
49 connect( this, &QgsWebView::pageLoadFinished, mPage, &QWebPage::loadFinished );
50 }
51
52 ~QgsWebView() override
53 {
54 delete mSettings;
55 delete mPage;
56 }
57
58 void setUrl( const QUrl &url ) { setSource( url ); }
59
60 void load( const QUrl &url ) { setSource( url ); }
61
62 QUrl url() const { return source(); }
63
64 QWebPage *page() const { return mPage; }
65
66 QWebSettings *settings() const { return mSettings; }
67
68 virtual QgsWebView *createWindow( QWebPage::WebWindowType ) { return new QgsWebView(); }
69
70 void setContent( const QByteArray &data, const QString &contentType, const QUrl & )
71 {
72 QString text = QString::fromUtf8( data );
73 if ( contentType == "text/html" )
74 setHtml( text );
75 else
76 setPlainText( text );
77
78 emit pageLoadFinished( true );
79 }
80
81 void print( QPrinter * ) {}
82
83 signals:
84 void linkClicked( const QUrl &link );
85
86 void pageLoadFinished( bool ok );
87
88 public slots:
89
90 void setHtml( const QString &text )
91 {
92 QTextBrowser::setHtml( text );
93 emit pageLoadFinished( true );
94 }
95
96 void setText( const QString &text )
97 {
98 QTextBrowser::setText( text );
99 emit pageLoadFinished( true );
100 }
101
102 private:
103 QWebSettings *mSettings = nullptr;
104 QWebPage *mPage = nullptr;
105
107};
108
109#endif // QGSWEBVIEW_H
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
A collection of stubs to mimic the API of QWebView on systems where the real library is not available...
Definition qgswebview.h:39