Skip to content

Commit

Permalink
fix crash when added features were deleted
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13257 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 6, 2010
1 parent 7c9598e commit e15562b
Showing 1 changed file with 27 additions and 35 deletions.
62 changes: 27 additions & 35 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -70,7 +70,6 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayerundocommand.h"
#include "qgsvectoroverlay.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsclipper.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -365,17 +364,15 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
catch ( QgsCsException &e )
{
Q_UNUSED( e );
QgsLogger::critical( "Error projecting label locations, caught in " + QString( __FILE__ ) + ", line " + QString( __LINE__ ) );
QgsDebugMsg( "Error projecting label locations" );
}

if ( mRendererV2 )
{
mRendererV2->stopRender( rendererContext );
}

#ifdef QGISDEBUG
QgsLogger::debug( "Total features processed", featureCount, 1, __FILE__, __FUNCTION__, __LINE__ );
#endif
QgsDebugMsg( QString( "Total features processed %1" ).arg( featureCount ) );

// XXX Something in our draw event is triggering an additional draw event when resizing [TE 01/26/06]
// XXX Calling this will begin processing the next draw event causing image havoc and recursion crashes.
Expand Down Expand Up @@ -768,10 +765,8 @@ void QgsVectorLayer::drawRendererV2( QgsRenderContext& rendererContext, bool lab
}
catch ( const QgsCsException &cse )
{
QString msg( "Failed to transform a point while drawing a feature of type '"
+ fet.typeName() + "'. Ignoring this feature." );
msg += cse.what();
QgsLogger::warning( msg );
QgsDebugMsg( QString( "Failed to transform a point while drawing a feature of type '%1'. Ignoring this feature. %2" )
.arg( fet.typeName() ).arg( cse.what() ) );
}
#ifndef Q_WS_MAC
++featureCount;
Expand Down Expand Up @@ -898,10 +893,8 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
}
catch ( const QgsCsException &cse )
{
QString msg( "Failed to transform a point while drawing a feature of type '"
+ fet.typeName() + "'. Ignoring this feature." );
msg += cse.what();
QgsLogger::warning( msg );
QgsDebugMsg( QString( "Failed to transform a point while drawing a feature of type '%1'. Ignoring this feature. %2" )
.arg( fet.typeName() ).arg( cse.what() ) );
}
#ifndef Q_WS_MAC
++featureCount;
Expand Down Expand Up @@ -1090,16 +1083,14 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
}
catch ( QgsCsException &cse )
{
QString msg( "Failed to transform a point while drawing a feature of type '"
+ fet.typeName() + "'. Rendering stopped." );
msg += cse.what();
QgsLogger::warning( msg );
QgsDebugMsg( QString( "Failed to transform a point while drawing a feature of type '%1'. Rendering stopped. %2" )
.arg( fet.typeName() ).arg( cse.what() ) );
return false;
}
}
else
{
QgsLogger::warning( "QgsRenderer is null in QgsVectorLayer::draw()" );
QgsDebugMsg( "QgsRenderer is null" );
}

if ( mEditable )
Expand Down Expand Up @@ -1392,18 +1383,18 @@ long QgsVectorLayer::featureCount() const
{
if ( !mDataProvider )
{
QgsLogger::warning( " QgsVectorLayer::featureCount() invoked with null mDataProvider" );
QgsDebugMsg( "invoked with null mDataProvider" );
return 0;
}

return mDataProvider->featureCount();
} // QgsVectorLayer::featureCount
}

long QgsVectorLayer::updateFeatureCount() const
{
if ( !mDataProvider )
{
QgsLogger::warning( " QgsVectorLayer::updateFeatureCount() invoked with null mDataProvider" );
QgsDebugMsg( "invoked with null mDataProvider" );
return 0;
}
return mDataProvider->updateFeatureCount();
Expand All @@ -1414,7 +1405,7 @@ void QgsVectorLayer::updateExtents()
mLayerExtent.setMinimal();

if ( !mDataProvider )
QgsLogger::warning( " QgsVectorLayer::updateExtents() invoked with null mDataProvider" );
QgsDebugMsg( "invoked with null mDataProvider" );

if ( mDeletedFeatureIds.isEmpty() && mChangedGeometries.isEmpty() )
{
Expand Down Expand Up @@ -1461,7 +1452,7 @@ QString QgsVectorLayer::subsetString()
{
if ( ! mDataProvider )
{
QgsLogger::warning( " QgsVectorLayer::subsetString() invoked with null mDataProvider" );
QgsDebugMsg( "invoked with null mDataProvider" );
return 0;
}
return mDataProvider->subsetString();
Expand All @@ -1471,7 +1462,7 @@ bool QgsVectorLayer::setSubsetString( QString subset )
{
if ( ! mDataProvider )
{
QgsLogger::warning( " QgsVectorLayer::setSubsetString() invoked with null mDataProvider" );
QgsDebugMsg( "invoked with null mDataProvider" );
return false;
}

Expand Down Expand Up @@ -1611,7 +1602,7 @@ bool QgsVectorLayer::nextFeature( QgsFeature &f )
}

if ( !found )
QgsLogger::warning( QString( "No attributes for the added feature %1 found" ).arg( f.id() ) );
QgsDebugMsg( QString( "No attributes for the added feature %1 found" ).arg( f.id() ) );
}
else
{
Expand Down Expand Up @@ -1712,7 +1703,7 @@ bool QgsVectorLayer::featureAtId( int featureId, QgsFeature& f, bool fetchGeomet
}

if ( !found )
QgsLogger::warning( QString( "No attributes for the added feature %1 found" ).arg( f.id() ) );
QgsDebugMsg( QString( "No attributes for the added feature %1 found" ).arg( f.id() ) );
}
else
{
Expand Down Expand Up @@ -3379,23 +3370,24 @@ bool QgsVectorLayer::commitChanges()
//
if ( mAddedFeatures.size() > 0 )
{
for ( QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter )
for ( int i = 0; i < mAddedFeatures.size(); i++ )
{
if ( mDeletedFeatureIds.contains( iter->id() ) )
{
mDeletedFeatureIds.remove( iter->id() );
QgsFeature &f = mAddedFeatures[i];

if ( mChangedGeometries.contains( iter->id() ) )
mChangedGeometries.remove( iter->id() );
if ( mDeletedFeatureIds.contains( f.id() ) )
{
mDeletedFeatureIds.remove( f.id() );

mAddedFeatures.erase( iter );
if ( mChangedGeometries.contains( f.id() ) )
mChangedGeometries.remove( f.id() );

mAddedFeatures.removeAt( i-- );
continue;
}

if ( mChangedGeometries.contains( iter->id() ) )
if ( mChangedGeometries.contains( f.id() ) )
{
iter->setGeometry( mChangedGeometries.take( iter->id() ) );
f.setGeometry( mChangedGeometries.take( f.id() ) );
}
}

Expand Down

0 comments on commit e15562b

Please sign in to comment.