Skip to content
Permalink
Browse files

Read composer legend content from project file for WMS print (ignorin…

…g the possibility of dynamically added layers for now)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15127 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Feb 4, 2011
1 parent 0e6aee3 commit 9ddeee3f06f00e05a83f070f3befecbbe5142f35
@@ -105,7 +105,7 @@ void QgsComposerSymbolItem::writeXML( QDomElement& elem, QDomDocument& doc ) con
elem.appendChild( vectorClassElem );
}

void QgsComposerSymbolItem::readXML( const QDomElement& itemElem )
void QgsComposerSymbolItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
{
if ( itemElem.isNull() )
{
@@ -123,6 +123,10 @@ void QgsComposerSymbolItem::readXML( const QDomElement& itemElem )
QgsSymbol* symbol = new QgsSymbol( vLayer->geometryType() );
symbol->readXML( symbolElem, vLayer );
setSymbol( symbol );
if ( !xServerAvailable ) //don't read icon without GUI
{
return;
}

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

void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem )
void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem, bool xServerAvailable )
{
if ( itemElem.isNull() )
{
@@ -213,7 +217,10 @@ void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem )
if ( symbolNg )
{
setSymbolV2( symbolNg );
setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolNg, QSize( 30, 30 ) ) );
if ( xServerAvailable )
{
setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolNg, QSize( 30, 30 ) ) );
}
}
}
}
@@ -259,7 +266,7 @@ void QgsComposerRasterSymbolItem::writeXML( QDomElement& elem, QDomDocument& doc
elem.appendChild( rasterClassElem );
}

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

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

void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
{
if ( itemElem.isNull() )
{
@@ -348,7 +355,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
{
continue; //unsupported child type
}
currentChildItem->readXML( currentElem );
currentChildItem->readXML( currentElem, xServerAvailable );
appendRow( currentChildItem );
}
}
@@ -382,7 +389,7 @@ void QgsComposerGroupItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
elem.appendChild( layerGroupElem );
}

void QgsComposerGroupItem::readXML( const QDomElement& itemElem )
void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
{
if ( itemElem.isNull() )
{
@@ -420,7 +427,7 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem )
{
continue; //unsupported child item type
}
currentChildItem->readXML( currentElem );
currentChildItem->readXML( currentElem, xServerAvailable );
appendRow( currentChildItem );
}
}
@@ -42,7 +42,9 @@ class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
};

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

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

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
virtual void readXML( const QDomElement& itemElem );
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );

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

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
virtual void readXML( const QDomElement& itemElem );
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );

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

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
virtual void readXML( const QDomElement& itemElem );
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );

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

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
virtual void readXML( const QDomElement& itemElem );
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );

ItemType itemType() const { return LayerItem; }

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

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
virtual void readXML( const QDomElement& itemElem );
virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );

ItemType itemType() const { return GroupItem; }
};
@@ -507,7 +507,7 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
{
currentItem = new QgsComposerGroupItem();
}
currentItem->readXML( currentElem );
currentItem->readXML( currentElem, mHasTopLevelWindow );
appendRow( currentItem );
}

@@ -904,9 +904,14 @@ QgsComposition* QgsProjectParser::initComposition( const QString& composerTempla
{
//legend needs to be loaded indirectly to have generic content
//and to avoid usage of x-server with pixmap icons

//read full legend from xml
QgsComposerLegend* legend = new QgsComposerLegend( composition );
legend->_readXML( currentElem.firstChildElement( "ComposerItem" ), *mXMLDoc );
legend->updateLegend();
legend->readXML( currentElem, *mXMLDoc );

//dynamic legend (would be interesting in case of layers dynamically defined in SLD)
//legend->_readXML( currentElem.firstChildElement( "ComposerItem" ), *mXMLDoc );
//legend->updateLegend();
composition->addItem( legend );
}
else if ( elemName == "ComposerShape" )

0 comments on commit 9ddeee3

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