Skip to content

Commit 098506d

Browse files
author
mhugent
committedFeb 4, 2011
Read composer legend content from project file for WMS print (ignoring the possibility of dynamically added layers for now)
git-svn-id: http://svn.osgeo.org/qgis/trunk@15127 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2d3c5fc commit 098506d

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed
 

‎src/core/composer/qgscomposerlegenditem.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void QgsComposerSymbolItem::writeXML( QDomElement& elem, QDomDocument& doc ) con
105105
elem.appendChild( vectorClassElem );
106106
}
107107

108-
void QgsComposerSymbolItem::readXML( const QDomElement& itemElem )
108+
void QgsComposerSymbolItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
109109
{
110110
if ( itemElem.isNull() )
111111
{
@@ -123,6 +123,10 @@ void QgsComposerSymbolItem::readXML( const QDomElement& itemElem )
123123
QgsSymbol* symbol = new QgsSymbol( vLayer->geometryType() );
124124
symbol->readXML( symbolElem, vLayer );
125125
setSymbol( symbol );
126+
if ( !xServerAvailable ) //don't read icon without GUI
127+
{
128+
return;
129+
}
126130

127131
//add icon
128132
switch ( symbol->type() )
@@ -193,7 +197,7 @@ void QgsComposerSymbolV2Item::writeXML( QDomElement& elem, QDomDocument& doc ) c
193197
elem.appendChild( vectorClassElem );
194198
}
195199

196-
void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem )
200+
void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem, bool xServerAvailable )
197201
{
198202
if ( itemElem.isNull() )
199203
{
@@ -213,7 +217,10 @@ void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem )
213217
if ( symbolNg )
214218
{
215219
setSymbolV2( symbolNg );
216-
setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolNg, QSize( 30, 30 ) ) );
220+
if ( xServerAvailable )
221+
{
222+
setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolNg, QSize( 30, 30 ) ) );
223+
}
217224
}
218225
}
219226
}
@@ -259,7 +266,7 @@ void QgsComposerRasterSymbolItem::writeXML( QDomElement& elem, QDomDocument& doc
259266
elem.appendChild( rasterClassElem );
260267
}
261268

262-
void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem )
269+
void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
263270
{
264271
if ( itemElem.isNull() )
265272
{
@@ -269,7 +276,7 @@ void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem )
269276
setLayerID( itemElem.attribute( "layerId", "" ) );
270277

271278
QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( QgsMapLayerRegistry::instance()->mapLayer( mLayerID ) );
272-
if ( rLayer )
279+
if ( rLayer && xServerAvailable )
273280
{
274281
setIcon( QIcon( rLayer->legendAsPixmap( true ) ) );
275282
}
@@ -306,7 +313,7 @@ void QgsComposerLayerItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
306313
elem.appendChild( layerItemElem );
307314
}
308315

309-
void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
316+
void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
310317
{
311318
if ( itemElem.isNull() )
312319
{
@@ -348,7 +355,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
348355
{
349356
continue; //unsupported child type
350357
}
351-
currentChildItem->readXML( currentElem );
358+
currentChildItem->readXML( currentElem, xServerAvailable );
352359
appendRow( currentChildItem );
353360
}
354361
}
@@ -382,7 +389,7 @@ void QgsComposerGroupItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
382389
elem.appendChild( layerGroupElem );
383390
}
384391

385-
void QgsComposerGroupItem::readXML( const QDomElement& itemElem )
392+
void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
386393
{
387394
if ( itemElem.isNull() )
388395
{
@@ -420,7 +427,7 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem )
420427
{
421428
continue; //unsupported child item type
422429
}
423-
currentChildItem->readXML( currentElem );
430+
currentChildItem->readXML( currentElem, xServerAvailable );
424431
appendRow( currentChildItem );
425432
}
426433
}

‎src/core/composer/qgscomposerlegenditem.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
4242
};
4343

4444
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0;
45-
virtual void readXML( const QDomElement& itemElem ) = 0;
45+
/**Read item content from xml
46+
@param xServerAvailable Read item icons if true (QIcon needs x-server)*/
47+
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) = 0;
4648

4749
virtual ItemType itemType() const = 0;
4850
virtual QStandardItem* clone() const = 0;
@@ -64,7 +66,7 @@ class CORE_EXPORT QgsComposerSymbolItem: public QgsComposerLegendItem
6466
virtual QStandardItem* clone() const;
6567

6668
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
67-
virtual void readXML( const QDomElement& itemElem );
69+
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
6870

6971
/**Set symbol (takes ownership)*/
7072
void setSymbol( QgsSymbol* s );
@@ -93,7 +95,7 @@ class CORE_EXPORT QgsComposerSymbolV2Item: public QgsComposerLegendItem
9395
virtual QStandardItem* clone() const;
9496

9597
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
96-
virtual void readXML( const QDomElement& itemElem );
98+
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
9799

98100
/**Set symbol (takes ownership)*/
99101
void setSymbolV2( QgsSymbolV2* s );
@@ -116,7 +118,7 @@ class CORE_EXPORT QgsComposerRasterSymbolItem: public QgsComposerLegendItem
116118
virtual QStandardItem* clone() const;
117119

118120
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
119-
virtual void readXML( const QDomElement& itemElem );
121+
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
120122

121123
void setLayerID( const QString& id ) { mLayerID = id; }
122124
QString layerID() const { return mLayerID; }
@@ -135,7 +137,7 @@ class CORE_EXPORT QgsComposerLayerItem: public QgsComposerLegendItem
135137
virtual QStandardItem* clone() const;
136138

137139
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
138-
virtual void readXML( const QDomElement& itemElem );
140+
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
139141

140142
ItemType itemType() const { return LayerItem; }
141143

@@ -155,7 +157,7 @@ class CORE_EXPORT QgsComposerGroupItem: public QgsComposerLegendItem
155157
virtual QStandardItem* clone() const;
156158

157159
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
158-
virtual void readXML( const QDomElement& itemElem );
160+
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
159161

160162
ItemType itemType() const { return GroupItem; }
161163
};

‎src/core/composer/qgslegendmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
507507
{
508508
currentItem = new QgsComposerGroupItem();
509509
}
510-
currentItem->readXML( currentElem );
510+
currentItem->readXML( currentElem, mHasTopLevelWindow );
511511
appendRow( currentItem );
512512
}
513513

‎src/mapserver/qgsprojectparser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,9 +904,14 @@ QgsComposition* QgsProjectParser::initComposition( const QString& composerTempla
904904
{
905905
//legend needs to be loaded indirectly to have generic content
906906
//and to avoid usage of x-server with pixmap icons
907+
908+
//read full legend from xml
907909
QgsComposerLegend* legend = new QgsComposerLegend( composition );
908-
legend->_readXML( currentElem.firstChildElement( "ComposerItem" ), *mXMLDoc );
909-
legend->updateLegend();
910+
legend->readXML( currentElem, *mXMLDoc );
911+
912+
//dynamic legend (would be interesting in case of layers dynamically defined in SLD)
913+
//legend->_readXML( currentElem.firstChildElement( "ComposerItem" ), *mXMLDoc );
914+
//legend->updateLegend();
910915
composition->addItem( legend );
911916
}
912917
else if ( elemName == "ComposerShape" )

0 commit comments

Comments
 (0)
Please sign in to comment.