Skip to content

Commit 2e6ecbc

Browse files
committedJul 30, 2012
Load / save html item and multi frames
1 parent 0e5e367 commit 2e6ecbc

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed
 

‎src/core/composer/qgscomposerframe.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,28 @@ QgsComposerFrame::~QgsComposerFrame()
2727

2828
bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const
2929
{
30-
return false; //_writeXML( element, doc );
30+
QDomElement frameElem = doc.createElement( "ComposerFrame" );
31+
frameElem.setAttribute( "sectionX", QString::number( mSection.x() ) );
32+
frameElem.setAttribute( "sectionY", QString::number( mSection.y() ) );
33+
frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) );
34+
frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) );
35+
elem.appendChild( frameElem );
36+
return _writeXML( frameElem, doc );
3137
}
3238

3339
bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument& doc )
3440
{
35-
return false; //_readXML( element, doc )
41+
double x = itemElem.attribute( "sectionX" ).toDouble();
42+
double y = itemElem.attribute( "sectionY" ).toDouble();
43+
double width = itemElem.attribute( "sectionWidth" ).toDouble();
44+
double height = itemElem.attribute( "sectionHeight" ).toDouble();
45+
mSection = QRectF( x, y, width, height );
46+
QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" );
47+
if ( composerItem.isNull() )
48+
{
49+
return false;
50+
}
51+
return _readXML( composerItem, doc );
3652
}
3753

3854
void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )

‎src/core/composer/qgscomposerhtml.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ QgsComposerHtml::QgsComposerHtml( QgsComposition* c, qreal x, qreal y, qreal wid
2828
mWebPage = new QWebPage();
2929
QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
3030

31-
if ( mComposition )
31+
if ( mComposition && width > 0 && height > 0 )
3232
{
3333
QgsComposerFrame* frame = new QgsComposerFrame( c, this, x, y, width, height );
3434
addFrame( frame );
3535
QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
36+
recalculateFrameSizes();
3637
}
37-
recalculateFrameSizes();
3838
}
3939

4040
QgsComposerHtml::QgsComposerHtml(): QgsComposerMultiFrame( 0 ), mWebPage( 0 ), mLoaded( false ), mHtmlUnitsToMM( 1.0 )
@@ -122,3 +122,13 @@ bool QgsComposerHtml::writeXML( QDomElement& elem, QDomDocument & doc ) const
122122
elem.appendChild( htmlElem );
123123
return state;
124124
}
125+
126+
bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument& doc )
127+
{
128+
QString urlString = itemElem.attribute( "url" );
129+
if ( !urlString.isEmpty() )
130+
{
131+
setUrl( QUrl( urlString ) );
132+
}
133+
return _readXML( itemElem, doc );
134+
}

‎src/core/composer/qgscomposerhtml.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class QgsComposerHtml: public QgsComposerMultiFrame
3636
void render( QPainter* p, const QRectF& renderExtent );
3737

3838
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
39+
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
3940

4041
protected:
4142
void addFrame( QgsComposerFrame* frame );

‎src/core/composer/qgscomposermultiframe.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,17 @@ bool QgsComposerMultiFrame::_writeXML( QDomElement& elem, QDomDocument& doc ) co
159159
}
160160
return true;
161161
}
162+
163+
bool QgsComposerMultiFrame::_readXML( const QDomElement& itemElem, const QDomDocument& doc )
164+
{
165+
mResizeMode = ( ResizeMode )itemElem.attribute( "resizeMode", "0" ).toInt();
166+
QDomNodeList frameList = itemElem.elementsByTagName( "ComposerFrame" );
167+
for ( int i = 0; i < frameList.size(); ++i )
168+
{
169+
QDomElement frameElem = frameList.at( i ).toElement();
170+
QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, 0, 0, 0, 0 );
171+
newFrame->readXML( frameElem, doc );
172+
addFrame( newFrame );
173+
}
174+
return true;
175+
}

‎src/core/composer/qgscomposermultiframe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class QgsComposerMultiFrame: public QObject
5353
virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
5454
bool _writeXML( QDomElement& elem, QDomDocument& doc ) const;
5555

56+
virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
57+
bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
58+
5659
protected:
5760
QgsComposition* mComposition;
5861
QList<QgsComposerFrame*> mFrameItems;

‎src/core/composer/qgscomposition.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
255255

256256
//save multiframes
257257
QSet<QgsComposerMultiFrame*>::const_iterator multiFrameIt = mMultiFrames.constBegin();
258-
for ( ; multiFrameIt != mMultiFrames.constEnd(); ++mMultiFrameIt )
258+
for ( ; multiFrameIt != mMultiFrames.constEnd(); ++multiFrameIt )
259259
{
260260
( *multiFrameIt )->writeXML( compositionElem, doc );
261261
}
@@ -454,6 +454,15 @@ void QgsComposition::addItemsFromXML( const QDomElement& elem, const QDomDocumen
454454
pushAddRemoveCommand( newTable, tr( "Table added" ) );
455455
}
456456
}
457+
//html
458+
QDomNodeList composerHtmlList = elem.elementsByTagName( "ComposerHtml" );
459+
for ( int i = 0; i < composerHtmlList.size(); ++i )
460+
{
461+
QDomElement currentHtmlElem = composerHtmlList.at( i ).toElement();
462+
QgsComposerHtml* newHtml = new QgsComposerHtml( this, 0, 0, 0, 0 );
463+
newHtml->readXML( currentHtmlElem, doc );
464+
this->addMultiFrame( newHtml );
465+
}
457466
}
458467

459468
void QgsComposition::addItemToZList( QgsComposerItem* item )

0 commit comments

Comments
 (0)
Please sign in to comment.