Skip to content
Permalink
Browse files
* speed up undo of attribute added with field calculator (fixes #9509)
* also improves performance of FilterFid requests in edit mode
  • Loading branch information
jef-n committed Feb 12, 2014
1 parent a646101 commit 5bee17218db3576a6a172eec5ef6d555fc023b4d
@@ -176,6 +176,11 @@ void QgsFieldCalculator::accept()
bool useGeometry = exp.needsGeometry();
int rownum = 1;

bool newField = !mUpdateExistingGroupBox->isChecked();
QVariant emptyAttribute;
if( newField )
emptyAttribute = QVariant( mVectorLayer->pendingFields()[mAttributeId].type() );

QgsFeatureIterator fit = mVectorLayer->getFeatures( QgsFeatureRequest().setFlags( useGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
while ( fit.nextFeature( feature ) )
{
@@ -197,7 +202,7 @@ void QgsFieldCalculator::accept()
}
else
{
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value, feature.attributes().value( mAttributeId ) );
mVectorLayer->changeAttributeValue( feature.id(), mAttributeId, value, newField ? emptyAttribute : feature.attributes().value( mAttributeId ) );
}

rownum++;
@@ -1490,7 +1490,7 @@ void QgsComposition::updateZValues( bool addUndoCommands )
QLinkedList<QgsComposerItem*>::iterator it = mItemZList.begin();
QgsComposerItem* currentItem = 0;

QUndoCommand* parentCommand;
QUndoCommand* parentCommand = 0;
if ( addUndoCommands )
{
parentCommand = new QUndoCommand( tr( "Item z-order changed" ) );
@@ -1500,7 +1500,7 @@ void QgsComposition::updateZValues( bool addUndoCommands )
currentItem = *it;
if ( currentItem )
{
QgsComposerItemCommand* subcommand;
QgsComposerItemCommand* subcommand = 0;
if ( addUndoCommands )
{
subcommand = new QgsComposerItemCommand( *it, "", parentCommand );
@@ -31,13 +31,35 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayer* la

if ( L->editBuffer() )
{
mAddedFeatures = QgsFeatureMap( L->editBuffer()->addedFeatures() );
mChangedGeometries = QgsGeometryMap( L->editBuffer()->changedGeometries() );
mDeletedFeatureIds = QgsFeatureIds( L->editBuffer()->deletedFeatureIds() );
mChangedAttributeValues = QgsChangedAttributesMap( L->editBuffer()->changedAttributeValues() );
if ( request.filterType() == QgsFeatureRequest::FilterFid )
{
// only copy relevant parts
if( L->editBuffer()->addedFeatures().contains( request.filterFid() ) )
mAddedFeatures.insert( request.filterFid(), L->editBuffer()->addedFeatures()[ request.filterFid() ] );

if( L->editBuffer()->changedGeometries().contains( request.filterFid() ) )
mChangedGeometries.insert( request.filterFid(), L->editBuffer()->changedGeometries()[ request.filterFid() ] );

if( L->editBuffer()->deletedFeatureIds().contains( request.filterFid() ) )
mDeletedFeatureIds.insert( request.filterFid() );

if( L->editBuffer()->changedAttributeValues().contains( request.filterFid() ) )
mChangedAttributeValues.insert( request.filterFid(), L->editBuffer()->changedAttributeValues()[ request.filterFid() ] );

if( L->editBuffer()->changedAttributeValues().contains( request.filterFid() ) )
mChangedFeaturesRequest.setFilterFids( QgsFeatureIds() << request.filterFid() );
}
else
{
mAddedFeatures = QgsFeatureMap( L->editBuffer()->addedFeatures() );
mChangedGeometries = QgsGeometryMap( L->editBuffer()->changedGeometries() );
mDeletedFeatureIds = QgsFeatureIds( L->editBuffer()->deletedFeatureIds() );
mChangedAttributeValues = QgsChangedAttributesMap( L->editBuffer()->changedAttributeValues() );
mChangedFeaturesRequest.setFilterFids( L->editBuffer()->changedAttributeValues().keys().toSet() );
}

mAddedAttributes = QList<QgsField>( L->editBuffer()->addedAttributes() );
mDeletedAttributeIds = QgsAttributeList( L->editBuffer()->deletedAttributeIds() );
mChangedFeaturesRequest.setFilterFids( L->editBuffer()->changedAttributeValues().keys().toSet() );
}

// prepare joins: may add more attributes to fetch (in order to allow join)

0 comments on commit 5bee172

Please sign in to comment.