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 && !QUrlQuery( context.
request()->
url() ).hasQueryItem( mName ) )
 
   51   if ( QUrlQuery( 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 )};
 
   70     if ( 
value.type() != targetType )
 
   73       if ( 
value.canConvert( 
static_cast<int>( targetType ) ) )
 
  103     if ( mCustomValidator && ! mCustomValidator( context, 
value ) )
 
  113   mCustomValidator = customValidator;
 
  118   const auto nameString { 
name().toStdString() };
 
  119   auto dataType { 
typeName( mType ).toLower().toStdString() };
 
  121   if ( dataType == 
"list" )
 
  125   else if ( dataType == 
"double" )
 
  131     { 
"name", nameString },
 
  133     { 
"required", mRequired },
 
  136     { 
"explode", 
false },
 
  137     { 
"schema", {{ 
"type", dataType }}},
 
  149   static const QMetaEnum metaEnum = QMetaEnum::fromType<Type>();
 
  150   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.
QString name() const
Returns the name of the parameter.
Type
The Type enum represents the parameter type.
@ Boolean
parameter is a double
@ List
parameter is a boolean
@ Integer
parameter is a string
@ Double
parameter is an integer
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.