Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vertex editor and fill ring editor not returning multi geometry when needed #5229

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/core/utils/geometryutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,31 @@ GeometryUtils::GeometryUtils( QObject *parent )
{
}

QgsGeometry GeometryUtils::polygonFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs )
QgsGeometry GeometryUtils::polygonFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs, Qgis::WkbType wkbType )
{
QgsPointSequence ring = rubberBandModel->pointSequence( crs, Qgis::WkbType::Point, true );
QgsLineString ext( ring );
std::unique_ptr<QgsPolygon> polygon = std::make_unique<QgsPolygon>();
polygon->setExteriorRing( ext.clone() );

QgsGeometry g( std::move( polygon ) );
if ( QgsWkbTypes::isMultiType( wkbType ) )
{
g.convertToMultiType();
}
return g;
}

QgsGeometry GeometryUtils::lineFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs )
QgsGeometry GeometryUtils::lineFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs, Qgis::WkbType wkbType )
{
QgsPointSequence points = rubberBandModel->pointSequence( crs, Qgis::WkbType::Point, false );
std::unique_ptr<QgsLineString> line = std::make_unique<QgsLineString>( points );

QgsGeometry g( std::move( line ) );
if ( QgsWkbTypes::isMultiType( wkbType ) )
{
g.convertToMultiType();
}
return g;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/utils/geometryutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class QFIELD_CORE_EXPORT GeometryUtils : public QObject
explicit GeometryUtils( QObject *parent = nullptr );

//! Returns a QgsGeometry with a polygon by using the point sequence in the rubberband model.
static Q_INVOKABLE QgsGeometry polygonFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs );
static Q_INVOKABLE QgsGeometry polygonFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs, Qgis::WkbType wkbType = Qgis::WkbType::Unknown );

//! Returns a QgsGeometry with a line by using the point sequence in the rubberband model.
static Q_INVOKABLE QgsGeometry lineFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs );
static Q_INVOKABLE QgsGeometry lineFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs, Qgis::WkbType wkbType = Qgis::WkbType::Unknown );

//! Creates a variable width buffer polygon using M values from a rubberband model
static Q_INVOKABLE QgsGeometry variableWidthBufferByMFromRubberband( RubberbandModel *rubberBandModel, const QgsCoordinateReferenceSystem &crs );
Expand Down
7 changes: 7 additions & 0 deletions src/core/vertexmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,14 @@ QgsGeometry VertexModel::geometry() const
}

if ( mTransform.isValid() )
{
geometry.transform( mTransform, Qgis::TransformDirection::Reverse );
}

if ( QgsWkbTypes::isMultiType( mGeometryWkbType ) )
{
geometry.convertToMultiType();
}

return geometry;
}
Expand Down
2 changes: 1 addition & 1 deletion src/qml/geometryeditors/FillRing.qml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ VisibilityFadingRow {

function fillWithPolygon()
{
var polygonGeometry = GeometryUtils.polygonFromRubberband(drawPolygonToolbar.rubberbandModel, featureModel.currentLayer.crs)
var polygonGeometry = GeometryUtils.polygonFromRubberband(drawPolygonToolbar.rubberbandModel, featureModel.currentLayer.crs, featureModel.currentLayer.wkbType())
var feature = FeatureUtils.createBlankFeature(featureModel.currentLayer.fields, polygonGeometry)

// Show form
Expand Down
Loading