Skip to content

Commit 4f52d9f

Browse files
committedJul 24, 2012
Add QWebPage to composer html, link core to webkit
1 parent 682d8b3 commit 4f52d9f

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed
 

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ SET(QGIS_CORE_MOC_HDRS
282282
composer/qgscomposerlabel.h
283283
composer/qgscomposershape.h
284284
composer/qgscomposerattributetable.h
285+
composer/qgscomposerhtml.h
285286
composer/qgscomposermultiframe.h
286287
composer/qgscomposition.h
287288

@@ -520,6 +521,7 @@ TARGET_LINK_LIBRARIES(qgis_core
520521
${QT_QTGUI_LIBRARY}
521522
${QT_QTNETWORK_LIBRARY}
522523
${QT_QTSVG_LIBRARY}
524+
${QT_QTWEBKIT_LIBRARY}
523525

524526
${PROJ_LIBRARY}
525527
${GEOS_LIBRARY}

‎src/core/composer/qgscomposerhtml.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,51 @@
1414
***************************************************************************/
1515

1616
#include "qgscomposerhtml.h"
17+
#include <QCoreApplication>
18+
#include <QWebFrame>
19+
#include <QWebPage>
1720

18-
QgsComposerHtml::QgsComposerHtml( QgsComposition* c ): QgsComposerMultiFrame( c )
21+
QgsComposerHtml::QgsComposerHtml( QgsComposition* c ): QgsComposerMultiFrame( c ), mWebPage( 0 ), mLoaded( false )
22+
{
23+
mWebPage = new QWebPage();
24+
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
25+
}
26+
27+
QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0 ), mWebPage( 0 ), mLoaded( false )
1928
{
2029
}
2130

2231
QgsComposerHtml::~QgsComposerHtml()
2332
{
33+
delete mWebPage;
34+
}
35+
36+
void QgsComposerHtml::setUrl( const QUrl& url )
37+
{
38+
if ( !mWebPage )
39+
{
40+
return;
41+
}
42+
43+
mUrl = url;
44+
mWebPage->mainFrame()->load( mUrl );
45+
while ( !mLoaded )
46+
{
47+
qApp->processEvents();
48+
}
49+
}
50+
51+
void QgsComposerHtml::frameLoaded( bool ok )
52+
{
53+
mLoaded = true;
2454
}
2555

2656
QSizeF QgsComposerHtml::totalSize() const
2757
{
2858
return QSizeF(); //soon...
2959
}
60+
61+
void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent )
62+
{
63+
//soon...
64+
}

‎src/core/composer/qgscomposerhtml.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@
1919
#include "qgscomposermultiframe.h"
2020
#include <QUrl>
2121

22+
class QWebPage;
23+
2224
class QgsComposerHtml: public QgsComposerMultiFrame
2325
{
26+
Q_OBJECT
2427
public:
2528
QgsComposerHtml( QgsComposition* c );
29+
QgsComposerHtml();
2630
~QgsComposerHtml();
2731

28-
void setUrl( const QUrl& url ) { mUrl = url; }
32+
void setUrl( const QUrl& url );
2933
const QUrl& url() const { return mUrl; }
3034

3135
QSizeF totalSize() const;
36+
void render( QPainter* p, const QRectF& renderExtent );
37+
38+
private slots:
39+
void frameLoaded( bool ok );
3240

3341
private:
3442
QUrl mUrl;
43+
QWebPage* mWebPage;
44+
bool mLoaded;
3545
};
3646

3747
#endif // QGSCOMPOSERHTML_H

‎src/core/composer/qgscomposermultiframe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
class QgsComposerItem;
2323
class QgsComposition;
24+
class QRectF;
25+
class QPainter;
2426

2527
/**Abstract base class for composer entries with the ability to distribute the content to several frames (items)*/
2628
class QgsComposerMultiFrame: public QObject
@@ -37,6 +39,7 @@ class QgsComposerMultiFrame: public QObject
3739
QgsComposerMultiFrame( QgsComposition* c );
3840
virtual ~QgsComposerMultiFrame();
3941
virtual QSizeF totalSize() const = 0;
42+
virtual void render( QPainter* p, const QRectF& renderExtent ) = 0;
4043

4144
protected:
4245
QgsComposition* mComposition;

0 commit comments

Comments
 (0)
Please sign in to comment.