Skip to content
Permalink
Browse files

available values of value map

  • Loading branch information
signedav committed Dec 16, 2019
1 parent a02cdbc commit 54f4efbd861cf50d201108892f159df2d6f8c563
@@ -46,6 +46,9 @@ 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 QList<QVariant> availableValues( const QVariantMap &config, int countLimit ) const;

};

/************************************************************************
@@ -19,6 +19,11 @@

const QString QgsValueMapFieldFormatter::NULL_VALUE = QStringLiteral( "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}" );

QgsValueMapFieldFormatter::QgsValueMapFieldFormatter()
{
setFlags( flags() | QgsFieldFormatter::CanProvideAvailableValues );
}

QString QgsValueMapFieldFormatter::id() const
{
return QStringLiteral( "ValueMap" );
@@ -62,3 +67,17 @@ QVariant QgsValueMapFieldFormatter::sortValue( QgsVectorLayer *layer, int fieldI
{
return representValue( layer, fieldIndex, config, cache, value );
}

QList<QVariant> QgsValueMapFieldFormatter::availableValues( const QVariantMap &config, int countLimit ) const
{
QList<QVariant> values;
QList<QVariant> valueList = config.value( QStringLiteral( "map" ) ).toList();
for ( const QVariant &item : valueList )
{
values.append( item.toMap().constBegin().value() );
if ( values.count() == countLimit )
break;
}

return values;
}
@@ -49,13 +49,15 @@ class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter
/**
* Default constructor of field formatter for a value map field.
*/
QgsValueMapFieldFormatter() = default;
QgsValueMapFieldFormatter();

QString id() const override;

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

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

QList<QVariant> availableValues( const QVariantMap &config, int countLimit ) const override;
};

#endif // QGSVALUEMAPFIELDKIT_H

0 comments on commit 54f4efb

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