From d393d268e1069dfea2cba0f74b994790d92bc2c1 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 20 May 2015 21:43:53 +1000 Subject: [PATCH] Fix up non-const getters for attributes and geometry in QgsFeature (preparation for implicit sharing) --- python/core/qgsfeature.sip | 22 ++++++++++++++----- src/app/qgisapp.cpp | 4 ++-- src/app/qgsclipboard.cpp | 2 +- src/app/qgsfeatureaction.cpp | 2 +- src/app/qgsidentifyresultsdialog.cpp | 4 ++-- src/app/qgslabelpropertydialog.cpp | 2 +- src/app/qgsmaptoollabel.cpp | 2 +- src/app/qgsmergeattributesdialog.cpp | 2 +- src/core/qgsfeature.cpp | 10 +++++---- src/core/qgsfeature.h | 21 +++++++++++++----- src/core/qgsvectordataprovider.cpp | 2 +- src/core/qgsvectorlayer.cpp | 4 ++-- src/core/qgsvectorlayereditbuffer.cpp | 10 ++++++--- src/core/qgsvectorlayerfeatureiterator.cpp | 9 +++++--- src/core/qgsvectorlayerimport.cpp | 2 +- src/core/qgsvectorlayerjoinbuffer.cpp | 2 +- .../qgscategorizedsymbolrendererv2.cpp | 2 +- .../qgsgraduatedsymbolrendererv2.cpp | 2 +- src/core/symbology-ng/qgsheatmaprenderer.cpp | 2 +- .../qgspointdisplacementrenderer.cpp | 2 +- src/gui/qgsformannotationitem.cpp | 2 +- .../evisgenericeventbrowsergui.cpp | 8 +++---- src/plugins/grass/qgsgrassmodule.cpp | 2 +- src/plugins/roadgraph/speedproperter.cpp | 2 +- src/providers/gpx/qgsgpxprovider.cpp | 2 +- src/providers/grass/qgis.v.in.cpp | 4 +++- src/providers/memory/qgsmemoryprovider.cpp | 8 +++++-- src/providers/mssql/qgsmssqlprovider.cpp | 2 +- src/providers/ogr/qgsogrprovider.cpp | 2 +- src/providers/oracle/qgsoracleprovider.cpp | 8 +++---- .../postgres/qgspostgresprovider.cpp | 8 +++---- .../spatialite/qgsspatialiteprovider.cpp | 4 ++-- tests/src/core/testqgsfeature.cpp | 2 +- 33 files changed, 100 insertions(+), 62 deletions(-) diff --git a/python/core/qgsfeature.sip b/python/core/qgsfeature.sip index 7b39a1333b1..0d6cb63657c 100644 --- a/python/core/qgsfeature.sip +++ b/python/core/qgsfeature.sip @@ -241,8 +241,8 @@ class QgsFeature */ void setFeatureId( qint64 id ); - const QgsAttributes& attributes() const; - //QgsAttributes& attributes(); + QgsAttributes attributes() const; + void setAttributes( const QgsAttributes& attrs ); /** @@ -312,26 +312,36 @@ class QgsFeature /** * Get the geometry object associated with this feature + * + * It is possible to modify the geometry in place but this will + * be removed in 3.0 and therefore @link setGeometry @endlink should be called explicitly. + * + * @note will be modified to return by value in QGIS 3.0: `QgsGeometry geometry() const;` */ - QgsGeometry* geometry() const; + QgsGeometry* geometry(); - /** Gets a const pointer to the geometry object associated with this feature + /** Gets a const pointer to the geometry object associated with this feature. + * @note this is a temporary method for 2.x release cycle. Will be removed in QGIS 3.0. * @note added in QGIS 2.9 + * @note will be removed in QGIS 3.0 */ const QgsGeometry* constGeometry() const; /** * Get the geometry object associated with this feature * The caller assumes responsibility for the QgsGeometry*'s destruction. + * @deprecated will be removed in QGIS 3.0 */ - QgsGeometry *geometryAndOwnership() /Factory/; + QgsGeometry *geometryAndOwnership() /Factory,Deprecated/; /** Set this feature's geometry from another QgsGeometry object (deep copy) */ void setGeometry( const QgsGeometry& geom ); /** Set this feature's geometry (takes geometry ownership) + * * @note not available in python bindings + * @deprecated will be removed in QGIS 3.0 */ // void setGeometry( QgsGeometry* geom /Transfer/ ); @@ -339,6 +349,8 @@ class QgsFeature * Set this feature's geometry from WKB * * This feature assumes responsibility for destroying geom. + * + * @deprecated will be removed in QGIS 3.0 */ void setGeometryAndOwnership( unsigned char * geom /Transfer/, size_t length ); diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 7e734a1c7b6..9688a01d8f2 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -5916,7 +5916,7 @@ void QgisApp::mergeAttributesOfSelectedFeatures() vl->beginEditCommand( tr( "Merged feature attributes" ) ); - const QgsAttributes &merged = d.mergedAttributes(); + QgsAttributes merged = d.mergedAttributes(); foreach ( QgsFeatureId fid, vl->selectedFeaturesIds() ) { @@ -6232,7 +6232,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer ) QgsFeatureList::iterator featureIt = features.begin(); while ( featureIt != features.end() ) { - const QgsAttributes &srcAttr = featureIt->attributes(); + QgsAttributes srcAttr = featureIt->attributes(); QgsAttributes dstAttr( dstAttrCount ); for ( int src = 0; src < srcAttr.count(); ++src ) diff --git a/src/app/qgsclipboard.cpp b/src/app/qgsclipboard.cpp index cb659482a65..f8a34a3c21e 100644 --- a/src/app/qgsclipboard.cpp +++ b/src/app/qgsclipboard.cpp @@ -99,7 +99,7 @@ void QgsClipboard::setSystemClipboard() // then the field contents for ( QgsFeatureList::iterator it = mFeatureClipboard.begin(); it != mFeatureClipboard.end(); ++it ) { - const QgsAttributes& attributes = it->attributes(); + QgsAttributes attributes = it->attributes(); // TODO: Set up Paste Transformations to specify the order in which fields are added. if ( copyWKT ) diff --git a/src/app/qgsfeatureaction.cpp b/src/app/qgsfeatureaction.cpp index 261f899dede..d181cba5a1e 100644 --- a/src/app/qgsfeatureaction.cpp +++ b/src/app/qgsfeatureaction.cpp @@ -229,7 +229,7 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature ) QgsFields fields = mLayer->pendingFields(); for ( int idx = 0; idx < fields.count(); ++idx ) { - const QgsAttributes &newValues = feature.attributes(); + QgsAttributes newValues = feature.attributes(); QgsAttributeMap origValues = sLastUsedValues[ mLayer ]; if ( origValues[idx] != newValues[idx] ) { diff --git a/src/app/qgsidentifyresultsdialog.cpp b/src/app/qgsidentifyresultsdialog.cpp index dc50eda9adb..8128fb5e94f 100644 --- a/src/app/qgsidentifyresultsdialog.cpp +++ b/src/app/qgsidentifyresultsdialog.cpp @@ -455,7 +455,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat } const QgsFields &fields = vlayer->pendingFields(); - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); bool featureLabeled = false; for ( int i = 0; i < attrs.count(); ++i ) { @@ -719,7 +719,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer, if ( feature.isValid() ) { QgsDebugMsg( QString( "fields size = %1 attributes size = %2" ).arg( fields.size() ).arg( feature.attributes().size() ) ); - const QgsAttributes& attrs = feature.attributes(); + QgsAttributes attrs = feature.attributes(); for ( int i = 0; i < attrs.count(); ++i ) { if ( i >= fields.count() ) diff --git a/src/app/qgslabelpropertydialog.cpp b/src/app/qgslabelpropertydialog.cpp index 09f787b8429..7a7d2433f12 100644 --- a/src/app/qgslabelpropertydialog.cpp +++ b/src/app/qgslabelpropertydialog.cpp @@ -69,7 +69,7 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const { return; } - const QgsAttributes& attributeValues = mCurLabelFeat.attributes(); + QgsAttributes attributeValues = mCurLabelFeat.attributes(); //get layerproperties. Problem: only for pallabeling... diff --git a/src/app/qgsmaptoollabel.cpp b/src/app/qgsmaptoollabel.cpp index fb35498fc9b..335db536bba 100644 --- a/src/app/qgsmaptoollabel.cpp +++ b/src/app/qgsmaptoollabel.cpp @@ -483,7 +483,7 @@ bool QgsMapToolLabel::dataDefinedPosition( QgsVectorLayer* vlayer, const QgsFeat return false; } - const QgsAttributes& attributes = f.attributes(); + QgsAttributes attributes = f.attributes(); if ( !attributes[xCol].isNull() ) x = attributes[xCol].toDouble( &xSuccess ); if ( !attributes[yCol].isNull() ) diff --git a/src/app/qgsmergeattributesdialog.cpp b/src/app/qgsmergeattributesdialog.cpp index 6067ad25038..e4f338b2717 100644 --- a/src/app/qgsmergeattributesdialog.cpp +++ b/src/app/qgsmergeattributesdialog.cpp @@ -119,7 +119,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents() { verticalHeaderLabels << FID_TO_STRING( mFeatureList[i].id() ); - const QgsAttributes &attrs = mFeatureList[i].attributes(); + QgsAttributes attrs = mFeatureList[i].attributes(); for ( int j = 0; j < mTableWidget->columnCount(); j++ ) { diff --git a/src/core/qgsfeature.cpp b/src/core/qgsfeature.cpp index 6af7c771910..d3b28b9c1cd 100644 --- a/src/core/qgsfeature.cpp +++ b/src/core/qgsfeature.cpp @@ -109,7 +109,7 @@ void QgsFeature::deleteAttribute( int field ) } -QgsGeometry *QgsFeature::geometry() const +QgsGeometry *QgsFeature::geometry() { return mGeometry; } @@ -257,9 +257,9 @@ QDataStream& operator<<( QDataStream& out, const QgsFeature& feature ) { out << feature.id(); out << feature.attributes(); - if ( feature.geometry() ) + if ( feature.constGeometry() ) { - out << *( feature.geometry() ); + out << *( feature.constGeometry() ); } else { @@ -275,9 +275,11 @@ QDataStream& operator>>( QDataStream& in, QgsFeature& feature ) QgsFeatureId id; QgsGeometry* geometry = new QgsGeometry(); bool valid; - in >> id >> feature.attributes() >> *geometry >> valid; + QgsAttributes attr; + in >> id >> attr >> *geometry >> valid; feature.setFeatureId( id ); feature.setGeometry( geometry ); + feature.setAttributes( attr ); feature.setValid( valid ); return in; } diff --git a/src/core/qgsfeature.h b/src/core/qgsfeature.h index 371e1e413fc..cd7cbd82149 100644 --- a/src/core/qgsfeature.h +++ b/src/core/qgsfeature.h @@ -144,8 +144,7 @@ class CORE_EXPORT QgsFeature */ void setFeatureId( QgsFeatureId id ); - const QgsAttributes& attributes() const { return mAttributes; } - QgsAttributes& attributes() { return mAttributes; } + QgsAttributes attributes() const { return mAttributes; } void setAttributes( const QgsAttributes& attrs ) { mAttributes = attrs; } /** @@ -189,26 +188,36 @@ class CORE_EXPORT QgsFeature /** * Get the geometry object associated with this feature + * + * It is possible to modify the geometry in place but this will + * be removed in 3.0 and therefore @link setGeometry @endlink should be called explicitly. + * + * @note will be modified to return by value in QGIS 3.0: `QgsGeometry geometry() const;` */ - QgsGeometry* geometry() const; + QgsGeometry* geometry(); - /** Gets a const pointer to the geometry object associated with this feature + /** Gets a const pointer to the geometry object associated with this feature. + * @note this is a temporary method for 2.x release cycle. Will be removed in QGIS 3.0. * @note added in QGIS 2.9 + * @note will be removed in QGIS 3.0 */ const QgsGeometry* constGeometry() const; /** * Get the geometry object associated with this feature * The caller assumes responsibility for the QgsGeometry*'s destruction. + * @deprecated will be removed in QGIS 3.0 */ - QgsGeometry *geometryAndOwnership(); + Q_DECL_DEPRECATED QgsGeometry *geometryAndOwnership(); /** Set this feature's geometry from another QgsGeometry object (deep copy) */ void setGeometry( const QgsGeometry& geom ); /** Set this feature's geometry (takes geometry ownership) + * * @note not available in python bindings + * @deprecated will be removed in QGIS 3.0 */ void setGeometry( QgsGeometry* geom ); @@ -216,6 +225,8 @@ class CORE_EXPORT QgsFeature * Set this feature's geometry from WKB * * This feature assumes responsibility for destroying geom. + * + * @deprecated will be removed in QGIS 3.0 */ void setGeometryAndOwnership( unsigned char * geom, size_t length ); diff --git a/src/core/qgsvectordataprovider.cpp b/src/core/qgsvectordataprovider.cpp index a0a307abd9e..00d9908d824 100644 --- a/src/core/qgsvectordataprovider.cpp +++ b/src/core/qgsvectordataprovider.cpp @@ -407,7 +407,7 @@ void QgsVectorDataProvider::fillMinMaxCache() while ( fi.nextFeature( f ) ) { - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it ) { const QVariant& varValue = attrs[*it]; diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 769f2a2ed18..4caf6b993c1 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -980,8 +980,8 @@ bool QgsVectorLayer::updateFeature( QgsFeature &f ) } } - const QgsAttributes &fa = f.attributes(); - const QgsAttributes &ca = current.attributes(); + QgsAttributes fa = f.attributes(); + QgsAttributes ca = current.attributes(); for ( int attr = 0; attr < fa.count(); ++attr ) { diff --git a/src/core/qgsvectorlayereditbuffer.cpp b/src/core/qgsvectorlayereditbuffer.cpp index 00b4095e5b2..96c6e65b402 100644 --- a/src/core/qgsvectorlayereditbuffer.cpp +++ b/src/core/qgsvectorlayereditbuffer.cpp @@ -84,7 +84,7 @@ void QgsVectorLayerEditBuffer::updateFeatureGeometry( QgsFeature &f ) void QgsVectorLayerEditBuffer::updateChangedAttributes( QgsFeature &f ) { - QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); // remove all attributes that will disappear - from higher indices to lower for ( int idx = mDeletedAttributeIds.count() - 1; idx >= 0; --idx ) @@ -102,6 +102,8 @@ void QgsVectorLayerEditBuffer::updateChangedAttributes( QgsFeature &f ) for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it ) attrs[it.key()] = it.value(); } + + f.setAttributes( attrs ); } @@ -579,8 +581,9 @@ void QgsVectorLayerEditBuffer::handleAttributeAdded( int index ) QgsFeatureMap::iterator featureIt = mAddedFeatures.begin(); for ( ; featureIt != mAddedFeatures.end(); ++featureIt ) { - QgsAttributes& attrs = featureIt->attributes(); + QgsAttributes attrs = featureIt->attributes(); attrs.insert( index, QVariant() ); + featureIt->setAttributes( attrs ); } } @@ -602,8 +605,9 @@ void QgsVectorLayerEditBuffer::handleAttributeDeleted( int index ) QgsFeatureMap::iterator featureIt = mAddedFeatures.begin(); for ( ; featureIt != mAddedFeatures.end(); ++featureIt ) { - QgsAttributes& attrs = featureIt->attributes(); + QgsAttributes attrs = featureIt->attributes(); attrs.remove( index ); + featureIt->setAttributes( attrs ); } } diff --git a/src/core/qgsvectorlayerfeatureiterator.cpp b/src/core/qgsvectorlayerfeatureiterator.cpp index da4cab612d4..e3b63041224 100644 --- a/src/core/qgsvectorlayerfeatureiterator.cpp +++ b/src/core/qgsvectorlayerfeatureiterator.cpp @@ -547,7 +547,9 @@ void QgsVectorLayerFeatureIterator::addJoinedAttributes( QgsFeature &f ) void QgsVectorLayerFeatureIterator::addVirtualAttributes( QgsFeature& f ) { // make sure we have space for newly added attributes - f.attributes().resize( mSource->mFields.count() ); // Provider attrs count + joined attrs count + expression attrs count + QgsAttributes attr = f.attributes(); + attr.resize( mSource->mFields.count() ); // Provider attrs count + joined attrs count + expression attrs count + f.setAttributes( attr ); if ( !mFetchJoinInfo.isEmpty() ) addJoinedAttributes( f ); @@ -684,7 +686,7 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg if ( fi.nextFeature( fet ) ) { int index = indexOffset; - const QgsAttributes& attr = fet.attributes(); + QgsAttributes attr = fet.attributes(); if ( hasSubset ) { for ( int i = 0; i < subsetIndices.count(); ++i ) @@ -756,7 +758,7 @@ bool QgsVectorLayerFeatureIterator::nextFeatureFid( QgsFeature& f ) void QgsVectorLayerFeatureIterator::updateChangedAttributes( QgsFeature &f ) { - QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); // remove all attributes that will disappear - from higher indices to lower for ( int idx = mSource->mDeletedAttributeIds.count() - 1; idx >= 0; --idx ) @@ -774,6 +776,7 @@ void QgsVectorLayerFeatureIterator::updateChangedAttributes( QgsFeature &f ) for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it ) attrs[it.key()] = it.value(); } + f.setAttributes( attrs ); } void QgsVectorLayerFeatureIterator::updateFeatureGeometry( QgsFeature &f ) diff --git a/src/core/qgsvectorlayerimport.cpp b/src/core/qgsvectorlayerimport.cpp index ead8c8d8ef1..cbc6c09d260 100644 --- a/src/core/qgsvectorlayerimport.cpp +++ b/src/core/qgsvectorlayerimport.cpp @@ -133,7 +133,7 @@ QString QgsVectorLayerImport::errorMessage() bool QgsVectorLayerImport::addFeature( QgsFeature& feat ) { - const QgsAttributes &attrs = feat.attributes(); + QgsAttributes attrs = feat.attributes(); QgsFeature newFeat; if ( feat.constGeometry() ) diff --git a/src/core/qgsvectorlayerjoinbuffer.cpp b/src/core/qgsvectorlayerjoinbuffer.cpp index 23082994e3f..93923ca08fa 100644 --- a/src/core/qgsvectorlayerjoinbuffer.cpp +++ b/src/core/qgsvectorlayerjoinbuffer.cpp @@ -152,7 +152,7 @@ void QgsVectorLayerJoinBuffer::cacheJoinLayer( QgsVectorJoinInfo& joinInfo ) QgsFeature f; while ( fit.nextFeature( f ) ) { - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); QString key = attrs[joinFieldIndex].toString(); if ( hasSubset ) { diff --git a/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp b/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp index 8ab5d14bb5a..3b3e5ddec93 100644 --- a/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp +++ b/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp @@ -237,7 +237,7 @@ QgsSymbolV2* QgsCategorizedSymbolRendererV2::symbolForFeature( QgsFeature& featu QgsSymbolV2* QgsCategorizedSymbolRendererV2::originalSymbolForFeature( QgsFeature& feature ) { - const QgsAttributes& attrs = feature.attributes(); + QgsAttributes attrs = feature.attributes(); QVariant value; if ( mAttrNum == -1 ) { diff --git a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp index ed631cae811..feaa6c1526d 100644 --- a/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp +++ b/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp @@ -350,7 +350,7 @@ QgsSymbolV2* QgsGraduatedSymbolRendererV2::symbolForFeature( QgsFeature& feature QgsSymbolV2* QgsGraduatedSymbolRendererV2::originalSymbolForFeature( QgsFeature& feature ) { - const QgsAttributes& attrs = feature.attributes(); + QgsAttributes attrs = feature.attributes(); QVariant value; if ( mAttrNum < 0 || mAttrNum >= attrs.count() ) { diff --git a/src/core/symbology-ng/qgsheatmaprenderer.cpp b/src/core/symbology-ng/qgsheatmaprenderer.cpp index 2ebbc6041fa..65c46b0d6ac 100644 --- a/src/core/symbology-ng/qgsheatmaprenderer.cpp +++ b/src/core/symbology-ng/qgsheatmaprenderer.cpp @@ -125,7 +125,7 @@ bool QgsHeatmapRenderer::renderFeature( QgsFeature& feature, QgsRenderContext& c } else { - const QgsAttributes& attrs = feature.attributes(); + QgsAttributes attrs = feature.attributes(); value = attrs.value( mWeightAttrNum ); } bool ok = false; diff --git a/src/core/symbology-ng/qgspointdisplacementrenderer.cpp b/src/core/symbology-ng/qgspointdisplacementrenderer.cpp index c53bc383353..fc157b5f573 100644 --- a/src/core/symbology-ng/qgspointdisplacementrenderer.cpp +++ b/src/core/symbology-ng/qgspointdisplacementrenderer.cpp @@ -435,7 +435,7 @@ void QgsPointDisplacementRenderer::printInfoDisplacementGroups() QString QgsPointDisplacementRenderer::getLabel( const QgsFeature& f ) { QString attribute; - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); if ( mLabelIndex >= 0 && mLabelIndex < attrs.count() ) { attribute = attrs[mLabelIndex].toString(); diff --git a/src/gui/qgsformannotationitem.cpp b/src/gui/qgsformannotationitem.cpp index 923f905eb9c..3507caeda60 100644 --- a/src/gui/qgsformannotationitem.cpp +++ b/src/gui/qgsformannotationitem.cpp @@ -94,7 +94,7 @@ QWidget* QgsFormAnnotationItem::createDesignerWidget( const QString& filePath ) if ( mVectorLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeature ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) ) { const QgsFields& fields = mVectorLayer->pendingFields(); - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); for ( int i = 0; i < attrs.count(); ++i ) { if ( i < fields.count() ) diff --git a/src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp b/src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp index 008fbde10f9..50b295264d3 100644 --- a/src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp +++ b/src/plugins/evis/eventbrowser/evisgenericeventbrowsergui.cpp @@ -595,7 +595,7 @@ void eVisGenericEventBrowserGui::loadRecord() QString myCompassOffsetField = cboxCompassOffsetField->currentText(); QString myEventImagePathField = cboxEventImagePathField->currentText(); const QgsFields& myFields = mDataProvider->fields(); - const QgsAttributes& myAttrs = myFeature->attributes(); + QgsAttributes myAttrs = myFeature->attributes(); //loop through the attributes and display their contents for ( int i = 0; i < myAttrs.count(); ++i ) { @@ -842,7 +842,7 @@ void eVisGenericEventBrowserGui::on_cboxEventImagePathField_currentIndexChanged( if ( 0 == myFeature ) return; - const QgsAttributes& myAttrs = myFeature->attributes(); + QgsAttributes myAttrs = myFeature->attributes(); for ( int i = 0 ; i < myAttrs.count(); ++i ) { if ( myFields[i].name() == cboxEventImagePathField->currentText() ) @@ -870,7 +870,7 @@ void eVisGenericEventBrowserGui::on_cboxCompassBearingField_currentIndexChanged( if ( 0 == myFeature ) return; - const QgsAttributes& myAttrs = myFeature->attributes(); + QgsAttributes myAttrs = myFeature->attributes(); for ( int i = 0; i < myAttrs.count(); ++i ) { if ( myFields[i].name() == cboxCompassBearingField->currentText() ) @@ -898,7 +898,7 @@ void eVisGenericEventBrowserGui::on_cboxCompassOffsetField_currentIndexChanged( if ( 0 == myFeature ) return; - const QgsAttributes& myAttrs = myFeature->attributes(); + QgsAttributes myAttrs = myFeature->attributes(); for ( int i = 0; i < myAttrs.count(); ++i ) { if ( myFields[i].name() == cboxCompassOffsetField->currentText() ) diff --git a/src/plugins/grass/qgsgrassmodule.cpp b/src/plugins/grass/qgsgrassmodule.cpp index 9d653485275..ecac7312e5a 100644 --- a/src/plugins/grass/qgsgrassmodule.cpp +++ b/src/plugins/grass/qgsgrassmodule.cpp @@ -3740,7 +3740,7 @@ void QgsGrassModuleSelection::updateSelection() if ( !selected.contains( feature.id() ) ) continue; - const QgsAttributes& attr = feature.attributes(); + QgsAttributes attr = feature.attributes(); if ( attr.size() > keyField ) { if ( i > 0 ) diff --git a/src/plugins/roadgraph/speedproperter.cpp b/src/plugins/roadgraph/speedproperter.cpp index 7ad23198f2a..0576281f558 100644 --- a/src/plugins/roadgraph/speedproperter.cpp +++ b/src/plugins/roadgraph/speedproperter.cpp @@ -21,7 +21,7 @@ RgSpeedProperter::RgSpeedProperter( int attributeId, double defaultValue, double QVariant RgSpeedProperter::property( double distance, const QgsFeature& f ) const { - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); if ( mAttributeId < 0 || mAttributeId >= attrs.count() ) return QVariant( distance / ( mDefaultValue*mToMetricFactor ) ); diff --git a/src/providers/gpx/qgsgpxprovider.cpp b/src/providers/gpx/qgsgpxprovider.cpp index 51536dcf85d..8c68ab69f18 100644 --- a/src/providers/gpx/qgsgpxprovider.cpp +++ b/src/providers/gpx/qgsgpxprovider.cpp @@ -219,7 +219,7 @@ bool QgsGPXProvider::addFeature( QgsFeature& f ) QGis::WkbType wkbType = f.constGeometry()->wkbType(); bool success = false; QgsGPSObject* obj = NULL; - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); QgsAttributeMap::const_iterator it; // is it a waypoint? diff --git a/src/providers/grass/qgis.v.in.cpp b/src/providers/grass/qgis.v.in.cpp index f9bef4774c2..61bdceaf955 100644 --- a/src/providers/grass/qgis.v.in.cpp +++ b/src/providers/grass/qgis.v.in.cpp @@ -295,7 +295,9 @@ int main( int argc, char **argv ) QgsFeature& centroid = centroids[id]; if ( feature.geometry()->contains( centroid.geometry() ) ) { - centroid.attributes().append( feature.id() ); + QgsAttributes attr = centroid.attributes(); + attr.append( feature.id() ); + centroid.setAttributes( attr ); } } } diff --git a/src/providers/memory/qgsmemoryprovider.cpp b/src/providers/memory/qgsmemoryprovider.cpp index 3b2152aaeda..4f4a47854d9 100644 --- a/src/providers/memory/qgsmemoryprovider.cpp +++ b/src/providers/memory/qgsmemoryprovider.cpp @@ -355,7 +355,9 @@ bool QgsMemoryProvider::addAttributes( const QList &attributes ) for ( QgsFeatureMap::iterator fit = mFeatures.begin(); fit != mFeatures.end(); ++fit ) { QgsFeature& f = fit.value(); - f.attributes().append( QVariant() ); + QgsAttributes attr = f.attributes(); + attr.append( QVariant() ); + f.setAttributes( attr ); } } return true; @@ -375,7 +377,9 @@ bool QgsMemoryProvider::deleteAttributes( const QgsAttributeIds& attributes ) for ( QgsFeatureMap::iterator fit = mFeatures.begin(); fit != mFeatures.end(); ++fit ) { QgsFeature& f = fit.value(); - f.attributes().remove( idx ); + QgsAttributes attr = f.attributes(); + attr.remove( idx ); + f.setAttributes( attr ); } } return true; diff --git a/src/providers/mssql/qgsmssqlprovider.cpp b/src/providers/mssql/qgsmssqlprovider.cpp index e6e545bb275..700fba60d64 100644 --- a/src/providers/mssql/qgsmssqlprovider.cpp +++ b/src/providers/mssql/qgsmssqlprovider.cpp @@ -765,7 +765,7 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList & flist ) QSqlQuery query = QSqlQuery( mDatabase ); query.setForwardOnly( true ); - const QgsAttributes& attrs = it->attributes(); + QgsAttributes attrs = it->attributes(); for ( int i = 0; i < attrs.count(); ++i ) { diff --git a/src/providers/ogr/qgsogrprovider.cpp b/src/providers/ogr/qgsogrprovider.cpp index d13c90ec69a..1fde55009bb 100644 --- a/src/providers/ogr/qgsogrprovider.cpp +++ b/src/providers/ogr/qgsogrprovider.cpp @@ -993,7 +993,7 @@ bool QgsOgrProvider::addFeature( QgsFeature& f ) } } - const QgsAttributes& attrs = f.attributes(); + QgsAttributes attrs = f.attributes(); char *oldlocale = setlocale( LC_NUMERIC, NULL ); if ( oldlocale ) diff --git a/src/providers/oracle/qgsoracleprovider.cpp b/src/providers/oracle/qgsoracleprovider.cpp index 5f4c36c2518..f086338e0c8 100644 --- a/src/providers/oracle/qgsoracleprovider.cpp +++ b/src/providers/oracle/qgsoracleprovider.cpp @@ -1203,7 +1203,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist ) } } - const QgsAttributes &attributevec = flist[0].attributes(); + QgsAttributes attributevec = flist[0].attributes(); // look for unique attribute values to place in statement instead of passing as parameter // e.g. for defaults @@ -1226,7 +1226,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist ) int i; for ( i = 1; i < flist.size(); i++ ) { - const QgsAttributes &attributevec = flist[i].attributes(); + QgsAttributes attributevec = flist[i].attributes(); QVariant v2 = attributevec[idx]; if ( !v2.isValid() ) @@ -1283,7 +1283,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist ) for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features ) { - const QgsAttributes &attributevec = features->attributes(); + QgsAttributes attributevec = features->attributes(); QgsDebugMsg( QString( "insert feature %1" ).arg( features->id() ) ); @@ -1340,7 +1340,7 @@ bool QgsOracleProvider::addFeatures( QgsFeatureList &flist ) { for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features ) { - const QgsAttributes &attributevec = features->attributes(); + QgsAttributes attributevec = features->attributes(); if ( mPrimaryKeyType == pktInt ) { diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index 7c0182f76dd..8d21bc4820b 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -1664,7 +1664,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist ) } } - const QgsAttributes &attributevec = flist[0].attributes(); + QgsAttributes attributevec = flist[0].attributes(); // look for unique attribute values to place in statement instead of passing as parameter // e.g. for defaults @@ -1688,7 +1688,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist ) int i; for ( i = 1; i < flist.size(); i++ ) { - const QgsAttributes &attrs2 = flist[i].attributes(); + QgsAttributes attrs2 = flist[i].attributes(); QVariant v2 = attrs2[idx]; if ( v2 != v ) @@ -1768,7 +1768,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist ) for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features ) { - const QgsAttributes &attrs = features->attributes(); + QgsAttributes attrs = features->attributes(); QStringList params; if ( !mGeometryColumn.isNull() ) @@ -1817,7 +1817,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist ) { for ( QgsFeatureList::iterator features = flist.begin(); features != flist.end(); ++features ) { - const QgsAttributes &attrs = features->attributes(); + QgsAttributes attrs = features->attributes(); if ( mPrimaryKeyType == pktInt ) { diff --git a/src/providers/spatialite/qgsspatialiteprovider.cpp b/src/providers/spatialite/qgsspatialiteprovider.cpp index 09c98a5f7e3..96cdec481e1 100644 --- a/src/providers/spatialite/qgsspatialiteprovider.cpp +++ b/src/providers/spatialite/qgsspatialiteprovider.cpp @@ -3549,7 +3549,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist ) if ( flist.size() == 0 ) return true; - const QgsAttributes & attributevec = flist[0].attributes(); + QgsAttributes attributevec = flist[0].attributes(); ret = sqlite3_exec( sqliteHandle, "BEGIN", NULL, NULL, &errMsg ); if ( ret == SQLITE_OK ) @@ -3594,7 +3594,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist ) for ( QgsFeatureList::iterator feature = flist.begin(); feature != flist.end(); ++feature ) { // looping on each feature to insert - const QgsAttributes& attributevec = feature->attributes(); + QgsAttributes attributevec = feature->attributes(); // resetting Prepared Statement and bindings sqlite3_reset( stmt ); diff --git a/tests/src/core/testqgsfeature.cpp b/tests/src/core/testqgsfeature.cpp index 385b913c997..ab6557309d9 100644 --- a/tests/src/core/testqgsfeature.cpp +++ b/tests/src/core/testqgsfeature.cpp @@ -154,7 +154,7 @@ void TestQgsFeature::attributes() //test implicit sharing detachment QgsFeature copy( feature ); QCOMPARE( copy.attributes(), feature.attributes() ); - copy.attributes().clear(); + copy.setAttributes( QgsAttributes() ); QVERIFY( copy.attributes().isEmpty() ); QCOMPARE( feature.attributes(), mAttrs );