Skip to content

Commit

Permalink
also create a virtual handler for QgsMapToolDigitizeFeature::featureD…
Browse files Browse the repository at this point in the history
…igitized
  • Loading branch information
3nids committed Jan 28, 2022
1 parent 281a327 commit c88a63f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
6 changes: 6 additions & 0 deletions python/gui/auto_generated/qgsmaptooldigitizefeature.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ Check if CaptureMode matches layer type. Default is ``True``.
.. versionadded:: 3.0
%End

private:
virtual void featureDigitized( const QgsFeature &feature );
%Docstring
Called when the feature has been digitized

.. versionadded:: 3.24
%End
};

/************************************************************************
Expand Down
11 changes: 5 additions & 6 deletions src/app/qgsmaptooladdfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ QgsMapToolAddFeature::QgsMapToolAddFeature( QgsMapCanvas *canvas, CaptureMode mo
mToolName = tr( "Add feature" );
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolAddFeature::stopCapturing );
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolAddFeature::stopCapturing );
connect( this, &QgsMapToolDigitizeFeature::digitizingCompleted, this, &QgsMapToolAddFeature::featureDigitized );
}

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

void QgsMapToolAddFeature::featureDigitized( const QgsFeature &f )
void QgsMapToolAddFeature::featureDigitized( const QgsFeature &feature )
{
QgsVectorLayer *vlayer = currentVectorLayer();
const bool res = addFeature( vlayer, f, false );
const bool res = addFeature( vlayer, feature, false );

if ( res )
{
Expand All @@ -87,7 +86,7 @@ void QgsMapToolAddFeature::featureDigitized( const QgsFeature &f )
//can only add topological points if background layer is editable...
if ( vl->geometryType() == QgsWkbTypes::PolygonGeometry && vl->isEditable() )
{
vl->addTopologicalPoints( f.geometry() );
vl->addTopologicalPoints( feature.geometry() );
}
}
}
Expand All @@ -99,10 +98,10 @@ void QgsMapToolAddFeature::featureDigitized( const QgsFeature &f )
{
if ( sm.at( i ).layer() )
{
sm.at( i ).layer()->addTopologicalPoints( f.geometry().vertexAt( i ) );
sm.at( i ).layer()->addTopologicalPoints( feature.geometry().vertexAt( i ) );
}
}
vlayer->addTopologicalPoints( f.geometry() );
vlayer->addTopologicalPoints( feature.geometry() );
}
}
}
2 changes: 1 addition & 1 deletion src/app/qgsmaptooladdfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class APP_EXPORT QgsMapToolAddFeature : public QgsMapToolDigitizeFeature

private slots:

void featureDigitized( const QgsFeature &f );
void featureDigitized( const QgsFeature &feature ) override;

private:

Expand Down
9 changes: 5 additions & 4 deletions src/gui/qgsmaptooldigitizefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ void QgsMapToolDigitizeFeature::geometryCaptured( const QgsGeometry &geometry )
{
layerGeometry = geometry;
}
std::unique_ptr< QgsFeature > f( new QgsFeature( vlayer->fields(), 0 ) );
f->setGeometry( layerGeometry );
f->setValid( true );
emit digitizingCompleted( *f );
QgsFeature f( vlayer->fields(), 0 );
f.setGeometry( layerGeometry );
f.setValid( true );
emit digitizingCompleted( f );
featureDigitized( f );
}

void QgsMapToolDigitizeFeature::activate()
Expand Down
20 changes: 13 additions & 7 deletions src/gui/qgsmaptooldigitizefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,25 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
void setCheckGeometryType( bool checkGeometryType );
// TODO QGIS 4: remove if GRASS plugin is dropped

/**
* individual layer per digitizing session
* \since QGIS 3.0
*/
QgsMapLayer *mLayer = nullptr;

private:

/**
* Called when the feature has been digitized.
* \param geometry the digitized geometry
*/
virtual void geometryCaptured( const QgsGeometry &geometry ) override;
void geometryCaptured( const QgsGeometry &geometry ) override FINAL;

/**
* Called when the feature has been digitized
* \since QGIS 3.24
*/
virtual void featureDigitized( const QgsFeature &feature ) {Q_UNUSED( feature )} SIP_FORCE

/**
* individual layer per digitizing session
* \since QGIS 3.0
*/
QgsMapLayer *mLayer = nullptr;

/**
* layer used before digitizing session
Expand Down

0 comments on commit c88a63f

Please sign in to comment.