Skip to content

Commit

Permalink
Remove sizeScaleField and sizeScaleMethods from renderers
Browse files Browse the repository at this point in the history
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 8301ba2
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 358 deletions.
4 changes: 3 additions & 1 deletion doc/api_break.dox
Expand Up @@ -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>


Expand Down
6 changes: 0 additions & 6 deletions python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions python/core/symbology-ng/qgsrenderer.sip
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions python/core/symbology-ng/qgssinglesymbolrenderer.sip
Expand Up @@ -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/;
Expand Down
83 changes: 1 addition & 82 deletions src/core/symbology-ng/qgscategorizedsymbolrenderer.cpp
Expand Up @@ -153,7 +153,6 @@ QgsCategorizedSymbolRenderer::QgsCategorizedSymbolRenderer( const QString& attrN
: QgsFeatureRenderer( "categorizedSymbol" )
, mAttrName( attrName )
, mInvertedColorRamp( false )
, mScaleMethod( DEFAULT_SCALE_METHOD )
, mAttrNum( -1 )
, mCounting( false )
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}

Expand All @@ -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 )
{
Expand Down Expand Up @@ -514,7 +463,6 @@ QgsCategorizedSymbolRenderer* QgsCategorizedSymbolRenderer::clone() const
r->setInvertedColorRamp( mInvertedColorRamp );
}
r->setUsingSymbolLevels( usingSymbolLevels() );
r->setSizeScaleField( sizeScaleField() );

copyRendererData( r );
return r;
Expand All @@ -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 )
Expand Down Expand Up @@ -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 ) )
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions src/core/symbology-ng/qgscategorizedsymbolrenderer.h
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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();
Expand Down

0 comments on commit 8301ba2

Please sign in to comment.