Skip to content

Commit

Permalink
Revert "[processing] Fix clipping of long WKT strings for geometry pa…
Browse files Browse the repository at this point in the history
…rameters by using our geometry widget"
  • Loading branch information
nyalldawson committed Oct 24, 2024
1 parent 296b3f4 commit d5aead3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
42 changes: 15 additions & 27 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
#include "qgsprocessingpointcloudexpressionlineedit.h"
#include "qgsprocessingrastercalculatorexpressionlineedit.h"
#include "qgsunittypes.h"
#include "qgsgeometrywidget.h"

#include <QToolButton>
#include <QLabel>
#include <QHBoxLayout>
Expand Down Expand Up @@ -4429,24 +4427,23 @@ QgsProcessingGeometryParameterDefinitionWidget::QgsProcessingGeometryParameterDe

vlayout->addWidget( new QLabel( tr( "Default value" ) ) );

mGeometryWidget = new QgsGeometryWidget();
mDefaultLineEdit = new QLineEdit();
mDefaultLineEdit->setToolTip( tr( "Geometry as WKT" ) );
mDefaultLineEdit->setPlaceholderText( tr( "Geometry as WKT" ) );
if ( const QgsProcessingParameterGeometry *geometryParam = dynamic_cast<const QgsProcessingParameterGeometry *>( definition ) )
{
QgsGeometry g = QgsProcessingParameters::parameterAsGeometry( geometryParam, geometryParam->defaultValueForGui(), context );
if ( !g.isNull() )
{
mGeometryWidget->setGeometryValue( QgsReferencedGeometry( g, QgsCoordinateReferenceSystem() ) );
}
mDefaultLineEdit->setText( g.asWkt() );
}

vlayout->addWidget( mGeometryWidget );
vlayout->addWidget( mDefaultLineEdit );
setLayout( vlayout );
}

QgsProcessingParameterDefinition *QgsProcessingGeometryParameterDefinitionWidget::createParameter( const QString &name, const QString &description, Qgis::ProcessingParameterFlags flags ) const
{
const QgsReferencedGeometry geometry = mGeometryWidget->geometryValue();
auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, geometry.isEmpty() ? QVariant() : geometry.asWkt() );
auto param = std::make_unique< QgsProcessingParameterGeometry >( name, description, mDefaultLineEdit->text() );
param->setFlags( flags );
return param.release();
}
Expand All @@ -4465,45 +4462,36 @@ QWidget *QgsProcessingGeometryWidgetWrapper::createWidget()
case QgsProcessingGui::Modeler:
case QgsProcessingGui::Batch:
{
mGeometryWidget = new QgsGeometryWidget();
mGeometryWidget->setToolTip( parameterDefinition()->toolTip() );
connect( mGeometryWidget, &QgsGeometryWidget::geometryValueChanged, this, [ = ]( const QgsReferencedGeometry & )
mLineEdit = new QLineEdit();
mLineEdit->setToolTip( parameterDefinition()->toolTip() );
connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]
{
emit widgetValueHasChanged( this );
} );
return mGeometryWidget;
return mLineEdit;
}
}
return nullptr;
}

void QgsProcessingGeometryWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
{
if ( mGeometryWidget )
if ( mLineEdit )
{
QgsGeometry g = QgsProcessingParameters::parameterAsGeometry( parameterDefinition(), value, context );
if ( !g.isNull() )
{
mGeometryWidget->setGeometryValue( QgsReferencedGeometry( g, QgsCoordinateReferenceSystem() ) );
}
mLineEdit->setText( g.asWkt() );
else
{
mGeometryWidget->clearGeometry();
}
mLineEdit->clear();
}
}

QVariant QgsProcessingGeometryWidgetWrapper::widgetValue() const
{
if ( mGeometryWidget )
{
const QgsReferencedGeometry geometry = mGeometryWidget->geometryValue();
return geometry.isEmpty() ? QVariant() : geometry.asWkt();
}
if ( mLineEdit )
return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
else
{
return QVariant();
}
}

QStringList QgsProcessingGeometryWidgetWrapper::compatibleParameterTypes() const
Expand Down
5 changes: 2 additions & 3 deletions src/gui/processing/qgsprocessingwidgetwrapperimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class QgsProcessingPointCloudExpressionLineEdit;
class QgsProcessingRasterCalculatorExpressionLineEdit;
class QgsRubberBand;
class QgsHighlightableLineEdit;
class QgsGeometryWidget;

///@cond PRIVATE

Expand Down Expand Up @@ -1239,7 +1238,7 @@ class GUI_EXPORT QgsProcessingGeometryParameterDefinitionWidget : public QgsProc

private:

QgsGeometryWidget *mGeometryWidget = nullptr;
QLineEdit *mDefaultLineEdit = nullptr;

};

Expand Down Expand Up @@ -1275,7 +1274,7 @@ class GUI_EXPORT QgsProcessingGeometryWidgetWrapper : public QgsAbstractProcessi
QString modelerExpressionFormatString() const override;
private:

QgsGeometryWidget *mGeometryWidget = nullptr;
QLineEdit *mLineEdit = nullptr;

friend class TestProcessingGui;
};
Expand Down

0 comments on commit d5aead3

Please sign in to comment.