Skip to content

Commit 8182f29

Browse files
committedAug 2, 2016
QgsFeatureRendererV2::Capabilities to flags
1 parent 2cf9243 commit 8182f29

17 files changed

+61
-26
lines changed
 

‎doc/api_break.dox

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ None will need to be modified, as the method will return an empty geometry if th
241241
<li>setFields( const QgsFields*, bool ) has been removed, use setFields( const QgsFields&, bool ) instead.</li>
242242
</ul>
243243

244+
\subsection qgis_api_break_3_0_QgsFeatureRendererV2 QgsFeatureRendererV2
245+
246+
<ul>
247+
<li>The method capabilities() returns QgsFeatureRendererV2::Capabilities flags instead of an integer. The two are binary compatible.
248+
</ul>
249+
244250
\subsection qgis_api_break_3_0_QgsGeometry QgsGeometry
245251

246252
<ul>

‎python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
6868
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
6969

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

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

‎python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
111111
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
112112

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

116116
//! @note symbol2 in python bindings
117117
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) /PyName=symbols2/;

‎python/core/symbology-ng/qgsinvertedpolygonrenderer.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class QgsInvertedPolygonRenderer : QgsFeatureRendererV2
4141
/** Proxy that will call this method on the embedded renderer. */
4242
virtual QList<QString> usedAttributes();
4343
/** Proxy that will call this method on the embedded renderer. */
44-
virtual int capabilities();
44+
virtual QgsFeatureRendererV2::Capabilities capabilities();
4545
/** Proxy that will call this method on the embedded renderer.
4646
* @note available in python bindings as symbol2
4747
*/

‎python/core/symbology-ng/qgspointdisplacementrenderer.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2
2626
/** Partial proxy that will call this method on the embedded renderer. */
2727
virtual QList<QString> usedAttributes();
2828
/** Proxy that will call this method on the embedded renderer. */
29-
virtual int capabilities();
29+
virtual QgsFeatureRendererV2::Capabilities capabilities();
3030
/** Proxy that will call this method on the embedded renderer.
3131
@note available in python as symbols2
3232
*/

‎python/core/symbology-ng/qgsrendererv2.sip

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class QgsFeatureRendererV2
172172
//! for debugging
173173
virtual QString dump() const;
174174

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

184+
typedef QFlags<QgsFeatureRendererV2::Capability> Capabilities;
185+
184186
//! returns bitwise OR-ed capabilities of the renderer
185-
virtual int capabilities();
187+
virtual QgsFeatureRendererV2::Capabilities capabilities();
186188

187189
/** For symbol levels
188190
* @deprecated use symbols( QgsRenderContext& context ) instead

‎python/core/symbology-ng/qgsrulebasedrendererv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
418418
virtual QSet<QString> legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );
419419

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

423423
/////
424424

‎python/core/symbology-ng/qgssinglesymbolrendererv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2
4141
static QgsFeatureRendererV2* createFromSld( QDomElement& element, Qgis::GeometryType geomType );
4242

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

4646
//! @note available in python as symbol2
4747
virtual QgsSymbolV2List symbols( QgsRenderContext& context ) /PyName=symbols2/;

‎src/core/symbology-ng/qgscategorizedsymbolrendererv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
102102
virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
103103

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

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

‎src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
155155
virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
156156

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

160160
//! @note symbol2 in python bindings
161161
virtual QgsSymbolV2List symbols( QgsRenderContext &context ) override;

‎src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ QgsSymbolV2List QgsInvertedPolygonRenderer::symbols( QgsRenderContext& context )
455455
return mSubRenderer->symbols( context );
456456
}
457457

458-
int QgsInvertedPolygonRenderer::capabilities()
458+
QgsFeatureRendererV2::Capabilities QgsInvertedPolygonRenderer::capabilities()
459459
{
460460
if ( !mSubRenderer )
461461
{

‎src/core/symbology-ng/qgsinvertedpolygonrenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CORE_EXPORT QgsInvertedPolygonRenderer : public QgsFeatureRendererV2
7676
/** Proxy that will call this method on the embedded renderer. */
7777
virtual QList<QString> usedAttributes() override;
7878
/** Proxy that will call this method on the embedded renderer. */
79-
virtual int capabilities() override;
79+
virtual Capabilities capabilities() override;
8080
/** Proxy that will call this method on the embedded renderer.
8181
* @note available in python bindings as symbol2
8282
*/

‎src/core/symbology-ng/qgspointdisplacementrenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ QList<QString> QgsPointDisplacementRenderer::usedAttributes()
275275
return attributeList;
276276
}
277277

278-
int QgsPointDisplacementRenderer::capabilities()
278+
QgsFeatureRendererV2::Capabilities QgsPointDisplacementRenderer::capabilities()
279279
{
280280
if ( !mRenderer )
281281
{

‎src/core/symbology-ng/qgspointdisplacementrenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
5454
/** Partial proxy that will call this method on the embedded renderer. */
5555
virtual QList<QString> usedAttributes() override;
5656
/** Proxy that will call this method on the embedded renderer. */
57-
virtual int capabilities() override;
57+
virtual Capabilities capabilities() override;
5858
/** Proxy that will call this method on the embedded renderer.
5959
@note available in python as symbols2
6060
*/

‎src/core/symbology-ng/qgsrendererv2.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ class CORE_EXPORT QgsFeatureRendererV2
169169
virtual QString filter( const QgsFields& fields = QgsFields() ) { Q_UNUSED( fields ); return QString::null; }
170170

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

178180
/**
@@ -182,6 +184,12 @@ class CORE_EXPORT QgsFeatureRendererV2
182184

183185
virtual ~QgsFeatureRendererV2();
184186

187+
/**
188+
* Create a deep copy of this renderer. Should be implemented by all subclasses
189+
* and generate a proper subclass.
190+
*
191+
* @return A copy of this renderer
192+
*/
185193
virtual QgsFeatureRendererV2* clone() const = 0;
186194

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

199-
//! for debugging
207+
//! Returns debug information about this renderer
200208
virtual QString dump() const;
201209

202-
enum Capabilities
210+
/**
211+
* Used to specify details about a renderer.
212+
* Is returned from the capabilities() method.
213+
*/
214+
enum Capability
203215
{
204-
SymbolLevels = 1, //!< rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
205-
RotationField = 1 << 1, //!< rotate symbols by attribute value
216+
SymbolLevels = 1, //!< rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
217+
RotationField = 1 << 1, //!< rotate symbols by attribute value
206218
MoreSymbolsPerFeature = 1 << 2, //!< may use more than one symbol to render a feature: symbolsForFeature() will return them
207-
Filter = 1 << 3, //!< features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
208-
ScaleDependent = 1 << 4 //!< depends on scale if feature will be rendered (rule based )
219+
Filter = 1 << 3, //!< features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
220+
ScaleDependent = 1 << 4 //!< depends on scale if feature will be rendered (rule based )
209221
};
210222

211-
//! returns bitwise OR-ed capabilities of the renderer
212-
virtual int capabilities() { return 0; }
223+
Q_DECLARE_FLAGS( Capabilities, Capability )
224+
225+
/**
226+
* Returns details about internals of this renderer.
227+
*
228+
* E.g. if you only want to deal with visible features:
229+
*
230+
* ~~~{.py}
231+
* if not renderer.capabilities().testFlag(QgsFeatureRendererV2.Filter) or renderer.willRenderFeature(feature, context):
232+
* deal_with_my_feature()
233+
* else:
234+
* skip_the_curren_feature()
235+
* ~~~
236+
*/
237+
virtual Capabilities capabilities() { return 0; }
213238

214239
/** For symbol levels
215240
* @deprecated use symbols( QgsRenderContext& context ) instead
@@ -517,6 +542,8 @@ class CORE_EXPORT QgsFeatureRendererV2
517542
Q_DISABLE_COPY( QgsFeatureRendererV2 )
518543
};
519544

545+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRendererV2::Capabilities )
546+
520547
// for some reason SIP compilation fails if these lines are not included:
521548
class QgsRendererV2Widget;
522549
class QgsPaintEffectWidget;

‎src/core/symbology-ng/qgsrulebasedrendererv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
489489
virtual QSet<QString> legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context ) override;
490490

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

494494
/////
495495

‎src/core/symbology-ng/qgssinglesymbolrendererv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2
6565
static QgsFeatureRendererV2* createFromSld( QDomElement& element, Qgis::GeometryType geomType );
6666

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.