Skip to content
Permalink
Browse files

Fix common memory leak after using QgsSymbolLayerV2Utils::loadSymbol

  • Loading branch information
nyalldawson committed Feb 3, 2015
1 parent 005e158 commit 93a86835d614822ca444825a20a35c13e43a93bd
@@ -75,7 +75,20 @@ class QgsSymbolLayerV2Utils
/**Returns the maximum estimated bleed for the symbol */
static double estimateMaxSymbolBleed( QgsSymbolV2* symbol );

static QgsSymbolV2* loadSymbol( QDomElement& element ) /Factory/;
/**Attempts to load a symbol from a DOM element
* @param element DOM element representing symbol
* @returns decoded symbol, if possible
*/
static QgsSymbolV2* loadSymbol( const QDomElement& element ) /Factory/;

/**Attempts to load a symbol from a DOM element and cast it to a particular symbol
* type.
* @param element DOM element representing symbol
* @returns decoded symbol cast to specified type, if possible
* @note not available in python bindings
*/
//template <class SymbolType> static SymbolType* loadSymbol( const QDomElement& element );

static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element ) /Factory/;
static QDomElement saveSymbol( QString symbolName, QgsSymbolV2* symbol, QDomDocument& doc );

@@ -135,7 +135,7 @@ void QgsDecorationGrid::projectRead()
{
doc.setContent( xml );
elem = doc.documentElement();
mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( elem ) );
mLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( elem );
}
if ( ! mLineSymbol )
mLineSymbol = new QgsLineSymbolV2();
@@ -147,7 +147,7 @@ void QgsDecorationGrid::projectRead()
{
doc.setContent( xml );
elem = doc.documentElement();
mMarkerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( elem ) );
mMarkerSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( elem );
}
if ( ! mMarkerSymbol )
{
@@ -523,7 +523,7 @@ bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument&
if ( !lineStyleElem.isNull() )
{
delete mLineSymbol;
mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( lineStyleElem ) );
mLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( lineStyleElem );
}
}
else
@@ -1454,7 +1454,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
}
else
{
lineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( gridSymbolElem ) );
lineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( gridSymbolElem );
}
mapGrid->setLineSymbol( lineSymbol );

@@ -1499,7 +1499,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement( "symbol" );
if ( !overviewFrameSymbolElem.isNull() )
{
fillSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( overviewFrameSymbolElem ) );
fillSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( overviewFrameSymbolElem );
mapOverview->setFrameSymbol( fillSymbol );
}
mOverviewStack->addOverview( mapOverview );
@@ -348,7 +348,7 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
if ( !symbolElem.isNull() )
{
delete mGridLineSymbol;
mGridLineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( symbolElem ) );
mGridLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( symbolElem );
}
}
else
@@ -368,7 +368,7 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
if ( !symbolElem.isNull() )
{
delete mGridMarkerSymbol;
mGridMarkerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( symbolElem ) );
mGridMarkerSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );
}
}

@@ -183,7 +183,7 @@ bool QgsComposerMapOverview::readXML( const QDomElement &itemElem, const QDomDoc
if ( !frameStyleElem.isNull() )
{
delete mFrameSymbol;
mFrameSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( frameStyleElem ) );
mFrameSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( frameStyleElem );
}
return ok;
}
@@ -315,7 +315,7 @@ bool QgsComposerShape::readXML( const QDomElement& itemElem, const QDomDocument&
if ( !shapeStyleSymbolElem.isNull() )
{
delete mShapeStyleSymbol;
mShapeStyleSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( shapeStyleSymbolElem ) );
mShapeStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( shapeStyleSymbolElem );
}
else
{
@@ -867,7 +867,7 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
if ( !pageStyleSymbolElem.isNull() )
{
delete mPageStyleSymbol;
mPageStyleSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( pageStyleSymbolElem ) );
mPageStyleSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( pageStyleSymbolElem );
}

if ( widthConversionOk && heightConversionOk )
@@ -350,7 +350,7 @@ QgsFeatureRendererV2* QgsPointDisplacementRenderer::create( QDomElement& symbolo
QDomElement centerSymbolElem = symbologyElem.firstChildElement( "symbol" );
if ( !centerSymbolElem.isNull() )
{
r->setCenterSymbol( dynamic_cast<QgsMarkerSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( centerSymbolElem ) ) );
r->setCenterSymbol( QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( centerSymbolElem ) );
}
return r;
}
@@ -852,7 +852,7 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
/////


QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( const QDomElement &element )
{
QgsSymbolLayerV2List layers;
QDomNode layerNode = element.firstChild();
@@ -3745,4 +3745,3 @@ QString QgsSymbolLayerV2Utils::fieldOrExpressionFromExpression( QgsExpression* e
return expression->expression();
}


@@ -115,7 +115,35 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
/**Returns the maximum estimated bleed for the symbol */
static double estimateMaxSymbolBleed( QgsSymbolV2* symbol );

static QgsSymbolV2* loadSymbol( QDomElement& element );
/**Attempts to load a symbol from a DOM element
* @param element DOM element representing symbol
* @returns decoded symbol, if possible
*/
static QgsSymbolV2* loadSymbol( const QDomElement& element );

/**Attempts to load a symbol from a DOM element and cast it to a particular symbol
* type.
* @param element DOM element representing symbol
* @returns decoded symbol cast to specified type, if possible
* @note not available in python bindings
*/
template <class SymbolType> static SymbolType* loadSymbol( const QDomElement& element )
{
QgsSymbolV2* tmpSymbol = QgsSymbolLayerV2Utils::loadSymbol( element );
SymbolType* symbolCastToType = dynamic_cast<SymbolType*>( tmpSymbol );

if ( symbolCastToType )
{
return symbolCastToType;
}
else
{
//could not cast
delete tmpSymbol;
return NULL;
}
}

static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element );
static QDomElement saveSymbol( QString symbolName, QgsSymbolV2* symbol, QDomDocument& doc );

@@ -443,7 +443,7 @@ void QgsAnnotationItem::_readXML( const QDomDocument& doc, const QDomElement& an
QDomElement symbolElem = annotationElem.firstChildElement( "symbol" );
if ( !symbolElem.isNull() )
{
QgsMarkerSymbolV2* symbol = dynamic_cast<QgsMarkerSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( symbolElem ) );
QgsMarkerSymbolV2* symbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );
if ( symbol )
{
delete mMarkerSymbol;

0 comments on commit 93a8683

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