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
This commit is contained in:
Nyall Dawson 2016-08-02 10:43:15 +10:00
parent 23909a123a
commit 967d37adc7
35 changed files with 121 additions and 166 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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 )

View File

@ -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 ) )

View File

@ -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

View File

@ -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 )
{

View File

@ -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 )

View File

@ -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 )
{

View File

@ -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;
}
/***************************************************************************

View File

@ -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.

View File

@ -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( '}' );
}

View File

@ -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 )

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -364,7 +364,7 @@ void QgsPointDisplacementRenderer::startRender( QgsRenderContext& context, const
if ( mCenterSymbol )
{
mCenterSymbol->startRender( context, &fields );
mCenterSymbol->startRender( context, fields );
}
return;
}

View File

@ -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)

View File

@ -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 )
{

View File

@ -335,38 +335,6 @@ QgsSymbolLayerV2::QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked )
mPaintEffect->setEnabled( false );
}
void QgsSymbolLayerV2::prepareExpressions( const QgsFields* fields, double scale )
{
QMap< QString, QgsDataDefined* >::const_iterator it = mDataDefinedProperties.constBegin();
for ( ; it != mDataDefinedProperties.constEnd(); ++it )
{
if ( it.value() )
{
QMap<QString, QVariant> params;
if ( scale > 0 )
{
params.insert( "scale", scale );
}
it.value()->setExpressionParams( params );
if ( fields )
{
it.value()->prepareExpression( QgsExpressionContextUtils::createFeatureBasedContext( QgsFeature(), *fields ) );
}
else
{
it.value()->prepareExpression();
}
}
}
if ( fields )
{
//QgsFields is implicitly shared, so it's cheap to make a copy
mFields = *fields;
}
}
void QgsSymbolLayerV2::prepareExpressions( const QgsSymbolV2RenderContext& context )
{
QMap< QString, QgsDataDefined* >::const_iterator it = mDataDefinedProperties.constBegin();
@ -384,10 +352,10 @@ void QgsSymbolLayerV2::prepareExpressions( const QgsSymbolV2RenderContext& conte
}
}
if ( context.fields() )
if ( !context.fields().isEmpty() )
{
//QgsFields is implicitly shared, so it's cheap to make a copy
mFields = *context.fields();
mFields = context.fields();
}
}

View File

@ -311,14 +311,6 @@ class CORE_EXPORT QgsSymbolLayerV2
static const bool selectFillBorder = false; // Fill symbol layer also selects border symbology
static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
/** 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
*/
Q_DECL_DEPRECATED virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 );
/** Prepares all data defined property expressions for evaluation. This should
* be called prior to evaluating data defined properties.
* @param context symbol render context

View File

@ -599,7 +599,7 @@ QPicture QgsSymbolLayerV2Utils::symbolLayerPreviewPicture( QgsSymbolLayerV2* lay
painter.setRenderHint( QPainter::Antialiasing );
QgsRenderContext renderContext = createRenderContext( &painter );
renderContext.setForceVectorOutput( true );
QgsSymbolV2RenderContext symbolContext( renderContext, units, 1.0, false, 0, nullptr, nullptr, scale );
QgsSymbolV2RenderContext symbolContext( renderContext, units, 1.0, false, 0, nullptr, QgsFields(), scale );
layer->drawPreviewIcon( symbolContext, size );
painter.end();
return picture;
@ -613,7 +613,7 @@ QIcon QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, Qg
painter.begin( &pixmap );
painter.setRenderHint( QPainter::Antialiasing );
QgsRenderContext renderContext = createRenderContext( &painter );
QgsSymbolV2RenderContext symbolContext( renderContext, u, 1.0, false, 0, nullptr, nullptr, scale );
QgsSymbolV2RenderContext symbolContext( renderContext, u, 1.0, false, 0, nullptr, QgsFields(), scale );
layer->drawPreviewIcon( symbolContext, size );
painter.end();
return QIcon( pixmap );

View File

@ -443,7 +443,7 @@ bool QgsSymbolV2::changeSymbolLayer( int index, QgsSymbolLayerV2* layer )
}
void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsFields* fields )
void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsFields& fields )
{
delete mSymbolRenderContext;
mSymbolRenderContext = new QgsSymbolV2RenderContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, fields, mapUnitScale() );
@ -497,7 +497,7 @@ void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size, QgsRenderConte
{
QgsRenderContext context = customContext ? *customContext : QgsSymbolLayerV2Utils::createRenderContext( painter );
context.setForceVectorOutput( true );
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, nullptr, mapUnitScale() );
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, nullptr, QgsFields(), mapUnitScale() );
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
{
@ -1024,7 +1024,7 @@ void QgsSymbolV2::renderVertexMarker( QPointF pt, QgsRenderContext& context, int
////////////////////
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f, const QgsFields* fields, const QgsMapUnitScale& mapUnitScale )
QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f, const QgsFields& fields, const QgsMapUnitScale& mapUnitScale )
: mRenderContext( c )
, mExpressionContextScope( nullptr )
, mOutputUnit( u )
@ -1472,7 +1472,7 @@ void QgsMarkerSymbolV2::renderPointUsingLayer( QgsMarkerSymbolLayerV2* layer, QP
void QgsMarkerSymbolV2::renderPoint( QPointF point, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, nullptr, mapUnitScale() );
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, QgsFields(), mapUnitScale() );
symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() );
symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() );
@ -1680,7 +1680,7 @@ void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature*
{
//save old painter
QPainter* renderPainter = context.painter();
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, nullptr, mapUnitScale() );
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, QgsFields(), mapUnitScale() );
symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() );
symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() );
@ -1759,7 +1759,7 @@ QgsFillSymbolV2::QgsFillSymbolV2( const QgsSymbolLayerV2List& layers )
void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layerIdx, bool selected )
{
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, nullptr, mapUnitScale() );
QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, QgsFields(), mapUnitScale() );
symbolContext.setGeometryPartCount( symbolRenderContext()->geometryPartCount() );
symbolContext.setGeometryPartNum( symbolRenderContext()->geometryPartNum() );

View File

@ -22,6 +22,7 @@
#include "qgsmapunitscale.h"
#include "qgspointv2.h"
#include "qgsfeature.h"
#include "qgsfield.h"
class QColor;
class QImage;
@ -148,7 +149,7 @@ class CORE_EXPORT QgsSymbolV2
//! delete layer at specified index and set a new one
bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer );
void startRender( QgsRenderContext& context, const QgsFields* fields = nullptr );
void startRender( QgsRenderContext& context, const QgsFields& fields = QgsFields() );
void stopRender( QgsRenderContext& context );
void setColor( const QColor& color );
@ -359,7 +360,7 @@ class CORE_EXPORT QgsSymbolV2RenderContext
* @param fields
* @param mapUnitScale
*/
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = nullptr, const QgsFields* fields = nullptr, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
QgsSymbolV2RenderContext( 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() );
~QgsSymbolV2RenderContext();
QgsRenderContext& renderContext() { return mRenderContext; }
@ -400,7 +401,7 @@ class CORE_EXPORT 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 { return mFields; }
QgsFields fields() const { return mFields; }
/** Part count of current geometry
* @note added in QGIS 2.16
@ -450,7 +451,7 @@ class CORE_EXPORT QgsSymbolV2RenderContext
bool mSelected;
int mRenderHints;
const QgsFeature* mFeature; //current feature
const QgsFields* mFields;
QgsFields mFields;
int mGeometryPartCount;
int mGeometryPartNum;

View File

@ -210,11 +210,11 @@ void QgsVectorFieldSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
mLineSymbol->startRender( context.renderContext(), context.fields() );
}
const QgsFields* fields = context.fields();
if ( fields )
QgsFields fields = context.fields();
if ( !fields.isEmpty() )
{
mXIndex = fields->fieldNameIndex( mXAttribute );
mYIndex = fields->fieldNameIndex( mYAttribute );
mXIndex = fields.fieldNameIndex( mXAttribute );
mYIndex = fields.fieldNameIndex( mYAttribute );
}
else
{

View File

@ -118,7 +118,7 @@ void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft )
description = layer()->editFormConfig()->expressionDescription( mFieldIdx );
QgsExpressionContext context =
QgsExpressionContextUtils::createFeatureBasedContext( ft, *ft.fields() );
QgsExpressionContextUtils::createFeatureBasedContext( ft, ft.fields() );
context << QgsExpressionContextUtils::layerScope( layer() );
context.setFeature( ft );
@ -142,7 +142,7 @@ void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft )
{
if ( !expression.isEmpty() )
{
QString fieldName = ft.fields()->field( mFieldIdx ).name();
QString fieldName = ft.fields().field( mFieldIdx ).name();
expression = "( " + expression + " ) AND ( " + fieldName + " IS NOT NULL)";
description = "( " + description + " ) AND NotNull";
}

View File

@ -869,7 +869,7 @@ void QgsAttributeForm::onUpdatedFields()
QgsAttributes attrs( layer()->fields().size() );
for ( int i = 0; i < layer()->fields().size(); i++ )
{
int idx = mFeature.fields()->indexFromName( layer()->fields().at( i ).name() );
int idx = mFeature.fields().indexFromName( layer()->fields().at( i ).name() );
if ( idx != -1 )
{
attrs[i] = mFeature.attributes().at( idx );

View File

@ -1268,7 +1268,7 @@ void QgsGrassProvider::onFeatureAdded( QgsFeatureId fid )
// It may be that user manualy entered cat value
QgsFeatureMap& addedFeatures = mEditBuffer->mAddedFeatures;
QgsFeature& feature = addedFeatures[fid];
int catIndex = feature.fields()->indexFromName( mLayer->keyColumnName() );
int catIndex = feature.fields().indexFromName( mLayer->keyColumnName() );
if ( catIndex != -1 )
{
QVariant userCatVariant = feature.attributes().value( catIndex );

View File

@ -838,12 +838,12 @@ void QgsGrassVectorMapLayer::insertAttributes( int cat, const QgsFeature &featur
cacheValues << QVariant();
}
if ( feature.fields() )
if ( !feature.fields().isEmpty() )
{
// append feature attributes if not null
for ( int i = 0; i < feature.fields()->size(); i++ )
for ( int i = 0; i < feature.fields().size(); i++ )
{
QString name = feature.fields()->at( i ).name();
QString name = feature.fields().at( i ).name();
QVariant valueVariant = feature.attributes().value( i );
if ( name != QgsGrassVectorMap::topoSymbolFieldName() )
@ -940,7 +940,7 @@ void QgsGrassVectorMapLayer::updateAttributes( int cat, QgsFeature &feature, QSt
error = tr( "Table does not exist" );
return;
}
if ( !feature.isValid() || !feature.fields() )
if ( !feature.isValid() || feature.fields().isEmpty() )
{
error = tr( "Feature invalid" );
return;
@ -949,9 +949,9 @@ void QgsGrassVectorMapLayer::updateAttributes( int cat, QgsFeature &feature, QSt
QStringList updates;
QMap<int, QVariant> cacheUpdates;
// append feature attributes if not null
for ( int i = 0; i < feature.fields()->size(); i++ )
for ( int i = 0; i < feature.fields().size(); i++ )
{
QString name = feature.fields()->at( i ).name();
QString name = feature.fields().at( i ).name();
if ( name == mFieldInfo->key )
{
continue;

View File

@ -955,7 +955,7 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature& f )
if ( !mShared->mGeometryAttribute.isEmpty() && mFetchGeometry )
{
int idx = cachedFeature.fields()->indexFromName( QgsWFSConstants::FIELD_HEXWKB_GEOM );
int idx = cachedFeature.fields().indexFromName( QgsWFSConstants::FIELD_HEXWKB_GEOM );
Q_ASSERT( idx >= 0 );
const QVariant &v = cachedFeature.attributes().value( idx );
@ -1183,7 +1183,7 @@ void QgsWFSFeatureIterator::copyFeature( const QgsFeature& srcFeature, QgsFeatur
{
Q_FOREACH ( int i, mSubSetAttributes )
{
int idx = srcFeature.fields()->indexFromName( fields.at( i ).name() );
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
if ( idx >= 0 )
{
const QVariant &v = srcFeature.attributes().value( idx );
@ -1200,7 +1200,7 @@ void QgsWFSFeatureIterator::copyFeature( const QgsFeature& srcFeature, QgsFeatur
{
for ( int i = 0; i < fields.size(); i++ )
{
int idx = srcFeature.fields()->indexFromName( fields.at( i ).name() );
int idx = srcFeature.fields().indexFromName( fields.at( i ).name() );
if ( idx >= 0 )
{
const QVariant &v = srcFeature.attributes().value( idx );

View File

@ -1896,16 +1896,16 @@ QString QgsWfsServer::createFeatureGeoJSON( QgsFeature* feat, int prec, QgsCoord
}
}
const QgsFields* fields = feat->fields();
QgsFields fields = feat->fields();
QgsAttributeList attrsToExport;
for ( int i = 0; i < attrIndexes.count(); ++i )
{
int idx = attrIndexes[i];
if ( idx >= fields->count() )
if ( idx >= fields.count() )
{
continue;
}
QString attributeName = fields->at( idx ).name();
QString attributeName = fields.at( idx ).name();
//skip attribute if it is excluded from WFS publication
if ( excludedAttributes.contains( attributeName ) )
{
@ -1972,15 +1972,15 @@ QDomElement QgsWfsServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
//read all attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
const QgsFields* fields = feat->fields();
QgsFields fields = feat->fields();
for ( int i = 0; i < attrIndexes.count(); ++i )
{
int idx = attrIndexes[i];
if ( idx >= fields->count() )
if ( idx >= fields.count() )
{
continue;
}
QString attributeName = fields->at( idx ).name();
QString attributeName = fields.at( idx ).name();
//skip attribute if it is excluded from WFS publication
if ( excludedAttributes.contains( attributeName ) )
{
@ -2047,15 +2047,15 @@ QDomElement QgsWfsServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
//read all attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
const QgsFields* fields = feat->fields();
QgsFields fields = feat->fields();
for ( int i = 0; i < attrIndexes.count(); ++i )
{
int idx = attrIndexes[i];
if ( idx >= fields->count() )
if ( idx >= fields.count() )
{
continue;
}
QString attributeName = fields->at( idx ).name();
QString attributeName = fields.at( idx ).name();
//skip attribute if it is excluded from WFS publication
if ( excludedAttributes.contains( attributeName ) )
{

View File

@ -3273,10 +3273,10 @@ QDomElement QgsWmsServer::createFeatureGML(
//read all allowed attribute values from the feature
QgsAttributes featureAttributes = feat->attributes();
const QgsFields* fields = feat->fields();
for ( int i = 0; i < fields->count(); ++i )
QgsFields fields = feat->fields();
for ( int i = 0; i < fields.count(); ++i )
{
QString attributeName = fields->at( i ).name();
QString attributeName = fields.at( i ).name();
//skip attribute if it is explicitly excluded from WMS publication
if ( layer && layer->excludeAttributesWms().contains( attributeName ) )
{

View File

@ -130,7 +130,7 @@ void TestQgsFeature::create()
QgsFeature featureFromFieldsId( mFields, 1001LL );
QCOMPARE( featureFromFieldsId.id(), 1001LL );
QCOMPARE( *featureFromFieldsId.fields(), mFields );
QCOMPARE( featureFromFieldsId.fields(), mFields );
QCOMPARE( featureFromFieldsId.isValid(), false );
//should be 3 invalid attributes
QCOMPARE( featureFromFieldsId.attributes().count(), 3 );
@ -303,24 +303,24 @@ void TestQgsFeature::asVariant()
QgsFeature fromVar = qvariant_cast<QgsFeature>( var );
//QCOMPARE( fromVar, original );
QCOMPARE( fromVar.id(), original.id() );
QCOMPARE( *fromVar.fields(), *original.fields() );
QCOMPARE( fromVar.fields(), original.fields() );
}
void TestQgsFeature::fields()
{
QgsFeature original;
QVERIFY( original.fields()->isEmpty() );
QVERIFY( original.fields().isEmpty() );
original.setFields( mFields );
QCOMPARE( *original.fields(), mFields );
QCOMPARE( original.fields(), mFields );
QgsFeature copy( original );
QCOMPARE( *copy.fields(), *original.fields() );
QCOMPARE( copy.fields(), original.fields() );
//test detach
QgsFields newFields( mFields );
newFields.remove( 2 );
copy.setFields( newFields );
QCOMPARE( *copy.fields(), newFields );
QCOMPARE( *original.fields(), mFields );
QCOMPARE( copy.fields(), newFields );
QCOMPARE( original.fields(), mFields );
//test that no init leaves attributes
copy = original;
@ -329,7 +329,7 @@ void TestQgsFeature::fields()
copy.setAttribute( 1, 2 );
copy.setAttribute( 2, 3 );
copy.setFields( mFields, false );
QCOMPARE( *copy.fields(), mFields );
QCOMPARE( copy.fields(), mFields );
//should be 3 invalid attributes
QCOMPARE( copy.attributes().count(), 3 );
QCOMPARE( copy.attributes().at( 0 ).toInt(), 1 );
@ -343,7 +343,7 @@ void TestQgsFeature::fields()
copy.setAttribute( 1, 2 );
copy.setAttribute( 2, 3 );
copy.setFields( mFields, true );
QCOMPARE( *copy.fields(), mFields );
QCOMPARE( copy.fields(), mFields );
//should be 3 invalid attributes
QCOMPARE( copy.attributes().count(), 3 );
Q_FOREACH ( const QVariant& a, copy.attributes() )

View File

@ -1112,7 +1112,7 @@ bool TestQgsGrassProvider::setAttributes( QgsFeature & feature, const QMap<QStri
bool attributesSet = true;
Q_FOREACH ( const QString fieldName, attributes.keys() )
{
int index = feature.fields()->indexFromName( fieldName );
int index = feature.fields().indexFromName( fieldName );
if ( index < 0 )
{
attributesSet = false;
@ -1501,26 +1501,26 @@ bool TestQgsGrassProvider::equal( QgsFeature feature, QgsFeature expectedFeature
}
// GRASS feature has always additional cat field
QSet<int> indexes;
for ( int i = 0; i < feature.fields()->size(); i++ )
for ( int i = 0; i < feature.fields().size(); i++ )
{
QString name = feature.fields()->at( i ).name();
QString name = feature.fields().at( i ).name();
if ( name == "cat" ) // skip cat
{
continue;
}
indexes << i;
}
for ( int i = 0; i < expectedFeature.fields()->size(); i++ )
for ( int i = 0; i < expectedFeature.fields().size(); i++ )
{
QString name = expectedFeature.fields()->at( i ).name();
int index = feature.fields()->indexFromName( name );
QString name = expectedFeature.fields().at( i ).name();
int index = feature.fields().indexFromName( name );
if ( index < 0 )
{
// not found
QStringList names;
for ( int j = 0; j < feature.fields()->size(); j++ )
for ( int j = 0; j < feature.fields().size(); j++ )
{
names << feature.fields()->at( j ).name();
names << feature.fields().at( j ).name();
}
reportRow( QString( "Attribute %1 not found, feature attributes: %2" ).arg( name, names.join( "," ) ) );
return false;
@ -1539,7 +1539,7 @@ bool TestQgsGrassProvider::equal( QgsFeature feature, QgsFeature expectedFeature
QStringList names;
Q_FOREACH ( int i, indexes )
{
names << feature.fields()->at( i ).name();
names << feature.fields().at( i ).name();
}
reportRow( QString( "feature has %1 unexpected attributes: %2" ).arg( indexes.size() ).arg( names.join( "," ) ) );
return false;