22 changes: 11 additions & 11 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "qgssymbolv2.h"
#include "qgsrendererv2.h"
#include "qgsexpression.h"
#include <memory>
#include <QScopedPointer>

class CORE_EXPORT QgsRendererRangeV2
{
Expand Down Expand Up @@ -49,7 +49,7 @@ class CORE_EXPORT QgsRendererRangeV2

protected:
double mLowerValue, mUpperValue;
std::auto_ptr<QgsSymbolV2> mSymbol;
QScopedPointer<QgsSymbolV2> mSymbol;
QString mLabel;

// for cpy+swap idiom
Expand Down Expand Up @@ -167,19 +167,19 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
void setRotationField( QString expression )
{
mRotation.reset( expression.isEmpty() ? NULL : new QgsExpression( expression ) );
Q_ASSERT( !mRotation.get() || !mRotation->hasParserError() );
Q_ASSERT( !mRotation.data() || !mRotation->hasParserError() );
}
//! @note added in 1.6
QString rotationField() const { return mRotation.get() ? mRotation->expression() : "";}
QString rotationField() const { return mRotation.data() ? mRotation->expression() : "";}

//! @note added in 1.6
void setSizeScaleField( QString expression )
{
mSizeScale.reset( expression.isEmpty() ? NULL : new QgsExpression( expression ) );
Q_ASSERT( !mSizeScale.get() || !mSizeScale->hasParserError() );
Q_ASSERT( !mSizeScale.data() || !mSizeScale->hasParserError() );
}
//! @note added in 1.6
QString sizeScaleField() const { return mSizeScale.get() ? mSizeScale->expression() : ""; }
QString sizeScaleField() const { return mSizeScale.data() ? mSizeScale->expression() : ""; }

//! @note added in 2.0
void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
Expand All @@ -191,13 +191,13 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
QString mAttrName;
QgsRangeList mRanges;
Mode mMode;
std::auto_ptr<QgsSymbolV2> mSourceSymbol;
std::auto_ptr<QgsVectorColorRampV2> mSourceColorRamp;
QScopedPointer<QgsSymbolV2> mSourceSymbol;
QScopedPointer<QgsVectorColorRampV2> mSourceColorRamp;
bool mInvertedColorRamp;
std::auto_ptr<QgsExpression> mRotation;
std::auto_ptr<QgsExpression> mSizeScale;
QScopedPointer<QgsExpression> mRotation;
QScopedPointer<QgsExpression> mSizeScale;
QgsSymbolV2::ScaleMethod mScaleMethod;
std::auto_ptr<QgsExpression> mExpression;
QScopedPointer<QgsExpression> mExpression;
//! attribute index (derived from attribute name in startRender)
int mAttrNum;

Expand Down
70 changes: 35 additions & 35 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ QgsSingleSymbolRendererV2::QgsSingleSymbolRendererV2( QgsSymbolV2* symbol )
// we need to clone symbol
QgsSingleSymbolRendererV2::QgsSingleSymbolRendererV2( const QgsSingleSymbolRendererV2 & src )
: QgsFeatureRendererV2( "singleSymbol" )
, mSymbol( src.mSymbol.get() ? src.mSymbol->clone() : NULL )
, mRotation( src.mRotation.get() ? new QgsExpression( src.mRotation->expression() ) : NULL )
, mSizeScale( src.mSizeScale.get() ? new QgsExpression( src.mSizeScale->expression() ) : NULL )
, mSymbol( src.mSymbol.data() ? src.mSymbol->clone() : NULL )
, mRotation( src.mRotation.data() ? new QgsExpression( src.mRotation->expression() ) : NULL )
, mSizeScale( src.mSizeScale.data() ? new QgsExpression( src.mSizeScale->expression() ) : NULL )
, mScaleMethod( src.mScaleMethod )
, mTempSymbol( src.mTempSymbol.get() ? src.mTempSymbol->clone() : NULL )
, mTempSymbol( src.mTempSymbol.data() ? src.mTempSymbol->clone() : NULL )
{
}

Expand Down Expand Up @@ -69,59 +69,59 @@ QgsSingleSymbolRendererV2::~QgsSingleSymbolRendererV2()

QgsSymbolV2* QgsSingleSymbolRendererV2::symbolForFeature( QgsFeature& feature )
{
if ( !mRotation.get() && !mSizeScale.get() ) return mSymbol.get();
if ( !mRotation.data() && !mSizeScale.data() ) return mSymbol.data();

const double rotation = mRotation.get() ? mRotation->evaluate( feature ).toDouble() : 0;
const double sizeScale = mSizeScale.get() ? mSizeScale->evaluate( feature ).toDouble() : 1.;
const double rotation = mRotation.data() ? mRotation->evaluate( feature ).toDouble() : 0;
const double sizeScale = mSizeScale.data() ? mSizeScale->evaluate( feature ).toDouble() : 1.;

if ( mTempSymbol->type() == QgsSymbolV2::Marker )
{
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol.get() );
QgsMarkerSymbolV2* markerSymbol = static_cast<QgsMarkerSymbolV2*>( mTempSymbol.data() );
markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * mOrigSize );
markerSymbol->setScaleMethod( mScaleMethod );
}
else if ( mTempSymbol->type() == QgsSymbolV2::Line )
{
QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>( mTempSymbol.get() );
QgsLineSymbolV2* lineSymbol = static_cast<QgsLineSymbolV2*>( mTempSymbol.data() );
lineSymbol->setWidth( sizeScale * mOrigSize );
}
else if ( mTempSymbol->type() == QgsSymbolV2::Fill )
{
QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol.get() );
QgsFillSymbolV2* fillSymbol = static_cast<QgsFillSymbolV2*>( mTempSymbol.data() );
fillSymbol->setAngle( rotation );
}

return mTempSymbol.get();
return mTempSymbol.data();
}

void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
{
if ( !mSymbol.get() ) return;
if ( !mSymbol.data() ) return;

mSymbol->startRender( context, vlayer );

if ( mRotation.get() || mSizeScale.get() )
if ( mRotation.data() || mSizeScale.data() )
{
// we are going to need a temporary symbol
mTempSymbol.reset( mSymbol->clone() );

int hints = 0;
if ( mRotation.get() )
if ( mRotation.data() )
hints |= QgsSymbolV2::DataDefinedRotation;
if ( mSizeScale.get() )
if ( mSizeScale.data() )
hints |= QgsSymbolV2::DataDefinedSizeScale;
mTempSymbol->setRenderHints( hints );

mTempSymbol->startRender( context, vlayer );

if ( mSymbol->type() == QgsSymbolV2::Marker )
{
mOrigSize = static_cast<QgsMarkerSymbolV2*>( mSymbol.get() )->size();
mOrigSize = static_cast<QgsMarkerSymbolV2*>( mSymbol.data() )->size();
}
else if ( mSymbol->type() == QgsSymbolV2::Line )
{
mOrigSize = static_cast<QgsLineSymbolV2*>( mSymbol.get() )->width();
mOrigSize = static_cast<QgsLineSymbolV2*>( mSymbol.data() )->width();
}
else
{
Expand All @@ -132,11 +132,11 @@ void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const Qg

void QgsSingleSymbolRendererV2::stopRender( QgsRenderContext& context )
{
if ( !mSymbol.get() ) return;
if ( !mSymbol.data() ) return;

mSymbol->stopRender( context );

if ( mRotation.get() || mSizeScale.get() )
if ( mRotation.data() || mSizeScale.data() )
{
// we are going to need a temporary symbol
mTempSymbol->stopRender( context );
Expand All @@ -147,15 +147,15 @@ void QgsSingleSymbolRendererV2::stopRender( QgsRenderContext& context )
QList<QString> QgsSingleSymbolRendererV2::usedAttributes()
{
QSet<QString> attributes;
if ( mSymbol.get() ) attributes.unite( mSymbol->usedAttributes() );
if ( mRotation.get() ) attributes.unite( mRotation->referencedColumns().toSet() );
if ( mSizeScale.get() ) attributes.unite( mSizeScale->referencedColumns().toSet() );
if ( mSymbol.data() ) attributes.unite( mSymbol->usedAttributes() );
if ( mRotation.data() ) attributes.unite( mRotation->referencedColumns().toSet() );
if ( mSizeScale.data() ) attributes.unite( mSizeScale->referencedColumns().toSet() );
return attributes.toList();
}

QgsSymbolV2* QgsSingleSymbolRendererV2::symbol() const
{
return mSymbol.get();
return mSymbol.data();
}

void QgsSingleSymbolRendererV2::setSymbol( QgsSymbolV2* s )
Expand All @@ -167,12 +167,12 @@ void QgsSingleSymbolRendererV2::setSymbol( QgsSymbolV2* s )
void QgsSingleSymbolRendererV2::setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod )
{
mScaleMethod = scaleMethod;
setScaleMethodToSymbol( mSymbol.get(), scaleMethod );
setScaleMethodToSymbol( mSymbol.data(), scaleMethod );
}

QString QgsSingleSymbolRendererV2::dump() const
{
return mSymbol.get() ? QString( "SINGLE: %1" ).arg( mSymbol->dump() ) : "" ;
return mSymbol.data() ? QString( "SINGLE: %1" ).arg( mSymbol->dump() ) : "" ;
}

QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone()
Expand All @@ -188,9 +188,9 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::clone()
void QgsSingleSymbolRendererV2::toSld( QDomDocument& doc, QDomElement &element ) const
{
QgsStringMap props;
if ( mRotation.get() )
if ( mRotation.data() )
props[ "angle" ] = qgsXmlEncode( mRotation->expression() ).append( "\"" ).prepend( "\"" );
if ( mSizeScale.get() )
if ( mSizeScale.data() )
props[ "scale" ] = qgsXmlEncode( mSizeScale->expression() ).append( "\"" ).prepend( "\"" );

QDomElement ruleElem = doc.createElement( "se:Rule" );
Expand All @@ -200,13 +200,13 @@ void QgsSingleSymbolRendererV2::toSld( QDomDocument& doc, QDomElement &element )
nameElem.appendChild( doc.createTextNode( "Single symbol" ) );
ruleElem.appendChild( nameElem );

if ( mSymbol.get() ) mSymbol->toSld( doc, ruleElem, props );
if ( mSymbol.data() ) mSymbol->toSld( doc, ruleElem, props );
}

QgsSymbolV2List QgsSingleSymbolRendererV2::symbols()
{
QgsSymbolV2List lst;
lst.append( mSymbol.get() );
lst.append( mSymbol.data() );
return lst;
}

Expand Down Expand Up @@ -336,17 +336,17 @@ QDomElement QgsSingleSymbolRendererV2::save( QDomDocument& doc )
rendererElem.setAttribute( "symbollevels", ( mUsingSymbolLevels ? "1" : "0" ) );

QgsSymbolV2Map symbols;
symbols["0"] = mSymbol.get();
symbols["0"] = mSymbol.data();
QDomElement symbolsElem = QgsSymbolLayerV2Utils::saveSymbols( symbols, "symbols", doc );
rendererElem.appendChild( symbolsElem );

QDomElement rotationElem = doc.createElement( "rotation" );
if ( mRotation.get() )
if ( mRotation.data() )
rotationElem.setAttribute( "field", qgsXmlEncode( mRotation->expression() ) );
rendererElem.appendChild( rotationElem );

QDomElement sizeScaleElem = doc.createElement( "sizescale" );
if ( mSizeScale.get() )
if ( mSizeScale.data() )
sizeScaleElem.setAttribute( "field", qgsXmlEncode( mSizeScale->expression() ) );
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod ) );
rendererElem.appendChild( sizeScaleElem );
Expand All @@ -357,9 +357,9 @@ QDomElement QgsSingleSymbolRendererV2::save( QDomDocument& doc )
QgsLegendSymbologyList QgsSingleSymbolRendererV2::legendSymbologyItems( QSize iconSize )
{
QgsLegendSymbologyList lst;
if ( mSymbol.get() )
if ( mSymbol.data() )
{
QPixmap pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mSymbol.get(), iconSize );
QPixmap pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mSymbol.data(), iconSize );
lst << qMakePair( QString(), pix );
}
return lst;
Expand All @@ -370,6 +370,6 @@ QgsLegendSymbolList QgsSingleSymbolRendererV2::legendSymbolItems( double scaleDe
Q_UNUSED( scaleDenominator );
Q_UNUSED( rule );
QgsLegendSymbolList lst;
lst << qMakePair( QString(), mSymbol.get() );
lst << qMakePair( QString(), mSymbol.data() );
return lst;
}
18 changes: 9 additions & 9 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "qgsrendererv2.h"
#include "qgssymbolv2.h"
#include "qgsexpression.h"
#include <memory>
#include <QScopedPointer>

class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
{
Expand Down Expand Up @@ -47,19 +47,19 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
void setRotationField( QString expression )
{
mRotation.reset( expression.isEmpty() ? NULL : new QgsExpression( expression ) );
Q_ASSERT( !mRotation.get() || !mRotation->hasParserError() );
Q_ASSERT( !mRotation.data() || !mRotation->hasParserError() );
}
//! @note added in 1.5
QString rotationField() const { return mRotation.get() ? mRotation->expression() : ""; }
QString rotationField() const { return mRotation.data() ? mRotation->expression() : ""; }

//! @note added in 1.5
void setSizeScaleField( QString expression )
{
mSizeScale.reset( expression.isEmpty() ? NULL : new QgsExpression( expression ) );
Q_ASSERT( !mSizeScale.get() || !mSizeScale->hasParserError() );
Q_ASSERT( !mSizeScale.data() || !mSizeScale->hasParserError() );
}
//! @note added in 1.5
QString sizeScaleField() const { return mSizeScale.get() ? mSizeScale->expression() : ""; }
QString sizeScaleField() const { return mSizeScale.data() ? mSizeScale->expression() : ""; }

//! @note added in 2.0
void setScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
Expand Down Expand Up @@ -94,13 +94,13 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );

protected:
std::auto_ptr<QgsSymbolV2> mSymbol;
std::auto_ptr<QgsExpression> mRotation;
std::auto_ptr<QgsExpression> mSizeScale;
QScopedPointer<QgsSymbolV2> mSymbol;
QScopedPointer<QgsExpression> mRotation;
QScopedPointer<QgsExpression> mSizeScale;
QgsSymbolV2::ScaleMethod mScaleMethod;

// temporary stuff for rendering
std::auto_ptr<QgsSymbolV2> mTempSymbol;
QScopedPointer<QgsSymbolV2> mTempSymbol;
double mOrigSize;

// for copy and swap idiom for assignment operator
Expand Down