mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-04 00:04:03 -04:00
WIP userFriendlString testing
This commit is contained in:
parent
b1fcfad0fa
commit
40b7b18358
@ -372,7 +372,7 @@ windows.
|
|||||||
.. versionadded:: 4.0
|
.. versionadded:: 4.0
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns a user-friendly string representation of the provided parameter
|
Returns a user-friendly string representation of the provided parameter
|
||||||
``value``.
|
``value``.
|
||||||
@ -1939,7 +1939,7 @@ A coordinate reference system parameter for processing algorithms.
|
|||||||
Constructor for QgsProcessingParameterCrs.
|
Constructor for QgsProcessingParameterCrs.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
|
|
||||||
static QString typeName();
|
static QString typeName();
|
||||||
@ -2115,7 +2115,7 @@ Sets the allow multipart geometries
|
|||||||
.. seealso:: :py:func:`allowMultipart`
|
.. seealso:: :py:func:`allowMultipart`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
static QgsProcessingParameterGeometry *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
|
static QgsProcessingParameterGeometry *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
|
||||||
%Docstring
|
%Docstring
|
||||||
@ -2570,7 +2570,7 @@ Constructor for QgsProcessingParameterDistance.
|
|||||||
Returns the type name for the parameter class.
|
Returns the type name for the parameter class.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
|
|
||||||
virtual QgsProcessingParameterDistance *clone() const /Factory/;
|
virtual QgsProcessingParameterDistance *clone() const /Factory/;
|
||||||
@ -3042,7 +3042,7 @@ values.
|
|||||||
Constructor for QgsProcessingParameterEnum.
|
Constructor for QgsProcessingParameterEnum.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
|
|
||||||
static QString typeName();
|
static QString typeName();
|
||||||
|
@ -372,7 +372,7 @@ windows.
|
|||||||
.. versionadded:: 4.0
|
.. versionadded:: 4.0
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
%Docstring
|
%Docstring
|
||||||
Returns a user-friendly string representation of the provided parameter
|
Returns a user-friendly string representation of the provided parameter
|
||||||
``value``.
|
``value``.
|
||||||
@ -1939,7 +1939,7 @@ A coordinate reference system parameter for processing algorithms.
|
|||||||
Constructor for QgsProcessingParameterCrs.
|
Constructor for QgsProcessingParameterCrs.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
|
|
||||||
static QString typeName();
|
static QString typeName();
|
||||||
@ -2115,7 +2115,7 @@ Sets the allow multipart geometries
|
|||||||
.. seealso:: :py:func:`allowMultipart`
|
.. seealso:: :py:func:`allowMultipart`
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
static QgsProcessingParameterGeometry *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
|
static QgsProcessingParameterGeometry *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
|
||||||
%Docstring
|
%Docstring
|
||||||
@ -2570,7 +2570,7 @@ Constructor for QgsProcessingParameterDistance.
|
|||||||
Returns the type name for the parameter class.
|
Returns the type name for the parameter class.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
|
|
||||||
virtual QgsProcessingParameterDistance *clone() const /Factory/;
|
virtual QgsProcessingParameterDistance *clone() const /Factory/;
|
||||||
@ -3042,7 +3042,7 @@ values.
|
|||||||
Constructor for QgsProcessingParameterEnum.
|
Constructor for QgsProcessingParameterEnum.
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
|
|
||||||
static QString typeName();
|
static QString typeName();
|
||||||
|
@ -3032,7 +3032,7 @@ QColor QgsProcessingParameterDefinition::modelColor() const
|
|||||||
return QgsProcessingParameterType::defaultModelColor();
|
return QgsProcessingParameterType::defaultModelColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsProcessingParameterDefinition::userFriendlyString( QVariant &value ) const
|
QString QgsProcessingParameterDefinition::userFriendlyString( const QVariant &value ) const
|
||||||
{
|
{
|
||||||
if ( value.userType() == qMetaTypeId<QgsPointXY>() )
|
if ( value.userType() == qMetaTypeId<QgsPointXY>() )
|
||||||
{
|
{
|
||||||
@ -3134,20 +3134,26 @@ QString QgsProcessingParameterDefinition::userFriendlyString( QVariant &value )
|
|||||||
.arg( dt.second() );
|
.arg( dt.second() );
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ( value.userType() == QMetaType::QString )
|
// else if ( value.userType() == QMetaType::QString )
|
||||||
{
|
// {
|
||||||
// In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
|
// // In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
|
||||||
// rather than the possibly very long WKT payload
|
// // rather than the possibly very long WKT payload
|
||||||
QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
|
// QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
|
||||||
if ( !g.isNull() )
|
// if ( !g.isNull() )
|
||||||
{
|
// {
|
||||||
return g.typeName();
|
// return g.typeName();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return value.toString();
|
// return value.toString();
|
||||||
|
return QStringLiteral( "%1 :: %2" )
|
||||||
|
.arg( value.userType() )
|
||||||
|
.arg( value.toString() );
|
||||||
|
|
||||||
|
// return value.userType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString QgsProcessingParameterBoolean::valueAsPythonString( const QVariant &val, QgsProcessingContext & ) const
|
QString QgsProcessingParameterBoolean::valueAsPythonString( const QVariant &val, QgsProcessingContext & ) const
|
||||||
{
|
{
|
||||||
if ( !val.isValid() )
|
if ( !val.isValid() )
|
||||||
@ -3307,11 +3313,18 @@ QgsProcessingParameterCrs *QgsProcessingParameterCrs::fromScriptCode( const QStr
|
|||||||
return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
|
return new QgsProcessingParameterCrs( name, description, definition.compare( QLatin1String( "none" ), Qt::CaseInsensitive ) == 0 ? QVariant() : definition, isOptional );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsProcessingParameterCrs::userFriendlyString( QVariant &value ) const
|
|
||||||
|
QString QgsProcessingParameterCrs::userFriendlyString( const QVariant &value ) const
|
||||||
{
|
{
|
||||||
return value.value<QgsCoordinateReferenceSystem>().authid();
|
QgsCoordinateReferenceSystem crs( value.toString() );
|
||||||
|
if ( crs.isValid() )
|
||||||
|
return crs.userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString );
|
||||||
|
|
||||||
|
return QObject::tr( "Invalid CRS" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
|
QgsProcessingParameterMapLayer::QgsProcessingParameterMapLayer( const QString &name, const QString &description, const QVariant &defaultValue, bool optional, const QList<int> &types )
|
||||||
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
|
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
|
||||||
, QgsProcessingParameterLimitedDataTypes( types )
|
, QgsProcessingParameterLimitedDataTypes( types )
|
||||||
@ -3875,6 +3888,7 @@ QgsProcessingParameterPoint *QgsProcessingParameterPoint::fromScriptCode( const
|
|||||||
return new QgsProcessingParameterPoint( name, description, definition, isOptional );
|
return new QgsProcessingParameterPoint( name, description, definition, isOptional );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
|
QgsProcessingParameterGeometry::QgsProcessingParameterGeometry( const QString &name, const QString &description,
|
||||||
const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
|
const QVariant &defaultValue, bool optional, const QList<int> &geometryTypes, bool allowMultipart )
|
||||||
: QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
|
: QgsProcessingParameterDefinition( name, description, defaultValue, optional ),
|
||||||
@ -4146,6 +4160,22 @@ QgsProcessingParameterGeometry *QgsProcessingParameterGeometry::fromScriptCode(
|
|||||||
return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
|
return new QgsProcessingParameterGeometry( name, description, definition, isOptional );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QgsProcessingParameterGeometry::userFriendlyString( const QVariant &value ) const
|
||||||
|
{
|
||||||
|
if ( value.isValid() && value.userType() == QMetaType::QString )
|
||||||
|
{
|
||||||
|
// In the case of a WKT-(string) encoded geometry, the type of geometry is going to be displayed
|
||||||
|
// rather than the possibly very long WKT payload
|
||||||
|
QgsGeometry g = QgsGeometry::fromWkt( value.toString() );
|
||||||
|
if ( !g.isNull() )
|
||||||
|
{
|
||||||
|
return g.typeName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return QObject::tr( "Invalid geometry" );
|
||||||
|
}
|
||||||
|
|
||||||
QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
|
QgsProcessingParameterFile::QgsProcessingParameterFile( const QString &name, const QString &description, Qgis::ProcessingFileParameterBehavior behavior, const QString &extension, const QVariant &defaultValue, bool optional, const QString &fileFilter )
|
||||||
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
|
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
|
||||||
, mBehavior( behavior )
|
, mBehavior( behavior )
|
||||||
@ -5400,7 +5430,7 @@ QString QgsProcessingParameterEnum::asPythonString( const QgsProcessing::PythonO
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsProcessingParameterEnum::userFriendlyString( QVariant &value ) const
|
QString QgsProcessingParameterEnum::userFriendlyString( const QVariant &value ) const
|
||||||
{
|
{
|
||||||
return options().at( value.toInt() );
|
return options().at( value.toInt() );
|
||||||
}
|
}
|
||||||
@ -7867,7 +7897,7 @@ bool QgsProcessingParameterDistance::fromVariantMap( const QVariantMap &map )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString QgsProcessingParameterDistance::userFriendlyString( QVariant &value ) const
|
QString QgsProcessingParameterDistance::userFriendlyString( const QVariant &value ) const
|
||||||
{
|
{
|
||||||
return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
|
return QStringLiteral( "%1 %2" ).arg( value.toString(), QgsUnitTypes::toAbbreviatedString( defaultUnit() ) );
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ class CORE_EXPORT QgsProcessingParameterDefinition
|
|||||||
* The returned string is to be used for display purposes only, and should be translated as required.
|
* The returned string is to be used for display purposes only, and should be translated as required.
|
||||||
* \since QGIS 4.0
|
* \since QGIS 4.0
|
||||||
*/
|
*/
|
||||||
virtual QString userFriendlyString( QVariant &value ) const;
|
virtual QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a clone of the parameter definition.
|
* Creates a clone of the parameter definition.
|
||||||
@ -1828,7 +1828,7 @@ class CORE_EXPORT QgsProcessingParameterCrs : public QgsProcessingParameterDefin
|
|||||||
QgsProcessingParameterCrs( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
|
QgsProcessingParameterCrs( const QString &name, const QString &description = QString(), const QVariant &defaultValue = QVariant(),
|
||||||
bool optional = false );
|
bool optional = false );
|
||||||
|
|
||||||
QString userFriendlyString( QVariant &value ) const override;
|
QString userFriendlyString( const QVariant &value ) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type name for the parameter class.
|
* Returns the type name for the parameter class.
|
||||||
@ -1978,7 +1978,7 @@ class CORE_EXPORT QgsProcessingParameterGeometry : public QgsProcessingParameter
|
|||||||
*/
|
*/
|
||||||
void setAllowMultipart( bool allowMultipart ) { mAllowMultipart = allowMultipart; }
|
void setAllowMultipart( bool allowMultipart ) { mAllowMultipart = allowMultipart; }
|
||||||
|
|
||||||
|
QString userFriendlyString( const QVariant &value ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new parameter using the definition from a script code.
|
* Creates a new parameter using the definition from a script code.
|
||||||
@ -2380,7 +2380,7 @@ class CORE_EXPORT QgsProcessingParameterDistance : public QgsProcessingParameter
|
|||||||
*/
|
*/
|
||||||
static QString typeName() { return QStringLiteral( "distance" ); } // cppcheck-suppress duplInheritedMember
|
static QString typeName() { return QStringLiteral( "distance" ); } // cppcheck-suppress duplInheritedMember
|
||||||
|
|
||||||
QString userFriendlyString( QVariant &value ) const override;
|
QString userFriendlyString( const QVariant &value ) const override;
|
||||||
|
|
||||||
QgsProcessingParameterDistance *clone() const override SIP_FACTORY;
|
QgsProcessingParameterDistance *clone() const override SIP_FACTORY;
|
||||||
|
|
||||||
@ -2802,7 +2802,7 @@ class CORE_EXPORT QgsProcessingParameterEnum : public QgsProcessingParameterDefi
|
|||||||
bool optional = false,
|
bool optional = false,
|
||||||
bool usesStaticStrings = false );
|
bool usesStaticStrings = false );
|
||||||
|
|
||||||
QString userFriendlyString( QVariant &value ) const override;
|
QString userFriendlyString( const QVariant &value ) const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type name for the parameter class.
|
* Returns the type name for the parameter class.
|
||||||
|
@ -854,7 +854,7 @@ QString QgsModelParameterGraphicItem::linkPointText( Qt::Edge, int index ) const
|
|||||||
// Getting the default value to append to the box name
|
// Getting the default value to append to the box name
|
||||||
if ( const QgsProcessingParameterDefinition *paramDef = this->model()->parameterDefinition( parameter->parameterName() ) )
|
if ( const QgsProcessingParameterDefinition *paramDef = this->model()->parameterDefinition( parameter->parameterName() ) )
|
||||||
{
|
{
|
||||||
QVariant paramValue = paramDef->defaultValue();
|
const QVariant paramValue = paramDef->defaultValue();
|
||||||
|
|
||||||
if ( paramValue.isValid() )
|
if ( paramValue.isValid() )
|
||||||
{
|
{
|
||||||
@ -1311,7 +1311,7 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind
|
|||||||
|
|
||||||
case Qgis::ProcessingModelChildParameterSource::StaticValue:
|
case Qgis::ProcessingModelChildParameterSource::StaticValue:
|
||||||
default:
|
default:
|
||||||
QVariant paramValue = paramSources[0].staticValue();
|
const QVariant paramValue = paramSources[0].staticValue();
|
||||||
parameterValueAsString = QStringLiteral( ": %1" ).arg( param->userFriendlyString( paramValue ) );
|
parameterValueAsString = QStringLiteral( ": %1" ).arg( param->userFriendlyString( paramValue ) );
|
||||||
}
|
}
|
||||||
title += parameterValueAsString;
|
title += parameterValueAsString;
|
||||||
|
@ -2995,6 +2995,9 @@ void TestQgsProcessing::parameterBoolean()
|
|||||||
QCOMPARE( def->valueAsPythonString( QVariant(), context ), QStringLiteral( "None" ) );
|
QCOMPARE( def->valueAsPythonString( QVariant(), context ), QStringLiteral( "None" ) );
|
||||||
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) );
|
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) );
|
||||||
|
|
||||||
|
QCOMPARE( def->userFriendlyString( QVariant( true ) ), QString( "true" ) );
|
||||||
|
QCOMPARE( def->userFriendlyString( QVariant( false ) ), QString( "false" ) );
|
||||||
|
|
||||||
QString pythonCode = def->asPythonString();
|
QString pythonCode = def->asPythonString();
|
||||||
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterBoolean('non_optional_default_false', '', defaultValue=None)" ) );
|
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterBoolean('non_optional_default_false', '', defaultValue=None)" ) );
|
||||||
|
|
||||||
@ -3210,6 +3213,8 @@ void TestQgsProcessing::parameterCrs()
|
|||||||
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSourceDefinition( QgsProperty::fromValue( QVariant::fromValue( r1 ) ) ) ) );
|
QVERIFY( def->checkValueIsAcceptable( QgsProcessingFeatureSourceDefinition( QgsProperty::fromValue( QVariant::fromValue( r1 ) ) ) ) );
|
||||||
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( r1->id() ) ) );
|
QVERIFY( def->checkValueIsAcceptable( QgsProcessingOutputLayerDefinition( r1->id() ) ) );
|
||||||
|
|
||||||
|
QCOMPARE( def->userFriendlyString( QVariant( "EPSG:3857" ) ), QgsCoordinateReferenceSystem( QVariant( "EPSG:3857" ).toString() ).userFriendlyIdentifier( Qgis::CrsIdentifierType::ShortString ) );
|
||||||
|
|
||||||
// using map layer
|
// using map layer
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert( "non_optional", v1->id() );
|
params.insert( "non_optional", v1->id() );
|
||||||
@ -6394,6 +6399,10 @@ void TestQgsProcessing::parameterEnum()
|
|||||||
QCOMPARE( def->valueAsPythonComment( QVariantList() << 1 << 2, context ), QStringLiteral( "B,C" ) );
|
QCOMPARE( def->valueAsPythonComment( QVariantList() << 1 << 2, context ), QStringLiteral( "B,C" ) );
|
||||||
QCOMPARE( def->valueAsPythonComment( QStringLiteral( "1,2" ), context ), QStringLiteral( "B,C" ) );
|
QCOMPARE( def->valueAsPythonComment( QStringLiteral( "1,2" ), context ), QStringLiteral( "B,C" ) );
|
||||||
|
|
||||||
|
QCOMPARE( def->userFriendlyString( QVariant( 0 ) ), QString( "A" ) );
|
||||||
|
QCOMPARE( def->userFriendlyString( QVariant( 1 ) ), QString( "B" ) );
|
||||||
|
QCOMPARE( def->userFriendlyString( QVariant( 2 ) ), QString( "C" ) );
|
||||||
|
|
||||||
pythonCode = def->asPythonString();
|
pythonCode = def->asPythonString();
|
||||||
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterEnum('non_optional', '', options=['A','B','C'], allowMultiple=True, usesStaticStrings=False, defaultValue=5)" ) );
|
QCOMPARE( pythonCode, QStringLiteral( "QgsProcessingParameterEnum('non_optional', '', options=['A','B','C'], allowMultiple=True, usesStaticStrings=False, defaultValue=5)" ) );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user