Skip to content

Commit 00a8fea

Browse files
authored
Merge pull request #3351 from nyalldawson/feature_geom
QgsFields cleanup
2 parents 23909a1 + c40d6d3 commit 00a8fea

File tree

76 files changed

+298
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+298
-307
lines changed

doc/api_break.dox

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ instead.</li>
233233
be returned in place of a null pointer.</li>
234234
</ul>
235235

236+
\subsection qgis_api_break_3_0_QgsDiagram QgsDiagram
237+
238+
<ul>
239+
<li>The deprecated getExpression( const QString& expression, const QgsFields* fields ) method has been removed.
240+
Use the variant which accepts an expression context instead.</li>
241+
</ul>
242+
236243
\subsection qgis_api_break_3_0_QgsDiagramLayerSettings QgsDiagramLayerSettings
237244

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

260268
\subsection qgis_api_break_3_0_QgsFeatureRendererV2 QgsFeatureRendererV2
@@ -263,6 +271,12 @@ None will need to be modified, as the method will return an empty geometry if th
263271
<li>The method capabilities() returns QgsFeatureRendererV2::Capabilities flags instead of an integer. The two are binary compatible.
264272
</ul>
265273

274+
\subsection qgis_api_break_3_0_QgsFields QgsFields
275+
276+
<ul>
277+
<li>All const methods which return a field from QgsFields now return a QgsField value, not a reference.</li>
278+
</ul>
279+
266280
\subsection qgis_api_break_3_0_QgsGeometry QgsGeometry
267281

268282
<ul>
@@ -523,6 +537,21 @@ be returned instead of a null pointer if no transformation is required.</li>
523537
<li>The OutputUnit enum, including QgsSymbolV2::MM, QgsSymbolV2::MapUnit, QgsSymbolV2::Mixed, QgsSymbolV2::Pixel and QgsSymbolV2::Percentage has been moved to QgsUnitTypes
524538
and renamed to RenderUnit. QgsSymbolV2::OutputUnitList was renamed to QgsUnitTypes::RenderUnitList. All methods which previously accepted QgsSymbolV2::OutputUnit
525539
parameters or QgsSymbolV2::OutputUnitList parameters now take QgsUnitTypes::RenderUnit or QgsUnitTypes::RenderUnitList parameters respectively.</li>
540+
<li>startRender() now accepts a QgsFields reference, not a pointer.</li>
541+
</ul>
542+
543+
\subsection qgis_api_break_3_0_QgsSymbolLayerV2 QgsSymbolLayerV2
544+
545+
<ul>
546+
<li>The deprecated prepareExpressions( const QgsFields* fields, double scale = -1.0 ) method has been removed. Use
547+
the variant which takes QgsSymbolV2RenderContext instead.</li>
548+
</ul>
549+
550+
\subsection qgis_api_break_3_0_QgsSymbolV2RenderContext QgsSymbolV2RenderContext
551+
552+
<ul>
553+
<li>The constructor now accepts a QgsFields reference, not a pointer.</li>
554+
<li>fields() now returns a QgsFields value, not a pointer.</li>
526555
</ul>
527556

528557
\subsection qgis_api_break_3_0_QgsSymbolLayerV2Utils QgsSymbolLayerV2Utils

python/core/diagram/qgsdiagram.sip

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class QgsDiagram
1111

1212
void clearCache();
1313

14-
//! @deprecated use QgsExpressionContext variant instead
15-
QgsExpression* getExpression( const QString& expression, const QgsFields* fields ) /Deprecated/;
16-
1714
/** Returns a prepared expression for the specified context.
1815
* @param expression expression string
1916
* @param context expression context

python/core/qgsfeature.sip

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,8 @@ class QgsFeature
361361

362362
/** Returns the field map associated with the feature.
363363
* @see setFields
364-
* TODO: QGIS 3 - return value, not pointer
365364
*/
366-
const QgsFields* fields() const;
365+
QgsFields fields() const;
367366

368367
/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
369368
* Field map must be associated using @link setFields @endlink before this method can be used.

python/core/qgsfield.sip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class QgsFields
262262
%End
263263

264264
//! Get field at particular index (must be in range 0..N-1)
265-
const QgsField& at( int i ) const /Factory/;
265+
QgsField at( int i ) const /Factory/;
266266
%MethodCode
267267
if ( a0 < 0 || a0 >= sipCpp->count() )
268268
{
@@ -276,7 +276,7 @@ class QgsFields
276276
%End
277277

278278
//! Get field at particular index (must be in range 0..N-1)
279-
const QgsField& field( int fieldIdx ) const /Factory/;
279+
QgsField field( int fieldIdx ) const /Factory/;
280280
%MethodCode
281281
if ( a0 < 0 || a0 >= sipCpp->count() )
282282
{
@@ -290,7 +290,7 @@ class QgsFields
290290
%End
291291

292292
//! Get field at particular index (must be in range 0..N-1)
293-
const QgsField& field( const QString& name ) const /Factory/;
293+
QgsField field( const QString& name ) const /Factory/;
294294
%MethodCode
295295
int fieldIdx = sipCpp->indexFromName(*a0);
296296
if (fieldIdx == -1)

python/core/symbology-ng/qgssymbollayerv2.sip

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,6 @@ class QgsSymbolLayerV2
301301
protected:
302302
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );
303303

304-
/** Prepares all data defined property expressions for evaluation. This should
305-
* be called prior to evaluating data defined properties.
306-
* @param fields associated layer fields
307-
* @param scale map scale
308-
* @deprecated use variant which takes QgsSymbolV2RenderContext instead
309-
*/
310-
virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 ) /Deprecated/;
311-
312304
/** Prepares all data defined property expressions for evaluation. This should
313305
* be called prior to evaluating data defined properties.
314306
* @param context symbol render context

python/core/symbology-ng/qgssymbolv2.sip

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,21 @@ class QgsSymbolV2
110110
//! delete layer at specified index and set a new one
111111
bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer /Transfer/ );
112112

113-
void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
113+
/** Begins the rendering process for the symbol. This must be called before renderFeature(),
114+
* and should be followed by a call to stopRender().
115+
* @param context render context which symbol will be drawn using
116+
* @param fields fields for features to be rendered (usually the associated
117+
* vector layer's fields). Required for correct calculation of data defined
118+
* overrides.
119+
* @see stopRender()
120+
*/
121+
void startRender( QgsRenderContext& context, const QgsFields& fields = QgsFields() );
122+
123+
/** Ends the rendering process. This should be called after rendering all desired features.
124+
* @param context render context, must match the context specified when startRender()
125+
* was called.
126+
* @see startRender()
127+
*/
114128
void stopRender( QgsRenderContext& context );
115129

116130
void setColor( const QColor& color );
@@ -205,7 +219,8 @@ class QgsSymbolV2
205219
const QgsVectorLayer* layer() const;
206220

207221
/**
208-
* Render a feature.
222+
* Render a feature. Before calling this the startRender() method should be called to initialise
223+
* the rendering process. After rendering all features stopRender() must be called.
209224
*/
210225
void renderFeature( const QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, int currentVertexMarkerSize = 0 );
211226

@@ -292,7 +307,7 @@ class QgsSymbolV2RenderContext
292307
* @param fields
293308
* @param mapUnitScale
294309
*/
295-
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() );
310+
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() );
296311
~QgsSymbolV2RenderContext();
297312

298313
QgsRenderContext& renderContext();
@@ -333,7 +348,7 @@ class QgsSymbolV2RenderContext
333348
//! to allow symbols with data-defined properties prepare the expressions
334349
//! (other times fields() returns null)
335350
//! @note added in 2.4
336-
const QgsFields* fields() const;
351+
QgsFields fields() const;
337352

338353
/** Part count of current geometry
339354
* @note added in QGIS 2.16

src/analysis/vector/qgsoverlayanalyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void QgsOverlayAnalyzer::combineFieldLists( QgsFields& fieldListA, const QgsFiel
192192

193193
for ( int idx = 0; idx < fieldListB.count(); ++idx )
194194
{
195-
QgsField field = fieldListB[idx];
195+
QgsField field = fieldListB.at( idx );
196196
int count = 0;
197197
while ( names.contains( field.name() ) )
198198
{

src/app/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
271271

272272
for ( int i = 0; i < mLayer->fields().size(); ++i )
273273
{
274-
const QgsField &fld = mLayer->fields().at( i );
274+
QgsField fld = mLayer->fields().at( i );
275275
Qt::ItemFlags flags = mLayer->providerType() != "oracle" || !fld.typeName().contains( "SDO_GEOMETRY" ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
276276
QTableWidgetItem *item;
277277
item = new QTableWidgetItem( fld.name() );

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6848,7 +6848,7 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
68486848
continue;
68496849

68506850
QVariant val = merged.at( i );
6851-
const QgsField &fld( vl->fields().at( i ) );
6851+
QgsField fld( vl->fields().at( i ) );
68526852
bool isDefaultValue = vl->fields().fieldOrigin( i ) == QgsFields::OriginProvider &&
68536853
vl->dataProvider() &&
68546854
vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( i ) ) == val;

src/app/qgsdecorationgrid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void QgsDecorationGrid::render( QPainter * p )
232232

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

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

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

315315
QPointF intersectionPoint;
316316
for ( ; vIt != verticalLines.constEnd(); ++vIt )

src/app/qgsdelattrdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ QgsDelAttrDialog::QgsDelAttrDialog( const QgsVectorLayer* vl )
3434
const QgsFields& layerAttributes = vl->fields();
3535
for ( int idx = 0; idx < layerAttributes.count(); ++idx )
3636
{
37-
QListWidgetItem* item = new QListWidgetItem( layerAttributes[idx].name(), listBox2 );
37+
QListWidgetItem* item = new QListWidgetItem( layerAttributes.at( idx ).name(), listBox2 );
3838
switch ( vl->fields().fieldOrigin( idx ) )
3939
{
4040
case QgsFields::OriginExpression:

src/app/qgsdiagramproperties.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer,
184184
for ( int idx = 0; idx < layerFields.count(); ++idx )
185185
{
186186
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
187-
QString name = QString( "\"%1\"" ).arg( layerFields[idx].name() );
187+
QString name = QString( "\"%1\"" ).arg( layerFields.at( idx ).name() );
188188
newItem->setText( 0, name );
189189
newItem->setData( 0, Qt::UserRole, name );
190190
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
191191

192-
mDataDefinedXComboBox->addItem( layerFields[idx].name(), idx );
193-
mDataDefinedYComboBox->addItem( layerFields[idx].name(), idx );
194-
mDataDefinedVisibilityComboBox->addItem( layerFields[idx].name(), idx );
192+
mDataDefinedXComboBox->addItem( layerFields.at( idx ).name(), idx );
193+
mDataDefinedYComboBox->addItem( layerFields.at( idx ).name(), idx );
194+
mDataDefinedVisibilityComboBox->addItem( layerFields.at( idx ).name(), idx );
195195
}
196196

197197
const QgsDiagramRendererV2* dr = layer->diagramRenderer();

src/app/qgsfieldcalculator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void QgsFieldCalculator::accept()
234234

235235
for ( int idx = 0; idx < fields.count(); ++idx )
236236
{
237-
if ( fields[idx].name() == mOutputFieldNameLineEdit->text() )
237+
if ( fields.at( idx ).name() == mOutputFieldNameLineEdit->text() )
238238
{
239239
mAttributeId = idx;
240240
break;

src/app/qgsfieldsproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ void QgsFieldsProperties::attributeAdded( int idx )
576576
const QgsFields &fields = mLayer->fields();
577577
int row = mFieldsList->rowCount();
578578
mFieldsList->insertRow( row );
579-
setRow( row, idx, fields[idx] );
579+
setRow( row, idx, fields.at( idx ) );
580580
mFieldsList->setCurrentCell( row, idx );
581581

582582
for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )

src/app/qgsidentifyresultsdialog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
493493
featItem->addChild( attrItem );
494494

495495
attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
496-
attrItem->setData( 0, Qt::UserRole, fields[i].name() );
496+
attrItem->setData( 0, Qt::UserRole, fields.at( i ).name() );
497497
attrItem->setData( 0, Qt::UserRole + 1, i );
498498

499499
attrItem->setData( 1, Qt::UserRole, value );
@@ -515,7 +515,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
515515
attrItem->treeWidget()->setItemWidget( attrItem, 1, nullptr );
516516
}
517517

518-
if ( fields[i].name() == vlayer->displayField() )
518+
if ( fields.at( i ).name() == vlayer->displayField() )
519519
{
520520
featItem->setText( 0, attrItem->text( 0 ) );
521521
featItem->setText( 1, attrItem->text( 1 ) );
@@ -560,11 +560,11 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
560560
tblResults->setItem( j, 1, item );
561561

562562
item = new QTableWidgetItem( QString::number( i ) );
563-
if ( fields[i].name() == vlayer->displayField() )
563+
if ( fields.at( i ).name() == vlayer->displayField() )
564564
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) + " *" );
565565
else
566566
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
567-
item->setData( Qt::UserRole, fields[i].name() );
567+
item->setData( Qt::UserRole, fields.at( i ).name() );
568568
item->setData( Qt::UserRole + 1, i );
569569
tblResults->setItem( j, 2, item );
570570

@@ -765,7 +765,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
765765

766766
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << attrs.at( i ).toString() );
767767

768-
attrItem->setData( 0, Qt::DisplayRole, fields[i].name() );
768+
attrItem->setData( 0, Qt::DisplayRole, fields.at( i ).name() );
769769

770770
QVariant value = attrs.at( i );
771771
attrItem->setData( 1, Qt::DisplayRole, value );
@@ -1188,7 +1188,7 @@ void QgsIdentifyResultsDialog::doAction( QTreeWidgetItem *item, int action )
11881188
const QgsFields& fields = layer->fields();
11891189
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
11901190
{
1191-
if ( fields[fldIdx].name() == fieldName )
1191+
if ( fields.at( fldIdx ).name() == fieldName )
11921192
{
11931193
idx = fldIdx;
11941194
break;
@@ -1741,7 +1741,7 @@ void QgsIdentifyResultsDialog::copyFeatureAttributes()
17411741
if ( attrIdx < 0 || attrIdx >= fields.count() )
17421742
continue;
17431743

1744-
text += QString( "%1: %2\n" ).arg( fields[attrIdx].name(), it.value().toString() );
1744+
text += QString( "%1: %2\n" ).arg( fields.at( attrIdx ).name(), it.value().toString() );
17451745
}
17461746
}
17471747
else if ( rlayer )

src/app/qgslabelpropertydialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void QgsLabelPropertyDialog::init( const QString& layerId, const QString& provid
103103
{
104104
mLabelTextLineEdit->setText( attributeValues.at( mCurLabelField ).toString() );
105105
const QgsFields& layerFields = vlayer->fields();
106-
switch ( layerFields[mCurLabelField].type() )
106+
switch ( layerFields.at( mCurLabelField ).type() )
107107
{
108108
case QVariant::Double:
109109
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );

src/app/qgsmergeattributesdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ QVariant QgsMergeAttributesDialog::calcStatistic( int col, QgsStatisticalSummary
358358

359359
if ( values.isEmpty() )
360360
{
361-
return QVariant( mVectorLayer->fields()[col].type() );
361+
return QVariant( mVectorLayer->fields().at( col ).type() );
362362
}
363363

364364
summary.calculate( values );

src/core/composer/qgscomposerattributetable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void QgsComposerAttributeTable::setDisplayAttributes( const QSet<int>& attr, boo
241241
}
242242
QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
243243
QgsComposerTableColumn* col = new QgsComposerTableColumn;
244-
col->setAttribute( fields[attrIdx].name() );
244+
col->setAttribute( fields.at( attrIdx ).name() );
245245
col->setHeading( currentAlias );
246246
mColumns.append( col );
247247
}
@@ -652,7 +652,7 @@ bool QgsComposerAttributeTable::readXml( const QDomElement& itemElem, const QDom
652652
//find corresponding column
653653
Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
654654
{
655-
if ( column->attribute() == fields[attribute].name() )
655+
if ( column->attribute() == fields.at( attribute ).name() )
656656
{
657657
column->setSortByRank( i + 1 );
658658
column->setSortOrder( order );

src/core/composer/qgscomposerattributetablev2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void QgsComposerAttributeTableV2::setDisplayAttributes( const QSet<int>& attr, b
338338
}
339339
QString currentAlias = source->attributeDisplayName( attrIdx );
340340
QgsComposerTableColumn* col = new QgsComposerTableColumn;
341-
col->setAttribute( fields[attrIdx].name() );
341+
col->setAttribute( fields.at( attrIdx ).name() );
342342
col->setHeading( currentAlias );
343343
mColumns.append( col );
344344
}

src/core/diagram/qgsdiagram.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ void QgsDiagram::clearCache()
4545
mExpressions.clear();
4646
}
4747

48-
QgsExpression* QgsDiagram::getExpression( const QString& expression, const QgsFields* fields )
49-
{
50-
Q_NOWARN_DEPRECATED_PUSH
51-
if ( !mExpressions.contains( expression ) )
52-
{
53-
QgsExpression* expr = new QgsExpression( expression );
54-
expr->prepare( *fields );
55-
mExpressions[expression] = expr;
56-
}
57-
return mExpressions[expression];
58-
Q_NOWARN_DEPRECATED_POP
59-
}
60-
6148
QgsExpression *QgsDiagram::getExpression( const QString &expression, const QgsExpressionContext &context )
6249
{
6350
if ( !mExpressions.contains( expression ) )

src/core/diagram/qgsdiagram.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class CORE_EXPORT QgsDiagram
4242

4343
void clearCache();
4444

45-
//! @deprecated use QgsExpressionContext variant instead
46-
Q_DECL_DEPRECATED QgsExpression* getExpression( const QString& expression, const QgsFields* fields );
47-
4845
/** Returns a prepared expression for the specified context.
4946
* @param expression expression string
5047
* @param context expression context

0 commit comments

Comments
 (0)