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