From ff87afd7903ba2b0dc02d3008748c1e5ce219e6f Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Thu, 17 Mar 2022 12:05:52 +0100 Subject: [PATCH] Fix regression when adding feature without geom #46687 --- src/gui/qgsmaptooldigitizefeature.cpp | 46 +++++++++++++++------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/gui/qgsmaptooldigitizefeature.cpp b/src/gui/qgsmaptooldigitizefeature.cpp index 51cf7be09d1a9..9191dfeb9971e 100644 --- a/src/gui/qgsmaptooldigitizefeature.cpp +++ b/src/gui/qgsmaptooldigitizefeature.cpp @@ -73,30 +73,34 @@ void QgsMapToolDigitizeFeature::layerGeometryCaptured( const QgsGeometry &geomet if ( !vlayer ) return; - const QgsWkbTypes::Type layerWKBType = vlayer->wkbType(); - - QgsGeometry layerGeometry; + QgsFeature f( vlayer->fields(), 0 ); - if ( mCheckGeometryType ) + if ( vlayer->isSpatial() ) { - double defaultZ = QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.value(); - double defaultM = QgsSettingsRegistryCore::settingsDigitizingDefaultMValue.value(); - QVector layerGeometries = geometry.coerceToType( layerWKBType, defaultZ, defaultM ); - if ( layerGeometries.count() > 0 ) - layerGeometry = layerGeometries.at( 0 ); - - if ( layerGeometry.wkbType() != layerWKBType && layerGeometry.wkbType() != QgsWkbTypes::linearType( layerWKBType ) ) - { - emit messageEmitted( tr( "The digitized geometry type (%1) does not correspond to the layer geometry type (%2)." ).arg( QgsWkbTypes::displayString( layerGeometry.wkbType() ) ).arg( QgsWkbTypes::displayString( layerWKBType ) ), Qgis::MessageLevel::Warning ); - return; - } + const QgsWkbTypes::Type layerWKBType = vlayer->wkbType(); + + QgsGeometry layerGeometry; + + if ( mCheckGeometryType ) + { + double defaultZ = QgsSettingsRegistryCore::settingsDigitizingDefaultZValue.value(); + double defaultM = QgsSettingsRegistryCore::settingsDigitizingDefaultMValue.value(); + QVector layerGeometries = geometry.coerceToType( layerWKBType, defaultZ, defaultM ); + if ( layerGeometries.count() > 0 ) + layerGeometry = layerGeometries.at( 0 ); + + if ( layerGeometry.wkbType() != layerWKBType && layerGeometry.wkbType() != QgsWkbTypes::linearType( layerWKBType ) ) + { + emit messageEmitted( tr( "The digitized geometry type (%1) does not correspond to the layer geometry type (%2)." ).arg( QgsWkbTypes::displayString( layerGeometry.wkbType() ), QgsWkbTypes::displayString( layerWKBType ) ), Qgis::MessageLevel::Warning ); + return; + } + } + else + { + layerGeometry = geometry; + } + f.setGeometry( layerGeometry ); } - else - { - layerGeometry = geometry; - } - QgsFeature f( vlayer->fields(), 0 ); - f.setGeometry( layerGeometry ); f.setValid( true ); emit digitizingCompleted( f ); featureDigitized( f );