Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #4535 from boundlessgeo/attributetable-fixes-16492
Attributetable fixes  crash #16492
  • Loading branch information
elpaso committed May 12, 2017
2 parents a0c6872 + 5134791 commit 3f9c4e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -1844,7 +1844,7 @@ Is emitted, before changes are rolled back
%Docstring
Emitted when a feature has been deleted.

If you do expensive operations in a slot connected to this, you should prever to use
If you do expensive operations in a slot connected to this, you should prefer to use
featuresDeleted( const QgsFeatureIds& ).

\param fid The id of the feature which has been deleted
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -1710,7 +1710,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
/**
* Emitted when a feature has been deleted.
*
* If you do expensive operations in a slot connected to this, you should prever to use
* If you do expensive operations in a slot connected to this, you should prefer to use
* featuresDeleted( const QgsFeatureIds& ).
*
* \param fid The id of the feature which has been deleted
Expand Down
15 changes: 12 additions & 3 deletions src/gui/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -97,9 +97,18 @@ void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemMode

if ( ( oldValue != newValue && newValue.isValid() ) || oldValue.isNull() != newValue.isNull() )
{
vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, newValue, oldValue );
vl->endEditCommand();
// This fixes https://issues.qgis.org/issues/16492
QgsFeatureRequest request( fid );
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setSubsetOfAttributes( QgsAttributeList( ) );
QgsFeature feature;
vl->getFeatures( request ).nextFeature( feature );
if ( feature.isValid( ) )
{
vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, newValue, oldValue );
vl->endEditCommand();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/src/app/testqgsattributetable.cpp
Expand Up @@ -251,6 +251,7 @@ void TestQgsAttributeTable::testSelected()

void TestQgsAttributeTable::testRegression15974()
{
// Test duplicated rows in attribute table + two crashes.
QString path = QDir::tempPath() + "/testshp15974.shp";
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QStringLiteral( "polygon?crs=epsg:4326&field=id:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
QVERIFY( tempLayer->isValid() );
Expand Down Expand Up @@ -281,5 +282,6 @@ void TestQgsAttributeTable::testRegression15974()
QCOMPARE( dlg->mMainView->filteredFeatureCount( ), 3 );
}


QGSTEST_MAIN( TestQgsAttributeTable )
#include "testqgsattributetable.moc"

0 comments on commit 3f9c4e5

Please sign in to comment.