Skip to content

Commit

Permalink
Merge pull request #3486 from nyalldawson/symbol
Browse files Browse the repository at this point in the history
Symbology QGIS 3.0 todos
  • Loading branch information
nyalldawson authored Sep 14, 2016
2 parents aac7e9a + b711177 commit de7475a
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 66 deletions.
26 changes: 26 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,12 @@ be returned instead of a null pointer if no transformation is required.</li>
plugins calling this method will need to be updated.</li>
</ul>

\subsection qgis_api_break_3_0_QgsMarkerSymbolLayer QgsMarkerSymbolLayer

<ul>
<li>bounds() is now pure virtual and must be implemented in all subclasses.</li>
</ul>

\subsection qgis_api_break_3_0_QgsMimeDataUtils QgsMimeDataUtils

<ul>
Expand Down Expand Up @@ -1013,9 +1019,16 @@ be returned instead of a null pointer if no transformation is required.</li>

<ul>
<li>QgsRuleBasedRenderer.Rule checkState() and setCheckState() were removed. Use active() and setActive() instead.</li>
<li>QgsRuleBasedRenderer.Rule updateElseRules() was removed.</li>
<li>startRender( QgsRenderContext& context, const QgsFields& fields ) was removed. Use startRender( QgsRenderContext& context, const QgsFields& fields, QString& filter ) instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsRuleBasedRendererWidget QgsRuleBasedRendererWidget

<ul>
<li>refineRuleCategoriesGui() and refineRuleRangesGui() no longer take a QModelIndexList argument.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSimpleMarkerSymbolLayer QgsSimpleMarkerSymbolLayer

<ul>
Expand All @@ -1024,6 +1037,13 @@ be returned instead of a null pointer if no transformation is required.</li>
<li>prepareShape() and preparePath() were removed. Calling these methods manually should no longer be required.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSimpleMarkerSymbolLayerWidget QgsSimpleMarkerSymbolLayerWidget

<ul>
<li>setName() was removed.</li>
</ul>


\subsection qgis_api_break_3_0_QgsSingleSymbolRendererWidget QgsSingleSymbolRendererWidget
<ul>
<li>sizeScaleFieldChanged() and scaleMethodChanged() were removed. These settings are no longer exposed in the widget's GUI.</li>
Expand All @@ -1050,6 +1070,10 @@ parameters or QgsSymbol::OutputUnitList parameters now take QgsUnitTypes::Render
<li>startRender() now accepts a QgsFields reference, not a pointer.</li>
<li>isSymbolLayerCompatible() was removed. Use QgsSymbolLayer::isCompatibleWithSymbol() instead.</li>
<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>
<li>The DataDefinedRotation RenderHint was renamed to DynamicRotation, as it is no longer used for
data defined rotation.</li>
<li>setRenderHints() and renderHints() now accept and return a QgsSymbol::RenderHints flag rather
than an integer value</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolLayer QgsSymbolLayer (renamed from QgsSymbolLayerV2)
Expand All @@ -1067,6 +1091,8 @@ the variant which takes QgsSymbolRenderContext instead.</li>

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

Expand Down
7 changes: 0 additions & 7 deletions python/core/symbology-ng/qgsrulebasedrenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,6 @@ class QgsRuleBasedRenderer : QgsFeatureRenderer
//! @note added in 2.6
QgsRuleBasedRenderer::Rule* findRuleByKey( const QString& key );

/**
* Check which child rules are else rules and update the internal list of else rules
*
* TODO QGIS 3: Does this need to be public?
*/
void updateElseRules();

/**
* Sets if this rule is an ELSE rule
*
Expand Down
33 changes: 26 additions & 7 deletions python/core/symbology-ng/qgssymbol.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class QgsSymbol
ScaleDiameter //!< Calculate scale by the diameter
};

//! Flags controlling behaviour of symbols during rendering
enum RenderHint
{
DataDefinedRotation
DynamicRotation, //!< Rotation of symbol may be changed during rendering and symbol should not be cached
};
typedef QFlags<QgsSymbol::RenderHint> RenderHints;

virtual ~QgsSymbol();

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

void setRenderHints( int hints );
int renderHints() const;
/** Sets rendering hint flags for the symbol.
* @see renderHints()
*/
void setRenderHints( RenderHints hints );

/** Returns the rendering hint flags for the symbol.
* @see setRenderHints()
*/
RenderHints renderHints() const;

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

QFlags<QgsSymbol::RenderHint> operator|(QgsSymbol::RenderHint f1, QFlags<QgsSymbol::RenderHint> f2);


///////////////////////

class QgsSymbolRenderContext
Expand All @@ -296,12 +308,12 @@ class QgsSymbolRenderContext
* @param u
* @param alpha
* @param selected set to true if symbol should be drawn in a "selected" state
* @param renderHints
* @param renderHints flags controlling rendering behaviour
* @param f
* @param fields
* @param mapUnitScale
*/
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() );
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() );
~QgsSymbolRenderContext();

QgsRenderContext& renderContext();
Expand Down Expand Up @@ -331,8 +343,15 @@ class QgsSymbolRenderContext
bool selected() const;
void setSelected( bool selected );

int renderHints() const;
void setRenderHints( int hints );
/** Returns the rendering hint flags for the symbol.
* @see setRenderHints()
*/
QgsSymbol::RenderHints renderHints() const;

/** Sets rendering hint flags for the symbol.
* @see renderHints()
*/
void setRenderHints( QgsSymbol::RenderHints hints );

void setFeature( const QgsFeature* f );
//! Current feature being rendered - may be null
Expand Down
4 changes: 1 addition & 3 deletions python/core/symbology-ng/qgssymbollayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,8 @@ class QgsMarkerSymbolLayer : QgsSymbolLayer
* any data defined overrides and offsets which are set for the marker layer.
* @returns approximate symbol bounds, in painter units
* @note added in QGIS 2.14
* @note this method will become pure virtual in QGIS 3.0
*/
//TODO QGIS 3.0 - make pure virtual
virtual QRectF bounds( QPointF point, QgsSymbolRenderContext& context );
virtual QRectF bounds( QPointF point, QgsSymbolRenderContext& context ) = 0;

protected:

Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgsvectorfieldsymbollayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ class QgsVectorFieldSymbolLayer : QgsMarkerSymbolLayer

void setDistanceMapUnitScale( const QgsMapUnitScale& scale );
const QgsMapUnitScale& distanceMapUnitScale() const;

QRectF bounds( QPointF point, QgsSymbolRenderContext& context );
};
6 changes: 4 additions & 2 deletions python/gui/symbology-ng/qgsrulebasedrendererwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class QgsRuleBasedRendererWidget : QgsRendererWidget

protected:
void refineRule( int type );
void refineRuleCategoriesGui( const QModelIndexList& index );
void refineRuleRangesGui( const QModelIndexList& index );
//! Opens the dialog for refining a rule using categories
void refineRuleCategoriesGui();
//! Opens the dialog for refining a rule using ranges
void refineRuleRangesGui();
void refineRuleScalesGui( const QModelIndexList& index );

QgsRuleBasedRenderer::Rule* currentRule();
Expand Down
1 change: 0 additions & 1 deletion python/gui/symbology-ng/qgssymbollayerwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class QgsSimpleMarkerSymbolLayerWidget : QgsSymbolLayerWidget
virtual QgsSymbolLayer* symbolLayer();

public slots:
void setName();
void setColorBorder( const QColor& color );
void setColorFill( const QColor& color );
void setSize();
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4168,7 +4168,7 @@ bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayer* sl, const Qgs
return false;
}

if ( symbol->renderHints() & QgsSymbol::DataDefinedRotation )
if ( symbol->renderHints() & QgsSymbol::DynamicRotation )
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsellipsesymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void QgsEllipseSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContext&
usingDataDefinedRotation = ok;
}

hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || usingDataDefinedRotation;
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,9 +809,9 @@ void QgsMarkerLineSymbolLayer::startRender( QgsSymbolRenderContext& context )
mMarker->setAlpha( context.alpha() );

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

mMarker->startRender( context.renderContext(), context.fields() );
Expand Down
11 changes: 5 additions & 6 deletions src/core/symbology-ng/qgsmarkersymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( QgsSimpleMarkerSymbolLayerBa

void QgsSimpleMarkerSymbolLayerBase::startRender( QgsSymbolRenderContext &context )
{
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
bool hasDataDefinedSize = hasDataDefinedProperty( QgsSymbolLayer::EXPR_SIZE );

// use either QPolygonF or QPainterPath for drawing
Expand Down Expand Up @@ -654,7 +654,7 @@ void QgsSimpleMarkerSymbolLayerBase::calculateOffsetAndRotation( QgsSymbolRender
usingDataDefinedRotation = ok;
}

hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || usingDataDefinedRotation;
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
Expand Down Expand Up @@ -689,7 +689,6 @@ QgsSimpleMarkerSymbolLayer::QgsSimpleMarkerSymbolLayer( QgsSimpleMarkerSymbolLay
, mOutlineWidth( 0 )
, mOutlineWidthUnit( QgsUnitTypes::RenderMillimeters )
, mPenJoinStyle( penJoinStyle )
, mName( encodeShape( shape ) )
, mUsingCache( false )
{
mColor = color;
Expand Down Expand Up @@ -824,7 +823,7 @@ void QgsSimpleMarkerSymbolLayer::startRender( QgsSymbolRenderContext& context )
mSelPen.setStyle( mOutlineStyle );
mSelPen.setWidthF( QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), mOutlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale ) );

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

// use caching only when:
Expand Down Expand Up @@ -2092,7 +2091,7 @@ void QgsSvgMarkerSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContext
angle = evaluateDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE, context, mAngle ).toDouble() + mLineAngle;
}

bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
bool hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || hasDataDefinedProperty( QgsSymbolLayer::EXPR_ANGLE );
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
Expand Down Expand Up @@ -2623,7 +2622,7 @@ void QgsFontMarkerSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContex
usingDataDefinedRotation = ok;
}

hasDataDefinedRotation = context.renderHints() & QgsSymbol::DataDefinedRotation || usingDataDefinedRotation;
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
Expand Down
3 changes: 0 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,6 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayer : public QgsSimpleMarkerSymbolLayer
//! QBrush corresponding to marker's fill style
QBrush mBrush;

//TODO QGIS 3.0 - remove
QString mName;

//! Cached image of marker, if using cached version
QImage mCache;
//! QPen to use as outline of selected symbols
Expand Down
13 changes: 6 additions & 7 deletions src/core/symbology-ng/qgsrulebasedrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,6 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer
//! @note added in 2.6
Rule* findRuleByKey( const QString& key );

/**
* Check which child rules are else rules and update the internal list of else rules
*
* TODO QGIS 3: Does this need to be public?
*/
void updateElseRules();

/**
* Sets if this rule is an ELSE rule
*
Expand Down Expand Up @@ -398,6 +391,12 @@ class CORE_EXPORT QgsRuleBasedRenderer : public QgsFeatureRenderer

Rule( const Rule& rh );
Rule& operator=( const Rule& rh );

/**
* Check which child rules are else rules and update the internal list of else rules
*
*/
void updateElseRules();
};

/////
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ void QgsSymbol::renderVertexMarker( QPointF pt, QgsRenderContext& context, int c
////////////////////


QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f, const QgsFields& fields, const QgsMapUnitScale& mapUnitScale )
QgsSymbolRenderContext::QgsSymbolRenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, QgsSymbol::RenderHints renderHints, const QgsFeature* f, const QgsFields& fields, const QgsMapUnitScale& mapUnitScale )
: mRenderContext( c )
, mExpressionContextScope( nullptr )
, mOutputUnit( u )
Expand Down
Loading

0 comments on commit de7475a

Please sign in to comment.