Skip to content
Permalink
Browse files

Better reusage of composer functionality between server and desktop

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Sep 6, 2012
1 parent a88af64 commit 4d90320d9c6d034a0574c53db4f34c34704d5928
Showing with 26 additions and 72 deletions.
  1. +18 −0 src/core/composer/qgscomposition.h
  2. +8 −72 src/mapserver/qgsprojectparser.cpp
@@ -120,6 +120,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Returns pointers to all composer maps in the scene*/
QList<const QgsComposerMap*> composerMapItems() const;

/**Return composer items of a specific type*/
template<class T> void composerItems( QList<T*>& itemList );

/**Returns the composer map with specified id
@return id or 0 pointer if the composer map item does not exist*/
const QgsComposerMap* getComposerMapById( int id ) const;
@@ -343,6 +346,21 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
void itemRemoved( QgsComposerItem* );
};

template<class T> void QgsComposition::composerItems( QList<T*>& itemList )
{
itemList.clear();
QList<QGraphicsItem *> graphicsItemList = items();
QList<QGraphicsItem *>::iterator itemIt = graphicsItemList.begin();
for ( ; itemIt != graphicsItemList.end(); ++itemIt )
{
T* item = dynamic_cast<T*>( *itemIt );
if ( item )
{
itemList.push_back( item );
}
}
}

#endif


@@ -1169,80 +1169,16 @@ QgsComposition* QgsProjectParser::initComposition( const QString& composerTempla
return 0;
}

//go through all the item elements and add them to the composition (and to the lists)
QDomNodeList itemNodes = compositionElem.childNodes();
for ( int i = 0; i < itemNodes.size(); ++i )
{
QDomElement currentElem = itemNodes.at( i ).toElement();
QString elemName = currentElem.tagName();
if ( elemName == "ComposerMap" )
{
QgsComposerMap* map = new QgsComposerMap( composition );
map->readXML( currentElem, *mXMLDoc );
map->setPreviewMode( QgsComposerMap::Rectangle );
composition->addItem( map );
mapList.push_back( map );
}
else if ( elemName == "ComposerLabel" )
{
QgsComposerLabel* label = new QgsComposerLabel( composition );
label->readXML( currentElem, *mXMLDoc );
composition->addItem( label );
labelList.push_back( label );
}
else if ( elemName == "ComposerLegend" )
{
//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, *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" )
{
QgsComposerShape* shape = new QgsComposerShape( composition );
shape->readXML( currentElem, *mXMLDoc );
composition->addItem( shape );
}
else if ( elemName == "ComposerArrow" )
{
QgsComposerArrow* arrow = new QgsComposerArrow( composition );
arrow->readXML( currentElem, *mXMLDoc );
composition->addItem( arrow );
}
else if ( elemName == "ComposerAttributeTable" )
{
QgsComposerAttributeTable* table = new QgsComposerAttributeTable( composition );
table->readXML( currentElem, *mXMLDoc );
composition->addItem( table );
}
}
composition->addItemsFromXML( compositionElem, *mXMLDoc );
composition->composerItems( mapList );
composition->composerItems( labelList );

//scalebars and pictures need to be loaded after the maps to receive the correct size / rotation
for ( int i = 0; i < itemNodes.size(); ++i )
QList< QgsComposerPicture* > pictureList;
composition->composerItems( pictureList );
QList< QgsComposerPicture* >::iterator picIt = pictureList.begin();
for ( ; picIt != pictureList.end(); ++picIt )
{
QDomElement currentElem = itemNodes.at( i ).toElement();
QString elemName = currentElem.tagName();
if ( elemName == "ComposerPicture" )
{
QgsComposerPicture* picture = new QgsComposerPicture( composition );
picture->readXML( currentElem, *mXMLDoc );
//qgis mapserver needs an absolute file path
picture->setPictureFile( convertToAbsolutePath( picture->pictureFile() ) );
composition->addItem( picture );
}
else if ( elemName == "ComposerScaleBar" )
{
QgsComposerScaleBar* bar = new QgsComposerScaleBar( composition );
bar->readXML( currentElem, *mXMLDoc );
composition->addItem( bar );
}
( *picIt )->setPictureFile( convertToAbsolutePath(( *picIt )->pictureFile() ) );
}

return composition;

0 comments on commit 4d90320

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