Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE]: initial support for wms printing with GetPrint-Request
git-svn-id: http://svn.osgeo.org/qgis/trunk@14973 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 24, 2010
1 parent 9cb73c0 commit 806afc9
Show file tree
Hide file tree
Showing 15 changed files with 567 additions and 82 deletions.
22 changes: 22 additions & 0 deletions src/mapserver/qgis_map_serv.cpp
Expand Up @@ -382,6 +382,28 @@ int main( int argc, char * argv[] )
continue;

}
else if ( requestIt->second == "GetPrint" )
{
QByteArray* printOutput = 0;
QString formatString;
try
{
printOutput = theServer->getPrint( formatString );
}
catch ( QgsMapServiceException& ex )
{
theRequestHandler->sendServiceException( ex );
}

if ( printOutput )
{
theRequestHandler->sendGetPrintResponse( printOutput, formatString );
}
delete printOutput;
delete theRequestHandler;
delete theServer;
continue;
}
else//unknown request
{
QgsMapServiceException e( "OperationNotSupported", "Operation " + requestIt->second + " not supported" );
Expand Down
107 changes: 107 additions & 0 deletions src/mapserver/qgsconfigparser.cpp
Expand Up @@ -17,6 +17,8 @@

#include "qgsconfigparser.h"
#include "qgsapplication.h"
#include "qgscomposermap.h"
#include "qgscomposition.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include <sqlite3.h>
Expand Down Expand Up @@ -269,3 +271,108 @@ void QgsConfigParser::appendCRSElementsToLayer( QDomElement& layerElement, QDomD
layerElement.appendChild( crsElement );
}
}

QgsComposition* QgsConfigParser::createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const
{
QList<QgsComposerMap*> composerMaps;
QList<QgsComposerLabel*> composerLabels;

QgsComposition* c = initComposition( composerTemplate, mapRenderer, composerMaps, composerLabels );
if ( !c )
{
return 0;
}

QMap< QString, QString >::const_iterator dpiIt = parameterMap.find( "DPI" );
if ( dpiIt != parameterMap.constEnd() )
{
c->setPrintResolution( dpiIt.value().toInt() );
}

//replace composer map parameters
QList<QgsComposerMap*>::iterator mapIt = composerMaps.begin();
QgsComposerMap* currentMap = 0;
for ( ; mapIt != composerMaps.end(); ++mapIt )
{
currentMap = *mapIt;
if ( !currentMap )
{
continue;
}

//search composer map title in parameter map-> string
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( "MAP" + QString::number( currentMap->id() ) );
if ( titleIt == parameterMap.constEnd() )
{
continue;
}
QString replaceString = titleIt.value();
QStringList replacementList = replaceString.split( "/" );

//get map extent from string
if ( replacementList.size() > 0 )
{
QStringList coordList = replacementList.at( 0 ).split( "," );
if ( coordList.size() > 3 )
{
bool xMinOk, yMinOk, xMaxOk, yMaxOk;
double xmin = coordList.at( 0 ).toDouble( &xMinOk );
double ymin = coordList.at( 1 ).toDouble( &yMinOk );
double xmax = coordList.at( 2 ).toDouble( &xMaxOk );
double ymax = coordList.at( 3 ).toDouble( &yMaxOk );
if ( xMinOk && yMinOk && xMaxOk && yMaxOk )
{
currentMap->setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
}
}
}

//get rotation from string
if ( replacementList.size() > 1 )
{
bool rotationOk;
double rotation = replacementList.at( 1 ).toDouble( &rotationOk );
if ( rotationOk )
{
currentMap->setMapRotation( rotation );
}
}

//get layer list from string
if ( replacementList.size() > 2 )
{
QStringList layerSet;
QStringList wmsLayerList = replacementList.at( 2 ).split( "," );
QStringList wmsStyleList;
if ( replacementList.size() > 3 )
{
wmsStyleList = replacementList.at( 3 ).split( "," );
}

for ( int i = 0; i < wmsLayerList.size(); ++i )
{
QString styleName;
if ( wmsStyleList.size() > i )
{
styleName = wmsStyleList.at( i );
}
QList<QgsMapLayer*> layerList = mapLayerFromStyle( wmsLayerList.at( i ), styleName );
QList<QgsMapLayer*>::const_iterator mapIdIt = layerList.constBegin();
for ( ; mapIdIt != layerList.constEnd(); ++mapIdIt )
{
if ( *mapIdIt )
{
layerSet.push_back(( *mapIdIt )->getLayerID() );
}
}
}

currentMap->setLayerSet( layerSet );
currentMap->setKeepLayerSet( true );
}
}

//replace composer label text

return c; //soon...
}
13 changes: 13 additions & 0 deletions src/mapserver/qgsconfigparser.h
Expand Up @@ -24,6 +24,9 @@
#include <QList>
#include <QSet>

class QgsComposition;
class QgsComposerLabel;
class QgsComposerMap;
class QDomElement;

/**Interface class for configuration parsing, e.g. SLD configuration or QGIS project file*/
Expand Down Expand Up @@ -56,6 +59,7 @@ class QgsConfigParser

/**Sets fallback parser (does not take ownership)*/
void setFallbackParser( QgsConfigParser* p );
const QgsConfigParser* fallbackParser() { return mFallbackParser; }

void setScaleDenominator( double denom ) {mScaleDenominator = denom;}

Expand Down Expand Up @@ -88,6 +92,15 @@ class QgsConfigParser
/**Returns information about vector attributes with hidden edit type. Key is layer id, value is a set containing the names of the hidden attributes*/
virtual QMap< QString, QSet<QString> > hiddenAttributes() const { return QMap< QString, QSet<QString> >(); }

/**Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
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;

/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
virtual void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;

protected:
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
QgsConfigParser* mFallbackParser;
Expand Down
9 changes: 5 additions & 4 deletions src/mapserver/qgsgetrequesthandler.cpp
Expand Up @@ -107,10 +107,6 @@ std::map<QString, QString> QgsGetRequestHandler::parseInput()
{
formatString = "PNG";
}
else
{
throw QgsMapServiceException( "InvalidFormat", "Invalid format, only jpg and png are supported" );
}
mFormat = formatString;
}
}
Expand Down Expand Up @@ -301,3 +297,8 @@ void QgsGetRequestHandler::sendServiceException( const QgsMapServiceException& e
QByteArray ba = exceptionDoc.toByteArray();
sendHttpResponse( &ba, "text/xml" );
}

void QgsGetRequestHandler::sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const
{
sendHttpResponse( ba, formatString );
}
1 change: 1 addition & 0 deletions src/mapserver/qgsgetrequesthandler.h
Expand Up @@ -29,4 +29,5 @@ class QgsGetRequestHandler: public QgsHttpRequestHandler
void sendGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) const;
void sendServiceException( const QgsMapServiceException& ex ) const;
void sendGetStyleResponse( const QDomDocument& doc ) const;
void sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const;
};
2 changes: 2 additions & 0 deletions src/mapserver/qgsmslayercache.cpp
Expand Up @@ -79,6 +79,7 @@ QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& la
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlNamePair );
if ( it == mEntries.end() )
{
QgsMSDebugMsg( "Layer not found in cache" )
return 0;
}
else
Expand All @@ -92,6 +93,7 @@ QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& la
vl->removeOverlay( "diagram" );
}
#endif //DIAGRAMSERVER
QgsMSDebugMsg( "Layer found in cache" )
return it->layerPointer;
}
}
Expand Down

0 comments on commit 806afc9

Please sign in to comment.