Skip to content
Permalink
Browse files

QgsFeature::fields() returns a value, not a pointer

Also remove all other QgsFields pointers and replace with
references/values, since QgsFields objects are implicitly shared
  • Loading branch information
nyalldawson committed Aug 2, 2016
1 parent 23909a1 commit 967d37adc77a82fba0e623946d149cdb45ffdf6c
Showing with 121 additions and 166 deletions.
  1. +23 −0 doc/api_break.dox
  2. +0 −3 python/core/diagram/qgsdiagram.sip
  3. +1 −2 python/core/qgsfeature.sip
  4. +0 −8 python/core/symbology-ng/qgssymbollayerv2.sip
  5. +3 −3 python/core/symbology-ng/qgssymbolv2.sip
  6. +2 −2 src/app/qgsdecorationgrid.cpp
  7. +0 −13 src/core/diagram/qgsdiagram.cpp
  8. +0 −3 src/core/diagram/qgsdiagram.h
  9. +4 −4 src/core/diagram/qgshistogramdiagram.cpp
  10. +4 −4 src/core/diagram/qgspiediagram.cpp
  11. +4 −4 src/core/diagram/qgstextdiagram.cpp
  12. +2 −2 src/core/qgsfeature.cpp
  13. +1 −2 src/core/qgsfeature.h
  14. +6 −6 src/core/qgsjsonutils.cpp
  15. +1 −1 src/core/symbology-ng/qgs25drenderer.cpp
  16. +2 −2 src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
  17. +2 −2 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
  18. +1 −1 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
  19. +1 −1 src/core/symbology-ng/qgsrulebasedrendererv2.cpp
  20. +2 −2 src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
  21. +2 −34 src/core/symbology-ng/qgssymbollayerv2.cpp
  22. +0 −8 src/core/symbology-ng/qgssymbollayerv2.h
  23. +2 −2 src/core/symbology-ng/qgssymbollayerv2utils.cpp
  24. +6 −6 src/core/symbology-ng/qgssymbolv2.cpp
  25. +5 −4 src/core/symbology-ng/qgssymbolv2.h
  26. +4 −4 src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
  27. +2 −2 src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
  28. +1 −1 src/gui/qgsattributeform.cpp
  29. +1 −1 src/providers/grass/qgsgrassprovider.cpp
  30. +6 −6 src/providers/grass/qgsgrassvectormaplayer.cpp
  31. +3 −3 src/providers/wfs/qgswfsfeatureiterator.cpp
  32. +9 −9 src/server/qgswfsserver.cpp
  33. +3 −3 src/server/qgswmsserver.cpp
  34. +9 −9 tests/src/core/testqgsfeature.cpp
  35. +9 −9 tests/src/providers/grass/testqgsgrassprovider.cpp
@@ -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>
@@ -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
@@ -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
@@ -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
@@ -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.
@@ -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
@@ -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 );
@@ -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();
@@ -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
@@ -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 )
{
@@ -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 )
@@ -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 ) )
@@ -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
@@ -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 )
{
@@ -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 )
{
@@ -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 );
@@ -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 )
@@ -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 )
@@ -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 )
{
@@ -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;
}

/***************************************************************************
@@ -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.
@@ -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;
@@ -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;
}
@@ -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( '}' );
}
@@ -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 )
@@ -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;
}
}
@@ -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;
}
}
@@ -364,7 +364,7 @@ void QgsPointDisplacementRenderer::startRender( QgsRenderContext& context, const

if ( mCenterSymbol )
{
mCenterSymbol->startRender( context, &fields );
mCenterSymbol->startRender( context, fields );
}
return;
}
@@ -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)
@@ -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() )
{
@@ -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 )
{

0 comments on commit 967d37a

Please sign in to comment.
You can’t perform that action at this time.