Skip to content

Commit

Permalink
Change getPrint syntax to use several parameters for composer maps, e…
Browse files Browse the repository at this point in the history
….g. map0:extent=xmin,ymin,xmax,ymax or map0:rotation=45

git-svn-id: http://svn.osgeo.org/qgis/trunk@15111 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 31, 2011
1 parent 1a98b90 commit 3836e48
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions src/mapserver/qgsconfigparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,69 +302,83 @@ QgsComposition* QgsConfigParser::createPrintComposition( const QString& composer
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() )
QString mapId = "MAP" + QString::number( currentMap->id() );
QMap< QString, QString >::const_iterator extentIt = parameterMap.find( mapId + ":EXTENT" );
if ( extentIt == parameterMap.constEnd() ) //map extent is mandatory
{
//remove map from composition if not referenced by the request
c->removeItem( *mapIt );
delete( *mapIt );
continue;
c->removeItem( *mapIt ); delete( *mapIt ); continue;
}

QStringList coordList = extentIt.value().split( "," );
if ( coordList.size() < 4 )
{
c->removeItem( *mapIt ); delete( *mapIt ); continue; //need at least four coordinates
}
QString replaceString = titleIt.value();
QStringList replacementList = replaceString.split( "/" );

//get map extent from string
if ( replacementList.size() > 0 )
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 )
{
QStringList coordList = replacementList.at( 0 ).split( "," );
if ( coordList.size() > 3 )
c->removeItem( *mapIt ); delete( *mapIt ); continue;
}

//Change x- and y- of extent for WMS 1.3.0 and geographic coordinate systems
QMap<QString, QString>::const_iterator versionIt = parameterMap.find( "VERSION" );
if ( versionIt != parameterMap.end() )
{
if ( mapRenderer && versionIt.value() == "1.3.0" && mapRenderer->destinationSrs().geographicFlag() )
{
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 ) );
}
//switch coordinates of extent
double tmp;
tmp = xmin;
xmin = ymin; ymin = tmp;
tmp = xmax;
xmax = ymax; ymax = tmp;
}
}
currentMap->setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );

//get rotation from string
if ( replacementList.size() > 1 )
//scale
QMap< QString, QString >::const_iterator scaleIt = parameterMap.find( mapId + ":SCALE" );
if ( scaleIt != parameterMap.constEnd() )
{
bool rotationOk;
double rotation = replacementList.at( 1 ).toDouble( &rotationOk );
if ( rotationOk )
bool scaleOk;
double scale = scaleIt->toDouble( &scaleOk );
if ( scaleOk )
{
currentMap->setMapRotation( rotation );
currentMap->setNewScale( scale );
}
}

//get forced scale from string
if ( replacementList.size() > 2 )
//rotation
QMap< QString, QString >::const_iterator rotationIt = parameterMap.find( mapId + ":ROTATION" );
if ( rotationIt != parameterMap.constEnd() )
{
bool conversionOk;
double scale = replacementList.at( 2 ).toDouble( &conversionOk );
if ( conversionOk )
bool rotationOk;
double rotation = rotationIt->toDouble( &rotationOk );
if ( rotationOk )
{
currentMap->setNewScale( scale );
currentMap->setMapRotation( rotation );
}
}

//get layer list from string
if ( replacementList.size() > 3 )
//layers / styles
QMap< QString, QString >::const_iterator layersIt = parameterMap.find( mapId + ":LAYERS" );
QMap< QString, QString >::const_iterator stylesIt = parameterMap.find( mapId + ":STYLES" );
if ( layersIt != parameterMap.constEnd() )
{
QStringList layerSet;
QStringList wmsLayerList = replacementList.at( 3 ).split( "," );
QStringList wmsLayerList = layersIt->split( "," );
QStringList wmsStyleList;
if ( replacementList.size() > 4 )

if ( stylesIt != parameterMap.constEnd() )
{
wmsStyleList = replacementList.at( 4 ).split( "," );
wmsStyleList = stylesIt->split( "," );
}

for ( int i = 0; i < wmsLayerList.size(); ++i )
{
QString styleName;
Expand Down

0 comments on commit 3836e48

Please sign in to comment.