From ea7805301a0e247c2870ce571fc7ca358e74344c Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 15 Oct 2024 11:29:42 +0700 Subject: [PATCH] [processing] Fix clipping of long WKT strings for geometry parameters by using our geometry widget --- .../qgsprocessingwidgetwrapperimpl.cpp | 42 ++++++++++++------- .../qgsprocessingwidgetwrapperimpl.h | 5 ++- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp b/src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp index 24c73257abce..25f12c8f646a 100644 --- a/src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp +++ b/src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp @@ -68,6 +68,8 @@ #include "qgsprocessingpointcloudexpressionlineedit.h" #include "qgsprocessingrastercalculatorexpressionlineedit.h" #include "qgsunittypes.h" +#include "qgsgeometrywidget.h" + #include #include #include @@ -4405,23 +4407,24 @@ QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDe vlayout->addWidget( new QLabel( tr( "Default value" ) ) ); - mDefaultLineEdit = new QLineEdit(); - mDefaultLineEdit->setToolTip( tr( "Geometry as WKT" ) ); - mDefaultLineEdit->setPlaceholderText( tr( "Geometry as WKT" ) ); + mGeometryWidget = new QgsGeometryWidget(); if ( const QgsProcessingParameterGeometry *geometryParam = dynamic_cast( definition ) ) { QgsGeometry g = QgsProcessingParameters::parameterAsGeometry( geometryParam, geometryParam->defaultValueForGui(), context ); if ( !g.isNull() ) - mDefaultLineEdit->setText( g.asWkt() ); + { + mGeometryWidget->setGeometryValue( QgsReferencedGeometry( g, QgsCoordinateReferenceSystem() ) ); + } } - vlayout->addWidget( mDefaultLineEdit ); + vlayout->addWidget( mGeometryWidget ); setLayout( vlayout ); } QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter( const QString &name, const QString &description, Qgis::ProcessingParameterFlags flags ) const { - auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() ); + const QgsReferencedGeometry geometry = mGeometryWidget->geometryValue(); + auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, geometry.isEmpty() ? QVariant() : geometry.asWkt() ); param->setFlags( flags ); return param.release(); } @@ -4440,13 +4443,13 @@ QWidget *QgsProcessingGeometryWidgetWrapper::createWidget() case QgsProcessingGui::Modeler: case QgsProcessingGui::Batch: { - mLineEdit = new QLineEdit(); - mLineEdit->setToolTip( parameterDefinition()->toolTip() ); - connect( mLineEdit, &QLineEdit::textChanged, this, [ = ] + mGeometryWidget = new QgsGeometryWidget(); + mGeometryWidget->setToolTip( parameterDefinition()->toolTip() ); + connect( mGeometryWidget, &QgsGeometryWidget::geometryValueChanged, this, [ = ]( const QgsReferencedGeometry & ) { emit widgetValueHasChanged( this ); } ); - return mLineEdit; + return mGeometryWidget; } } return nullptr; @@ -4454,22 +4457,31 @@ QWidget *QgsProcessingGeometryWidgetWrapper::createWidget() void QgsProcessingGeometryWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context ) { - if ( mLineEdit ) + if ( mGeometryWidget ) { QgsGeometry g = QgsProcessingParameters::parameterAsGeometry( parameterDefinition(), value, context ); if ( !g.isNull() ) - mLineEdit->setText( g.asWkt() ); + { + mGeometryWidget->setGeometryValue( QgsReferencedGeometry( g, QgsCoordinateReferenceSystem() ) ); + } else - mLineEdit->clear(); + { + mGeometryWidget->clearGeometry(); + } } } QVariant QgsProcessingGeometryWidgetWrapper::widgetValue() const { - if ( mLineEdit ) - return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text(); + if ( mGeometryWidget ) + { + const QgsReferencedGeometry geometry = mGeometryWidget->geometryValue(); + return geometry.isEmpty() ? QVariant() : geometry.asWkt(); + } else + { return QVariant(); + } } QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes() const diff --git a/src/gui/processing/qgsprocessingwidgetwrapperimpl.h b/src/gui/processing/qgsprocessingwidgetwrapperimpl.h index 134b87870443..7b330af94478 100644 --- a/src/gui/processing/qgsprocessingwidgetwrapperimpl.h +++ b/src/gui/processing/qgsprocessingwidgetwrapperimpl.h @@ -75,6 +75,7 @@ class QgsProcessingPointCloudExpressionLineEdit; class QgsProcessingRasterCalculatorExpressionLineEdit; class QgsRubberBand; class QgsHighlightableLineEdit; +class QgsGeometryWidget; ///@cond PRIVATE @@ -1234,7 +1235,7 @@ class GUI_EXPORT QgsProcessingGeometryParameterDefinitionWidget : public QgsProc private: - QLineEdit *mDefaultLineEdit = nullptr; + QgsGeometryWidget *mGeometryWidget = nullptr; }; @@ -1270,7 +1271,7 @@ class GUI_EXPORT QgsProcessingGeometryWidgetWrapper : public QgsAbstractProcessi QString modelerExpressionFormatString() const override; private: - QLineEdit *mLineEdit = nullptr; + QgsGeometryWidget *mGeometryWidget = nullptr; friend class TestProcessingGui; };