Skip to content
Permalink
Browse files

Load / save html item and multi frames

  • Loading branch information
mhugent committed Jul 30, 2012
1 parent 0e5e367 commit 2e6ecbc3536e725c6640b1878c78d4c87f8c7c1d
@@ -27,12 +27,28 @@ QgsComposerFrame::~QgsComposerFrame()

bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const
{
return false; //_writeXML( element, doc );
QDomElement frameElem = doc.createElement( "ComposerFrame" );
frameElem.setAttribute( "sectionX", QString::number( mSection.x() ) );
frameElem.setAttribute( "sectionY", QString::number( mSection.y() ) );
frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) );
frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) );
elem.appendChild( frameElem );
return _writeXML( frameElem, doc );
}

bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
return false; //_readXML( element, doc )
double x = itemElem.attribute( "sectionX" ).toDouble();
double y = itemElem.attribute( "sectionY" ).toDouble();
double width = itemElem.attribute( "sectionWidth" ).toDouble();
double height = itemElem.attribute( "sectionHeight" ).toDouble();
mSection = QRectF( x, y, width, height );
QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" );
if ( composerItem.isNull() )
{
return false;
}
return _readXML( composerItem, doc );
}

void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
@@ -28,13 +28,13 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal wid
mWebPage = new QWebPage();
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );

if ( mComposition )
if ( mComposition && width > 0 && height > 0 )
{
QgsComposerFrame* frame = new QgsComposerFrame( c, this, x, y, width, height );
addFrame( frame );
QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
recalculateFrameSizes();
}
recalculateFrameSizes();
}

QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0 ), mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 )
@@ -122,3 +122,13 @@ bool QgsComposerHtml::writeXML( QDomElement& elem, QDomDocument & doc ) const
elem.appendChild( htmlElem );
return state;
}

bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
QString urlString = itemElem.attribute( "url" );
if ( !urlString.isEmpty() )
{
setUrl( QUrl( urlString ) );
}
return _readXML( itemElem, doc );
}
@@ -36,6 +36,7 @@ class QgsComposerHtml: public QgsComposerMultiFrame
void render( QPainter* p, const QRectF& renderExtent );

bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );

protected:
void addFrame( QgsComposerFrame* frame );
@@ -159,3 +159,17 @@ bool QgsComposerMultiFrame::_writeXML( QDomElement& elem, QDomDocument& doc ) co
}
return true;
}

bool QgsComposerMultiFrame::_readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
mResizeMode = ( ResizeMode )itemElem.attribute( "resizeMode", "0" ).toInt();
QDomNodeList frameList = itemElem.elementsByTagName( "ComposerFrame" );
for ( int i = 0; i < frameList.size(); ++i )
{
QDomElement frameElem = frameList.at( i ).toElement();
QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, 0, 0, 0, 0 );
newFrame->readXML( frameElem, doc );
addFrame( newFrame );
}
return true;
}
@@ -53,6 +53,9 @@ class QgsComposerMultiFrame: public QObject
virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
bool _writeXML( QDomElement& elem, QDomDocument& doc ) const;

virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );

protected:
QgsComposition* mComposition;
QList<QgsComposerFrame*> mFrameItems;
@@ -255,7 +255,7 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )

//save multiframes
QSet<QgsComposerMultiFrame*>::const_iterator multiFrameIt = mMultiFrames.constBegin();
for ( ; multiFrameIt != mMultiFrames.constEnd(); ++mMultiFrameIt )
for ( ; multiFrameIt != mMultiFrames.constEnd(); ++multiFrameIt )
{
( *multiFrameIt )->writeXML( compositionElem, doc );
}
@@ -454,6 +454,15 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
pushAddRemoveCommand( newTable, tr( "Table added" ) );
}
}
//html
QDomNodeList composerHtmlList = elem.elementsByTagName( "ComposerHtml" );
for ( int i = 0; i < composerHtmlList.size(); ++i )
{
QDomElement currentHtmlElem = composerHtmlList.at( i ).toElement();
QgsComposerHtml* newHtml = new QgsComposerHtml( this, 0, 0, 0, 0 );
newHtml->readXML( currentHtmlElem, doc );
this->addMultiFrame( newHtml );
}
}

void QgsComposition::addItemToZList( QgsComposerItem* item )

0 comments on commit 2e6ecbc

Please sign in to comment.
You can’t perform that action at this time.