18#include "moc_qgsserverquerystringparameter.cpp"
21#include "nlohmann/json.hpp"
24 : mName( name ), mRequired( required ), mType( type ), mDescription( description ), mDefaultValue( defaultValue )
35 if ( mRequired && !QUrlQuery( context.
request()->
url() ).hasQueryItem( mName ) )
42 if ( QUrlQuery( context.
request()->
url() ).hasQueryItem( mName ) )
44 value = QUrlQuery( context.
request()->
url() ).queryItemValue( mName, QUrl::FullyDecoded );
46 else if ( mDefaultValue.isValid() )
48 value = mDefaultValue;
51 if (
value.isValid() )
54 const QMetaType::Type targetType {
static_cast<QMetaType::Type
>( mType ) };
60 if (
value.userType() != targetType )
63 if (
value.canConvert(
static_cast<int>( targetType ) ) )
93 if ( mCustomValidator && !mCustomValidator( context,
value ) )
103 mCustomValidator = customValidator;
108 const auto nameString {
name().toStdString() };
109 auto dataType {
typeName( mType ).toLower().toStdString() };
111 if ( dataType ==
"list" )
115 else if ( dataType ==
"double" )
120 {
"name", nameString },
122 {
"required", mRequired },
125 {
"explode",
false },
126 {
"schema", { {
"type", dataType } } },
138 static const QMetaEnum metaEnum = QMetaEnum::fromType<Type>();
139 return metaEnum.valueToKey(
static_cast<int>( type ) );
Bad request error API exception.
The QgsServerApiContext class encapsulates the resources for a particular client request: the request...
const QgsServerRequest * request() const
Returns the server request object.
QString description() const
Returns parameter description.
virtual QVariant value(const QgsServerApiContext &context) const
Extracts the value from the request context by validating the parameter value and converting it to it...
QgsServerQueryStringParameter(const QString name, bool required=false, Type type=QgsServerQueryStringParameter::Type::String, const QString &description=QString(), const QVariant &defaultValue=QVariant())
Constructs a QgsServerQueryStringParameter object.
void setHidden(bool hidden)
Set the parameter's hidden status, parameters are not hidden by default.
QString name() const
Returns the name of the parameter.
Type
The Type enum represents the parameter type.
@ String
Parameter is a string.
@ Boolean
Parameter is a boolean.
@ List
Parameter is a (comma separated) list of strings, the handler will perform any further required conve...
@ Integer
Parameter is an integer.
@ Double
Parameter is a double.
json data() const
Returns the handler information as a JSON object.
virtual ~QgsServerQueryStringParameter()
static QString typeName(const Type type)
Returns the name of the type.
void setDescription(const QString &description)
Sets validator description.
void setCustomValidator(const customValidator &customValidator)
Sets the custom validation function to customValidator.
bool hidden() const
Returns true if the parameter is hidden from the schema.