24 #include <QNetworkReply>
25 #include <QNetworkRequest>
32 const QVariant defaultValue )
34 , mDefaultValue( defaultValue )
40 return QVariant::typeToName(
mType );
47 QString cStr =
mValue.toString();
49 if ( !cStr.isEmpty() )
52 if ( cStr.startsWith( QLatin1String(
"0x" ), Qt::CaseInsensitive ) )
54 cStr.replace( 0, 2, QStringLiteral(
"#" ) );
57 color = QColor( cStr );
67 QString value =
mValue.toString();
69 if ( value.isEmpty() && defaultValue )
79 return toString().split( delimiter, QString::SkipEmptyParts );
86 list =
toString().split( delimiter, QString::KeepEmptyParts );
95 QList<QgsGeometry> geoms;
108 return QList<QgsGeometry>();
118 QList<QColor> colors;
122 QString cStr( part );
123 if ( !cStr.isEmpty() )
126 if ( cStr.startsWith( QLatin1String(
"0x" ), Qt::CaseInsensitive ) )
128 cStr.replace( 0, 2, QStringLiteral(
"#" ) );
131 const QColor color = QColor( cStr );
132 ok = color.isValid();
136 return QList<QColor>();
139 colors.append( color );
153 const int val = part.toInt( &ok );
173 const double val = part.toDouble( &ok );
177 return QList<double>();
191 if ( !
mValue.toString().isEmpty() )
193 QStringList corners =
mValue.toString().split(
',' );
195 if ( corners.size() == 4 )
199 for (
int i = 0; i < 4; i++ )
201 corners[i].replace(
' ',
'+' );
202 d[i] = corners[i].toDouble( &ok );
209 if ( d[0] > d[2] || d[1] > d[3] )
232 QUrl url =
toUrl( ok );
244 QObject::tr(
"Request started [url: %1]" ).arg( url.toString() ),
245 QStringLiteral(
"Server" ) );
246 QNetworkRequest request( url );
247 request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
248 request.setAttribute( QNetworkRequest::CacheSaveControlAttribute,
true );
252 loop.exec( QEventLoop::ExcludeUserInputEvents );
254 QNetworkReply *reply = fetcher.
reply();
259 QObject::tr(
"Request failed [error: no reply - url: %1]" ).arg( url.toString() ),
260 QStringLiteral(
"Server" ) );
264 QVariant status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
265 if ( !status.isNull() && status.toInt() >= 400 )
268 if ( reply->error() != QNetworkReply::NoError )
271 QObject::tr(
"Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ),
272 QStringLiteral(
"Server" ) );
274 QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
276 QObject::tr(
"Request error [status: %1 - reason phrase: %2] for %3" ).arg( status.toInt() ).arg( phrase.toString(), reply->url().toString() ),
277 QStringLiteral(
"Server" ) );
281 if ( reply->error() != QNetworkReply::NoError )
285 QObject::tr(
"Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ),
286 QStringLiteral(
"Server" ) );
291 QObject::tr(
"Request finished [url: %1]" ).arg( url.toString() ),
292 QStringLiteral(
"Server" ) );
295 ok = ( !content.isEmpty() );
304 if ( !
mValue.toString().isEmpty() )
309 ok = ( !val.isEmpty() && val.isValid() );
318 if ( !
mValue.toString().isEmpty() )
320 val =
mValue.toInt( &ok );
330 if ( !
mValue.toString().isEmpty() )
343 if ( !
mValue.toString().isEmpty() )
345 val =
mValue.toDouble( &ok );
365 const QVariant::Type type,
const QVariant defaultValue )
375 return QStringLiteral(
"VERSION" );
379 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerParameter::Name>() );
380 return metaEnum.valueToKey(
name );
386 if (
name.compare( QLatin1String(
"VERSION" ) ) == 0 )
392 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerParameter::Name>() );
399 const QString msg = QString(
"%1 ('%2') cannot be converted into %3" ).arg(
name(
mName ),
mValue.toString(),
typeName() );
424 mParameters[ parameter.
mName ] = parameter;
430 query.addQueryItem( key,
value );
436 QUrlQuery query = mUrlQuery;
438 if ( query.isEmpty() )
442 for (
auto param :
toMap().toStdMap() )
444 query.addQueryItem( param.first, param.second );
465 if ( mParameters.contains( paramName ) )
467 mParameters.take( paramName );
491 if ( serviceValue.isEmpty() )
494 if (
request() == QLatin1String(
"GetMap" ) \
495 ||
request() == QLatin1String(
"GetFeatureInfo" ) )
497 serviceValue =
"WMS";
508 for (
const auto ¶meter : mParameters.toStdMap() )
510 if ( parameter.second.mValue.isNull() )
515 params[
"VERSION"] = parameter.second.mValue.toString();
520 params[paramName] = parameter.second.mValue.toString();
546 return mParameters[name].mValue;
552 QUrlQuery cleanQuery( query );
553 cleanQuery.setQuery( query.query().replace(
'+', QStringLiteral(
"%20" ) ) );
556 for (
const auto &item : cleanQuery.queryItems( QUrl::FullyDecoded ) )
561 mParameters[name].mValue = item.second;
562 if ( ! mParameters[name].isValid() )
564 mParameters[name].raiseError();
567 else if ( item.first.compare( QLatin1String(
"VERSION" ), Qt::CaseInsensitive ) == 0 )
570 mParameters[name].mValue = item.second;
571 if ( ! mParameters[name].isValid() )
573 mParameters[name].raiseError();