Skip to content
Permalink
Browse files

pass field formatter context as a reference instead of a pointer to i…

…mplify his not optionality
  • Loading branch information
signedav committed Dec 19, 2019
1 parent 7f9aa3d commit 1f1a3fe6b78a659d49409cde25952e61a1834c15
@@ -40,7 +40,7 @@ Default constructor of field formatter for a relation reference field.



virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const;
virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const;



@@ -47,7 +47,7 @@ Default constructor of field formatter for a value map field.
virtual QVariant sortValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const;


virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const;
virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const;

};

@@ -129,7 +129,7 @@ Returns the (possibly NULL) layer from the widget's ``config`` and ``project``
%End


virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const;
virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const;

};

@@ -128,7 +128,7 @@ make use of a cache if present.
%End


virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const;
virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const;
%Docstring
Returns a list of the values that would be possible to select with this widget type
On a RelationReference that would be the parents ids or on ValueMap all the configured keys
@@ -187,15 +187,15 @@ QList<QgsVectorLayerRef> QgsRelationReferenceFieldFormatter::layerDependencies(
return result;
}

QVariantList QgsRelationReferenceFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const
QVariantList QgsRelationReferenceFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const
{
QVariantList values;
if ( context->project() )
if ( context.project() )
{
const QgsVectorLayer *referencedLayer = context->project()->relationManager()->relation( config[QStringLiteral( "Relation" )].toString() ).referencedLayer();
const QgsVectorLayer *referencedLayer = context.project()->relationManager()->relation( config[QStringLiteral( "Relation" )].toString() ).referencedLayer();
if ( referencedLayer )
{
int fieldIndex = context->project()->relationManager()->relation( config[QStringLiteral( "Relation" )].toString() ).referencedFields().first();
int fieldIndex = context.project()->relationManager()->relation( config[QStringLiteral( "Relation" )].toString() ).referencedFields().first();
values = referencedLayer->uniqueValues( fieldIndex, countLimit ).toList();
}
}
@@ -46,7 +46,7 @@ class CORE_EXPORT QgsRelationReferenceFieldFormatter : public QgsFieldFormatter

QList<QgsVectorLayerRef> layerDependencies( const QVariantMap &config ) const override SIP_SKIP;

QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const override;
QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const override;

//friend class TestQgsRelationReferenceFieldFormatter;

@@ -68,7 +68,7 @@ QVariant QgsValueMapFieldFormatter::sortValue( QgsVectorLayer *layer, int fieldI
return representValue( layer, fieldIndex, config, cache, value );
}

QVariantList QgsValueMapFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const
QVariantList QgsValueMapFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const
{
Q_UNUSED( context )

@@ -57,7 +57,7 @@ class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter

QVariant sortValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;

QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const override;
QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const override;
};

#endif // QGSVALUEMAPFIELDKIT_H
@@ -188,13 +188,13 @@ QList<QgsVectorLayerRef> QgsValueRelationFieldFormatter::layerDependencies( cons
return result;
}

QVariantList QgsValueRelationFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const
QVariantList QgsValueRelationFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const
{
QVariantList values;

if ( context->project() )
if ( context.project() )
{
const QgsVectorLayer *referencedLayer = qobject_cast<QgsVectorLayer *>( context->project()->mapLayer( config[QStringLiteral( "Layer" )].toString() ) );
const QgsVectorLayer *referencedLayer = qobject_cast<QgsVectorLayer *>( context.project()->mapLayer( config[QStringLiteral( "Layer" )].toString() ) );
if ( referencedLayer )
{
int fieldIndex = referencedLayer->fields().indexOf( config.value( QStringLiteral( "Key" ) ).toString() );
@@ -127,7 +127,7 @@ class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter

QList<QgsVectorLayerRef> layerDependencies( const QVariantMap &config ) const override SIP_SKIP;

QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const override;
QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const override;
};

Q_DECLARE_METATYPE( QgsValueRelationFieldFormatter::ValueRelationCache )
@@ -69,7 +69,7 @@ QList<QgsVectorLayerRef> QgsFieldFormatter::layerDependencies( const QVariantMap
return QList<QgsVectorLayerRef>();
}

QVariantList QgsFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const
QVariantList QgsFieldFormatter::availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const
{
Q_UNUSED( config )
Q_UNUSED( countLimit )
@@ -156,7 +156,7 @@ class CORE_EXPORT QgsFieldFormatter
* according to the settings in the \a config
* \since QGIS 3.12
*/
virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext *context ) const;
virtual QVariantList availableValues( const QVariantMap &config, int countLimit, const QgsFieldFormatterContext &context ) const;

/**
* Returns the flags
@@ -494,7 +494,7 @@ void QgsExpressionBuilderWidget::fillFieldValues( const QString &fieldName, int
{
QgsFieldFormatterContext fieldFormatterContext;
fieldFormatterContext.setProject( mProject );
values = formatter->availableValues( setup.config(), countLimit, &fieldFormatterContext );
values = formatter->availableValues( setup.config(), countLimit, fieldFormatterContext );
}
else
{
@@ -3,7 +3,7 @@
---------------------
begin : 7.12.2017
copyright : (C) 2017 by by David Signer
copyright : (C) 2017 by David Signer
email : david at opengis dot ch
***************************************************************************
* *

0 comments on commit 1f1a3fe

Please sign in to comment.
You can’t perform that action at this time.