mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
always return "main" label for main annotation layer
This commit is contained in:
parent
ba555f1380
commit
e7d22c7e7c
@ -335,7 +335,7 @@ Normalizes a layer ``source`` string for safe comparison across different
|
||||
operating system environments.
|
||||
%End
|
||||
|
||||
static QString layerToStringIdentifier( const QgsMapLayer *layer ) /HoldGIL/;
|
||||
static QString layerToStringIdentifier( const QgsMapLayer *layer, const QString &layerName = QString() ) /HoldGIL/;
|
||||
%Docstring
|
||||
Returns a string representation of the source for a ``layer``. The returned
|
||||
value is suitable for storage for subsequent executions of an algorithm
|
||||
|
@ -335,7 +335,7 @@ Normalizes a layer ``source`` string for safe comparison across different
|
||||
operating system environments.
|
||||
%End
|
||||
|
||||
static QString layerToStringIdentifier( const QgsMapLayer *layer ) /HoldGIL/;
|
||||
static QString layerToStringIdentifier( const QgsMapLayer *layer, const QString &layerName = QString() ) /HoldGIL/;
|
||||
%Docstring
|
||||
Returns a string representation of the source for a ``layer``. The returned
|
||||
value is suitable for storage for subsequent executions of an algorithm
|
||||
|
@ -2704,7 +2704,7 @@ QVariant QgsProcessingParameterDefinition::valueAsJsonObjectPrivate( const QVari
|
||||
p.insert( name(), value );
|
||||
if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
|
||||
{
|
||||
return QgsProcessingUtils::layerToStringIdentifier( layer );
|
||||
return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -2882,7 +2882,7 @@ QString QgsProcessingParameterDefinition::valueAsStringPrivate( const QVariant &
|
||||
p.insert( name(), value );
|
||||
if ( QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( this, p, context ) )
|
||||
{
|
||||
return QgsProcessingUtils::layerToStringIdentifier( layer );
|
||||
return QgsProcessingUtils::layerToStringIdentifier( layer, value.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,7 +748,7 @@ QString QgsProcessingUtils::normalizeLayerSource( const QString &source )
|
||||
return normalized.trimmed();
|
||||
}
|
||||
|
||||
QString QgsProcessingUtils::layerToStringIdentifier( const QgsMapLayer *layer )
|
||||
QString QgsProcessingUtils::layerToStringIdentifier( const QgsMapLayer *layer, const QString &layerName )
|
||||
{
|
||||
if ( !layer )
|
||||
return QString();
|
||||
@ -766,6 +766,12 @@ QString QgsProcessingUtils::layerToStringIdentifier( const QgsMapLayer *layer )
|
||||
|
||||
return QStringLiteral( "%1://%2" ).arg( provider, source );
|
||||
}
|
||||
|
||||
if ( layer->dataProvider()->name() == QLatin1String( "annotation" ) && layerName.compare( QLatin1String( "main" ), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
return layerName;
|
||||
}
|
||||
|
||||
return layer->id();
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ class CORE_EXPORT QgsProcessingUtils
|
||||
*
|
||||
* \since QGIS 3.34
|
||||
*/
|
||||
static QString layerToStringIdentifier( const QgsMapLayer *layer ) SIP_HOLDGIL;
|
||||
static QString layerToStringIdentifier( const QgsMapLayer *layer, const QString &layerName = QString() ) SIP_HOLDGIL;
|
||||
|
||||
/**
|
||||
* Converts a variant to a Python literal.
|
||||
|
@ -11474,14 +11474,14 @@ void TestQgsProcessing::parameterAnnotationLayer()
|
||||
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) );
|
||||
|
||||
QCOMPARE( def->valueAsJsonObject( QVariant(), context ), QVariant() );
|
||||
QCOMPARE( def->valueAsJsonObject( QStringLiteral( "main" ), context ), QVariant( context.project()->mainAnnotationLayer()->id() ) );
|
||||
QCOMPARE( def->valueAsJsonObject( QStringLiteral( "main" ), context ), QVariant( QStringLiteral( "main" ) ) );
|
||||
QCOMPARE( def->valueAsJsonObject( al->id(), context ), QVariant( al->id() ) );
|
||||
QCOMPARE( def->valueAsJsonObject( QVariant::fromValue( al ), context ), QVariant( al->id() ) );
|
||||
|
||||
bool ok = false;
|
||||
QCOMPARE( def->valueAsString( QVariant(), context, ok ), QString() );
|
||||
QVERIFY( ok );
|
||||
QCOMPARE( def->valueAsString( QStringLiteral( "main" ), context, ok ), context.project()->mainAnnotationLayer()->id() );
|
||||
QCOMPARE( def->valueAsString( QStringLiteral( "main" ), context, ok ), QStringLiteral( "main" ) );
|
||||
QVERIFY( ok );
|
||||
QCOMPARE( def->valueAsString( al->id(), context, ok ), al->id() );
|
||||
QVERIFY( ok );
|
||||
|
Loading…
x
Reference in New Issue
Block a user