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 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
80 return toString().split( delimiter, QString::SkipEmptyParts );
82 return toString().split( delimiter, Qt::SkipEmptyParts );
90 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
91 list =
toString().split( delimiter, QString::KeepEmptyParts );
93 list =
toString().split( delimiter, Qt::KeepEmptyParts );
103 QList<QgsGeometry> geoms;
105 const auto constStringList(
toStringList( delimiter ) );
106 for (
const auto &wkt : constStringList )
117 return QList<QgsGeometry>();
130 while ( pos < filter.size() )
132 if ( pos + 1 < filter.size() && filter[pos] ==
'(' && filter[pos + 1] ==
'<' )
135 int posEnd = filter.indexOf(
"Filter>)", pos );
138 posEnd = filter.size();
140 filters.append( filter.mid( pos + 1, posEnd - pos + 6 ) );
143 else if ( pos + 1 < filter.size() && filter[pos] ==
'(' && filter[pos + 1] ==
')' )
146 filters.append(
"" );
149 else if ( filter[pos] ==
'<' && pos + 7 < filter.size() && filter.mid( pos + 1, 6 ).compare( QLatin1String(
"Filter" ) ) == 0 )
152 filters.append( filter.mid( pos ) );
170 auto isOgcFilter = [filter]()
172 return filter.contains( QStringLiteral(
"<Filter>" ) ) or filter.contains( QStringLiteral(
"()" ) );
175 while ( pos < filter.size() )
177 int posEnd = filter.indexOf(
';', pos );
179 if ( posEnd == pos + 1 )
181 if ( ! isOgcFilter() )
182 filters.append( QString() );
187 if ( ! isOgcFilter() )
188 filters.append( filter.mid( pos, posEnd - pos ) );
200 if ( ! filter.isEmpty() && filter.back() ==
';' )
202 filters.append( QString() );
211 QList<QColor> colors;
213 const auto constStringList(
toStringList( delimiter ) );
214 for (
const auto &part : constStringList )
216 QString cStr( part );
217 if ( !cStr.isEmpty() )
220 if ( cStr.startsWith( QLatin1String(
"0x" ), Qt::CaseInsensitive ) )
222 cStr.replace( 0, 2, QStringLiteral(
"#" ) );
225 const QColor color = QColor( cStr );
226 ok = color.isValid();
230 return QList<QColor>();
233 colors.append( color );
245 const auto constStringList(
toStringList( delimiter ) );
246 for (
const auto &part : constStringList )
248 const int val = part.toInt( &ok );
266 const auto constStringList(
toStringList( delimiter ) );
267 for (
const auto &part : constStringList )
269 const double val = part.toDouble( &ok );
273 return QList<double>();
287 if ( !
mValue.toString().isEmpty() )
289 QStringList corners =
mValue.toString().split(
',' );
291 if ( corners.size() == 4 )
295 for (
int i = 0; i < 4; i++ )
297 corners[i].replace(
' ',
'+' );
298 d[i] = corners[i].toDouble( &ok );
305 if ( d[0] > d[2] || d[1] > d[3] )
328 const QUrl url =
toUrl( ok );
340 QObject::tr(
"Request started [url: %1]" ).arg( url.toString() ),
341 QStringLiteral(
"Server" ) );
342 QNetworkRequest request( url );
343 request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
344 request.setAttribute( QNetworkRequest::CacheSaveControlAttribute,
true );
348 loop.exec( QEventLoop::ExcludeUserInputEvents );
350 QNetworkReply *reply = fetcher.
reply();
355 QObject::tr(
"Request failed [error: no reply - url: %1]" ).arg( url.toString() ),
356 QStringLiteral(
"Server" ) );
360 const QVariant status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
361 if ( !status.isNull() && status.toInt() >= 400 )
364 if ( reply->error() != QNetworkReply::NoError )
367 QObject::tr(
"Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ),
368 QStringLiteral(
"Server" ) );
370 const QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
372 QObject::tr(
"Request error [status: %1 - reason phrase: %2] for %3" ).arg( status.toInt() ).arg( phrase.toString(), reply->url().toString() ),
373 QStringLiteral(
"Server" ) );
377 if ( reply->error() != QNetworkReply::NoError )
381 QObject::tr(
"Request failed [error: %1 - url: %2]" ).arg( reply->errorString(), reply->url().toString() ),
382 QStringLiteral(
"Server" ) );
387 QObject::tr(
"Request finished [url: %1]" ).arg( url.toString() ),
388 QStringLiteral(
"Server" ) );
391 ok = ( !content.isEmpty() );
400 if ( !
mValue.toString().isEmpty() )
405 ok = ( !val.isEmpty() && val.isValid() );
414 if ( !
mValue.toString().isEmpty() )
416 val =
mValue.toInt( &ok );
426 if ( !
mValue.toString().isEmpty() )
439 if ( !
mValue.toString().isEmpty() )
441 val =
mValue.toDouble( &ok );
461 const QVariant::Type type,
const QVariant defaultValue )
471 return QStringLiteral(
"VERSION" );
475 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerParameter::Name>() );
476 return metaEnum.valueToKey(
name );
482 if (
name.compare( QLatin1String(
"VERSION" ) ) == 0 )
488 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerParameter::Name>() );
495 const QString msg = QString(
"%1 ('%2') cannot be converted into %3" ).arg(
name(
mName ),
mValue.toString(),
typeName() );
520 mParameters[ parameter.
mName ] = parameter;
526 query.addQueryItem( key,
value );
532 QUrlQuery query = mUrlQuery;
534 if ( query.isEmpty() )
538 const auto constMap(
toMap().toStdMap() );
539 for (
const auto ¶m : constMap )
541 const QString
value = QUrl::toPercentEncoding( QString( param.second ) );
542 query.addQueryItem( param.first,
value );
563 if ( mParameters.contains( paramName ) )
565 mParameters.take( paramName );
589 if ( serviceValue.isEmpty() )
592 if (
request() == QLatin1String(
"GetMap" ) \
593 ||
request() == QLatin1String(
"GetFeatureInfo" ) )
595 serviceValue =
"WMS";
606 for (
const auto ¶meter : mParameters.toStdMap() )
608 if ( parameter.second.mValue.isNull() )
613 params[
"VERSION"] = parameter.second.mValue.toString();
618 params[paramName] = parameter.second.mValue.toString();
644 return mParameters[name].mValue;
650 QUrlQuery cleanQuery( query );
651 cleanQuery.setQuery( query.query().replace(
'+', QLatin1String(
"%20" ) ) );
654 const auto constQueryItems( cleanQuery.queryItems( QUrl::FullyDecoded ) );
655 for (
const auto &item : constQueryItems )
660 mParameters[name].mValue = item.second;
661 if ( ! mParameters[name].isValid() )
663 mParameters[name].raiseError();
666 else if ( item.first.compare( QLatin1String(
"VERSION" ), Qt::CaseInsensitive ) == 0 )
669 mParameters[name].mValue = item.second;
670 if ( ! mParameters[name].isValid() )
672 mParameters[name].raiseError();