Skip to content

Commit

Permalink
QgsFeature::fields() returns a value, not a pointer
Browse files Browse the repository at this point in the history
Also remove all other QgsFields pointers and replace with
references/values, since QgsFields objects are implicitly shared
  • Loading branch information
nyalldawson committed Aug 4, 2016
1 parent 23909a1 commit 967d37a
Show file tree
Hide file tree
Showing 35 changed files with 121 additions and 166 deletions.
23 changes: 23 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ instead.</li>
be returned in place of a null pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsDiagram QgsDiagram

<ul>
<li>The deprecated getExpression( const QString& expression, const QgsFields* fields ) method has been removed.
Use the variant which accepts an expression context instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsDiagramLayerSettings QgsDiagramLayerSettings

<ul>
Expand All @@ -255,6 +262,7 @@ a feature has a geometry is now done using the new hasGeometry() method. Any cod
None will need to be modified, as the method will return an empty geometry if the feature has no geometry.</b></li>
<li>The temporary constGeometry() method has been removed. Use geometry() instead.</li>
<li>setFields( const QgsFields*, bool ) has been removed, use setFields( const QgsFields&, bool ) instead.</li>
<li>fields() no longer returns a pointer, but instead a QgsFields value.</li>
</ul>

\subsection qgis_api_break_3_0_QgsFeatureRendererV2 QgsFeatureRendererV2
Expand Down Expand Up @@ -523,6 +531,21 @@ be returned instead of a null pointer if no transformation is required.</li>
<li>The OutputUnit enum, including QgsSymbolV2::MM, QgsSymbolV2::MapUnit, QgsSymbolV2::Mixed, QgsSymbolV2::Pixel and QgsSymbolV2::Percentage has been moved to QgsUnitTypes
and renamed to RenderUnit. QgsSymbolV2::OutputUnitList was renamed to QgsUnitTypes::RenderUnitList. All methods which previously accepted QgsSymbolV2::OutputUnit
parameters or QgsSymbolV2::OutputUnitList parameters now take QgsUnitTypes::RenderUnit or QgsUnitTypes::RenderUnitList parameters respectively.</li>
<li>startRender() now accepts a QgsFields reference, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolLayerV2 QgsSymbolLayerV2

<ul>
<li>The deprecated prepareExpressions( const QgsFields* fields, double scale = -1.0 ) method has been removed. Use
the variant which takes QgsSymbolV2RenderContext instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolV2RenderContext QgsSymbolV2RenderContext

<ul>
<li>The constructor now accepts a QgsFields reference, not a pointer.</li>
<li>fields() now returns a QgsFields value, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolLayerV2Utils QgsSymbolLayerV2Utils
Expand Down
3 changes: 0 additions & 3 deletions python/core/diagram/qgsdiagram.sip
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class QgsDiagram

void clearCache();

//! @deprecated use QgsExpressionContext variant instead
QgsExpression* getExpression( const QString& expression, const QgsFields* fields ) /Deprecated/;

/** Returns a prepared expression for the specified context.
* @param expression expression string
* @param context expression context
Expand Down
3 changes: 1 addition & 2 deletions python/core/qgsfeature.sip
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,8 @@ class QgsFeature

/** Returns the field map associated with the feature.
* @see setFields
* TODO: QGIS 3 - return value, not pointer
*/
const QgsFields* fields() const;
QgsFields fields() const;

/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated using @link setFields @endlink before this method can be used.
Expand Down
8 changes: 0 additions & 8 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,6 @@ class QgsSymbolLayerV2
protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );

/** Prepares all data defined property expressions for evaluation. This should
* be called prior to evaluating data defined properties.
* @param fields associated layer fields
* @param scale map scale
* @deprecated use variant which takes QgsSymbolV2RenderContext instead
*/
virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 ) /Deprecated/;

/** Prepares all data defined property expressions for evaluation. This should
* be called prior to evaluating data defined properties.
* @param context symbol render context
Expand Down
6 changes: 3 additions & 3 deletions python/core/symbology-ng/qgssymbolv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class QgsSymbolV2
//! delete layer at specified index and set a new one
bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer /Transfer/ );

void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
void startRender( QgsRenderContext& context, const QgsFields& fields = QgsFields() );
void stopRender( QgsRenderContext& context );

void setColor( const QColor& color );
Expand Down Expand Up @@ -292,7 +292,7 @@ class QgsSymbolV2RenderContext
* @param fields
* @param mapUnitScale
*/
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* fields = 0, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
QgsSymbolV2RenderContext( 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() );
~QgsSymbolV2RenderContext();

QgsRenderContext& renderContext();
Expand Down Expand Up @@ -333,7 +333,7 @@ class QgsSymbolV2RenderContext
//! to allow symbols with data-defined properties prepare the expressions
//! (other times fields() returns null)
//! @note added in 2.4
const QgsFields* fields() const;
QgsFields fields() const;

/** Part count of current geometry
* @note added in QGIS 2.16
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsdecorationgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void QgsDecorationGrid::render( QPainter * p )

QgsRenderContext context = QgsRenderContext::fromMapSettings( QgisApp::instance()->mapCanvas()->mapSettings() );
context.setPainter( p );
mLineSymbol->startRender( context, nullptr );
mLineSymbol->startRender( context );

for ( ; vIt != verticalLines.constEnd(); ++vIt )
{
Expand Down Expand Up @@ -310,7 +310,7 @@ void QgsDecorationGrid::render( QPainter * p )

QgsRenderContext context = QgsRenderContext::fromMapSettings( QgisApp::instance()->mapCanvas()->mapSettings() );
context.setPainter( p );
mMarkerSymbol->startRender( context, nullptr );
mMarkerSymbol->startRender( context );

QPointF intersectionPoint;
for ( ; vIt != verticalLines.constEnd(); ++vIt )
Expand Down
13 changes: 0 additions & 13 deletions src/core/diagram/qgsdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ void QgsDiagram::clearCache()
mExpressions.clear();
}

QgsExpression* QgsDiagram::getExpression( const QString& expression, const QgsFields* fields )
{
Q_NOWARN_DEPRECATED_PUSH
if ( !mExpressions.contains( expression ) )
{
QgsExpression* expr = new QgsExpression( expression );
expr->prepare( *fields );
mExpressions[expression] = expr;
}
return mExpressions[expression];
Q_NOWARN_DEPRECATED_POP
}

QgsExpression *QgsDiagram::getExpression( const QString &expression, const QgsExpressionContext &context )
{
if ( !mExpressions.contains( expression ) )
Expand Down
3 changes: 0 additions & 3 deletions src/core/diagram/qgsdiagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class CORE_EXPORT QgsDiagram

void clearCache();

//! @deprecated use QgsExpressionContext variant instead
Q_DECL_DEPRECATED QgsExpression* getExpression( const QString& expression, const QgsFields* fields );

/** Returns a prepared expression for the specified context.
* @param expression expression string
* @param context expression context
Expand Down
8 changes: 4 additions & 4 deletions src/core/diagram/qgshistogramdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ QSizeF QgsHistogramDiagram::diagramSize( const QgsFeature& feature, const QgsRen

QgsExpressionContext expressionContext = c.expressionContext();
expressionContext.setFeature( feature );
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

Q_FOREACH ( const QString& cat, s.categoryAttributes )
{
Expand Down Expand Up @@ -147,8 +147,8 @@ void QgsHistogramDiagram::renderDiagram( const QgsFeature& feature, QgsRenderCon

QgsExpressionContext expressionContext = c.expressionContext();
expressionContext.setFeature( feature );
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

Q_FOREACH ( const QString& cat, s.categoryAttributes )
{
Expand Down
8 changes: 4 additions & 4 deletions src/core/diagram/qgspiediagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ QSizeF QgsPieDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCon
if ( is.classificationAttributeIsExpression )
{
QgsExpressionContext expressionContext = c.expressionContext();
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );
expressionContext.setFeature( feature );

QgsExpression* expression = getExpression( is.classificationAttributeExpression, expressionContext );
Expand Down Expand Up @@ -94,8 +94,8 @@ void QgsPieDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext&

QgsExpressionContext expressionContext = c.expressionContext();
expressionContext.setFeature( feature );
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

QList<QString>::const_iterator catIt = s.categoryAttributes.constBegin();
for ( ; catIt != s.categoryAttributes.constEnd(); ++catIt )
Expand Down
8 changes: 4 additions & 4 deletions src/core/diagram/qgstextdiagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ QSizeF QgsTextDiagram::diagramSize( const QgsFeature& feature, const QgsRenderCo
{
QgsExpressionContext expressionContext = c.expressionContext();
expressionContext.setFeature( feature );
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

QVariant attrVal;
if ( is.classificationAttributeIsExpression )
Expand Down Expand Up @@ -198,8 +198,8 @@ void QgsTextDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext&

QgsExpressionContext expressionContext = c.expressionContext();
expressionContext.setFeature( feature );
if ( feature.fields() )
expressionContext.setFields( *feature.fields() );
if ( !feature.fields().isEmpty() )
expressionContext.setFields( feature.fields() );

for ( int i = 0; i < textPositions.size(); ++i )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ void QgsFeature::setFields( const QgsFields &fields, bool init )
}
}

const QgsFields *QgsFeature::fields() const
QgsFields QgsFeature::fields() const
{
return &( d->fields );
return d->fields;
}

/***************************************************************************
Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,8 @@ class CORE_EXPORT QgsFeature

/** Returns the field map associated with the feature.
* @see setFields
* TODO: QGIS 3 - return value, not pointer
*/
const QgsFields* fields() const;
QgsFields fields() const;

/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated using @link setFields @endlink before this method can be used.
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsjsonutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ QString QgsJSONExporter::exportFeature( const QgsFeature& feature, const QVarian

if ( mIncludeAttributes )
{
const QgsFields* fields = feature.fields();
QgsFields fields = feature.fields();

for ( int i = 0; i < fields->count(); ++i )
for ( int i = 0; i < fields.count(); ++i )
{
if (( !mAttributeIndexes.isEmpty() && !mAttributeIndexes.contains( i ) ) || mExcludedAttributeIndexes.contains( i ) )
continue;
Expand All @@ -127,7 +127,7 @@ QString QgsJSONExporter::exportFeature( const QgsFeature& feature, const QVarian
properties += ",\n";
QVariant val = feature.attributes().at( i );

properties += QString( " \"%1\":%2" ).arg( fields->at( i ).name(), QgsJSONUtils::encodeValue( val ) );
properties += QString( " \"%1\":%2" ).arg( fields.at( i ).name(), QgsJSONUtils::encodeValue( val ) );

++attributeCounter;
}
Expand Down Expand Up @@ -296,15 +296,15 @@ QString QgsJSONUtils::encodeValue( const QVariant &value )

QString QgsJSONUtils::exportAttributes( const QgsFeature& feature )
{
const QgsFields* fields = feature.fields();
QgsFields fields = feature.fields();
QString attrs;
for ( int i = 0; i < fields->count(); ++i )
for ( int i = 0; i < fields.count(); ++i )
{
if ( i > 0 )
attrs += ",\n";

QVariant val = feature.attributes().at( i );
attrs += encodeValue( fields->at( i ).name() ) + ':' + encodeValue( val );
attrs += encodeValue( fields.at( i ).name() ) + ':' + encodeValue( val );
}
return attrs.prepend( '{' ).append( '}' );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgs25drenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ QgsFeatureRendererV2* Qgs25DRenderer::create( QDomElement& element )

void Qgs25DRenderer::startRender( QgsRenderContext& context, const QgsFields& fields )
{
mSymbol->startRender( context, &fields );
mSymbol->startRender( context, fields );
}

void Qgs25DRenderer::stopRender( QgsRenderContext& context )
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,14 @@ void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, con

Q_FOREACH ( const QgsRendererCategoryV2& cat, mCategories )
{
cat.symbol()->startRender( context, &fields );
cat.symbol()->startRender( context, fields );

if ( mRotation.data() || mSizeScale.data() )
{
QgsSymbolV2* tempSymbol = cat.symbol()->clone();
tempSymbol->setRenderHints(( mRotation.data() ? QgsSymbolV2::DataDefinedRotation : 0 ) |
( mSizeScale.data() ? QgsSymbolV2::DataDefinedSizeScale : 0 ) );
tempSymbol->startRender( context, &fields );
tempSymbol->startRender( context, fields );
mTempSymbols[ cat.symbol()] = tempSymbol;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,14 @@ void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const
if ( !range.symbol() )
continue;

range.symbol()->startRender( context, &fields );
range.symbol()->startRender( context, fields );

if ( mRotation.data() || mSizeScale.data() )
{
QgsSymbolV2* tempSymbol = range.symbol()->clone();
tempSymbol->setRenderHints(( mRotation.data() ? QgsSymbolV2::DataDefinedRotation : 0 ) |
( mSizeScale.data() ? QgsSymbolV2::DataDefinedSizeScale : 0 ) );
tempSymbol->startRender( context, &fields );
tempSymbol->startRender( context, fields );
mTempSymbols[ range.symbol()] = tempSymbol;
}
}
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 @@ -364,7 +364,7 @@ void QgsPointDisplacementRenderer::startRender( QgsRenderContext& context, const

if ( mCenterSymbol )
{
mCenterSymbol->startRender( context, &fields );
mCenterSymbol->startRender( context, fields );
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsrulebasedrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ bool QgsRuleBasedRendererV2::Rule::startRender( QgsRenderContext& context, const
if ( mFilter )
mFilter->prepare( &context.expressionContext() );
if ( mSymbol )
mSymbol->startRender( context, &fields );
mSymbol->startRender( context, fields );

// init children
// build temporary list of active rules (usable with this scale)
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const Qg
if ( !mSymbol.data() )
return;

mSymbol->startRender( context, &fields );
mSymbol->startRender( context, fields );

if ( mRotation.data() || mSizeScale.data() )
{
Expand All @@ -101,7 +101,7 @@ void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const Qg
hints |= QgsSymbolV2::DataDefinedSizeScale;
mTempSymbol->setRenderHints( hints );

mTempSymbol->startRender( context, &fields );
mTempSymbol->startRender( context, fields );

if ( mSymbol->type() == QgsSymbolV2::Marker )
{
Expand Down
Loading

0 comments on commit 967d37a

Please sign in to comment.