Skip to content
Permalink
Browse files

avoid leak

  • Loading branch information
jef-n committed Sep 8, 2017
1 parent 133d16c commit 25c27b3c80aeaca924140a66ae8e2ac4ce991f88
@@ -33,11 +33,10 @@ namespace QgsWms
QgsServerRequest::Parameters params = request.parameters();
QgsRenderer renderer( serverIface, project, params, getConfigParser( serverIface ) );

std::unique_ptr<QByteArray> result( renderer.getFeatureInfo( version ) );
QString infoFormat = params.value( QStringLiteral( "INFO_FORMAT" ), QStringLiteral( "text/plain" ) );

response.setHeader( QStringLiteral( "Content-Type" ), infoFormat + QStringLiteral( "; charset=utf-8" ) );
response.write( *result );
response.write( renderer.getFeatureInfo( version ) );
}


@@ -63,9 +63,8 @@ namespace QgsWms
QString( "Output format %1 is not supported by the GetPrint request" ).arg( format ) );
}

std::unique_ptr<QByteArray> result( renderer.getPrint( format ) );
response.setHeader( QStringLiteral( "Content-Type" ), contentType );
response.write( *result );
response.write( renderer.getPrint( format ) );
}

} // samespace QgsWms
@@ -272,7 +272,7 @@ namespace QgsWms
}


QByteArray *QgsRenderer::getPrint( const QString &formatString )
QByteArray QgsRenderer::getPrint( const QString &formatString )
{
QStringList layersList, stylesList, layerIdList;
QgsMapSettings mapSettings;
@@ -330,17 +330,17 @@ namespace QgsWms
return nullptr;
}

QByteArray *ba = nullptr;
c->setPlotStyle( QgsComposition::Print );

QByteArray ba;

//SVG export without a running X-Server is a problem. See e.g. http://developer.qt.nokia.com/forums/viewthread/2038
if ( formatString.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
{
c->setPlotStyle( QgsComposition::Print );

QSvgGenerator generator;
ba = new QByteArray();
QBuffer svgBuffer( ba );
QBuffer svgBuffer( &ba );
generator.setOutputDevice( &svgBuffer );
int width = ( int )( c->paperWidth() * c->printResolution() / 25.4 ); //width in pixel
int height = ( int )( c->paperHeight() * c->printResolution() / 25.4 ); //height in pixel
@@ -363,8 +363,7 @@ namespace QgsWms
{
QImage image = c->printPageAsRaster( 0 ); //can only return the first page if pixmap is requested

ba = new QByteArray();
QBuffer buffer( ba );
QBuffer buffer( &ba );
buffer.open( QIODevice::WriteOnly );
image.save( &buffer, formatString.toLocal8Bit().data(), -1 );
}
@@ -380,8 +379,7 @@ namespace QgsWms
}

c->exportAsPDF( tempFile.fileName() );
ba = new QByteArray();
*ba = tempFile.readAll();
ba = tempFile.readAll();
}
else //unknown format
{
@@ -642,7 +640,7 @@ namespace QgsWms
infoPoint->setY( mapSettings.extent().yMaximum() - j * yRes - yRes / 2.0 );
}

QByteArray *QgsRenderer::getFeatureInfo( const QString &version )
QByteArray QgsRenderer::getFeatureInfo( const QString &version )
{
// Verifying Mandatory parameters
// The QUERY_LAYERS parameter is Mandatory
@@ -735,16 +733,15 @@ namespace QgsWms

QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );

QByteArray *ba = nullptr;
ba = new QByteArray();
QByteArray ba;

QgsWmsParameters::Format infoFormat = mWmsParameters.infoFormat();
if ( infoFormat == QgsWmsParameters::Format::TEXT )
*ba = convertFeatureInfoToText( result );
ba = convertFeatureInfoToText( result );
else if ( infoFormat == QgsWmsParameters::Format::HTML )
*ba = convertFeatureInfoToHtml( result );
ba = convertFeatureInfoToHtml( result );
else
*ba = result.toByteArray();
ba = result.toByteArray();

return ba;
}
@@ -111,12 +111,12 @@ namespace QgsWms
/** Returns printed page as binary
\param formatString out: format of the print output (e.g. pdf, svg, png, ...)
\returns printed page as binary or 0 in case of error*/
QByteArray *getPrint( const QString &formatString );
QByteArray getPrint( const QString &formatString );

/** Creates an xml document that describes the result of the getFeatureInfo request.
* May throw an exception
*/
QByteArray *getFeatureInfo( const QString &version = "1.3.0" );
QByteArray getFeatureInfo( const QString &version = "1.3.0" );

private:

0 comments on commit 25c27b3

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