Skip to content
Permalink
Browse files

Fix fill ring tool creates more features than needed (fix #13354)

(cherry-picked from 45a6f71)
  • Loading branch information
nyalldawson committed Nov 19, 2015
1 parent 4d7cb24 commit 29e2b6a245ca618d756f40420c9e7f27b290e321
@@ -595,7 +595,9 @@ class QgsVectorLayer : QgsMapLayer
*/
bool deleteSelectedFeatures( int *deletedCount = 0 );

/**Adds a ring to polygon/multipolygon features
/** Adds a ring to polygon/multipolygon features
* @param ring ring to add
* @param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
@return
0 in case of success,
1 problem with feature type,
@@ -604,7 +606,7 @@ class QgsVectorLayer : QgsMapLayer
4 ring crosses existing rings,
5 no feature found where ring can be inserted
6 layer not editable */
int addRing( const QList<QgsPoint>& ring );
int addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId = 0 );

/**Adds a new part polygon to a multipart feature
@return
@@ -26,14 +26,16 @@ class QgsVectorLayerEditUtils
bool deleteVertex( QgsFeatureId atFeatureId, int atVertex );

/** Adds a ring to polygon/multipolygon features
* @param ring ring to add
* @param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
@return
0 in case of success,
1 problem with feature type,
2 ring not closed,
3 ring not valid,
4 ring crosses existing rings,
5 no feature found where ring can be inserted*/
int addRing( const QList<QgsPoint>& ring );
int addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId = 0 );

/** Adds a new part polygon to a multipart feature
@return
@@ -79,7 +79,10 @@ void QgsMapToolFillRing::canvasMapReleaseEvent( QgsMapMouseEvent * e )
closePolygon();

vlayer->beginEditCommand( tr( "Ring added and filled" ) );
int addRingReturnCode = vlayer->addRing( points() );
QList< QgsPoint > pointList = points();

QgsFeatureId modifiedFid;
int addRingReturnCode = vlayer->addRing( pointList, &modifiedFid );
if ( addRingReturnCode != 0 )
{
QString errorMessage;
@@ -122,7 +125,7 @@ void QgsMapToolFillRing::canvasMapReleaseEvent( QgsMapMouseEvent * e )
yMin = std::numeric_limits<double>::max();
yMax = -std::numeric_limits<double>::max();

Q_FOREACH ( const QgsPoint& point, points() )
Q_FOREACH ( const QgsPoint& point, pointList )
{
xMin = qMin( xMin, point.x() );
xMax = qMax( xMax, point.x() );
@@ -135,18 +138,16 @@ void QgsMapToolFillRing::canvasMapReleaseEvent( QgsMapMouseEvent * e )
bBox.setXMaximum( xMax );
bBox.setYMaximum( yMax );

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bBox ).setFlags( QgsFeatureRequest::ExactIntersect ) );
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterFid( modifiedFid ) );

QgsFeature f;
bool res = false;
while ( fit.nextFeature( f ) )
if ( fit.nextFeature( f ) )
{
//create QgsFeature with wkb representation
QgsFeature* ft = new QgsFeature( vlayer->pendingFields(), 0 );

QgsGeometry *g;
g = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
ft->setGeometry( g );
ft->setGeometry( QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() ) );
ft->setAttributes( f.attributes() );

if ( QgsApplication::keyboardModifiers() == Qt::ControlModifier )
@@ -1065,13 +1065,13 @@ bool QgsVectorLayer::deleteSelectedFeatures( int* deletedCount )
return deleted == count;
}

int QgsVectorLayer::addRing( const QList<QgsPoint>& ring )
int QgsVectorLayer::addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId )
{
if ( !mEditBuffer || !mDataProvider )
return 6;

QgsVectorLayerEditUtils utils( this );
return utils.addRing( ring );
return utils.addRing( ring, featureId );
}

int QgsVectorLayer::addPart( const QList<QgsPoint> &points )
@@ -958,7 +958,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
bool deleteSelectedFeatures( int *deletedCount = 0 );

/**Adds a ring to polygon/multipolygon features
/** Adds a ring to polygon/multipolygon features
* @param ring ring to add
* @param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
@return
0 in case of success,
1 problem with feature type,
@@ -967,7 +969,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
4 ring crosses existing rings,
5 no feature found where ring can be inserted
6 layer not editable */
int addRing( const QList<QgsPoint>& ring );
int addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId = 0 );

/**Adds a new part polygon to a multipart feature
@return
@@ -97,7 +97,7 @@ bool QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId atFeatureId, int atVert
}


int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring )
int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId )
{
if ( !L->hasGeometryType() )
return 5;
@@ -125,7 +125,8 @@ int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring )
if ( addRingReturnCode == 0 )
{
L->editBuffer()->changeGeometry( f.id(), f.geometry() );

if ( featureId )
*featureId = f.id();
//setModified( true, true );
break;
}
@@ -47,14 +47,16 @@ class CORE_EXPORT QgsVectorLayerEditUtils
bool deleteVertex( QgsFeatureId atFeatureId, int atVertex );

/** Adds a ring to polygon/multipolygon features
* @param ring ring to add
* @param featureId if specified, feature ID for feature ring was added to will be stored in this parameter
@return
0 in case of success,
1 problem with feature type,
2 ring not closed,
3 ring not valid,
4 ring crosses existing rings,
5 no feature found where ring can be inserted*/
int addRing( const QList<QgsPoint>& ring );
int addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId = 0 );

/** Adds a new part polygon to a multipart feature
@return

0 comments on commit 29e2b6a

Please sign in to comment.
You can’t perform that action at this time.