Skip to content

Commit

Permalink
QgsFeatureRendererV2::Capabilities to flags
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 2, 2016
1 parent 2cf9243 commit 8182f29
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 26 deletions.
6 changes: 6 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ None will need to be modified, as the method will return an empty geometry if th
<li>setFields( const QgsFields*, bool ) has been removed, use setFields( const QgsFields&, bool ) instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsFeatureRendererV2 QgsFeatureRendererV2

<ul>
<li>The method capabilities() returns QgsFeatureRendererV2::Capabilities flags instead of an integer. The two are binary compatible.
</ul>

\subsection qgis_api_break_3_0_QgsGeometry QgsGeometry

<ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();

virtual QString filter( const QgsFields& fields = QgsFields() );

Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();

//! @note symbol2 in python bindings
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) /PyName=symbols2/;
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgsinvertedpolygonrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
/** Proxy that will call this method on the embedded renderer. */
virtual QList<QString> usedAttributes();
/** Proxy that will call this method on the embedded renderer. */
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();
/** Proxy that will call this method on the embedded renderer.
* @note available in python bindings as symbol2
*/
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgspointdisplacementrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
/** Partial proxy that will call this method on the embedded renderer. */
virtual QList<QString> usedAttributes();
/** Proxy that will call this method on the embedded renderer. */
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();
/** Proxy that will call this method on the embedded renderer.
@note available in python as symbols2
*/
Expand Down
6 changes: 4 additions & 2 deletions python/core/symbology-ng/qgsrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class QgsFeatureRendererV2
//! for debugging
virtual QString dump() const;

enum Capabilities
enum Capability
{
SymbolLevels, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField, // rotate symbols by attribute value
Expand All @@ -181,8 +181,10 @@ class QgsFeatureRendererV2
ScaleDependent // depends on scale if feature will be rendered (rule based )
};

typedef QFlags<QgsFeatureRendererV2::Capability> Capabilities;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();

/** For symbol levels
* @deprecated use symbols( QgsRenderContext& context ) instead
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgsrulebasedrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
virtual QSet<QString> legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();

/////

Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgssinglesymbolrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2
static QgsFeatureRendererV2* createFromSld( QDomElement& element, Qgis::GeometryType geomType );

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
virtual QgsFeatureRendererV2::Capabilities capabilities();

//! @note available in python as symbol2
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) /PyName=symbols2/;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities() override { return SymbolLevels | RotationField | Filter; }
virtual Capabilities capabilities() override { return SymbolLevels | RotationField | Filter; }

virtual QString filter( const QgsFields& fields = QgsFields() ) override;

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities() override { return SymbolLevels | RotationField | Filter; }
virtual Capabilities capabilities() override { return SymbolLevels | RotationField | Filter; }

//! @note symbol2 in python bindings
virtual QgsSymbolV2List symbols( QgsRenderContext &context ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ QgsSymbolV2List QgsInvertedPolygonRenderer::symbols( QgsRenderContext& context )
return mSubRenderer->symbols( context );
}

int QgsInvertedPolygonRenderer::capabilities()
QgsFeatureRendererV2::Capabilities QgsInvertedPolygonRenderer::capabilities()
{
if ( !mSubRenderer )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsinvertedpolygonrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
/** Proxy that will call this method on the embedded renderer. */
virtual QList<QString> usedAttributes() override;
/** Proxy that will call this method on the embedded renderer. */
virtual int capabilities() override;
virtual Capabilities capabilities() override;
/** Proxy that will call this method on the embedded renderer.
* @note available in python bindings as symbol2
*/
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgspointdisplacementrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ QList<QString> QgsPointDisplacementRenderer::usedAttributes()
return attributeList;
}

int QgsPointDisplacementRenderer::capabilities()
QgsFeatureRendererV2::Capabilities QgsPointDisplacementRenderer::capabilities()
{
if ( !mRenderer )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgspointdisplacementrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
/** Partial proxy that will call this method on the embedded renderer. */
virtual QList<QString> usedAttributes() override;
/** Proxy that will call this method on the embedded renderer. */
virtual int capabilities() override;
virtual Capabilities capabilities() override;
/** Proxy that will call this method on the embedded renderer.
@note available in python as symbols2
*/
Expand Down
47 changes: 37 additions & 10 deletions src/core/symbology-ng/qgsrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ class CORE_EXPORT QgsFeatureRendererV2
virtual QString filter( const QgsFields& fields = QgsFields() ) { Q_UNUSED( fields ); return QString::null; }

/**
* Returns a set of attributes required for this renderer.
* Return a list of attributes required by this renderer. Attributes not listed in here may
* not have been requested from the provider at rendering time.
*
* TODO QGIS3: Change QList to QSet
* @return A set of attributes
*/
// TODO QGIS3: Change QList to QSet
virtual QList<QString> usedAttributes() = 0;

/**
Expand All @@ -182,6 +184,12 @@ class CORE_EXPORT QgsFeatureRendererV2

virtual ~QgsFeatureRendererV2();

/**
* Create a deep copy of this renderer. Should be implemented by all subclasses
* and generate a proper subclass.
*
* @return A copy of this renderer
*/
virtual QgsFeatureRendererV2* clone() const = 0;

/**
Expand All @@ -196,20 +204,37 @@ class CORE_EXPORT QgsFeatureRendererV2
*/
virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );

//! for debugging
//! Returns debug information about this renderer
virtual QString dump() const;

enum Capabilities
/**
* Used to specify details about a renderer.
* Is returned from the capabilities() method.
*/
enum Capability
{
SymbolLevels = 1, //!< rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField = 1 << 1, //!< rotate symbols by attribute value
SymbolLevels = 1, //!< rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField = 1 << 1, //!< rotate symbols by attribute value
MoreSymbolsPerFeature = 1 << 2, //!< may use more than one symbol to render a feature: symbolsForFeature() will return them
Filter = 1 << 3, //!< features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
ScaleDependent = 1 << 4 //!< depends on scale if feature will be rendered (rule based )
Filter = 1 << 3, //!< features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
ScaleDependent = 1 << 4 //!< depends on scale if feature will be rendered (rule based )
};

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities() { return 0; }
Q_DECLARE_FLAGS( Capabilities, Capability )

/**
* Returns details about internals of this renderer.
*
* E.g. if you only want to deal with visible features:
*
* ~~~{.py}
* if not renderer.capabilities().testFlag(QgsFeatureRendererV2.Filter) or renderer.willRenderFeature(feature, context):
* deal_with_my_feature()
* else:
* skip_the_curren_feature()
* ~~~
*/
virtual Capabilities capabilities() { return 0; }

/** For symbol levels
* @deprecated use symbols( QgsRenderContext& context ) instead
Expand Down Expand Up @@ -517,6 +542,8 @@ class CORE_EXPORT QgsFeatureRendererV2
Q_DISABLE_COPY( QgsFeatureRendererV2 )
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRendererV2::Capabilities )

// for some reason SIP compilation fails if these lines are not included:
class QgsRendererV2Widget;
class QgsPaintEffectWidget;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsrulebasedrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
virtual QSet<QString> legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context ) override;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities() override { return MoreSymbolsPerFeature | Filter | ScaleDependent; }
virtual Capabilities capabilities() override { return MoreSymbolsPerFeature | Filter | ScaleDependent; }

/////

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssinglesymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
static QgsFeatureRendererV2* createFromSld( QDomElement& element, Qgis::GeometryType geomType );

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities() override { return SymbolLevels | RotationField; }
virtual Capabilities capabilities() override { return SymbolLevels | RotationField; }

//! @note available in python as symbol2
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) override;
Expand Down

0 comments on commit 8182f29

Please sign in to comment.