Skip to content

Commit 806afc9

Browse files
author
mhugent
committed
[FEATURE]: initial support for wms printing with GetPrint-Request
git-svn-id: http://svn.osgeo.org/qgis/trunk@14973 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9cb73c0 commit 806afc9

15 files changed

+567
-82
lines changed

src/mapserver/qgis_map_serv.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,28 @@ int main( int argc, char * argv[] )
382382
continue;
383383

384384
}
385+
else if ( requestIt->second == "GetPrint" )
386+
{
387+
QByteArray* printOutput = 0;
388+
QString formatString;
389+
try
390+
{
391+
printOutput = theServer->getPrint( formatString );
392+
}
393+
catch ( QgsMapServiceException& ex )
394+
{
395+
theRequestHandler->sendServiceException( ex );
396+
}
397+
398+
if ( printOutput )
399+
{
400+
theRequestHandler->sendGetPrintResponse( printOutput, formatString );
401+
}
402+
delete printOutput;
403+
delete theRequestHandler;
404+
delete theServer;
405+
continue;
406+
}
385407
else//unknown request
386408
{
387409
QgsMapServiceException e( "OperationNotSupported", "Operation " + requestIt->second + " not supported" );

src/mapserver/qgsconfigparser.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "qgsconfigparser.h"
1919
#include "qgsapplication.h"
20+
#include "qgscomposermap.h"
21+
#include "qgscomposition.h"
2022
#include "qgsrasterlayer.h"
2123
#include "qgsvectorlayer.h"
2224
#include <sqlite3.h>
@@ -269,3 +271,108 @@ void QgsConfigParser::appendCRSElementsToLayer( QDomElement& layerElement, QDomD
269271
layerElement.appendChild( crsElement );
270272
}
271273
}
274+
275+
QgsComposition* QgsConfigParser::createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const
276+
{
277+
QList<QgsComposerMap*> composerMaps;
278+
QList<QgsComposerLabel*> composerLabels;
279+
280+
QgsComposition* c = initComposition( composerTemplate, mapRenderer, composerMaps, composerLabels );
281+
if ( !c )
282+
{
283+
return 0;
284+
}
285+
286+
QMap< QString, QString >::const_iterator dpiIt = parameterMap.find( "DPI" );
287+
if ( dpiIt != parameterMap.constEnd() )
288+
{
289+
c->setPrintResolution( dpiIt.value().toInt() );
290+
}
291+
292+
//replace composer map parameters
293+
QList<QgsComposerMap*>::iterator mapIt = composerMaps.begin();
294+
QgsComposerMap* currentMap = 0;
295+
for ( ; mapIt != composerMaps.end(); ++mapIt )
296+
{
297+
currentMap = *mapIt;
298+
if ( !currentMap )
299+
{
300+
continue;
301+
}
302+
303+
//search composer map title in parameter map-> string
304+
QMap< QString, QString >::const_iterator titleIt = parameterMap.find( "MAP" + QString::number( currentMap->id() ) );
305+
if ( titleIt == parameterMap.constEnd() )
306+
{
307+
continue;
308+
}
309+
QString replaceString = titleIt.value();
310+
QStringList replacementList = replaceString.split( "/" );
311+
312+
//get map extent from string
313+
if ( replacementList.size() > 0 )
314+
{
315+
QStringList coordList = replacementList.at( 0 ).split( "," );
316+
if ( coordList.size() > 3 )
317+
{
318+
bool xMinOk, yMinOk, xMaxOk, yMaxOk;
319+
double xmin = coordList.at( 0 ).toDouble( &xMinOk );
320+
double ymin = coordList.at( 1 ).toDouble( &yMinOk );
321+
double xmax = coordList.at( 2 ).toDouble( &xMaxOk );
322+
double ymax = coordList.at( 3 ).toDouble( &yMaxOk );
323+
if ( xMinOk && yMinOk && xMaxOk && yMaxOk )
324+
{
325+
currentMap->setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
326+
}
327+
}
328+
}
329+
330+
//get rotation from string
331+
if ( replacementList.size() > 1 )
332+
{
333+
bool rotationOk;
334+
double rotation = replacementList.at( 1 ).toDouble( &rotationOk );
335+
if ( rotationOk )
336+
{
337+
currentMap->setMapRotation( rotation );
338+
}
339+
}
340+
341+
//get layer list from string
342+
if ( replacementList.size() > 2 )
343+
{
344+
QStringList layerSet;
345+
QStringList wmsLayerList = replacementList.at( 2 ).split( "," );
346+
QStringList wmsStyleList;
347+
if ( replacementList.size() > 3 )
348+
{
349+
wmsStyleList = replacementList.at( 3 ).split( "," );
350+
}
351+
352+
for ( int i = 0; i < wmsLayerList.size(); ++i )
353+
{
354+
QString styleName;
355+
if ( wmsStyleList.size() > i )
356+
{
357+
styleName = wmsStyleList.at( i );
358+
}
359+
QList<QgsMapLayer*> layerList = mapLayerFromStyle( wmsLayerList.at( i ), styleName );
360+
QList<QgsMapLayer*>::const_iterator mapIdIt = layerList.constBegin();
361+
for ( ; mapIdIt != layerList.constEnd(); ++mapIdIt )
362+
{
363+
if ( *mapIdIt )
364+
{
365+
layerSet.push_back(( *mapIdIt )->getLayerID() );
366+
}
367+
}
368+
}
369+
370+
currentMap->setLayerSet( layerSet );
371+
currentMap->setKeepLayerSet( true );
372+
}
373+
}
374+
375+
//replace composer label text
376+
377+
return c; //soon...
378+
}

src/mapserver/qgsconfigparser.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <QList>
2525
#include <QSet>
2626

27+
class QgsComposition;
28+
class QgsComposerLabel;
29+
class QgsComposerMap;
2730
class QDomElement;
2831

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

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

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

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

95+
/**Creates a print composition, usually for a GetPrint request. Replaces map and label parameters*/
96+
QgsComposition* createPrintComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, const QMap< QString, QString >& parameterMap ) const;
97+
98+
/**Creates a composition from the project file (probably delegated to the fallback parser)*/
99+
virtual QgsComposition* initComposition( const QString& composerTemplate, QgsMapRenderer* mapRenderer, QList< QgsComposerMap*>& mapList, QList< QgsComposerLabel* > labelList ) const = 0;
100+
101+
/**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
102+
virtual void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
103+
91104
protected:
92105
/**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
93106
QgsConfigParser* mFallbackParser;

src/mapserver/qgsgetrequesthandler.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ std::map<QString, QString> QgsGetRequestHandler::parseInput()
107107
{
108108
formatString = "PNG";
109109
}
110-
else
111-
{
112-
throw QgsMapServiceException( "InvalidFormat", "Invalid format, only jpg and png are supported" );
113-
}
114110
mFormat = formatString;
115111
}
116112
}
@@ -301,3 +297,8 @@ void QgsGetRequestHandler::sendServiceException( const QgsMapServiceException& e
301297
QByteArray ba = exceptionDoc.toByteArray();
302298
sendHttpResponse( &ba, "text/xml" );
303299
}
300+
301+
void QgsGetRequestHandler::sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const
302+
{
303+
sendHttpResponse( ba, formatString );
304+
}

src/mapserver/qgsgetrequesthandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ class QgsGetRequestHandler: public QgsHttpRequestHandler
2929
void sendGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) const;
3030
void sendServiceException( const QgsMapServiceException& ex ) const;
3131
void sendGetStyleResponse( const QDomDocument& doc ) const;
32+
void sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const;
3233
};

src/mapserver/qgsmslayercache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& la
7979
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlNamePair );
8080
if ( it == mEntries.end() )
8181
{
82+
QgsMSDebugMsg( "Layer not found in cache" )
8283
return 0;
8384
}
8485
else
@@ -92,6 +93,7 @@ QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& la
9293
vl->removeOverlay( "diagram" );
9394
}
9495
#endif //DIAGRAMSERVER
96+
QgsMSDebugMsg( "Layer found in cache" )
9597
return it->layerPointer;
9698
}
9799
}

0 commit comments

Comments
 (0)