Skip to content
Permalink
Browse files

[Feature][QGIS-Server] Specifying url for QgsComposerHtml in GetPRint…

… Request

The idea is to add the capability to specify an URL to a QgsComposerHtml
element in the GetPrint request.
This will give the ability to get PDF with content base on a web
service.
  • Loading branch information
rldhont committed Jun 12, 2013
1 parent 85e1ab9 commit 6d9cec52a9f873d01422d464f2ee5d5f8a9d73f9
@@ -20,6 +20,8 @@
#include "qgsapplication.h"
#include "qgscomposerlabel.h"
#include "qgscomposermap.h"
#include "qgscomposerhtml.h"
#include "qgscomposerframe.h"
#include "qgscomposition.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
@@ -407,8 +409,9 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
{
QList<QgsComposerMap*> composerMaps;
QList<QgsComposerLabel*> composerLabels;
QList<const QgsComposerHtml*> composerHtmls;

QgsComposition* c = initComposition( composerTemplate, mapRenderer, composerMaps, composerLabels );
QgsComposition* c = initComposition( composerTemplate, mapRenderer, composerMaps, composerLabels, composerHtmls );
if ( !c )
{
return 0;
@@ -545,13 +548,35 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
}

currentLabel->setText( title );
/* the method adjustSizeToText has some rendering issue
* for HTML or Simple String
if ( !currentLabel->htmlState() )
}

//replace html url
foreach (const QgsComposerHtml *currentHtml, composerHtmls )
{
QgsComposerHtml * html = const_cast<QgsComposerHtml *>(currentHtml);
QgsComposerFrame *htmlFrame = html->frame( 0 );
QString htmlId = htmlFrame->id();
QString url = parameterMap.value( htmlId.toUpper() );

if ( url.isEmpty() )
{
currentLabel->adjustSizeToText();
//remove exported Htmls referenced in the request
//but with empty string
if ( parameterMap.contains( htmlId.toUpper() ) )
{
c->removeMultiFrame( html );
delete currentHtml;
}
else
{
html->update();
}
continue;
}
*/

QUrl newUrl( url );
html->setUrl( newUrl );
html->update();
}

return c;
@@ -29,6 +29,9 @@
class QgsComposition;
class QgsComposerLabel;
class QgsComposerMap;
class QgsComposerFrame;
class QgsComposerMultiFrame;
class QgsComposerHtml;
class QDomElement;

/**Interface class for configuration parsing, e.g. SLD configuration or QGIS project file*/
@@ -117,7 +120,7 @@ class QgsConfigParser
QgsComposition* createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const;

/**Creates a composition from the project file (probably delegated to the fallback parser)*/
virtual QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList ) const = 0;
virtual QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlFrameList ) const = 0;

/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
virtual void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
@@ -32,6 +32,7 @@
#include "qgscomposerlabel.h"
#include "qgscomposerlegend.h"
#include "qgscomposermap.h"
#include "qgscomposerhtml.h"
#include "qgscomposerpicture.h"
#include "qgscomposerscalebar.h"
#include "qgscomposershape.h"
@@ -2187,7 +2188,7 @@ QString QgsProjectParser::layerIdFromLegendLayer( const QDomElement& legendLayer
return legendLayerFileList.at( 0 ).toElement().attribute( "layerid" );
}

QgsComposition* QgsProjectParser::initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList ) const
QgsComposition* QgsProjectParser::initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const
{
//Create composition from xml
QDomElement composerElem = composerByName( composerTemplate );
@@ -2210,15 +2211,40 @@ QgsComposition* QgsProjectParser::initComposition( const QString& composerTempla
}

composition->addItemsFromXML( compositionElem, *mXMLDoc );
composition->composerItems( mapList );
composition->composerItems( labelList );

QList< QgsComposerPicture* > pictureList;
composition->composerItems( pictureList );
QList< QgsComposerPicture* >::iterator picIt = pictureList.begin();
for ( ; picIt != pictureList.end(); ++picIt )
labelList.clear();
mapList.clear();
htmlList.clear();

QList<QgsComposerItem* > itemList;
composition->composerItems( itemList );
QList<QgsComposerItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
( *picIt )->setPictureFile( convertToAbsolutePath(( *picIt )->pictureFile() ) );
QgsComposerLabel* label = dynamic_cast< QgsComposerLabel *>( *itemIt );
if ( label )
{
labelList.push_back( label );
continue;
}
QgsComposerMap* map = dynamic_cast< QgsComposerMap *>( *itemIt );
if ( map )
{
mapList.push_back( map );
continue;
}
QgsComposerPicture* pic = dynamic_cast< QgsComposerPicture *>( *itemIt );
if ( pic )
{
pic->setPictureFile( convertToAbsolutePath(( pic )->pictureFile() ) );
continue;
}
const QgsComposerHtml* html = composition->getComposerHtmlByItem( *itemIt );
if ( html )
{
htmlList.push_back( html );
continue;
}
}

return composition;
@@ -2294,6 +2320,21 @@ void QgsProjectParser::printCapabilities( QDomElement& parentElement, QDomDocume
composerTemplateElem.appendChild( composerLabelElem );
}

//add available composer HTML
QDomNodeList composerHtmlList = currentComposerElem.elementsByTagName( "ComposerHtml" );
for ( int j = 0; j < composerHtmlList.size(); ++j )
{
QDomElement citem = composerHtmlList.at( j ).firstChildElement( "ComposerFrame" ).firstChildElement( "ComposerItem" );
QString id = citem.attribute( "id" );
if ( id.isEmpty() ) //only export labels with ids for text replacement
{
continue;
}
QDomElement composerHtmlElem = doc.createElement( "ComposerHtml" );
composerHtmlElem.setAttribute( "name", id );
composerTemplateElem.appendChild( composerHtmlElem );
}

composerTemplatesElem.appendChild( composerTemplateElem );
}
parentElement.appendChild( composerTemplatesElem );
@@ -105,7 +105,7 @@ class QgsProjectParser: public QgsConfigParser
const QDomDocument* xmlDoc() const { return mXMLDoc; }

/**Creates a composition from the project file (probably delegated to the fallback parser)*/
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList ) const;
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const;

/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
@@ -1544,11 +1544,11 @@ void QgsSLDParser::setCrsForLayer( const QDomElement& layerElem, QgsMapLayer* ml
}
}

QgsComposition* QgsSLDParser::initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList ) const
QgsComposition* QgsSLDParser::initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const
{
if ( mFallbackParser )
{
return mFallbackParser->initComposition( composerTemplate, mapRenderer, mapList, labelList );
return mFallbackParser->initComposition( composerTemplate, mapRenderer, mapList, labelList, htmlList );
}
return 0;
}
@@ -79,7 +79,7 @@ class QgsSLDParser: public QgsConfigParser
virtual void setParameterMap( const QMap<QString, QString>& parameterMap ) { mParameterMap = parameterMap; }

/**Creates a composition from the project file (delegated to the fallback parser)*/
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList ) const;
QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* >& labelList, QList<const QgsComposerHtml *>& htmlList ) const;

/**Adds print capabilities to xml document. Delegated to fallback parser*/
void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

0 comments on commit 6d9cec5

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