Showing with 51 additions and 1 deletion.
  1. +8 −0 python/core/qgsvectorlayer.sip
  2. +1 −1 src/core/qgsapplication.cpp
  3. +36 −0 src/core/qgsvectorlayer.cpp
  4. +6 −0 src/core/qgsvectorlayer.h
8 changes: 8 additions & 0 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,18 @@ public:
bool featureAtId(int featureId, QgsFeature& f, bool fetchGeometries = true, bool fetchAttributes = true);

/** Adds a feature
@param f feature to add
@param alsoUpdateExtent If True, will also go to the effort of e.g. updating the extents.
@return True in case of success and False in case of error
*/
bool addFeature(QgsFeature& f, bool alsoUpdateExtent = TRUE);

/** Update an existing feature
@param f feature to update
@return True in case of success and False in case of error
@note added in 1.8
*/
bool updateFeature(QgsFeature& f );


/** Insert a new vertex before the given vertex number,
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void QgsApplication::setPluginPath( const QString thePluginPath )
void QgsApplication::setPkgDataPath( const QString thePkgDataPath )
{
mPkgDataPath = thePkgDataPath;
QString mySvgPath = svgPath();
QString mySvgPath = thePkgDataPath + ( mRunningFromBuildDir ? "/images/svg/" : "/svg/" );
// avoid duplicate entries
if ( !mDefaultSvgPaths.contains( mySvgPath ) )
mDefaultSvgPaths << mySvgPath;
Expand Down
36 changes: 36 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,42 @@ bool QgsVectorLayer::addFeature( QgsFeature& f, bool alsoUpdateExtent )
return true;
}

bool QgsVectorLayer::updateFeature( QgsFeature &f )
{
QgsFeature current;
if ( !featureAtId( f.id(), current, f.geometry(), !f.attributeMap().isEmpty() ) )
{
QgsDebugMsg( QString( "feature %1 could not be retrieved" ).arg( f.id() ) );
return false;
}

if ( f.geometry() && current.geometry() && f.geometry() != current.geometry() && !f.geometry()->isGeosEqual( *current.geometry() ) )
{
if ( !changeGeometry( f.id(), f.geometry() ) )
{
QgsDebugMsg( QString( "geometry of feature %1 could not be changed." ).arg( f.id() ) );
return false;
}
}

const QgsAttributeMap &fa = f.attributeMap();
const QgsAttributeMap &ca = current.attributeMap();

foreach( int attr, fa.keys() )
{
if ( fa.contains( attr ) && ca.contains( attr ) && fa[attr] != ca[attr] )
{
if ( !changeAttributeValue( f.id(), attr, fa[attr] ) )
{
QgsDebugMsg( QString( "attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( f.id() ) );
return false;
}
}
}

return true;
}


bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex )
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
bool addFeature( QgsFeature& f, bool alsoUpdateExtent = true );

/** Updates an existing feature
@param f feature to update
@return True in case of success and False in case of error
@note added in 1.8
*/
bool updateFeature( QgsFeature &f );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature
Expand Down