Skip to content

Commit c88a63f

Browse files
committedJan 28, 2022
also create a virtual handler for QgsMapToolDigitizeFeature::featureDigitized
1 parent 281a327 commit c88a63f

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed
 

‎python/gui/auto_generated/qgsmaptooldigitizefeature.sip.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ Check if CaptureMode matches layer type. Default is ``True``.
8383
.. versionadded:: 3.0
8484
%End
8585

86+
private:
87+
virtual void featureDigitized( const QgsFeature &feature );
88+
%Docstring
89+
Called when the feature has been digitized
8690

91+
.. versionadded:: 3.24
92+
%End
8793
};
8894

8995
/************************************************************************

‎src/app/qgsmaptooladdfeature.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas *canvas, CaptureMode mo
4646
mToolName = tr( "Add feature" );
4747
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolAddFeature::stopCapturing );
4848
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolAddFeature::stopCapturing );
49-
connect( this, &QgsMapToolDigitizeFeature::digitizingCompleted, this, &QgsMapToolAddFeature::featureDigitized );
5049
}
5150

5251
bool QgsMapToolAddFeature::addFeature( QgsVectorLayer *vlayer, const QgsFeature &f, bool showModal )
@@ -62,10 +61,10 @@ bool QgsMapToolAddFeature::addFeature( QgsVectorLayer *vlayer, const QgsFeature
6261
return res;
6362
}
6463

65-
void QgsMapToolAddFeature::featureDigitized( const QgsFeature &f )
64+
void QgsMapToolAddFeature::featureDigitized( const QgsFeature &feature )
6665
{
6766
QgsVectorLayer *vlayer = currentVectorLayer();
68-
const bool res = addFeature( vlayer, f, false );
67+
const bool res = addFeature( vlayer, feature, false );
6968

7069
if ( res )
7170
{
@@ -87,7 +86,7 @@ void QgsMapToolAddFeature::featureDigitized( const QgsFeature &f )
8786
//can only add topological points if background layer is editable...
8887
if ( vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )
8988
{
90-
vl->addTopologicalPoints( f.geometry() );
89+
vl->addTopologicalPoints( feature.geometry() );
9190
}
9291
}
9392
}
@@ -99,10 +98,10 @@ void QgsMapToolAddFeature::featureDigitized( const QgsFeature &f )
9998
{
10099
if ( sm.at( i ).layer() )
101100
{
102-
sm.at( i ).layer()->addTopologicalPoints( f.geometry().vertexAt( i ) );
101+
sm.at( i ).layer()->addTopologicalPoints( feature.geometry().vertexAt( i ) );
103102
}
104103
}
105-
vlayer->addTopologicalPoints( f.geometry() );
104+
vlayer->addTopologicalPoints( feature.geometry() );
106105
}
107106
}
108107
}

‎src/app/qgsmaptooladdfeature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class APP_EXPORT QgsMapToolAddFeature : public QgsMapToolDigitizeFeature
2626

2727
private slots:
2828

29-
void featureDigitized( const QgsFeature &f );
29+
void featureDigitized( const QgsFeature &feature ) override;
3030

3131
private:
3232

‎src/gui/qgsmaptooldigitizefeature.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ void QgsMapToolDigitizeFeature::geometryCaptured( const QgsGeometry &geometry )
9191
{
9292
layerGeometry = geometry;
9393
}
94-
std::unique_ptr< QgsFeature > f( new QgsFeature( vlayer->fields(), 0 ) );
95-
f->setGeometry( layerGeometry );
96-
f->setValid( true );
97-
emit digitizingCompleted( *f );
94+
QgsFeature f( vlayer->fields(), 0 );
95+
f.setGeometry( layerGeometry );
96+
f.setValid( true );
97+
emit digitizingCompleted( f );
98+
featureDigitized( f );
9899
}
99100

100101
void QgsMapToolDigitizeFeature::activate()

‎src/gui/qgsmaptooldigitizefeature.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,25 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
8585
void setCheckGeometryType( bool checkGeometryType );
8686
// TODO QGIS 4: remove if GRASS plugin is dropped
8787

88-
/**
89-
* individual layer per digitizing session
90-
* \since QGIS 3.0
91-
*/
92-
QgsMapLayer *mLayer = nullptr;
93-
9488
private:
9589

9690
/**
9791
* Called when the feature has been digitized.
9892
* \param geometry the digitized geometry
9993
*/
100-
virtual void geometryCaptured( const QgsGeometry &geometry ) override;
94+
void geometryCaptured( const QgsGeometry &geometry ) override FINAL;
95+
96+
/**
97+
* Called when the feature has been digitized
98+
* \since QGIS 3.24
99+
*/
100+
virtual void featureDigitized( const QgsFeature &feature ) {Q_UNUSED( feature )} SIP_FORCE
101+
102+
/**
103+
* individual layer per digitizing session
104+
* \since QGIS 3.0
105+
*/
106+
QgsMapLayer *mLayer = nullptr;
101107

102108
/**
103109
* layer used before digitizing session

0 commit comments

Comments
 (0)
Please sign in to comment.