Skip to content

Commit e122546

Browse files
committed
Change QgsSymbol and QgsSymbolRenderContext render hint to use a
QgsSymbol::RenderHints QFlags value instead of a raw int Also rename DataDefinedRotation to DynamicRotation since it is no longer used for data defined rotation
1 parent 5617dbc commit e122546

File tree

8 files changed

+70
-26
lines changed

8 files changed

+70
-26
lines changed

doc/api_break.dox

+6
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,10 @@ parameters or QgsSymbol::OutputUnitList parameters now take QgsUnitTypes::Render
951951
<li>startRender() now accepts a QgsFields reference, not a pointer.</li>
952952
<li>isSymbolLayerCompatible() was removed. Use QgsSymbolLayer::isCompatibleWithSymbol() instead.</li>
953953
<li>The DataDefinedSizeScale flag has been removed. This is no longer used and data defined scaling on a symbol layer level should be used instead.</li>
954+
<li>The DataDefinedRotation RenderHint was renamed to DynamicRotation, as it is no longer used for
955+
data defined rotation.</li>
956+
<li>setRenderHints() and renderHints() now accept and return a QgsSymbol::RenderHints flag rather
957+
than an integer value</li>
954958
</ul>
955959

956960
\subsection qgis_api_break_3_0_QgsSymbolLayer QgsSymbolLayer (renamed from QgsSymbolLayerV2)
@@ -968,6 +972,8 @@ the variant which takes QgsSymbolRenderContext instead.</li>
968972

969973
<ul>
970974
<li>The constructor now accepts a QgsFields reference, not a pointer.</li>
975+
<li>The constructor, setRenderHints() and renderHints() now accept and return a QgsSymbol::RenderHints flag rather
976+
than an integer value</li>
971977
<li>fields() now returns a QgsFields value, not a pointer.</li>
972978
</ul>
973979

python/core/symbology-ng/qgssymbol.sip

+26-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ class QgsSymbol
3939
ScaleDiameter //!< Calculate scale by the diameter
4040
};
4141

42+
//! Flags controlling behaviour of symbols during rendering
4243
enum RenderHint
4344
{
44-
DataDefinedRotation
45+
DynamicRotation, //!< Rotation of symbol may be changed during rendering and symbol should not be cached
4546
};
47+
typedef QFlags<QgsSymbol::RenderHint> RenderHints;
4648

4749
virtual ~QgsSymbol();
4850

@@ -178,8 +180,15 @@ class QgsSymbol
178180
//! Set alpha transparency 1 for opaque, 0 for invisible
179181
void setAlpha( qreal alpha );
180182

181-
void setRenderHints( int hints );
182-
int renderHints() const;
183+
/** Sets rendering hint flags for the symbol.
184+
* @see renderHints()
185+
*/
186+
void setRenderHints( RenderHints hints );
187+
188+
/** Returns the rendering hint flags for the symbol.
189+
* @see setRenderHints()
190+
*/
191+
RenderHints renderHints() const;
183192

184193
/** Sets whether features drawn by the symbol should be clipped to the render context's
185194
* extent. If this option is enabled then features which are partially outside the extent
@@ -281,6 +290,9 @@ class QgsSymbol
281290
QgsSymbol( const QgsSymbol& );
282291
};
283292

293+
QFlags<QgsSymbol::RenderHint> operator|(QgsSymbol::RenderHint f1, QFlags<QgsSymbol::RenderHint> f2);
294+
295+
284296
///////////////////////
285297

286298
class QgsSymbolRenderContext
@@ -296,12 +308,12 @@ class QgsSymbolRenderContext
296308
* @param u
297309
* @param alpha
298310
* @param selected set to true if symbol should be drawn in a "selected" state
299-
* @param renderHints
311+
* @param renderHints flags controlling rendering behaviour
300312
* @param f
301313
* @param fields
302314
* @param mapUnitScale
303315
*/
304-
QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields& fields = QgsFields(), const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
316+
QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, QgsSymbol::RenderHints renderHints = 0, const QgsFeature* f = 0, const QgsFields& fields = QgsFields(), const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
305317
~QgsSymbolRenderContext();
306318

307319
QgsRenderContext& renderContext();
@@ -331,8 +343,15 @@ class QgsSymbolRenderContext
331343
bool selected() const;
332344
void setSelected( bool selected );
333345

334-
int renderHints() const;
335-
void setRenderHints( int hints );
346+
/** Returns the rendering hint flags for the symbol.
347+
* @see setRenderHints()
348+
*/
349+
QgsSymbol::RenderHints renderHints() const;
350+
351+
/** Sets rendering hint flags for the symbol.
352+
* @see renderHints()
353+
*/
354+
void setRenderHints( QgsSymbol::RenderHints hints );
336355

337356
void setFeature( const QgsFeature* f );
338357
//! Current feature being rendered - may be null

src/core/dxf/qgsdxfexport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4168,7 +4168,7 @@ bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayer* sl, const Qgs
41684168
return false;
41694169
}
41704170

4171-
if ( symbol->renderHints() & QgsSymbol::DataDefinedRotation )
4171+
if ( symbol->renderHints() & QgsSymbol::DynamicRotation )
41724172
{
41734173
return true;
41744174
}

src/core/symbology-ng/qgsellipsesymbollayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void QgsEllipseSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContext&
312312
usingDataDefinedRotation = ok;
313313
}
314314

315-
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || usingDataDefinedRotation;
315+
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
316316
if ( hasDataDefinedRotation )
317317
{
318318
// For non-point markers, "dataDefinedRotation" means following the

src/core/symbology-ng/qgslinesymbollayer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,9 @@ void QgsMarkerLineSymbolLayer::startRender( QgsSymbolRenderContext& context )
809809
mMarker->setAlpha( context.alpha() );
810810

811811
// if being rotated, it gets initialized with every line segment
812-
int hints = 0;
812+
QgsSymbol::RenderHints hints = 0;
813813
if ( mRotateMarker )
814-
hints |= QgsSymbol::DataDefinedRotation;
814+
hints |= QgsSymbol::DynamicRotation;
815815
mMarker->setRenderHints( hints );
816816

817817
mMarker->startRender( context.renderContext(), context.fields() );

src/core/symbology-ng/qgsmarkersymbollayer.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( QgsSimpleMarkerSymbolLayerBa
130130

131131
void QgsSimpleMarkerSymbolLayerBase::startRender( QgsSymbolRenderContext &context )
132132
{
133-
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
133+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
134134
bool hasDataDefinedSize = hasDataDefinedProperty( QgsSymbolLayer::EXPR_SIZE );
135135

136136
// use either QPolygonF or QPainterPath for drawing
@@ -654,7 +654,7 @@ void QgsSimpleMarkerSymbolLayerBase::calculateOffsetAndRotation( QgsSymbolRender
654654
usingDataDefinedRotation = ok;
655655
}
656656

657-
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || usingDataDefinedRotation;
657+
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
658658
if ( hasDataDefinedRotation )
659659
{
660660
// For non-point markers, "dataDefinedRotation" means following the
@@ -824,7 +824,7 @@ void QgsSimpleMarkerSymbolLayer::startRender( QgsSymbolRenderContext& context )
824824
mSelPen.setStyle( mOutlineStyle );
825825
mSelPen.setWidthF( QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), mOutlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale ) );
826826

827-
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
827+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
828828
bool hasDataDefinedSize = hasDataDefinedProperty( QgsSymbolLayer::EXPR_SIZE );
829829

830830
// use caching only when:
@@ -2092,7 +2092,7 @@ void QgsSvgMarkerSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContext
20922092
angle = evaluateDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE, context, mAngle ).toDouble() + mLineAngle;
20932093
}
20942094

2095-
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
2095+
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
20962096
if ( hasDataDefinedRotation )
20972097
{
20982098
// For non-point markers, "dataDefinedRotation" means following the
@@ -2623,7 +2623,7 @@ void QgsFontMarkerSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContex
26232623
usingDataDefinedRotation = ok;
26242624
}
26252625

2626-
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || usingDataDefinedRotation;
2626+
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
26272627
if ( hasDataDefinedRotation )
26282628
{
26292629
// For non-point markers, "dataDefinedRotation" means following the

src/core/symbology-ng/qgssymbol.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext& context, int c
942942
////////////////////
943943

944944

945-
QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f, const QgsFields& fields, const QgsMapUnitScale& mapUnitScale )
945+
QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, QgsSymbol::RenderHints renderHints, const QgsFeature* f, const QgsFields& fields, const QgsMapUnitScale& mapUnitScale )
946946
: mRenderContext( c )
947947
, mExpressionContextScope( nullptr )
948948
, mOutputUnit( u )

src/core/symbology-ng/qgssymbol.h

+28-9
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ class CORE_EXPORT QgsSymbol
8080
ScaleDiameter //!< Calculate scale by the diameter
8181
};
8282

83+
84+
//! Flags controlling behaviour of symbols during rendering
8385
enum RenderHint
8486
{
85-
DataDefinedRotation = 2
87+
DynamicRotation = 2, //!< Rotation of symbol may be changed during rendering and symbol should not be cached
8688
};
89+
Q_DECLARE_FLAGS( RenderHints, RenderHint )
8790

8891
virtual ~QgsSymbol();
8992

@@ -224,8 +227,15 @@ class CORE_EXPORT QgsSymbol
224227
//! Set alpha transparency 1 for opaque, 0 for invisible
225228
void setAlpha( qreal alpha ) { mAlpha = alpha; }
226229

227-
void setRenderHints( int hints ) { mRenderHints = hints; }
228-
int renderHints() const { return mRenderHints; }
230+
/** Sets rendering hint flags for the symbol.
231+
* @see renderHints()
232+
*/
233+
void setRenderHints( RenderHints hints ) { mRenderHints = hints; }
234+
235+
/** Returns the rendering hint flags for the symbol.
236+
* @see setRenderHints()
237+
*/
238+
RenderHints renderHints() const { return mRenderHints; }
229239

230240
/** Sets whether features drawn by the symbol should be clipped to the render context's
231241
* extent. If this option is enabled then features which are partially outside the extent
@@ -343,7 +353,7 @@ class CORE_EXPORT QgsSymbol
343353
/** Symbol opacity (in the range 0 - 1)*/
344354
qreal mAlpha;
345355

346-
int mRenderHints;
356+
RenderHints mRenderHints;
347357
bool mClipFeaturesToExtent;
348358

349359
const QgsVectorLayer* mLayer; //current vectorlayer
@@ -356,6 +366,8 @@ class CORE_EXPORT QgsSymbol
356366

357367
};
358368

369+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSymbol::RenderHints )
370+
359371
///////////////////////
360372

361373
/** \ingroup core
@@ -370,12 +382,12 @@ class CORE_EXPORT QgsSymbolRenderContext
370382
* @param u
371383
* @param alpha
372384
* @param selected set to true if symbol should be drawn in a "selected" state
373-
* @param renderHints
385+
* @param renderHints flags controlling rendering behaviour
374386
* @param f
375387
* @param fields
376388
* @param mapUnitScale
377389
*/
378-
QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = nullptr, const QgsFields& fields = QgsFields(), const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
390+
QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, QgsSymbol::RenderHints renderHints = 0, const QgsFeature* f = nullptr, const QgsFields& fields = QgsFields(), const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
379391
~QgsSymbolRenderContext();
380392

381393
QgsRenderContext& renderContext() { return mRenderContext; }
@@ -405,8 +417,15 @@ class CORE_EXPORT QgsSymbolRenderContext
405417
bool selected() const { return mSelected; }
406418
void setSelected( bool selected ) { mSelected = selected; }
407419

408-
int renderHints() const { return mRenderHints; }
409-
void setRenderHints( int hints ) { mRenderHints = hints; }
420+
/** Returns the rendering hint flags for the symbol.
421+
* @see setRenderHints()
422+
*/
423+
QgsSymbol::RenderHints renderHints() const { return mRenderHints; }
424+
425+
/** Sets rendering hint flags for the symbol.
426+
* @see renderHints()
427+
*/
428+
void setRenderHints( QgsSymbol::RenderHints hints ) { mRenderHints = hints; }
410429

411430
void setFeature( const QgsFeature* f ) { mFeature = f; }
412431
//! Current feature being rendered - may be null
@@ -464,7 +483,7 @@ class CORE_EXPORT QgsSymbolRenderContext
464483
QgsMapUnitScale mMapUnitScale;
465484
qreal mAlpha;
466485
bool mSelected;
467-
int mRenderHints;
486+
QgsSymbol::RenderHints mRenderHints;
468487
const QgsFeature* mFeature; //current feature
469488
QgsFields mFields;
470489
int mGeometryPartCount;

0 commit comments

Comments
 (0)