20 #include "nlohmann/json.hpp" 25 const QString &description,
26 const QVariant &defaultValue ):
28 mRequired( required ),
30 mDescription( description ),
31 mDefaultValue( defaultValue )
44 if ( mRequired && ! context.
request()->
url().hasQueryItem( mName ) )
51 if ( context.
request()->
url().hasQueryItem( mName ) )
53 value = QUrlQuery( context.
request()->
url() ).queryItemValue( mName, QUrl::FullyDecoded );
55 else if ( mDefaultValue.isValid() )
57 value = mDefaultValue;
60 if ( value.isValid() )
64 const QVariant::Type targetType {
static_cast< QVariant::Type
>( mType )};
68 value = value.toString().split(
',' );
70 if ( value.type() != targetType )
73 if ( value.canConvert( static_cast<int>( targetType ) ) )
79 value = value.toString( );
82 value = value.toBool( );
85 value = value.toDouble( &ok );
88 value = value.toLongLong( &ok );
104 if ( mCustomValidator && ! mCustomValidator( context, value ) )
114 mCustomValidator = customValidator;
119 const auto nameString {
name().toStdString() };
120 auto dataType {
typeName( mType ).toLower().toStdString() };
122 if ( dataType ==
"list" )
128 {
"name", nameString },
129 {
"description",
"Filter the collection by '" + nameString +
"'" },
130 {
"required", mRequired },
133 {
"explode",
false },
134 {
"schema", {{
"type", dataType }}},
146 static QMetaEnum metaEnum = QMetaEnum::fromType<Type>();
147 return metaEnum.valueToKey( static_cast<int>( type ) );
void setDescription(const QString &description)
Sets validator description.
virtual ~QgsServerQueryStringParameter()
QString name() const
Returns the name of the parameter.
static QString typeName(const Type type)
Returns the name of the type.
void setCustomValidator(const customValidator &customValidator)
Sets the custom validation function to customValidator.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
QString description() const
Returns parameter description.
QgsServerQueryStringParameter(const QString name, bool required=false, Type type=QgsServerQueryStringParameter::Type::String, const QString &description=QString(), const QVariant &defaultValue=QVariant())
Constructs a QgsServerQueryStringParameter object.
Bad request error API exception.
json data() const
Returns the handler information as a JSON object.
virtual QVariant value(const QgsServerApiContext &context) const
Extracts the value from the request context by validating the parameter value and converting it to it...
Type
The Type enum represents the parameter type.
const QgsServerRequest * request() const
Returns the server request object.