Skip to content

Commit

Permalink
Avoid storing and cloning paint effects for layers if they are just
Browse files Browse the repository at this point in the history
the default stack unchanged

Speeds up cloning of symbol layers
  • Loading branch information
nyalldawson committed Jul 24, 2019
1 parent d2f07e8 commit 436509b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 17 deletions.
28 changes: 28 additions & 0 deletions python/core/auto_generated/symbology/qgssymbollayer.sip.in
Expand Up @@ -146,6 +146,8 @@ Returns the symbol layer property definitions.

virtual ~QgsSymbolLayer();



bool enabled() const;
%Docstring
Returns ``True`` if symbol layer is enabled and will be drawn.
Expand Down Expand Up @@ -461,6 +463,8 @@ Copies paint effect of this layer to another symbol layer
.. versionadded:: 2.9
%End

private:
QgsSymbolLayer( const QgsSymbolLayer &other );
};


Expand Down Expand Up @@ -489,8 +493,13 @@ Abstract base class for marker symbol layers.
Bottom,
};



virtual void startRender( QgsSymbolRenderContext &context );

%Docstring
QgsMarkerSymbolLayer cannot be copied
%End

virtual void stopRender( QgsSymbolRenderContext &context );

Expand Down Expand Up @@ -834,6 +843,8 @@ Adjusts a marker offset to account for rotation.
%End


private:
QgsMarkerSymbolLayer( const QgsMarkerSymbolLayer &other );
};

class QgsLineSymbolLayer : QgsSymbolLayer
Expand All @@ -851,8 +862,13 @@ class QgsLineSymbolLayer : QgsSymbolLayer
InteriorRingsOnly,
};



virtual void setOutputUnit( QgsUnitTypes::RenderUnit unit );

%Docstring
QgsLineSymbolLayer cannot be copied
%End
virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual void setMapUnitScale( const QgsMapUnitScale &scale );
Expand Down Expand Up @@ -1044,6 +1060,9 @@ for a polygon.
QgsLineSymbolLayer( bool locked = false );



private:
QgsLineSymbolLayer( const QgsLineSymbolLayer &other );
};

class QgsFillSymbolLayer : QgsSymbolLayer
Expand All @@ -1053,7 +1072,13 @@ class QgsFillSymbolLayer : QgsSymbolLayer
#include "qgssymbollayer.h"
%End
public:



virtual void renderPolygon( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) = 0;
%Docstring
QgsFillSymbolLayer cannot be copied
%End

virtual void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size );

Expand All @@ -1068,6 +1093,9 @@ class QgsFillSymbolLayer : QgsSymbolLayer
Default method to render polygon
%End


private:
QgsFillSymbolLayer( const QgsFillSymbolLayer &other );
};


Expand Down
23 changes: 11 additions & 12 deletions src/core/symbology/qgssymbollayer.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgsproperty.h"
#include "qgsexpressioncontext.h"
#include "qgssymbollayerutils.h"
#include "qgsapplication.h"

#include <QSize>
#include <QPainter>
Expand Down Expand Up @@ -163,23 +164,21 @@ Qt::BrushStyle QgsSymbolLayer::dxfBrushStyle() const

QgsPaintEffect *QgsSymbolLayer::paintEffect() const
{
return mPaintEffect;
return mPaintEffect.get();
}

void QgsSymbolLayer::setPaintEffect( QgsPaintEffect *effect )
{
delete mPaintEffect;
mPaintEffect = effect;
if ( effect == mPaintEffect.get() )
return;

mPaintEffect.reset( effect );
}

QgsSymbolLayer::QgsSymbolLayer( QgsSymbol::SymbolType type, bool locked )
: mType( type )
, mEnabled( true )
, mLocked( locked )

{
mPaintEffect = QgsPaintEffectRegistry::defaultStack();
mPaintEffect->setEnabled( false );
}

void QgsSymbolLayer::prepareExpressions( const QgsSymbolRenderContext &context )
Expand All @@ -204,10 +203,7 @@ const QgsPropertiesDefinition &QgsSymbolLayer::propertyDefinitions()
return sPropertyDefinitions;
}

QgsSymbolLayer::~QgsSymbolLayer()
{
delete mPaintEffect;
}
QgsSymbolLayer::~QgsSymbolLayer() = default;

bool QgsSymbolLayer::isCompatibleWithSymbol( QgsSymbol *symbol ) const
{
Expand Down Expand Up @@ -392,7 +388,10 @@ void QgsSymbolLayer::copyPaintEffect( QgsSymbolLayer *destLayer ) const
if ( !destLayer || !mPaintEffect )
return;

destLayer->setPaintEffect( mPaintEffect->clone() );
if ( !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect.get() ) )
destLayer->setPaintEffect( mPaintEffect->clone() );
else
destLayer->setPaintEffect( nullptr );
}

QgsMarkerSymbolLayer::QgsMarkerSymbolLayer( bool locked )
Expand Down
49 changes: 46 additions & 3 deletions src/core/symbology/qgssymbollayer.h
Expand Up @@ -187,6 +187,12 @@ class CORE_EXPORT QgsSymbolLayer

virtual ~QgsSymbolLayer();

//! QgsSymbolLayer cannot be copied
QgsSymbolLayer( const QgsSymbolLayer &other ) = delete;

//! QgsSymbolLayer cannot be copied
QgsSymbolLayer &operator=( const QgsSymbolLayer &other ) = delete;

/**
* Returns TRUE if symbol layer is enabled and will be drawn.
* \see setEnabled()
Expand Down Expand Up @@ -427,15 +433,15 @@ class CORE_EXPORT QgsSymbolLayer
QgsSymbol::SymbolType mType;

//! True if layer is enabled and should be drawn
bool mEnabled;
bool mEnabled = true;

bool mLocked;
bool mLocked = false;
QColor mColor;
int mRenderingPass = 0;

QgsPropertyCollection mDataDefinedProperties;

QgsPaintEffect *mPaintEffect = nullptr;
std::unique_ptr< QgsPaintEffect > mPaintEffect;
QgsFields mFields;

// Configuration of selected symbology implementation
Expand Down Expand Up @@ -471,6 +477,10 @@ class CORE_EXPORT QgsSymbolLayer
//! Property definitions
static QgsPropertiesDefinition sPropertyDefinitions;

#ifdef SIP_RUN
QgsSymbolLayer( const QgsSymbolLayer &other );
#endif

};

//////////////////////
Expand Down Expand Up @@ -500,6 +510,12 @@ class CORE_EXPORT QgsMarkerSymbolLayer : public QgsSymbolLayer
Bottom, //!< Align to bottom of symbol
};

//! QgsMarkerSymbolLayer cannot be copied
QgsMarkerSymbolLayer( const QgsMarkerSymbolLayer &other ) = delete;

//! QgsMarkerSymbolLayer cannot be copied
QgsMarkerSymbolLayer &operator=( const QgsMarkerSymbolLayer &other ) = delete;

void startRender( QgsSymbolRenderContext &context ) override;

void stopRender( QgsSymbolRenderContext &context ) override;
Expand Down Expand Up @@ -783,6 +799,10 @@ class CORE_EXPORT QgsMarkerSymbolLayer : public QgsSymbolLayer
private:
static QgsMarkerSymbolLayer::HorizontalAnchorPoint decodeHorizontalAnchorPoint( const QString &str );
static QgsMarkerSymbolLayer::VerticalAnchorPoint decodeVerticalAnchorPoint( const QString &str );

#ifdef SIP_RUN
QgsMarkerSymbolLayer( const QgsMarkerSymbolLayer &other );
#endif
};

/**
Expand All @@ -801,6 +821,12 @@ class CORE_EXPORT QgsLineSymbolLayer : public QgsSymbolLayer
InteriorRingsOnly, //!< Render the interior rings only
};

//! QgsLineSymbolLayer cannot be copied
QgsLineSymbolLayer( const QgsLineSymbolLayer &other ) = delete;

//! QgsLineSymbolLayer cannot be copied
QgsLineSymbolLayer &operator=( const QgsLineSymbolLayer &other ) = delete;

void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
QgsUnitTypes::RenderUnit outputUnit() const override;
void setMapUnitScale( const QgsMapUnitScale &scale ) override;
Expand Down Expand Up @@ -970,6 +996,11 @@ class CORE_EXPORT QgsLineSymbolLayer : public QgsSymbolLayer
QgsMapUnitScale mOffsetMapUnitScale;

RenderRingFilter mRingFilter = AllRings;

private:
#ifdef SIP_RUN
QgsLineSymbolLayer( const QgsLineSymbolLayer &other );
#endif
};

/**
Expand All @@ -979,6 +1010,13 @@ class CORE_EXPORT QgsLineSymbolLayer : public QgsSymbolLayer
class CORE_EXPORT QgsFillSymbolLayer : public QgsSymbolLayer
{
public:

//! QgsFillSymbolLayer cannot be copied
QgsFillSymbolLayer( const QgsFillSymbolLayer &other ) = delete;

//! QgsFillSymbolLayer cannot be copied
QgsFillSymbolLayer &operator=( const QgsFillSymbolLayer &other ) = delete;

virtual void renderPolygon( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) = 0;

void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;
Expand All @@ -992,6 +1030,11 @@ class CORE_EXPORT QgsFillSymbolLayer : public QgsSymbolLayer
void _renderPolygon( QPainter *p, const QPolygonF &points, const QList<QPolygonF> *rings, QgsSymbolRenderContext &context );

double mAngle = 0.0;

private:
#ifdef SIP_RUN
QgsFillSymbolLayer( const QgsFillSymbolLayer &other );
#endif
};

class QgsSymbolLayerWidget; // why does SIP fail, when this isn't here
Expand Down
7 changes: 5 additions & 2 deletions src/core/symbology/qgssymbollayerutils.cpp
Expand Up @@ -32,6 +32,7 @@
#include "qgsrendercontext.h"
#include "qgsunittypes.h"
#include "qgsexpressioncontextutils.h"
#include "qgseffectstack.h"

#include <QColor>
#include <QFont>
Expand Down Expand Up @@ -1025,7 +1026,9 @@ QgsSymbolLayer *QgsSymbolLayerUtils::loadSymbolLayer( QDomElement &element, cons
QDomElement effectElem = element.firstChildElement( QStringLiteral( "effect" ) );
if ( !effectElem.isNull() )
{
layer->setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
std::unique_ptr< QgsPaintEffect > effect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
if ( effect && !QgsPaintEffectRegistry::isDefaultStack( effect.get() ) )
layer->setPaintEffect( effect.release() );
}

// restore data defined properties
Expand Down Expand Up @@ -1086,7 +1089,7 @@ QDomElement QgsSymbolLayerUtils::saveSymbol( const QString &name, QgsSymbol *sym
QgsApplication::symbolLayerRegistry()->resolvePaths( layer->layerType(), props, context.pathResolver(), true );

saveProperties( props, doc, layerEl );
if ( !QgsPaintEffectRegistry::isDefaultStack( layer->paintEffect() ) )
if ( layer->paintEffect() && !QgsPaintEffectRegistry::isDefaultStack( layer->paintEffect() ) )
layer->paintEffect()->saveProperties( doc, layerEl );

QDomElement ddProps = doc.createElement( QStringLiteral( "data_defined_properties" ) );
Expand Down
6 changes: 6 additions & 0 deletions src/gui/symbology/qgslayerpropertieswidget.cpp
Expand Up @@ -23,6 +23,7 @@

#include "qgssymbollayer.h"
#include "qgssymbollayerregistry.h"
#include "qgspainteffectregistry.h"

#include "qgsapplication.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -132,6 +133,11 @@ QgsLayerPropertiesWidget::QgsLayerPropertiesWidget( QgsSymbolLayer *layer, const

this->connectChildPanel( mEffectWidget );

if ( !mLayer->paintEffect() )
{
mLayer->setPaintEffect( QgsPaintEffectRegistry::defaultStack() );
mLayer->paintEffect()->setEnabled( false );
}
mEffectWidget->setPaintEffect( mLayer->paintEffect() );

registerDataDefinedButton( mEnabledDDBtn, QgsSymbolLayer::PropertyLayerEnabled );
Expand Down

0 comments on commit 436509b

Please sign in to comment.