Skip to content
Permalink
Browse files

Remove sizeScaleField and sizeScaleMethods from renderers

These were unused (since they were moved to data defined properties
at the symbol layer level) and were not set anywhere in
core QGIS (ie, the only way to set them was by manually calling
this api)
  • Loading branch information
nyalldawson committed Sep 13, 2016
1 parent 041ceea commit 8301ba26c4d02f959f5e98be26c5bba4d0086ffc
@@ -1123,7 +1123,9 @@ in code which previously passed a null pointer to QgsVectorFileWriter.</li>
<ul>
<li>New virtual method <code>bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, QgsStringMap props = QgsStringMap() )</code> accepts an
optional property map passing down layer level properties to the SLD encoders. If scale based visibility is enabled, it will contain the
<code>scaleMinDenom</code> and <code>scaleMaxDenom</code> properties.
<code>scaleMinDenom</code> and <code>scaleMaxDenom</code> properties.</li>
<li>The RotationField capabitity was removed. This is now handled using data defined rotation at a symbol layer level</li>
<li>setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level</li>
</ul>


@@ -168,12 +168,6 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
*/
void updateColorRamp( QgsColorRamp* ramp /Transfer/, bool inverted = false );

void setSizeScaleField( const QString& fieldOrExpression );
QString sizeScaleField() const;

void setScaleMethod( QgsSymbol::ScaleMethod scaleMethod );
QgsSymbol::ScaleMethod scaleMethod() const;

//! items of symbology items in legend should be checkable
//! @note added in 2.5
virtual bool legendSymbolItemsCheckable() const;
@@ -293,12 +293,6 @@ class QgsGraduatedSymbolRenderer : QgsFeatureRenderer
//! @note added in 2.10
void setGraduatedMethod( GraduatedMethod method );

void setSizeScaleField( const QString& fieldOrExpression );
QString sizeScaleField() const;

void setScaleMethod( QgsSymbol::ScaleMethod scaleMethod );
QgsSymbol::ScaleMethod scaleMethod() const;

//! items of symbology items in legend should be checkable
//! @note added in 2.5
virtual bool legendSymbolItemsCheckable() const;
@@ -149,7 +149,6 @@ class QgsFeatureRenderer
enum Capability
{
SymbolLevels, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField, // rotate symbols by attribute value
MoreSymbolsPerFeature, // may use more than one symbol to render a feature: symbolsForFeature() will return them
Filter, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
ScaleDependent // depends on scale if feature will be rendered (rule based )
@@ -360,8 +359,6 @@ class QgsFeatureRenderer
*/
static QPointF _getPoint( QgsRenderContext& context, const QgsPointV2& point );

void setScaleMethodToSymbol( QgsSymbol* symbol, int scaleMethod );

/**
* Clones generic renderer data to another renderer.
* Currently clones
@@ -24,12 +24,6 @@ class QgsSingleSymbolRenderer : QgsFeatureRenderer
QgsSymbol* symbol() const;
void setSymbol( QgsSymbol* s /Transfer/ );

void setSizeScaleField( const QString& fieldOrExpression );
QString sizeScaleField() const;

void setScaleMethod( QgsSymbol::ScaleMethod scaleMethod );
QgsSymbol::ScaleMethod scaleMethod() const;

virtual QString dump() const;

virtual QgsSingleSymbolRenderer* clone() const /Factory/;
@@ -153,7 +153,6 @@ QgsCategorizedSymbolRenderer::QgsCategorizedSymbolRenderer( const QString& attrN
: QgsFeatureRenderer( "categorizedSymbol" )
, mAttrName( attrName )
, mInvertedColorRamp( false )
, mScaleMethod( DEFAULT_SCALE_METHOD )
, mAttrNum( -1 )
, mCounting( false )
{
@@ -216,38 +215,9 @@ QgsSymbol* QgsCategorizedSymbolRenderer::symbolForValue( const QVariant& value )

QgsSymbol* QgsCategorizedSymbolRenderer::symbolForFeature( QgsFeature& feature, QgsRenderContext &context )
{
QgsSymbol* symbol = originalSymbolForFeature( feature, context );
if ( !symbol )
return nullptr;

if ( !mRotation.data() && !mSizeScale.data() )
return symbol; // no data-defined rotation/scaling - just return the symbol

// find out rotation, size scale
const double rotation = mRotation.data() ? mRotation->evaluate( &context.expressionContext() ).toDouble() : 0;
const double sizeScale = mSizeScale.data() ? mSizeScale->evaluate( &context.expressionContext() ).toDouble() : 1.;

// take a temporary symbol (or create it if doesn't exist)
QgsSymbol* tempSymbol = mTempSymbols[symbol];

// modify the temporary symbol and return it
if ( tempSymbol->type() == QgsSymbol::Marker )
{
QgsMarkerSymbol* markerSymbol = static_cast<QgsMarkerSymbol*>( tempSymbol );
if ( mRotation.data() ) markerSymbol->setAngle( rotation );
markerSymbol->setSize( sizeScale * static_cast<QgsMarkerSymbol*>( symbol )->size() );
markerSymbol->setScaleMethod( mScaleMethod );
}
else if ( tempSymbol->type() == QgsSymbol::Line )
{
QgsLineSymbol* lineSymbol = static_cast<QgsLineSymbol*>( tempSymbol );
lineSymbol->setWidth( sizeScale * static_cast<QgsLineSymbol*>( symbol )->width() );
}

return tempSymbol;
return originalSymbolForFeature( feature, context );
}


QVariant QgsCategorizedSymbolRenderer::valueForFeature( QgsFeature& feature, QgsRenderContext &context ) const
{
QgsAttributes attrs = feature.attributes();
@@ -435,15 +405,6 @@ void QgsCategorizedSymbolRenderer::startRender( QgsRenderContext& context, const
Q_FOREACH ( const QgsRendererCategory& cat, mCategories )
{
cat.symbol()->startRender( context, fields );

if ( mRotation.data() || mSizeScale.data() )
{
QgsSymbol* tempSymbol = cat.symbol()->clone();
tempSymbol->setRenderHints(( mRotation.data() ? QgsSymbol::DataDefinedRotation : 0 ) |
( mSizeScale.data() ? QgsSymbol::DataDefinedSizeScale : 0 ) );
tempSymbol->startRender( context, fields );
mTempSymbols[ cat.symbol()] = tempSymbol;
}
}
return;
}
@@ -454,15 +415,6 @@ void QgsCategorizedSymbolRenderer::stopRender( QgsRenderContext& context )
{
cat.symbol()->stopRender( context );
}

// cleanup mTempSymbols
QHash<QgsSymbol*, QgsSymbol*>::const_iterator it2 = mTempSymbols.constBegin();
for ( ; it2 != mTempSymbols.constEnd(); ++it2 )
{
it2.value()->stopRender( context );
delete it2.value();
}
mTempSymbols.clear();
mExpression.reset();
}

@@ -480,9 +432,6 @@ QList<QString> QgsCategorizedSymbolRenderer::usedAttributes()
if ( !testExpr.hasParserError() )
attributes.unite( testExpr.referencedColumns().toSet() );

if ( mRotation.data() ) attributes.unite( mRotation->referencedColumns().toSet() );
if ( mSizeScale.data() ) attributes.unite( mSizeScale->referencedColumns().toSet() );

QgsCategoryList::const_iterator catIt = mCategories.constBegin();
for ( ; catIt != mCategories.constEnd(); ++catIt )
{
@@ -514,7 +463,6 @@ QgsCategorizedSymbolRenderer* QgsCategorizedSymbolRenderer::clone() const
r->setInvertedColorRamp( mInvertedColorRamp );
}
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setSizeScaleField( sizeScaleField() );

copyRendererData( r );
return r;
@@ -523,10 +471,6 @@ QgsCategorizedSymbolRenderer* QgsCategorizedSymbolRenderer::clone() const
void QgsCategorizedSymbolRenderer::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{
props[ "attribute" ] = mAttrName;
if ( mRotation.data() )
props[ "angle" ] = mRotation->expression();
if ( mSizeScale.data() )
props[ "scale" ] = mSizeScale->expression();

// create a Rule for each range
for ( QgsCategoryList::const_iterator it = mCategories.constBegin(); it != mCategories.constEnd(); ++it )
@@ -770,14 +714,9 @@ QDomElement QgsCategorizedSymbolRenderer::save( QDomDocument& doc )
}

QDomElement rotationElem = doc.createElement( "rotation" );
if ( mRotation.data() )
rotationElem.setAttribute( "field", QgsSymbolLayerUtils::fieldOrExpressionFromExpression( mRotation.data() ) );
rendererElem.appendChild( rotationElem );

QDomElement sizeScaleElem = doc.createElement( "sizescale" );
if ( mSizeScale.data() )
sizeScaleElem.setAttribute( "field", QgsSymbolLayerUtils::fieldOrExpressionFromExpression( mSizeScale.data() ) );
sizeScaleElem.setAttribute( "scalemethod", QgsSymbolLayerUtils::encodeScaleMethod( mScaleMethod ) );
rendererElem.appendChild( sizeScaleElem );

if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
@@ -936,16 +875,6 @@ void QgsCategorizedSymbolRenderer::updateColorRamp( QgsColorRamp* ramp, bool inv
}
}

void QgsCategorizedSymbolRenderer::setSizeScaleField( const QString& fieldOrExpression )
{
mSizeScale.reset( QgsSymbolLayerUtils::fieldOrExpressionToExpression( fieldOrExpression ) );
}

QString QgsCategorizedSymbolRenderer::sizeScaleField() const
{
return mSizeScale.data() ? QgsSymbolLayerUtils::fieldOrExpressionFromExpression( mSizeScale.data() ) : QString();
}

void QgsCategorizedSymbolRenderer::updateSymbols( QgsSymbol * sym )
{
int i = 0;
@@ -959,16 +888,6 @@ void QgsCategorizedSymbolRenderer::updateSymbols( QgsSymbol * sym )
setSourceSymbol( sym->clone() );
}

void QgsCategorizedSymbolRenderer::setScaleMethod( QgsSymbol::ScaleMethod scaleMethod )
{
mScaleMethod = scaleMethod;
QgsCategoryList::const_iterator catIt = mCategories.constBegin();
for ( ; catIt != mCategories.constEnd(); ++catIt )
{
setScaleMethodToSymbol( catIt->symbol(), scaleMethod );
}
}

bool QgsCategorizedSymbolRenderer::legendSymbolItemsCheckable() const
{
return true;
@@ -90,7 +90,7 @@ class CORE_EXPORT QgsCategorizedSymbolRenderer : public QgsFeatureRenderer
virtual QString dump() const override;
virtual QgsCategorizedSymbolRenderer* clone() const override;
virtual void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props = QgsStringMap() ) const override;
virtual Capabilities capabilities() override { return SymbolLevels | RotationField | Filter; }
virtual Capabilities capabilities() override { return SymbolLevels | Filter; }
virtual QString filter( const QgsFields& fields = QgsFields() ) override;
virtual QgsSymbolList symbols( QgsRenderContext& context ) override;

@@ -178,12 +178,6 @@ class CORE_EXPORT QgsCategorizedSymbolRenderer : public QgsFeatureRenderer
*/
void updateColorRamp( QgsColorRamp* ramp, bool inverted = false );

void setSizeScaleField( const QString& fieldOrExpression );
QString sizeScaleField() const;

void setScaleMethod( QgsSymbol::ScaleMethod scaleMethod );
QgsSymbol::ScaleMethod scaleMethod() const { return mScaleMethod; }

virtual bool legendSymbolItemsCheckable() const override;
virtual bool legendSymbolItemChecked( const QString& key ) override;
virtual void setLegendSymbolItem( const QString& key, QgsSymbol* symbol ) override;
@@ -201,9 +195,6 @@ class CORE_EXPORT QgsCategorizedSymbolRenderer : public QgsFeatureRenderer
QScopedPointer<QgsSymbol> mSourceSymbol;
QScopedPointer<QgsColorRamp> mSourceColorRamp;
bool mInvertedColorRamp;
QScopedPointer<QgsExpression> mRotation;
QScopedPointer<QgsExpression> mSizeScale;
QgsSymbol::ScaleMethod mScaleMethod;
QScopedPointer<QgsExpression> mExpression;

//! attribute index (derived from attribute name in startRender)
@@ -213,9 +204,6 @@ class CORE_EXPORT QgsCategorizedSymbolRenderer : public QgsFeatureRenderer
QHash<QString, QgsSymbol*> mSymbolHash;
bool mCounting;

//! temporary symbols, used for data-defined rotation and scaling
QHash<QgsSymbol*, QgsSymbol*> mTempSymbols;

void rebuildHash();

QgsSymbol* skipRender();

0 comments on commit 8301ba2

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