Skip to content

Commit

Permalink
Read composer legend content from project file for WMS print (ignorin…
Browse files Browse the repository at this point in the history
…g the possibility of dynamically added layers for now)

git-svn-id: http://svn.osgeo.org/qgis/trunk@15127 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 4, 2011
1 parent 2d3c5fc commit 098506d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
25 changes: 16 additions & 9 deletions src/core/composer/qgscomposerlegenditem.cpp
Expand Up @@ -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() )
{
Expand All @@ -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() )
Expand Down Expand Up @@ -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() )
{
Expand All @@ -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 ) ) );
}
}
}
}
Expand Down Expand Up @@ -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() )
{
Expand All @@ -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 ) ) );
}
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -348,7 +355,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
{
continue; //unsupported child type
}
currentChildItem->readXML( currentElem );
currentChildItem->readXML( currentElem, xServerAvailable );
appendRow( currentChildItem );
}
}
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -420,7 +427,7 @@ void QgsComposerGroupItem::readXML( const QDomElement& itemElem )
{
continue; //unsupported child item type
}
currentChildItem->readXML( currentElem );
currentChildItem->readXML( currentElem, xServerAvailable );
appendRow( currentChildItem );
}
}
14 changes: 8 additions & 6 deletions src/core/composer/qgscomposerlegenditem.h
Expand Up @@ -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;
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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; }
Expand All @@ -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; }

Expand All @@ -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; }
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgslegendmodel.cpp
Expand Up @@ -507,7 +507,7 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
{
currentItem = new QgsComposerGroupItem();
}
currentItem->readXML( currentElem );
currentItem->readXML( currentElem, mHasTopLevelWindow );
appendRow( currentItem );
}

Expand Down
9 changes: 7 additions & 2 deletions src/mapserver/qgsprojectparser.cpp
Expand Up @@ -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" )
Expand Down

0 comments on commit 098506d

Please sign in to comment.