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