mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
available values in value relations
This commit is contained in:
parent
54f4efbd86
commit
5e6e75662f
@ -128,6 +128,9 @@ Returns the (possibly NULL) layer from the widget's ``config`` and ``project``
|
||||
.. versionadded:: 3.8
|
||||
%End
|
||||
|
||||
|
||||
virtual QList<QVariant> availableValues( const QVariantMap &config, int countLimit ) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -40,6 +40,11 @@ bool orderByValueLessThan( const QgsValueRelationFieldFormatter::ValueRelationIt
|
||||
return qgsVariantLessThan( p1.value, p2.value );
|
||||
}
|
||||
|
||||
QgsValueRelationFieldFormatter::QgsValueRelationFieldFormatter()
|
||||
{
|
||||
setFlags( flags() | QgsFieldFormatter::CanProvideAvailableValues );
|
||||
}
|
||||
|
||||
QString QgsValueRelationFieldFormatter::id() const
|
||||
{
|
||||
return QStringLiteral( "ValueRelation" );
|
||||
@ -183,6 +188,19 @@ QList<QgsVectorLayerRef> QgsValueRelationFieldFormatter::layerDependencies( cons
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<QVariant> QgsValueRelationFieldFormatter::availableValues( const QVariantMap &config, int countLimit ) const
|
||||
{
|
||||
QList<QVariant> values;
|
||||
|
||||
const QgsVectorLayer *referencedLayer = qobject_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( config[QStringLiteral( "Layer" )].toString() ) );
|
||||
if ( referencedLayer )
|
||||
{
|
||||
int fieldIndex = referencedLayer->fields().indexOf( config.value( QStringLiteral( "Key" ) ).toString() );
|
||||
values = referencedLayer->uniqueValues( fieldIndex, countLimit ).toList();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
QStringList QgsValueRelationFieldFormatter::valueToStringList( const QVariant &value )
|
||||
{
|
||||
QStringList checkList;
|
||||
|
@ -56,7 +56,7 @@ class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter
|
||||
/**
|
||||
* Constructor for QgsValueRelationFieldFormatter.
|
||||
*/
|
||||
QgsValueRelationFieldFormatter() = default;
|
||||
QgsValueRelationFieldFormatter();
|
||||
|
||||
QString id() const override;
|
||||
QString representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const override;
|
||||
@ -126,6 +126,8 @@ class CORE_EXPORT QgsValueRelationFieldFormatter : public QgsFieldFormatter
|
||||
static QgsVectorLayer *resolveLayer( const QVariantMap &config, const QgsProject *project );
|
||||
|
||||
QList<QgsVectorLayerRef> layerDependencies( const QVariantMap &config ) const override SIP_SKIP;
|
||||
|
||||
QList<QVariant> availableValues( const QVariantMap &config, int countLimit ) const override;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( QgsValueRelationFieldFormatter::ValueRelationCache )
|
||||
|
Loading…
x
Reference in New Issue
Block a user