Skip to content

Commit

Permalink
Add QWebPage to composer html, link core to webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 24, 2012
1 parent 682d8b3 commit 4f52d9f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ SET(QGIS_CORE_MOC_HDRS
composer/qgscomposerlabel.h
composer/qgscomposershape.h
composer/qgscomposerattributetable.h
composer/qgscomposerhtml.h
composer/qgscomposermultiframe.h
composer/qgscomposition.h

Expand Down Expand Up @@ -520,6 +521,7 @@ TARGET_LINK_LIBRARIES(qgis_core
${QT_QTGUI_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${QT_QTSVG_LIBRARY}
${QT_QTWEBKIT_LIBRARY}

${PROJ_LIBRARY}
${GEOS_LIBRARY}
Expand Down
37 changes: 36 additions & 1 deletion src/core/composer/qgscomposerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,51 @@
***************************************************************************/

#include "qgscomposerhtml.h"
#include <QCoreApplication>
#include <QWebFrame>
#include <QWebPage>

QgsComposerHtml::QgsComposerHtml( QgsComposition* c ): QgsComposerMultiFrame( c )
QgsComposerHtml::QgsComposerHtml( QgsComposition* c ): QgsComposerMultiFrame( c ), mWebPage( 0 ), mLoaded( false )
{
mWebPage = new QWebPage();
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
}

QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0 ), mWebPage( 0 ), mLoaded( false )
{
}

QgsComposerHtml::~QgsComposerHtml()
{
delete mWebPage;
}

void QgsComposerHtml::setUrl( const QUrl& url )
{
if ( !mWebPage )
{
return;
}

mUrl = url;
mWebPage->mainFrame()->load( mUrl );
while ( !mLoaded )
{
qApp->processEvents();
}
}

void QgsComposerHtml::frameLoaded( bool ok )
{
mLoaded = true;
}

QSizeF QgsComposerHtml::totalSize() const
{
return QSizeF(); //soon...
}

void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent )
{
//soon...
}
12 changes: 11 additions & 1 deletion src/core/composer/qgscomposerhtml.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,29 @@
#include "qgscomposermultiframe.h"
#include <QUrl>

class QWebPage;

class QgsComposerHtml: public QgsComposerMultiFrame
{
Q_OBJECT
public:
QgsComposerHtml( QgsComposition* c );
QgsComposerHtml();
~QgsComposerHtml();

void setUrl( const QUrl& url ) { mUrl = url; }
void setUrl( const QUrl& url );
const QUrl& url() const { return mUrl; }

QSizeF totalSize() const;
void render( QPainter* p, const QRectF& renderExtent );

private slots:
void frameLoaded( bool ok );

private:
QUrl mUrl;
QWebPage* mWebPage;
bool mLoaded;
};

#endif // QGSCOMPOSERHTML_H
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermultiframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

class QgsComposerItem;
class QgsComposition;
class QRectF;
class QPainter;

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

protected:
QgsComposition* mComposition;
Expand Down

0 comments on commit 4f52d9f

Please sign in to comment.