mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Fix fill ring tool creates more features than needed (fix #13354)
This commit is contained in:
parent
aa4d65d3b8
commit
45a6f715b3
@ -653,6 +653,8 @@ class QgsVectorLayer : QgsMapLayer
|
||||
bool deleteSelectedFeatures( int *deletedCount = 0 );
|
||||
|
||||
/** 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,
|
||||
@ -661,7 +663,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,6 +26,8 @@ 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,
|
||||
@ -33,7 +35,7 @@ class QgsVectorLayerEditUtils
|
||||
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::cadCanvasReleaseEvent( 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::cadCanvasReleaseEvent( 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::cadCanvasReleaseEvent( 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->fields(), 0 );
|
||||
|
||||
QgsGeometry *g;
|
||||
g = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
|
||||
ft->setGeometry( g );
|
||||
ft->setGeometry( QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() ) );
|
||||
ft->setAttributes( f.attributes() );
|
||||
|
||||
if ( QApplication::keyboardModifiers() == Qt::ControlModifier )
|
||||
|
||||
@ -1058,16 +1058,16 @@ 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::addRing( QgsCurveV2* ring )
|
||||
int QgsVectorLayer::addRing( QgsCurveV2* ring, QgsFeatureId* featureId )
|
||||
{
|
||||
if ( !mEditBuffer || !mDataProvider )
|
||||
{
|
||||
@ -1087,7 +1087,7 @@ int QgsVectorLayer::addRing( QgsCurveV2* ring )
|
||||
}
|
||||
|
||||
QgsVectorLayerEditUtils utils( this );
|
||||
return utils.addRing( ring );
|
||||
return utils.addRing( ring, featureId );
|
||||
}
|
||||
|
||||
int QgsVectorLayer::addPart( const QList<QgsPoint> &points )
|
||||
|
||||
@ -1162,6 +1162,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
||||
bool deleteSelectedFeatures( int *deletedCount = 0 );
|
||||
|
||||
/** 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,
|
||||
@ -1170,15 +1172,17 @@ 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 ring to polygon/multipolygon features (takes ownership)
|
||||
* @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
|
||||
6 layer not editable*/
|
||||
int addRing( QgsCurveV2* ring );
|
||||
int addRing( QgsCurveV2* ring, QgsFeatureId* featureId = 0 );
|
||||
|
||||
/** Adds a new part polygon to a multipart feature
|
||||
@return
|
||||
|
||||
@ -104,7 +104,7 @@ bool QgsVectorLayerEditUtils::deleteVertex( QgsFeatureId atFeatureId, int atVert
|
||||
return true;
|
||||
}
|
||||
|
||||
int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring )
|
||||
int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring, QgsFeatureId* featureId )
|
||||
{
|
||||
QgsLineStringV2* ringLine = new QgsLineStringV2();
|
||||
QList< QgsPointV2 > ringPoints;
|
||||
@ -114,10 +114,10 @@ int QgsVectorLayerEditUtils::addRing( const QList<QgsPoint>& ring )
|
||||
ringPoints.append( QgsPointV2( ringIt->x(), ringIt->y() ) );
|
||||
}
|
||||
ringLine->setPoints( ringPoints );
|
||||
return addRing( ringLine );
|
||||
return addRing( ringLine, featureId );
|
||||
}
|
||||
|
||||
int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring )
|
||||
int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring, QgsFeatureId* featureId )
|
||||
{
|
||||
if ( !L->hasGeometryType() )
|
||||
{
|
||||
@ -137,6 +137,8 @@ int QgsVectorLayerEditUtils::addRing( QgsCurveV2* ring )
|
||||
if ( addRingReturnCode == 0 )
|
||||
{
|
||||
L->editBuffer()->changeGeometry( f.id(), f.geometry() );
|
||||
if ( featureId )
|
||||
*featureId = f.id();
|
||||
|
||||
//setModified( true, true );
|
||||
break;
|
||||
|
||||
@ -54,6 +54,8 @@ 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,
|
||||
@ -61,9 +63,11 @@ class CORE_EXPORT QgsVectorLayerEditUtils
|
||||
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 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,
|
||||
@ -71,7 +75,7 @@ class CORE_EXPORT QgsVectorLayerEditUtils
|
||||
3 ring not valid,
|
||||
4 ring crosses existing rings,
|
||||
5 no feature found where ring can be inserted*/
|
||||
int addRing( QgsCurveV2* ring );
|
||||
int addRing( QgsCurveV2* ring, QgsFeatureId* featureId = 0 );
|
||||
|
||||
/** Adds a new part polygon to a multipart feature
|
||||
@return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user