Skip to content
Permalink
Browse files

CanProvideAvailableValues as a flag on fieldformatter

  • Loading branch information
signedav committed Dec 16, 2019
1 parent 6baaae5 commit a02cdbc39a518ffb3db7f8428d3b8ee93a61e2f5
@@ -37,6 +37,13 @@ Default constructor

virtual ~QgsFieldFormatter();

enum Flag
{
CanProvideAvailableValues
};
typedef QFlags<QgsFieldFormatter::Flag> Flags;


virtual QString id() const = 0;
%Docstring
Returns a unique id for this field formatter.
@@ -96,6 +103,15 @@ according to the settings in the ``config``
.. versionadded:: 3.12
%End

Flags flags() const;
%Docstring
Returns the flags
%End

void setFlags( const Flags &flags );
%Docstring
Sets the ``flags``
%End

};

@@ -23,6 +23,11 @@
#include "qgsvectorlayer.h"
#include "qgsexpressioncontextutils.h"

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

QString QgsRelationReferenceFieldFormatter::id() const
{
return QStringLiteral( "RelationReference" );
@@ -34,7 +34,7 @@ class CORE_EXPORT QgsRelationReferenceFieldFormatter : public QgsFieldFormatter
/**
* Default constructor of field formatter for a relation reference field.
*/
QgsRelationReferenceFieldFormatter() = default;
QgsRelationReferenceFieldFormatter();

QString id() const override;

@@ -76,3 +76,8 @@ QList<QVariant> QgsFieldFormatter::availableValues( const QVariantMap &config, i

return QList<QVariant>();
}

void QgsFieldFormatter::setFlags( const Flags &flags )
{
mFlags = flags;
}
@@ -49,6 +49,12 @@ class CORE_EXPORT QgsFieldFormatter

virtual ~QgsFieldFormatter() = default;

enum Flag
{
CanProvideAvailableValues = 1 //!< Can provide possible values
};
Q_DECLARE_FLAGS( Flags, Flag )

/**
* Returns a unique id for this field formatter.
* This id will later be used to identify this field formatter in the registry with QgsFieldFormatterRegistry::fieldFormatter().
@@ -120,7 +126,18 @@ class CORE_EXPORT QgsFieldFormatter
*/
virtual QList<QVariant> availableValues( const QVariantMap &config, int countLimit ) const;

/**
* Returns the flags
*/
Flags flags() const { return mFlags; }

/**
* Sets the \a flags
*/
void setFlags( const Flags &flags );

private:
Flags mFlags;
};

#endif // QGSFIELDKIT_H
@@ -248,7 +248,9 @@ void QgsExpressionBuilderWidget::currentChanged( const QModelIndex &index, const
if ( fieldIndex != -1 )
{
const QgsEditorWidgetSetup setup = fields.at( fieldIndex ).editorWidgetSetup();
cbxValuesInUse->setVisible( setup.config().contains( QStringLiteral( "Relation" ) ) );
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );

cbxValuesInUse->setVisible( formatter->flags() & QgsFieldFormatter::CanProvideAvailableValues );
cbxValuesInUse->setChecked( false );
}
}

0 comments on commit a02cdbc

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