QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgswmsparameters.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswmsparameters.cpp
3 --------------------
4 begin : March 17, 2017
5 copyright : (C) 2017 by Paul Blottiere
6 email : paul dot blottiere at oslandia dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgswmsparameters.h"
19#include "moc_qgswmsparameters.cpp"
20#include "qgsdatasourceuri.h"
22#include "qgsmessagelog.h"
24#include "qgsfontutils.h"
25
26#include <QRegularExpression>
27
28const QString EXTERNAL_LAYER_PREFIX = QStringLiteral( "EXTERNAL_WMS:" );
29
30namespace QgsWms
31{
32 //
33 // QgsWmsParameter
34 //
35 QgsWmsParameter::QgsWmsParameter( const QgsWmsParameter::Name name, const QMetaType::Type type, const QVariant defaultValue )
36 : QgsServerParameterDefinition( type, defaultValue )
37 , mName( name )
38 {
39 }
40
45
47 {
48 const QString msg = QString( "%1 ('%2') cannot be converted into %3" ).arg( name( mName ), toString(), typeName() );
50 }
51
52 QStringList QgsWmsParameter::toStyleList( const char delimiter ) const
53 {
54 return QgsServerParameterDefinition::toStringList( delimiter, false );
55 }
56
57 QList<QgsGeometry> QgsWmsParameter::toGeomList( const char delimiter ) const
58 {
59 bool ok = true;
60 const QList<QgsGeometry> geoms = QgsServerParameterDefinition::toGeomList( ok, delimiter );
61
62 if ( !ok )
63 {
64 const QString msg = QString( "%1 ('%2') cannot be converted into a list of geometries" ).arg( name( mName ), toString() );
66 }
67
68 return geoms;
69 }
70
72 {
73 bool ok = true;
75
76 if ( !ok )
77 {
78 const QString msg = QString( "%1 ('%2') cannot be converted into a rectangle" ).arg( name( mName ), toString() );
80 }
81
82 return rect;
83 }
84
86 {
87 bool ok = false;
88 const int val = QgsServerParameterDefinition::toInt( ok );
89
90 if ( !ok )
91 {
92 raiseError();
93 }
94
95 return val;
96 }
97
99 {
100 // Check URL -- it will be used in error messages
101 const QUrl url = toUrl();
102
103 bool ok = false;
104 const QString content = QgsServerParameterDefinition::loadUrl( ok );
105
106 if ( !ok )
107 {
108 const QString msg = QString( "%1 request error for %2" ).arg( name( mName ), url.toString() );
110 }
111
112 return content;
113 }
114
116 {
117 bool ok = false;
118 const QUrl url = QgsServerParameterDefinition::toUrl( ok );
119
120 if ( !ok )
121 {
122 raiseError();
123 }
124
125 return url;
126 }
127
129 {
130 bool ok = false;
131 const QColor col = QgsServerParameterDefinition::toColor( ok );
132
133 if ( !ok )
134 {
135 raiseError();
136 }
137
138 return col;
139 }
140
141 QList<QColor> QgsWmsParameter::toColorList( const char delimiter ) const
142 {
143 bool ok = false;
144 const QList<QColor> vals = QgsServerParameterDefinition::toColorList( ok, delimiter );
145
146 if ( !ok )
147 {
148 const QString msg = QString( "%1 ('%2') cannot be converted into a list of colors" ).arg( name( mName ), toString() );
150 }
151
152 return vals;
153 }
154
155 QList<int> QgsWmsParameter::toIntList( const char delimiter ) const
156 {
157 bool ok = false;
158 const QList<int> vals = QgsServerParameterDefinition::toIntList( ok, delimiter );
159
160 if ( !ok )
161 {
162 const QString msg = QString( "%1 ('%2') cannot be converted into a list of int" ).arg( name( mName ), toString() );
164 }
165
166 return vals;
167 }
168
169 QList<double> QgsWmsParameter::toDoubleList( const char delimiter ) const
170 {
171 bool ok = false;
172 const QList<double> vals = QgsServerParameterDefinition::toDoubleList( ok, delimiter );
173
174 if ( !ok )
175 {
176 const QString msg = QString( "%1 ('%2') cannot be converted into a list of float" ).arg( name( mName ), toString() );
178 }
179
180 return vals;
181 }
182
184 {
185 bool ok = false;
186 const double val = QgsServerParameterDefinition::toDouble( ok );
187
188 if ( !ok )
189 {
190 raiseError();
191 }
192
193 return val;
194 }
195
196 QString QgsWmsParameter::name() const
197 {
199 }
200
202 {
203 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
204 return metaEnum.valueToKey( name );
205 }
206
208 {
209 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
210 return ( QgsWmsParameter::Name ) metaEnum.keyToValue( name.toUpper().toStdString().c_str() );
211 }
212
213 //
214 // QgsWmsParameters
215 //
218 {
219 // Available version number
220 mVersions.append( QgsProjectVersion( 1, 1, 1 ) );
221 mVersions.append( QgsProjectVersion( 1, 3, 0 ) );
222
223 // WMS parameters definition
224 const QgsWmsParameter pQuality( QgsWmsParameter::IMAGE_QUALITY, QMetaType::Type::Int, QVariant( 0 ) );
225 save( pQuality );
226
227 const QgsWmsParameter pTiled( QgsWmsParameter::TILED, QMetaType::Type::Bool, QVariant( false ) );
228 save( pTiled );
229
230 const QgsWmsParameter pBoxSpace( QgsWmsParameter::BOXSPACE, QMetaType::Type::Double, QVariant( 2.0 ) );
231 save( pBoxSpace );
232
233 const QgsWmsParameter pSymbSpace( QgsWmsParameter::SYMBOLSPACE, QMetaType::Type::Double, QVariant( 2.0 ) );
234 save( pSymbSpace );
235
236 const QgsWmsParameter pLayerSpace( QgsWmsParameter::LAYERSPACE, QMetaType::Type::Double, QVariant( 3.0 ) );
237 save( pLayerSpace );
238
239 const QgsWmsParameter pTitleSpace( QgsWmsParameter::LAYERTITLESPACE, QMetaType::Type::Double, QVariant( 3.0 ) );
240 save( pTitleSpace );
241
242 const QgsWmsParameter pSymbHeight( QgsWmsParameter::SYMBOLHEIGHT, QMetaType::Type::Double, QVariant( 4.0 ) );
243 save( pSymbHeight );
244
245 const QgsWmsParameter pSymbWidth( QgsWmsParameter::SYMBOLWIDTH, QMetaType::Type::Double, QVariant( 7.0 ) );
246 save( pSymbWidth );
247
248 const QgsWmsParameter pIcLabelSpace( QgsWmsParameter::ICONLABELSPACE, QMetaType::Type::Double, QVariant( 2.0 ) );
249 save( pIcLabelSpace );
250
252 save( pItFontFamily );
253
254 const QgsWmsParameter pItFontBold( QgsWmsParameter::ITEMFONTBOLD, QMetaType::Type::Bool, QVariant( false ) );
255 save( pItFontBold );
256
257 const QgsWmsParameter pItFontItalic( QgsWmsParameter::ITEMFONTITALIC, QMetaType::Type::Bool, QVariant( false ) );
258 save( pItFontItalic );
259
260 const QgsWmsParameter pItFontSize( QgsWmsParameter::ITEMFONTSIZE, QMetaType::Type::Double, QVariant( -1 ) );
261 save( pItFontSize );
262
263 const QgsWmsParameter pItFontColor( QgsWmsParameter::ITEMFONTCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
264 save( pItFontColor );
265
266 const QgsWmsParameter pHighlightGeom( QgsWmsParameter::HIGHLIGHT_GEOM );
267 save( pHighlightGeom );
268
269 const QgsWmsParameter pShowFeatureCount( QgsWmsParameter::SHOWFEATURECOUNT, QMetaType::Type::Bool, QVariant( false ) );
270 save( pShowFeatureCount );
271
272 const QgsWmsParameter pHighlightSymbol( QgsWmsParameter::HIGHLIGHT_SYMBOL );
273 save( pHighlightSymbol );
274
276 save( pHighlightLabel );
277
278 const QgsWmsParameter pHighlightColor( QgsWmsParameter::HIGHLIGHT_LABELCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
279 save( pHighlightColor );
280
281 const QgsWmsParameter pHighlightFontSize( QgsWmsParameter::HIGHLIGHT_LABELSIZE );
282 save( pHighlightFontSize );
283
284 const QgsWmsParameter pHighlightFontWeight( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT );
285 save( pHighlightFontWeight );
286
288 save( pHighlightFont );
289
290 const QgsWmsParameter pHighlightBufferColor( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
291 save( pHighlightBufferColor );
292
294 save( pHighlightBufferSize );
295
296 const QgsWmsParameter pLabelRotation( QgsWmsParameter::HIGHLIGHT_LABEL_ROTATION, QMetaType::Type::Double );
297 save( pLabelRotation );
298
299 const QgsWmsParameter pLabelDistance( QgsWmsParameter::HIGHLIGHT_LABEL_DISTANCE, QMetaType::Type::Double );
300 save( pLabelDistance );
301
303 save( pLabelHali );
304
306 save( pLabelVali );
307
309 save( pCRS );
310
312 save( pSRS );
313
314 const QgsWmsParameter pFormat( QgsWmsParameter::FORMAT, QMetaType::Type::QString, QVariant( "png" ) );
315 save( pFormat );
316
318 save( pInfoFormat );
319
320 const QgsWmsParameter pI( QgsWmsParameter::I, QMetaType::Type::Int, QVariant( -1 ) );
321 save( pI );
322
323 const QgsWmsParameter pJ( QgsWmsParameter::J, QMetaType::Type::Int, QVariant( -1 ) );
324 save( pJ );
325
326 const QgsWmsParameter pX( QgsWmsParameter::X, QMetaType::Type::Int, QVariant( -1 ) );
327 save( pX );
328
329 const QgsWmsParameter pY( QgsWmsParameter::Y, QMetaType::Type::Int, QVariant( -1 ) );
330 save( pY );
331
333 save( pRule );
334
335 const QgsWmsParameter pRuleLabel( QgsWmsParameter::RULELABEL, QMetaType::Type::Bool, QVariant( true ) );
336 save( pRuleLabel );
337
338 const QgsWmsParameter pShowRuleDetails( QgsWmsParameter::SHOWRULEDETAILS, QMetaType::Type::Bool, QVariant( false ) );
339 save( pShowRuleDetails );
340
341 const QgsWmsParameter pScale( QgsWmsParameter::SCALE, QMetaType::Type::Double, QVariant( -1 ) );
342 save( pScale );
343
344 const QgsWmsParameter pHeight( QgsWmsParameter::HEIGHT, QMetaType::Type::Int, QVariant( 0 ) );
345 save( pHeight );
346
347 const QgsWmsParameter pWidth( QgsWmsParameter::WIDTH, QMetaType::Type::Int, QVariant( 0 ) );
348 save( pWidth );
349
350 const QgsWmsParameter pSrcHeight( QgsWmsParameter::SRCHEIGHT, QMetaType::Type::Int, QVariant( 0 ) );
351 save( pSrcHeight );
352
353 const QgsWmsParameter pSrcWidth( QgsWmsParameter::SRCWIDTH, QMetaType::Type::Int, QVariant( 0 ) );
354 save( pSrcWidth );
355
357 save( pBbox );
358
360 save( pSld );
361
363 save( pSldBody );
364
366 save( pLayer );
367
369 save( pLayers );
370
372 save( pQueryLayers );
373
374 const QgsWmsParameter pFeatureCount( QgsWmsParameter::FEATURE_COUNT, QMetaType::Type::Int, QVariant( 1 ) );
375 save( pFeatureCount );
376
377 const QgsWmsParameter pLayerTitle( QgsWmsParameter::LAYERTITLE, QMetaType::Type::Bool, QVariant( true ) );
378 save( pLayerTitle );
379
381 save( pLayerFtFamily );
382
383 const QgsWmsParameter pLayerFtBold( QgsWmsParameter::LAYERFONTBOLD, QMetaType::Type::Bool, QVariant( false ) );
384 save( pLayerFtBold );
385
386 const QgsWmsParameter pLayerFtItalic( QgsWmsParameter::LAYERFONTITALIC, QMetaType::Type::Bool, QVariant( false ) );
387 save( pLayerFtItalic );
388
389 const QgsWmsParameter pLayerFtSize( QgsWmsParameter::LAYERFONTSIZE, QMetaType::Type::Double, QVariant( -1 ) );
390 save( pLayerFtSize );
391
392 const QgsWmsParameter pLayerFtColor( QgsWmsParameter::LAYERFONTCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
393 save( pLayerFtColor );
394
396 save( pStyle );
397
399 save( pStyles );
400
402 save( pOpacities );
403
405 save( pFilter );
406
408 save( pFilterGeom );
409
410 const QgsWmsParameter pPolygTol( QgsWmsParameter::FI_POLYGON_TOLERANCE, QMetaType::Type::Double, QVariant( 0.0 ) );
411 save( pPolygTol );
412
413 const QgsWmsParameter pLineTol( QgsWmsParameter::FI_LINE_TOLERANCE, QMetaType::Type::Double, QVariant( 0.0 ) );
414 save( pLineTol );
415
416 const QgsWmsParameter pPointTol( QgsWmsParameter::FI_POINT_TOLERANCE, QMetaType::Type::Double, QVariant( 0.0 ) );
417 save( pPointTol );
418
420 save( pSelection );
421
422 const QgsWmsParameter pWmsPrecision( QgsWmsParameter::WMS_PRECISION, QMetaType::Type::Int, QVariant( -1 ) );
423 save( pWmsPrecision );
424
425 const QgsWmsParameter pTransparent( QgsWmsParameter::TRANSPARENT, QMetaType::Type::Bool, QVariant( false ) );
426 save( pTransparent );
427
428 const QgsWmsParameter pBgColor( QgsWmsParameter::BGCOLOR, QMetaType::Type::QString, QVariant( "white" ) );
429 save( pBgColor );
430
431 const QgsWmsParameter pDpi( QgsWmsParameter::DPI, QMetaType::Type::Int, QVariant( -1 ) );
432 save( pDpi );
433
435 save( pTemplate );
436
438 save( pExtent );
439
440 const QgsWmsParameter pRotation( QgsWmsParameter::ROTATION, QMetaType::Type::Double, QVariant( 0.0 ) );
441 save( pRotation );
442
443 const QgsWmsParameter pGridX( QgsWmsParameter::GRID_INTERVAL_X, QMetaType::Type::Double, QVariant( 0.0 ) );
444 save( pGridX );
445
446 const QgsWmsParameter pGridY( QgsWmsParameter::GRID_INTERVAL_Y, QMetaType::Type::Double, QVariant( 0.0 ) );
447 save( pGridY );
448
449 const QgsWmsParameter pWithGeometry( QgsWmsParameter::WITH_GEOMETRY, QMetaType::Type::Bool, QVariant( false ) );
450 save( pWithGeometry );
451
452 const QgsWmsParameter pWithMapTip( QgsWmsParameter::WITH_MAPTIP, QMetaType::Type::QString );
453 save( pWithMapTip );
454
455 const QgsWmsParameter pWithDisplayName( QgsWmsParameter::WITH_DISPLAY_NAME, QMetaType::Type::Bool, QVariant( false ) );
456 save( pWithDisplayName );
457
459 save( pWmtver );
460
461 const QgsWmsParameter pAtlasPk( QgsWmsParameter::ATLAS_PK, QMetaType::Type::QStringList );
462 save( pAtlasPk );
463
464 const QgsWmsParameter pFormatOpts( QgsWmsParameter::FORMAT_OPTIONS, QMetaType::Type::QString );
465 save( pFormatOpts );
466
467 const QgsWmsParameter pAddLayerGroups( QgsWmsParameter::ADDLAYERGROUPS, QMetaType::Type::Bool, QVariant( false ) );
468 save( pAddLayerGroups );
469 }
470
473 {
474 load( parameters.urlQuery() );
475
476 auto it = mWmsParameters.constFind( QgsWmsParameter::SLD );
477 if ( it != mWmsParameters.constEnd() && !it->toString().isEmpty() )
478 {
479 const QString sldBody = it->loadUrl();
480 if ( !sldBody.isEmpty() )
481 {
483 }
484 }
485 }
486
488 {
489 return mWmsParameters.value( name );
490 }
491
492 void QgsWmsParameters::set( QgsWmsParameter::Name name, const QVariant &value )
493 {
494 auto it = mWmsParameters.find( name );
495 if ( it == mWmsParameters.end() )
496 {
497 it = mWmsParameters.insert( name, QgsWmsParameter() );
498 }
499
500 it->mValue = value;
501 }
502
503 bool QgsWmsParameters::loadParameter( const QString &key, const QString &value )
504 {
505 bool loaded = false;
506
507 const thread_local QRegularExpression composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), QRegularExpression::CaseInsensitiveOption );
508 if ( key.contains( composerParamRegExp ) )
509 {
510 const int mapId = QStringView { key }.mid( 3, key.indexOf( ':' ) - 3 ).toInt();
511 const QString theKey = key.mid( key.indexOf( ':' ) + 1 );
512 const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey );
513
514 if ( name >= 0 )
515 {
516 QgsWmsParameter param = mWmsParameters.value( name );
517 param.mValue = value;
518 param.mMapId = mapId;
519
520 if ( !param.isValid() )
521 {
522 param.raiseError();
523 }
524
525 save( param, true ); // multi MAP parameters for composer
526 loaded = true;
527 }
528 }
529 else
530 {
532 if ( name >= 0 )
533 {
534 auto it = mWmsParameters.find( name );
535 if ( it == mWmsParameters.end() )
536 it = mWmsParameters.insert( name, QgsWmsParameter() );
537
538 it->mValue = value;
539 if ( !it->isValid() )
540 {
541 it->raiseError();
542 }
543
544 loaded = true;
545 }
546 else //maybe an external wms parameter?
547 {
548 int separator = key.indexOf( QLatin1Char( ':' ) );
549 if ( separator >= 1 )
550 {
551 QString id = key.left( separator );
552 QString param = key.right( key.length() - separator - 1 );
553 mExternalWMSParameters[id].insert( param, value );
554
555 loaded = true;
556 }
557 }
558 }
559
560 return loaded;
561 }
562
564 {
565 log( QStringLiteral( "WMS Request parameters:" ) );
566 for ( auto it = mWmsParameters.constBegin(); it != mWmsParameters.constEnd(); ++it )
567 {
568 const QString value = it->toString();
569
570 if ( !value.isEmpty() )
571 {
572 QString name = QgsWmsParameter::name( it.key() );
573
574 if ( it->mMapId >= 0 )
575 {
576 name = QStringLiteral( "%1:%2" ).arg( QString::number( it->mMapId ), name );
577 }
578
579 log( QStringLiteral( " - %1 : %2" ).arg( name, value ) );
580 }
581 }
582
583 if ( !version().isEmpty() )
584 log( QStringLiteral( " - VERSION : %1" ).arg( version() ) );
585 }
586
587 void QgsWmsParameters::save( const QgsWmsParameter &parameter, bool multi )
588 {
589 if ( multi )
590 {
591 mWmsParameters.insert( parameter.mName, parameter );
592 }
593 else
594 {
595 mWmsParameters.replace( parameter.mName, parameter );
596 }
597 }
598
600 {
601 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_GEOM ).toStringList( ';' );
602 }
603
604 QList<QgsGeometry> QgsWmsParameters::highlightGeomAsGeom() const
605 {
606 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_GEOM ).toGeomList( ';' );
607 }
608
610 {
611 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_SYMBOL ).toStringList( ';' );
612 }
613
614 QString QgsWmsParameters::crs() const
615 {
616 QString rs;
617 const QString srs = mWmsParameters.value( QgsWmsParameter::SRS ).toString();
618 const QString crs = mWmsParameters.value( QgsWmsParameter::CRS ).toString();
619
620 // both SRS/CRS are supported but there's a priority according to the
621 // specified version when both are defined in the request
622 if ( !srs.isEmpty() && crs.isEmpty() )
623 rs = srs;
624 else if ( srs.isEmpty() && !crs.isEmpty() )
625 rs = crs;
626 else if ( !srs.isEmpty() && !crs.isEmpty() )
627 {
628 if ( versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
629 rs = crs;
630 else
631 rs = srs;
632 }
633
634 return rs;
635 }
636
638 {
639 return mWmsParameters.value( QgsWmsParameter::BBOX ).toString();
640 }
641
643 {
644 return mWmsParameters.value( QgsWmsParameter::BBOX ).toRectangle();
645 }
646
648 {
649 return mWmsParameters.value( QgsWmsParameter::HEIGHT ).toString();
650 }
651
653 {
654 return mWmsParameters.value( QgsWmsParameter::WIDTH ).toString();
655 }
656
658 {
659 return mWmsParameters.value( QgsWmsParameter::HEIGHT ).toInt();
660 }
661
663 {
664 return mWmsParameters.value( QgsWmsParameter::WIDTH ).toInt();
665 }
666
668 {
669 return mWmsParameters.value( QgsWmsParameter::SRCHEIGHT ).toString();
670 }
671
673 {
674 return mWmsParameters.value( QgsWmsParameter::SRCWIDTH ).toString();
675 }
676
678 {
679 return mWmsParameters.value( QgsWmsParameter::SRCHEIGHT ).toInt();
680 }
681
683 {
684 return mWmsParameters.value( QgsWmsParameter::SRCWIDTH ).toInt();
685 }
686
687 QString QgsWmsParameters::dpi() const
688 {
689 return mWmsParameters.value( QgsWmsParameter::DPI ).toString();
690 }
691
693 {
694 return mWmsParameters.value( QgsWmsParameter::DPI ).toDouble();
695 }
696
698 {
700
701 if ( QgsServerParameters::request().compare( QLatin1String( "GetProjectSettings" ), Qt::CaseInsensitive ) == 0 )
702 {
703 version = QStringLiteral( "1.3.0" );
704 }
705 else if ( version.isEmpty() )
706 {
707 if ( !wmtver().isEmpty() )
708 {
709 version = wmtver();
710 }
711 else
712 {
713 version = QStringLiteral( "1.3.0" );
714 }
715 }
716 else if ( !mVersions.contains( QgsProjectVersion( version ) ) )
717 {
718 // WMS 1.3.0 specification: If a version lower than any of those
719 // known to the server is requested, then the server shall send the
720 // lowest version it supports.
721 if ( QgsProjectVersion( 1, 1, 1 ) > QgsProjectVersion( version ) )
722 {
723 version = QStringLiteral( "1.1.1" );
724 }
725 else
726 {
727 version = QStringLiteral( "1.3.0" );
728 }
729 }
730
731 return version;
732 }
733
735 {
736 QString req = QgsServerParameters::request();
737
738 if ( version().compare( QLatin1String( "1.1.1" ) ) == 0
739 && req.compare( QLatin1String( "capabilities" ), Qt::CaseInsensitive ) == 0 )
740 {
741 req = QStringLiteral( "GetCapabilities" );
742 }
743
744 return req;
745 }
746
751
752 bool QgsWmsParameters::versionIsValid( const QString version ) const
753 {
754 return mVersions.contains( QgsProjectVersion( version ) );
755 }
756
758 {
759 return mWmsParameters.value( QgsWmsParameter::FORMAT ).toString( true );
760 }
761
763 {
764 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameters::Format>() );
765 return metaEnum.valueToKey( format );
766 }
767
769 {
770 const QString fStr = formatAsString();
771
773 if ( fStr.compare( QLatin1String( "image/png" ), Qt::CaseInsensitive ) == 0 || fStr.compare( QLatin1String( "png" ), Qt::CaseInsensitive ) == 0 )
774 {
775 f = Format::PNG;
776 }
777 else if ( fStr.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0
778 || fStr.compare( QLatin1String( "jpeg" ), Qt::CaseInsensitive ) == 0
779 || fStr.compare( QLatin1String( "image/jpeg" ), Qt::CaseInsensitive ) == 0 )
780 {
781 f = Format::JPG;
782 }
783 else if ( fStr.compare( QLatin1String( "image/svg" ), Qt::CaseInsensitive ) == 0 || fStr.compare( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive ) == 0 || fStr.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
784 {
785 f = Format::SVG;
786 }
787 else if ( fStr.compare( QLatin1String( "application/pdf" ), Qt::CaseInsensitive ) == 0 || fStr.compare( QLatin1String( "pdf" ), Qt::CaseInsensitive ) == 0 )
788 {
789 f = Format::PDF;
790 }
791 else if ( fStr.compare( QLatin1String( "application/json" ), Qt::CaseInsensitive ) == 0 || fStr.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 )
792 {
793 f = Format::JSON;
794 }
795 return f;
796 }
797
799 {
800 return mWmsParameters.value( QgsWmsParameter::INFO_FORMAT ).toString();
801 }
802
804 {
805 return infoFormat() == Format::PNG || infoFormat() == Format::JPG;
806 }
807
809 {
810 QString fStr = infoFormatAsString();
811
813 if ( fStr.isEmpty() )
814 return f;
815
816 if ( fStr.startsWith( QLatin1String( "text/xml" ), Qt::CaseInsensitive ) )
817 f = Format::XML;
818 else if ( fStr.startsWith( QLatin1String( "text/html" ), Qt::CaseInsensitive ) )
819 f = Format::HTML;
820 else if ( fStr.startsWith( QLatin1String( "text/plain" ), Qt::CaseInsensitive ) )
821 f = Format::TEXT;
822 else if ( fStr.startsWith( QLatin1String( "application/vnd.ogc.gml" ), Qt::CaseInsensitive ) )
823 f = Format::GML;
824 else if ( fStr.startsWith( QLatin1String( "application/json" ), Qt::CaseInsensitive )
825 || fStr.startsWith( QLatin1String( "application/geo+json" ), Qt::CaseInsensitive ) )
826 f = Format::JSON;
827 else
828 f = Format::NONE;
829
830 return f;
831 }
832
834 {
835 if ( infoFormat() != Format::GML )
836 return -1;
837
838 QString fStr = infoFormatAsString();
839 if ( fStr.startsWith( QLatin1String( "application/vnd.ogc.gml/3" ), Qt::CaseInsensitive ) )
840 return 3;
841 else
842 return 2;
843 }
844
845 QString QgsWmsParameters::i() const
846 {
847 return mWmsParameters.value( QgsWmsParameter::I ).toString();
848 }
849
850 QString QgsWmsParameters::j() const
851 {
852 return mWmsParameters.value( QgsWmsParameter::J ).toString();
853 }
854
856 {
857 return mWmsParameters.value( QgsWmsParameter::I ).toInt();
858 }
859
861 {
862 return mWmsParameters.value( QgsWmsParameter::J ).toInt();
863 }
864
865 QString QgsWmsParameters::x() const
866 {
867 return mWmsParameters.value( QgsWmsParameter::X ).toString();
868 }
869
870 QString QgsWmsParameters::y() const
871 {
872 return mWmsParameters.value( QgsWmsParameter::Y ).toString();
873 }
874
876 {
877 return mWmsParameters.value( QgsWmsParameter::X ).toInt();
878 }
879
881 {
882 return mWmsParameters.value( QgsWmsParameter::Y ).toInt();
883 }
884
886 {
887 return mWmsParameters.value( QgsWmsParameter::RULE ).toString();
888 }
889
891 {
892 return mWmsParameters.value( QgsWmsParameter::SHOWRULEDETAILS ).toBool();
893 }
894
896 {
897 return mWmsParameters.value( QgsWmsParameter::RULELABEL ).toString();
898 }
899
901 {
902 return mWmsParameters.value( QgsWmsParameter::RULELABEL ).toBool();
903 }
904
906 {
907 return mWmsParameters.value( QgsWmsParameter::TRANSPARENT ).toString();
908 }
909
911 {
912 return mWmsParameters.value( QgsWmsParameter::TRANSPARENT ).toBool();
913 }
914
916 {
917 return mWmsParameters.value( QgsWmsParameter::SCALE ).toString();
918 }
919
921 {
922 return mWmsParameters.value( QgsWmsParameter::SCALE ).toDouble();
923 }
924
926 {
927 return mWmsParameters.value( QgsWmsParameter::IMAGE_QUALITY ).toString();
928 }
929
931 {
932 return mWmsParameters.value( QgsWmsParameter::IMAGE_QUALITY ).toInt();
933 }
934
936 {
937 return mWmsParameters.value( QgsWmsParameter::TILED ).toString();
938 }
939
941 {
942 return mWmsParameters.value( QgsWmsParameter::TILED ).toBool();
943 }
944
946 {
947 return mWmsParameters.value( QgsWmsParameter::ADDLAYERGROUPS ).toBool();
948 }
949
951 {
952 return mWmsParameters.value( QgsWmsParameter::SHOWFEATURECOUNT ).toString();
953 }
954
956 {
957 return mWmsParameters.value( QgsWmsParameter::SHOWFEATURECOUNT ).toBool();
958 }
959
961 {
962 return mWmsParameters.value( QgsWmsParameter::FEATURE_COUNT ).toString();
963 }
964
966 {
967 return mWmsParameters.value( QgsWmsParameter::FEATURE_COUNT ).toInt();
968 }
969
971 {
972 return mWmsParameters.value( QgsWmsParameter::BOXSPACE ).toString();
973 }
974
976 {
977 return mWmsParameters.value( QgsWmsParameter::BOXSPACE ).toDouble();
978 }
979
981 {
982 return mWmsParameters.value( QgsWmsParameter::LAYERSPACE ).toString();
983 }
984
986 {
987 return mWmsParameters.value( QgsWmsParameter::LAYERSPACE ).toDouble();
988 }
989
991 {
992 return mWmsParameters.value( QgsWmsParameter::LAYERTITLESPACE ).toString();
993 }
994
996 {
997 return mWmsParameters.value( QgsWmsParameter::LAYERTITLESPACE ).toDouble();
998 }
999
1001 {
1002 return mWmsParameters.value( QgsWmsParameter::SYMBOLSPACE ).toString();
1003 }
1004
1006 {
1007 return mWmsParameters.value( QgsWmsParameter::SYMBOLSPACE ).toDouble();
1008 }
1009
1011 {
1012 return mWmsParameters.value( QgsWmsParameter::SYMBOLHEIGHT ).toString();
1013 }
1014
1016 {
1017 return mWmsParameters.value( QgsWmsParameter::SYMBOLHEIGHT ).toDouble();
1018 }
1019
1021 {
1022 return mWmsParameters.value( QgsWmsParameter::SYMBOLWIDTH ).toString();
1023 }
1024
1026 {
1027 return mWmsParameters.value( QgsWmsParameter::SYMBOLWIDTH ).toDouble();
1028 }
1029
1031 {
1032 return mWmsParameters.value( QgsWmsParameter::ICONLABELSPACE ).toString();
1033 }
1034
1036 {
1037 return mWmsParameters.value( QgsWmsParameter::ICONLABELSPACE ).toDouble();
1038 }
1039
1041 {
1042 return mWmsParameters.value( QgsWmsParameter::LAYERFONTFAMILY ).toString();
1043 }
1044
1046 {
1047 return mWmsParameters.value( QgsWmsParameter::ITEMFONTFAMILY ).toString();
1048 }
1049
1051 {
1052 return mWmsParameters.value( QgsWmsParameter::LAYERFONTBOLD ).toString();
1053 }
1054
1056 {
1057 return mWmsParameters.value( QgsWmsParameter::LAYERFONTBOLD ).toBool();
1058 }
1059
1061 {
1062 return mWmsParameters.value( QgsWmsParameter::ITEMFONTBOLD ).toString();
1063 }
1064
1066 {
1067 return mWmsParameters.value( QgsWmsParameter::FI_POLYGON_TOLERANCE ).toString();
1068 }
1069
1071 {
1072 return mWmsParameters.value( QgsWmsParameter::FI_LINE_TOLERANCE ).toString();
1073 }
1074
1076 {
1077 return mWmsParameters.value( QgsWmsParameter::FI_POINT_TOLERANCE ).toString();
1078 }
1079
1081 {
1082 return mWmsParameters.value( QgsWmsParameter::FI_POLYGON_TOLERANCE ).toInt();
1083 }
1084
1086 {
1087 return mWmsParameters.value( QgsWmsParameter::FI_LINE_TOLERANCE ).toInt();
1088 }
1089
1091 {
1092 return mWmsParameters.value( QgsWmsParameter::FI_POINT_TOLERANCE ).toInt();
1093 }
1094
1096 {
1097 return mWmsParameters.value( QgsWmsParameter::ITEMFONTBOLD ).toBool();
1098 }
1099
1101 {
1102 return mWmsParameters.value( QgsWmsParameter::LAYERFONTITALIC ).toString();
1103 }
1104
1106 {
1107 return mWmsParameters.value( QgsWmsParameter::LAYERFONTITALIC ).toBool();
1108 }
1109
1111 {
1112 return mWmsParameters.value( QgsWmsParameter::ITEMFONTITALIC ).toString();
1113 }
1114
1116 {
1117 return mWmsParameters.value( QgsWmsParameter::ITEMFONTITALIC ).toBool();
1118 }
1119
1121 {
1122 return mWmsParameters.value( QgsWmsParameter::LAYERFONTSIZE ).toString();
1123 }
1124
1126 {
1127 return mWmsParameters.value( QgsWmsParameter::LAYERFONTSIZE ).toDouble();
1128 }
1129
1131 {
1132 return mWmsParameters.value( QgsWmsParameter::LAYERFONTCOLOR ).toString();
1133 }
1134
1136 {
1137 return mWmsParameters.value( QgsWmsParameter::LAYERFONTCOLOR ).toColor();
1138 }
1139
1141 {
1142 return mWmsParameters.value( QgsWmsParameter::ITEMFONTSIZE ).toString();
1143 }
1144
1146 {
1147 return mWmsParameters.value( QgsWmsParameter::ITEMFONTSIZE ).toDouble();
1148 }
1149
1151 {
1152 return mWmsParameters.value( QgsWmsParameter::ITEMFONTCOLOR ).toString();
1153 }
1154
1156 {
1157 return mWmsParameters.value( QgsWmsParameter::ITEMFONTCOLOR ).toColor();
1158 }
1159
1161 {
1162 QFont font;
1163 font.fromString( "" );
1164 font.setBold( layerFontBoldAsBool() );
1165 font.setItalic( layerFontItalicAsBool() );
1166
1167 if ( !layerFontSize().isEmpty() )
1168 font.setPointSizeF( layerFontSizeAsDouble() );
1169
1170 if ( !layerFontFamily().isEmpty() )
1172
1173 return font;
1174 }
1175
1177 {
1178 QFont font;
1179 font.fromString( "" );
1180
1181 font.setBold( itemFontBoldAsBool() );
1182 font.setItalic( itemFontItalicAsBool() );
1183
1184 if ( !itemFontSize().isEmpty() )
1185 font.setPointSizeF( itemFontSizeAsDouble() );
1186
1187 if ( !itemFontFamily().isEmpty() )
1189
1190 return font;
1191 }
1192
1194 {
1195 return mWmsParameters.value( QgsWmsParameter::LAYERTITLE ).toString();
1196 }
1197
1199 {
1200 return mWmsParameters.value( QgsWmsParameter::LAYERTITLE ).toBool();
1201 }
1202
1204 {
1205 QgsLegendSettings settings;
1206 settings.setTitle( QString() );
1207 settings.setBoxSpace( boxSpaceAsDouble() );
1208 settings.setSymbolSize( QSizeF( symbolWidthAsDouble(), symbolHeightAsDouble() ) );
1209
1212
1213 // text format must be set before setting the format's colors
1216
1217 if ( !itemFontColor().isEmpty() )
1218 {
1223 }
1224
1225 // Ok, this is tricky: because QgsLegendSettings's layerFontColor was added to the API after
1226 // fontColor, to fix regressions #21871 and #21870 and the previous behavior was to use fontColor
1227 // for the whole legend we need to preserve that behavior.
1228 // But, the 2.18 server parameters ITEMFONTCOLOR did not have effect on the layer titles too, so
1229 // we set explicitly layerFontColor to black if it's not overridden by LAYERFONTCOLOR argument.
1230 settings.rstyle( QgsLegendStyle::Group ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() );
1231 settings.rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() );
1232
1235
1236 // When processing a request involving an upstream WMS server, any responses from such a remote
1237 // server must be awaited. This was not the case for GetLegendGraphic requests (#42063). If not,
1238 // the response to the current request will never contain any data from upstream.
1239 // A quick way to fix this is to force upstream `GetLegendRequest' requests to be synchronous.
1240 // The problem with this approach is that if the GetLegendGraphic contains multiple layers, the
1241 // remote calls are made one at a time. This increases the response time. Making concurrent
1242 // asynchronous requests and waiting for them all would be a better approach.
1243 settings.setSynchronousLegendRequests( true );
1244
1245 return settings;
1246 }
1247
1248 QString QgsWmsParameters::layoutParameter( const QString &id, bool &ok ) const
1249 {
1250 QString label;
1251 ok = false;
1252
1253 if ( mUnmanagedParameters.contains( id.toUpper() ) )
1254 {
1255 label = mUnmanagedParameters[id.toUpper()];
1256 ok = true;
1257 }
1258
1259 return label;
1260 }
1261
1262 QStringList QgsWmsParameters::atlasPk() const
1263 {
1264 return mWmsParameters.value( QgsWmsParameter::ATLAS_PK ).toStringList();
1265 }
1266
1268 {
1269 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELSTRING ).toStringList( ';', false );
1270 }
1271
1273 {
1274 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELSIZE ).toStringList( ';' );
1275 }
1276
1278 {
1279 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELSIZE ).toIntList( ';' );
1280 }
1281
1283 {
1284 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELCOLOR ).toStringList( ';' );
1285 }
1286
1288 {
1289 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELCOLOR ).toColorList( ';' );
1290 }
1291
1293 {
1294 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT ).toStringList( ';' );
1295 }
1296
1298 {
1299 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT ).toIntList( ';' );
1300 }
1301
1303 {
1304 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELFONT ).toStringList( ';' );
1305 }
1306
1308 {
1309 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR ).toStringList( ';' );
1310 }
1311
1313 {
1314 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR ).toColorList( ';' );
1315 }
1316
1318 {
1319 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE ).toStringList( ';' );
1320 }
1321
1323 {
1324 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE ).toDoubleList( ';' );
1325 }
1326
1328 {
1329 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_ROTATION ).toDoubleList( ';' );
1330 }
1331
1333 {
1334 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_DISTANCE ).toDoubleList( ';' );
1335 }
1336
1338 {
1339 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_HORIZONTAL_ALIGNMENT ).toStringList( ';' );
1340 }
1341
1343 {
1344 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_VERTICAL_ALIGNMENT ).toStringList( ';' );
1345 }
1346
1348 {
1349 return mWmsParameters.value( QgsWmsParameter::WMS_PRECISION ).toString();
1350 }
1351
1353 {
1354 return mWmsParameters.value( QgsWmsParameter::WMS_PRECISION ).toInt();
1355 }
1356
1358 {
1359 return mWmsParameters.value( QgsWmsParameter::SLD_BODY ).toString();
1360 }
1361
1362 QStringList QgsWmsParameters::filters() const
1363 {
1364 QStringList filters = mWmsParameters.value( QgsWmsParameter::FILTER ).toOgcFilterList();
1365 if ( filters.isEmpty() )
1366 filters = mWmsParameters.value( QgsWmsParameter::FILTER ).toExpressionList();
1367 return filters;
1368 }
1369
1371 {
1372 return mWmsParameters.value( QgsWmsParameter::FILTER_GEOM ).toString();
1373 }
1374
1376 {
1377 return mWmsParameters.value( QgsWmsParameter::SELECTION ).toStringList( ';' );
1378 }
1379
1381 {
1382 return mWmsParameters.value( QgsWmsParameter::OPACITIES ).toStringList();
1383 }
1384
1386 {
1387 return mWmsParameters.value( QgsWmsParameter::OPACITIES ).toIntList();
1388 }
1389
1391 {
1392 // We don't want duplicates but order does matter, so no QSet
1393 QStringList result;
1394
1395 // LAYER
1396 QList<QgsWmsParameter> cLayer { mWmsParameters.values( QgsWmsParameter::LAYER ) };
1397 // Sort by map id
1398 std::sort( cLayer.begin(), cLayer.end(), []( const QgsWmsParameter &a, const QgsWmsParameter &b ) -> bool { return a.mMapId < b.mMapId; } );
1399 for ( const QgsWmsParameter &param : std::as_const( cLayer ) )
1400 {
1401 const QStringList layersList { param.toStringList() };
1402 for ( const QString &layerName : std::as_const( layersList ) )
1403 {
1404 if ( !result.contains( layerName ) )
1405 result.append( layerName );
1406 }
1407 }
1408
1409 // LAYERS
1410 QList<QgsWmsParameter> cLayers { mWmsParameters.values( QgsWmsParameter::LAYERS ) };
1411 // Sort by map id
1412 std::sort( cLayers.begin(), cLayers.end(), []( const QgsWmsParameter &a, const QgsWmsParameter &b ) -> bool { return a.mMapId < b.mMapId; } );
1413 for ( const QgsWmsParameter &param : std::as_const( cLayers ) )
1414 {
1415 const QStringList layersList { param.toStringList() };
1416 for ( const QString &layerName : std::as_const( layersList ) )
1417 {
1418 if ( !result.contains( layerName ) )
1419 result.append( layerName );
1420 }
1421 }
1422 return result;
1423 }
1424
1426 {
1427 return mWmsParameters.value( QgsWmsParameter::QUERY_LAYERS ).toStringList();
1428 }
1429
1431 {
1432 QStringList style = mWmsParameters.value( QgsWmsParameter::STYLE ).toStyleList();
1433 const QStringList styles = mWmsParameters.value( QgsWmsParameter::STYLES ).toStyleList();
1434 return style << styles;
1435 }
1436
1437 QMultiMap<QString, QgsWmsParametersFilter> QgsWmsParameters::layerFilters( const QStringList &layers ) const
1438 {
1439 const QString nsWfs2 = QStringLiteral( "http://www.opengis.net/fes/2.0" );
1440 const QString prefixWfs2 = QStringLiteral( "<fes:" );
1441
1442 const QStringList rawFilters = filters();
1443 QMultiMap<QString, QgsWmsParametersFilter> filters;
1444 for ( int i = 0; i < rawFilters.size(); i++ )
1445 {
1446 const QString f = rawFilters[i];
1447 if ( f.startsWith( QLatin1Char( '<' ) )
1448 && f.endsWith( QLatin1String( "Filter>" ) )
1449 && i < layers.size() )
1450 {
1452 filter.mFilter = f;
1455
1456 if ( filter.mFilter.contains( nsWfs2 )
1457 || filter.mFilter.contains( prefixWfs2 ) )
1458 {
1460 }
1461
1462 filters.insert( layers[i], filter );
1463 }
1464 else if ( !f.isEmpty() )
1465 {
1466 // filter format: "LayerName,LayerName2:filterString;LayerName3:filterString2;..."
1467 // several filters can be defined for one layer
1468 const int colonIndex = f.indexOf( ':' );
1469 if ( colonIndex != -1 )
1470 {
1471 const QString layers = f.section( ':', 0, 0 );
1472 const QString filter = f.section( ':', 1 );
1473 const QStringList layersList = layers.split( ',' );
1474 for ( const QString &layer : layersList )
1475 {
1476 QgsWmsParametersFilter parametersFilter;
1477 parametersFilter.mFilter = filter;
1478 parametersFilter.mType = QgsWmsParametersFilter::SQL;
1479 filters.insert( layer, parametersFilter );
1480 }
1481 }
1482 else
1483 {
1484 QString filterStr = mWmsParameters.value( QgsWmsParameter::FILTER ).toString();
1485 raiseError( QStringLiteral( "FILTER ('" ) + filterStr + QStringLiteral( "') is not properly formatted" ) );
1486 }
1487 }
1488 }
1489 return filters;
1490 }
1491
1493 {
1494 bool force2D = false;
1495 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
1496
1497 if ( options.contains( DxfFormatOption::FORCE_2D ) )
1498 {
1499 force2D = QVariant( options[DxfFormatOption::FORCE_2D] ).toBool();
1500 }
1501
1502 return force2D;
1503 }
1504
1506 {
1507 bool zeroWidth = false;
1508 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
1509
1510 if ( options.contains( DxfFormatOption::EXPORT_LINES_WITH_ZERO_WIDTH ) )
1511 {
1512 zeroWidth = QVariant( options[DxfFormatOption::EXPORT_LINES_WITH_ZERO_WIDTH] ).toBool();
1513 }
1514
1515 return zeroWidth;
1516 }
1517
1519 {
1520 bool noMText = false;
1521 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
1522
1523 if ( options.contains( DxfFormatOption::NO_MTEXT ) )
1524 {
1525 noMText = QVariant( options[DxfFormatOption::NO_MTEXT] ).toBool();
1526 }
1527
1528 return noMText;
1529 }
1530
1531
1532 QList<QgsWmsParametersLayer> QgsWmsParameters::layersParameters() const
1533 {
1534 const QStringList layers = allLayersNickname();
1535 const QStringList styles = allStyles();
1536 const QStringList selection = selections();
1537 const QList<int> opacities = opacitiesAsInt();
1538 const QMultiMap<QString, QgsWmsParametersFilter> filters = layerFilters( layers );
1539
1540 // selection format: "LayerName:id0,id1;LayerName2:id0,id1;..."
1541 // several filters can be defined for one layer
1542 QMultiMap<QString, QString> layerSelections;
1543 for ( const QString &s : selection )
1544 {
1545 const QStringList splits = s.split( ':' );
1546 if ( splits.size() == 2 )
1547 {
1548 layerSelections.insert( splits[0], splits[1] );
1549 }
1550 else
1551 {
1552 QString selStr = mWmsParameters.value( QgsWmsParameter::SELECTION ).toString();
1553 raiseError( QStringLiteral( "SELECTION ('" ) + selStr + QStringLiteral( "') is not properly formatted" ) );
1554 }
1555 }
1556
1557 QList<QgsWmsParametersLayer> parameters;
1558 for ( int i = 0; i < layers.size(); i++ )
1559 {
1560 QString layer = layers[i];
1561
1563 param.mNickname = layer;
1564
1565 if ( i < opacities.count() )
1566 param.mOpacity = opacities[i];
1567
1568 if ( isExternalLayer( layer ) )
1569 {
1570 const QgsWmsParametersExternalLayer extParam = externalLayerParameter( layer );
1571 param.mNickname = extParam.mName;
1572 param.mExternalUri = extParam.mUri;
1573 }
1574 else
1575 {
1576 if ( i < styles.count() )
1577 param.mStyle = styles[i];
1578
1579 if ( filters.contains( layer ) )
1580 {
1581 auto it = filters.find( layer );
1582 while ( it != filters.end() && it.key() == layer )
1583 {
1584 param.mFilter.append( it.value() );
1585 ++it;
1586 }
1587 }
1588
1589 if ( layerSelections.contains( layer ) )
1590 {
1591 QMultiMap<QString, QString>::const_iterator it;
1592 it = layerSelections.constFind( layer );
1593 while ( it != layerSelections.constEnd() && it.key() == layer )
1594 {
1595 param.mSelection << it.value().split( ',' );
1596 ++it;
1597 }
1598 }
1599 }
1600
1601 parameters.append( param );
1602 }
1603
1604 return parameters;
1605 }
1606
1607 QList<QgsWmsParametersHighlightLayer> QgsWmsParameters::highlightLayersParameters() const
1608 {
1609 QList<QgsWmsParametersHighlightLayer> params;
1610 const QList<QgsGeometry> geoms = highlightGeomAsGeom();
1611 const QStringList slds = highlightSymbol();
1612 const QStringList labels = highlightLabelString();
1613 const QList<QColor> colors = highlightLabelColorAsColor();
1614 const QList<int> sizes = highlightLabelSizeAsInt();
1615 const QList<int> weights = highlightLabelWeightAsInt();
1616 const QStringList fonts = highlightLabelFont();
1617 const QList<QColor> bufferColors = highlightLabelBufferColorAsColor();
1618 const QList<double> bufferSizes = highlightLabelBufferSizeAsFloat();
1619 const QList<double> rotation = highlightLabelRotation();
1620 const QList<double> distance = highlightLabelDistance();
1621 const QStringList hali = highlightLabelHorizontalAlignment();
1622 const QStringList vali = highlightLabelVerticalAlignment();
1623
1624 int nLayers = std::min( geoms.size(), slds.size() );
1625 for ( int i = 0; i < nLayers; i++ )
1626 {
1628 param.mName = QStringLiteral( "highlight_" ) + QString::number( i );
1629 param.mGeom = geoms[i];
1630 param.mSld = slds[i];
1631
1632 if ( i < labels.count() )
1633 param.mLabel = labels[i];
1634
1635 if ( i < colors.count() )
1636 param.mColor = colors[i];
1637
1638 if ( i < sizes.count() )
1639 param.mSize = sizes[i];
1640
1641 if ( i < weights.count() )
1642 param.mWeight = weights[i];
1643
1644 if ( i < fonts.count() )
1645 param.mFont = fonts[i];
1646
1647 if ( i < bufferColors.count() )
1648 param.mBufferColor = bufferColors[i];
1649
1650 if ( i < bufferSizes.count() )
1651 param.mBufferSize = bufferSizes[i];
1652
1653 if ( i < rotation.count() )
1654 param.mLabelRotation = rotation[i];
1655
1656 if ( i < distance.count() )
1657 param.mLabelDistance = distance[i];
1658
1659 if ( i < hali.count() )
1660 param.mHali = hali[i];
1661
1662 if ( i < vali.count() )
1663 param.mVali = vali[i];
1664
1665
1666 params.append( param );
1667 }
1668
1669 return params;
1670 }
1671
1672 QList<QgsWmsParametersExternalLayer> QgsWmsParameters::externalLayersParameters() const
1673 {
1674 auto notExternalLayer = []( const QString &name ) { return !QgsWmsParameters::isExternalLayer( name ); };
1675
1676 QList<QgsWmsParametersExternalLayer> externalLayers;
1677
1678 QStringList layers = allLayersNickname();
1679 QStringList::iterator rit = std::remove_if( layers.begin(), layers.end(), notExternalLayer );
1680
1681 for ( QStringList::iterator it = layers.begin(); it != rit; ++it )
1682 {
1683 externalLayers << externalLayerParameter( *it );
1684 }
1685
1686 return externalLayers;
1687 }
1688
1690 {
1691 return mWmsParameters.value( QgsWmsParameter::BGCOLOR ).toString();
1692 }
1693
1695 {
1696 return mWmsParameters.value( QgsWmsParameter::BGCOLOR ).toColor();
1697 }
1698
1700 {
1701 return mWmsParameters.value( QgsWmsParameter::TEMPLATE ).toString();
1702 }
1703
1705 {
1706 QgsWmsParameter wmsParam;
1708 param.mId = mapId;
1709
1710 QString pMapId = QStringLiteral( "MAP" ) + QString::number( mapId );
1711
1712 wmsParam = idParameter( QgsWmsParameter::EXTENT, mapId );
1713 QgsRectangle extent;
1714 if ( wmsParam.isValid() )
1715 {
1716 extent = wmsParam.toRectangle();
1717 }
1718
1719 param.mHasExtent = !extent.isEmpty();
1720 param.mExtent = extent;
1721
1722 // scale
1723 wmsParam = idParameter( QgsWmsParameter::SCALE, mapId );
1724 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1725 {
1726 param.mScale = wmsParam.toDouble();
1727 }
1728
1729 // rotation
1730 wmsParam = idParameter( QgsWmsParameter::ROTATION, mapId );
1731 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1732 {
1733 param.mRotation = wmsParam.toDouble();
1734 }
1735
1736 //grid space x / y
1737 double gridx( -1 ), gridy( -1 );
1738
1739 wmsParam = idParameter( QgsWmsParameter::GRID_INTERVAL_X, mapId );
1740 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1741 {
1742 gridx = wmsParam.toDouble();
1743 }
1744
1745 wmsParam = idParameter( QgsWmsParameter::GRID_INTERVAL_Y, mapId );
1746 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1747 {
1748 gridy = wmsParam.toDouble();
1749 }
1750
1751 if ( gridx != -1 && gridy != -1 )
1752 {
1753 param.mGridX = gridx;
1754 param.mGridY = gridy;
1755 }
1756
1757 //layers
1758 QStringList allLayers;
1759 wmsParam = idParameter( QgsWmsParameter::LAYERS, mapId );
1760 if ( wmsParam.isValid() )
1761 {
1762 allLayers = wmsParam.toStringList();
1763 }
1764
1765 // external layers
1766 QStringList layers;
1767
1768 for ( const auto &layer : std::as_const( allLayers ) )
1769 {
1770 if ( isExternalLayer( layer ) )
1771 {
1772 const QgsWmsParametersExternalLayer extParam = externalLayerParameter( layer );
1773 layers << extParam.mName;
1774 }
1775 else
1776 {
1777 layers << layer;
1778 }
1779 }
1780
1781 QStringList styles;
1782 wmsParam = idParameter( QgsWmsParameter::STYLES, mapId );
1783 if ( wmsParam.isValid() )
1784 {
1785 styles = wmsParam.toStyleList();
1786 }
1787
1788 QList<QgsWmsParametersLayer> lParams;
1789 for ( int i = 0; i < layers.size(); i++ )
1790 {
1791 QString layer = layers[i];
1792 QgsWmsParametersLayer lParam;
1793 lParam.mNickname = layer;
1794
1795 if ( i < styles.count() )
1796 lParam.mStyle = styles[i];
1797
1798 lParams.append( lParam );
1799 }
1800 param.mLayers = lParams;
1801
1802 //highlight layers
1803 QList<QgsWmsParametersHighlightLayer> hParams;
1804
1805 QList<QgsGeometry> geoms;
1806 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_GEOM, mapId );
1807 if ( wmsParam.isValid() )
1808 {
1809 geoms = wmsParam.toGeomList( ';' );
1810 }
1811
1812 QStringList slds;
1813 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_SYMBOL, mapId );
1814 if ( wmsParam.isValid() )
1815 {
1816 slds = wmsParam.toStringList( ';' );
1817 }
1818
1819 QStringList labels;
1820 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELSTRING, mapId );
1821 if ( wmsParam.isValid() )
1822 {
1823 labels = wmsParam.toStringList( ';' );
1824 }
1825
1826 QStringList fonts;
1827 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELFONT, mapId );
1828 if ( wmsParam.isValid() )
1829 {
1830 fonts = wmsParam.toStringList( ';' );
1831 }
1832
1833 QList<QColor> colors;
1834 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELCOLOR, mapId );
1835 if ( wmsParam.isValid() )
1836 {
1837 colors = wmsParam.toColorList( ';' );
1838 }
1839
1840 QList<int> sizes;
1841 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELSIZE, mapId );
1842 if ( wmsParam.isValid() )
1843 {
1844 sizes = wmsParam.toIntList( ';' );
1845 }
1846
1847 QList<int> weights;
1848 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT, mapId );
1849 if ( wmsParam.isValid() )
1850 {
1851 weights = wmsParam.toIntList( ';' );
1852 }
1853
1854 QList<QColor> bufferColors;
1855 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR, mapId );
1856 if ( wmsParam.isValid() )
1857 {
1858 bufferColors = wmsParam.toColorList( ';' );
1859 }
1860
1861 QList<double> bufferSizes;
1862 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE, mapId );
1863 if ( wmsParam.isValid() )
1864 {
1865 bufferSizes = wmsParam.toDoubleList( ';' );
1866 }
1867
1868 QList<double> rotations;
1869 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_ROTATION, mapId );
1870 if ( wmsParam.isValid() )
1871 {
1872 rotations = wmsParam.toDoubleList( ';' );
1873 }
1874
1875 QList<double> distances;
1876 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_DISTANCE, mapId );
1877 if ( wmsParam.isValid() )
1878 {
1879 distances = wmsParam.toDoubleList( ';' );
1880 }
1881
1882 QStringList halis;
1883 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_HORIZONTAL_ALIGNMENT, mapId );
1884 if ( wmsParam.isValid() )
1885 {
1886 halis = wmsParam.toStringList();
1887 }
1888
1889 QStringList valis;
1890 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_VERTICAL_ALIGNMENT, mapId );
1891 if ( wmsParam.isValid() )
1892 {
1893 valis = wmsParam.toStringList();
1894 }
1895
1896 int nHLayers = std::min( geoms.size(), slds.size() );
1897 for ( int i = 0; i < nHLayers; i++ )
1898 {
1900 hParam.mName = pMapId + QStringLiteral( "_highlight_" ) + QString::number( i );
1901 hParam.mGeom = geoms[i];
1902 hParam.mSld = slds[i];
1903
1904 if ( i < labels.count() )
1905 hParam.mLabel = labels[i];
1906
1907 if ( i < colors.count() )
1908 hParam.mColor = colors[i];
1909
1910 if ( i < sizes.count() )
1911 hParam.mSize = sizes[i];
1912
1913 if ( i < weights.count() )
1914 hParam.mWeight = weights[i];
1915
1916 if ( i < fonts.count() )
1917 hParam.mFont = fonts[i];
1918
1919 if ( i < bufferColors.count() )
1920 hParam.mBufferColor = bufferColors[i];
1921
1922 if ( i < bufferSizes.count() )
1923 hParam.mBufferSize = bufferSizes[i];
1924
1925 if ( i < rotations.count() )
1926 hParam.mLabelRotation = rotations[i];
1927
1928 if ( i < distances.count() )
1929 hParam.mLabelDistance = distances[i];
1930
1931 if ( i < halis.count() )
1932 hParam.mHali = halis[i];
1933
1934 if ( i < valis.count() )
1935 hParam.mVali = valis[i];
1936
1937 hParams.append( hParam );
1938 }
1939 param.mHighlightLayers = hParams;
1940
1941 return param;
1942 }
1943
1944 QString QgsWmsParameters::externalWMSUri( const QString &layerId ) const
1945 {
1946 // Param names may be uppercased.
1947 QString id { layerId };
1948
1949 for ( auto it = mExternalWMSParameters.cbegin(); it != mExternalWMSParameters.cend(); ++it )
1950 {
1951 if ( it.key().compare( id, Qt::CaseSensitivity::CaseInsensitive ) == 0 )
1952 {
1953 id = it.key();
1954 break;
1955 }
1956 }
1957
1958 if ( !mExternalWMSParameters.contains( id ) )
1959 {
1960 return QString();
1961 }
1962
1963 QgsDataSourceUri wmsUri;
1964 const QMap<QString, QString> &paramMap = mExternalWMSParameters[id];
1965 QMap<QString, QString>::const_iterator paramIt = paramMap.constBegin();
1966 for ( ; paramIt != paramMap.constEnd(); ++paramIt )
1967 {
1968 QString paramName = paramIt.key().toLower();
1969 if ( paramName == QLatin1String( "layers" ) || paramName == QLatin1String( "styles" ) || paramName == QLatin1String( "opacities" ) )
1970 {
1971 const QStringList values = paramIt.value().split( ',' );
1972 for ( const QString &value : values )
1973 wmsUri.setParam( paramName, value );
1974 }
1975 else if ( paramName == QLatin1String( "ignorereportedlayerextents" ) )
1976 {
1977 wmsUri.setParam( QStringLiteral( "IgnoreReportedLayerExtents" ), paramIt.value() );
1978 }
1979 else if ( paramName == QLatin1String( "smoothpixmaptransform" ) )
1980 {
1981 wmsUri.setParam( QStringLiteral( "SmoothPixmapTransform" ), paramIt.value() );
1982 }
1983 else if ( paramName == QLatin1String( "ignoregetmapurl" ) )
1984 {
1985 wmsUri.setParam( QStringLiteral( "IgnoreGetMapUrl" ), paramIt.value() );
1986 }
1987 else if ( paramName == QLatin1String( "ignoregetfeatureinfourl" ) )
1988 {
1989 wmsUri.setParam( QStringLiteral( "IgnoreGetFeatureInfoUrl" ), paramIt.value() );
1990 }
1991 else if ( paramName == QLatin1String( "ignoreaxisorientation" ) )
1992 {
1993 wmsUri.setParam( QStringLiteral( "IgnoreAxisOrientation" ), paramIt.value() );
1994 }
1995 else if ( paramName == QLatin1String( "invertaxisorientation" ) )
1996 {
1997 wmsUri.setParam( QStringLiteral( "InvertAxisOrientation" ), paramIt.value() );
1998 }
1999 else if ( paramName == QLatin1String( "dpimode" ) )
2000 {
2001 wmsUri.setParam( QStringLiteral( "dpiMode" ), paramIt.value() );
2002 }
2003 else if ( paramName == QLatin1String( "stepwidth" ) )
2004 {
2005 wmsUri.setParam( QStringLiteral( "stepWidth" ), paramIt.value() );
2006 }
2007 else if ( paramName == QLatin1String( "stepheight" ) )
2008 {
2009 wmsUri.setParam( QStringLiteral( "stepHeight" ), paramIt.value() );
2010 }
2011 else
2012 {
2013 wmsUri.setParam( paramName, paramIt.value() );
2014 }
2015 }
2016 return wmsUri.encodedUri();
2017 }
2018
2020 {
2021 return mWmsParameters.value( QgsWmsParameter::WITH_GEOMETRY ).toBool();
2022 }
2023
2025 {
2026 return mWmsParameters.value( QgsWmsParameter::WITH_MAPTIP ).toString();
2027 }
2028
2030 {
2031 const QString mStr = withMapTipAsString();
2032
2033 if ( mStr.startsWith( QLatin1String( "true" ), Qt::CaseInsensitive ) || mStr.startsWith( QLatin1String( "on" ), Qt::CaseInsensitive ) || mStr.startsWith( QLatin1String( "yes" ), Qt::CaseInsensitive ) || mStr.startsWith( QLatin1Char( '1' ) ) )
2034 return true;
2035 else
2036 return false;
2037 }
2038
2040 {
2041 const QString mStr = withMapTipAsString();
2042
2043 if ( mStr.startsWith( QLatin1String( "html_fi_only_maptip" ), Qt::CaseInsensitive ) )
2044 return true;
2045 else
2046 return false;
2047 }
2048
2050 {
2051 return mWmsParameters.value( QgsWmsParameter::WITH_DISPLAY_NAME ).toBool();
2052 }
2053
2055 {
2056 return mWmsParameters.value( QgsWmsParameter::WMTVER ).toString();
2057 }
2058
2059 void QgsWmsParameters::log( const QString &msg ) const
2060 {
2061 QgsMessageLog::logMessage( msg, QStringLiteral( "Server" ), Qgis::MessageLevel::Info );
2062 }
2063
2064 void QgsWmsParameters::raiseError( const QString &msg ) const
2065 {
2067 }
2068
2069 QgsWmsParameter QgsWmsParameters::idParameter( const QgsWmsParameter::Name name, const int id ) const
2070 {
2071 QgsWmsParameter p;
2072
2073 for ( const auto &param : mWmsParameters.values( name ) )
2074 {
2075 if ( param.mMapId == id )
2076 {
2077 p = param;
2078 }
2079 }
2080
2081 return p;
2082 }
2083
2084 QgsWmsParametersExternalLayer QgsWmsParameters::externalLayerParameter( const QString &name ) const
2085 {
2086 QgsWmsParametersExternalLayer param;
2087
2088 param.mName = name;
2089 param.mName.remove( 0, EXTERNAL_LAYER_PREFIX.size() );
2090 param.mUri = externalWMSUri( param.mName );
2091
2092 return param;
2093 }
2094
2095 bool QgsWmsParameters::isExternalLayer( const QString &name )
2096 {
2097 return name.startsWith( EXTERNAL_LAYER_PREFIX );
2098 }
2099
2101 {
2102 QStringList attributes;
2103 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2104
2105 if ( options.contains( DxfFormatOption::LAYERATTRIBUTES ) )
2106 {
2107 attributes = options[DxfFormatOption::LAYERATTRIBUTES].split( ',' );
2108 }
2109
2110 return attributes;
2111 }
2112
2114 {
2115 bool use = false;
2116 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2117
2118 if ( options.contains( DxfFormatOption::USE_TITLE_AS_LAYERNAME ) )
2119 {
2120 use = QVariant( options[DxfFormatOption::USE_TITLE_AS_LAYERNAME] ).toBool();
2121 }
2122
2123 return use;
2124 }
2125
2127 {
2128 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2129
2130 double scale = -1;
2131 if ( options.contains( DxfFormatOption::SCALE ) )
2132 {
2133 scale = options[DxfFormatOption::SCALE].toDouble();
2134 }
2135
2136 return scale;
2137 }
2138
2140 {
2141 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2142
2144
2145 if ( !options.contains( DxfFormatOption::MODE ) )
2146 {
2147 return symbol;
2148 }
2149
2150 const QString mode = options[DxfFormatOption::MODE];
2151 if ( mode.compare( QLatin1String( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 )
2152 {
2154 }
2155 else if ( mode.compare( QLatin1String( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 )
2156 {
2158 }
2159
2160 return symbol;
2161 }
2162
2164 {
2165 QString codec = QStringLiteral( "ISO-8859-1" );
2166
2167 if ( formatOptions<QgsWmsParameters::DxfFormatOption>().contains( DxfFormatOption::CODEC ) )
2168 {
2169 codec = formatOptions<QgsWmsParameters::DxfFormatOption>()[DxfFormatOption::CODEC];
2170 }
2171
2172 return codec;
2173 }
2174
2176 {
2177 bool geospatialPdf = false;
2178 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2179 if ( options.contains( PdfFormatOption::WRITE_GEO_PDF ) )
2180 {
2181 geospatialPdf = QVariant( options[PdfFormatOption::WRITE_GEO_PDF] ).toBool();
2182 }
2183 return geospatialPdf;
2184 }
2185
2187 {
2188 bool forceVector = false;
2189 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2190 if ( options.contains( PdfFormatOption::FORCE_VECTOR_OUTPUT ) )
2191 {
2192 forceVector = QVariant( options[PdfFormatOption::FORCE_VECTOR_OUTPUT] ).toBool();
2193 }
2194 return forceVector;
2195 }
2196
2198 {
2199 bool appendGeoref = true;
2200 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2201 if ( options.contains( PdfFormatOption::APPEND_GEOREFERENCE ) )
2202 {
2203 appendGeoref = QVariant( options[PdfFormatOption::APPEND_GEOREFERENCE] ).toBool();
2204 }
2205 return appendGeoref;
2206 }
2207
2209 {
2210 bool simplify = true;
2211 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2212 if ( options.contains( PdfFormatOption::SIMPLIFY_GEOMETRY ) )
2213 {
2214 simplify = QVariant( options[PdfFormatOption::SIMPLIFY_GEOMETRY] ).toBool();
2215 }
2216 return simplify;
2217 }
2218
2220 {
2221 bool exportMetadata = false;
2222 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2223 if ( options.contains( PdfFormatOption::EXPORT_METADATA ) )
2224 {
2225 exportMetadata = QVariant( options[PdfFormatOption::EXPORT_METADATA] ).toBool();
2226 }
2227 return exportMetadata;
2228 }
2229
2231 {
2233 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2234 if ( options.contains( PdfFormatOption::TEXT_RENDER_FORMAT ) )
2235 {
2236 if ( options[PdfFormatOption::TEXT_RENDER_FORMAT].compare( QStringLiteral( "AlwaysText" ), Qt::CaseInsensitive ) == 0 )
2237 {
2239 }
2240 else if ( options[PdfFormatOption::TEXT_RENDER_FORMAT].compare( QStringLiteral( "PreferText" ), Qt::CaseInsensitive ) == 0 )
2241 {
2243 }
2244 }
2245 return format;
2246 }
2247
2249 {
2250 bool losslessCompression = false;
2251 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2252 if ( options.contains( PdfFormatOption::LOSSLESS_IMAGE_COMPRESSION ) )
2253 {
2254 losslessCompression = QVariant( options[PdfFormatOption::LOSSLESS_IMAGE_COMPRESSION] ).toBool();
2255 }
2256 return losslessCompression;
2257 }
2258
2260 {
2261 bool disableTiledRaster = false;
2262 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2263 if ( options.contains( PdfFormatOption::DISABLE_TILED_RASTER_RENDERING ) )
2264 {
2265 disableTiledRaster = QVariant( options[PdfFormatOption::DISABLE_TILED_RASTER_RENDERING] ).toBool();
2266 }
2267 return disableTiledRaster;
2268 }
2269
2271 {
2272 bool useIso32000 = true;
2273 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2275 {
2276 useIso32000 = QVariant( options[PdfFormatOption::USE_ISO_32000_EXTENSION_FORMAT_GEOREFERENCING] ).toBool();
2277 }
2278 return useIso32000;
2279 }
2280
2282 {
2283 bool useOgcGeoreferencing = false;
2284 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2286 {
2287 useOgcGeoreferencing = QVariant( options[PdfFormatOption::USE_OGC_BEST_PRACTICE_FORMAT_GEOREFERENCING] ).toBool();
2288 }
2289 return useOgcGeoreferencing;
2290 }
2291
2293 {
2294 QStringList themes;
2295 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2296 if ( options.contains( PdfFormatOption::EXPORT_THEMES ) )
2297 {
2298 themes = options[PdfFormatOption::EXPORT_THEMES].split( ',' );
2299 }
2300 return themes;
2301 }
2302
2304 {
2305 QVector<qreal> scales;
2306 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2307 if ( options.contains( PdfFormatOption::PREDEFINED_MAP_SCALES ) )
2308 {
2309 const QStringList scaleList = options[PdfFormatOption::PREDEFINED_MAP_SCALES].split( ',' );
2310 for ( const QString &it : std::as_const( scaleList ) )
2311 {
2312 bool ok = false;
2313 qreal scale = it.toDouble( &ok );
2314 if ( ok )
2315 {
2316 scales.append( scale );
2317 }
2318 }
2319 }
2320 return scales;
2321 }
2322
2323 QMap<QString, QString> QgsWmsParameters::dimensionValues() const
2324 {
2325 QMap<QString, QString> dimValues;
2326 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
2327 const QStringList unmanagedNames = mUnmanagedParameters.keys();
2328 for ( const QString &key : unmanagedNames )
2329 {
2330 if ( key.startsWith( QLatin1String( "DIM_" ) ) )
2331 {
2332 dimValues[key.mid( 4 )] = mUnmanagedParameters[key];
2333 }
2334 else if ( pnMetaEnum.keyToValue( key.toUpper().toStdString().c_str() ) != -1 )
2335 {
2336 dimValues[key] = mUnmanagedParameters[key];
2337 }
2338 }
2339 return dimValues;
2340 }
2341} // namespace QgsWms
@ Info
Information message.
Definition qgis.h:155
TextRenderFormat
Options for rendering text.
Definition qgis.h:2687
@ PreferText
Render text as text objects, unless doing so results in rendering artifacts or poor quality rendering...
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
@ AlwaysText
Always render text as text objects. While this mode preserves text objects as text for post-processin...
FeatureSymbologyExport
Options for exporting features considering their symbology.
Definition qgis.h:5218
@ PerFeature
Keeps the number of features and export symbology per feature.
@ PerSymbolLayer
Exports one feature per symbol layer (considering symbol levels)
@ NoSymbology
Export only data.
Exception thrown in case of malformed request.
Class for storing the component parts of a RDBMS data source URI (e.g.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
void setTitle(const QString &t)
Sets the title for the legend, which will be rendered above all legend items.
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns modifiable reference to the style for a legend component.
void setBoxSpace(double s)
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend...
void setSynchronousLegendRequests(bool b)
Sets whether to request legend graphics synchronously.
void setSymbolSize(QSizeF s)
Sets the default symbol size (in millimeters) used for legend items.
QgsTextFormat & textFormat()
Returns the text format used for rendering this legend component.
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
@ Left
Left side.
@ Bottom
Bottom side.
@ Group
Legend group title.
@ Symbol
Symbol icon (excluding label)
@ Subgroup
Legend subgroup title.
@ Title
Legend title.
@ SymbolLabel
Symbol label (excluding icon)
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for rendering this legend component.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A class to describe the version of a project.
A rectangle specified with double values.
Definition of a parameter with basic conversion methods.
QList< QgsGeometry > toGeomList(bool &ok, char delimiter=',') const
Converts the parameter into a list of geometries.
QString loadUrl(bool &ok) const
Loads the data associated to the parameter converted into an url.
QUrl toUrl(bool &ok) const
Converts the parameter into an url.
QString toString(bool defaultValue=false) const
Converts the parameter into a string.
QList< double > toDoubleList(bool &ok, char delimiter=',') const
Converts the parameter into a list of doubles.
QStringList toStringList(char delimiter=',', bool skipEmptyParts=true) const
Converts the parameter into a list of strings.
virtual bool isValid() const
Returns true if the parameter is valid, false otherwise.
QString typeName() const
Returns the type of the parameter as a string.
static void raiseError(const QString &msg)
Raises an exception in case of an invalid parameters.
int toInt(bool &ok) const
Converts the parameter into an integer.
QList< int > toIntList(bool &ok, char delimiter=',') const
Converts the parameter into a list of integers.
QColor toColor(bool &ok) const
Converts the parameter into a color.
double toDouble(bool &ok) const
Converts the parameter into a double.
QgsRectangle toRectangle(bool &ok) const
Converts the parameter into a rectangle.
QList< QColor > toColorList(bool &ok, char delimiter=',') const
Converts the parameter into a list of colors.
QgsServerParameters provides an interface to retrieve and manipulate global parameters received from ...
virtual QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
QUrlQuery urlQuery() const
Returns a url query with underlying parameters.
QMap< QString, QString > mUnmanagedParameters
void load(const QUrlQuery &query)
Loads new parameters.
virtual QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
QString value(const QString &key) const
Returns the value of a parameter.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
WMS parameter received from the client.
int toInt() const
Converts the parameter into an integer.
QList< double > toDoubleList(const char delimiter=',') const
Converts the parameter into a list of doubles.
QList< QColor > toColorList(const char delimiter=',') const
Converts the parameter into a list of colors.
double toDouble() const
Converts the parameter into a double.
void raiseError() const
Raises an error in case of an invalid conversion.
QgsWmsParameter(const QgsWmsParameter::Name name=QgsWmsParameter::UNKNOWN, const QMetaType::Type type=QMetaType::Type::QString, const QVariant defaultValue=QVariant(""))
Constructor for QgsWmsParameter.
Name
Available parameters for WMS requests.
QUrl toUrl() const
Converts the parameter into an url.
QList< QgsGeometry > toGeomList(const char delimiter=',') const
Converts the parameter into a list of geometries.
bool isValid() const override
Returns true if the parameter is valid, false otherwise.
QString name() const
Returns the name of the parameter.
QgsRectangle toRectangle() const
Converts the parameter into a rectangle.
QColor toColor() const
Converts the parameter into a color.
QgsWmsParameter::Name mName
QList< int > toIntList(const char delimiter=',') const
Converts the parameter into a list of integers.
QStringList toStyleList(const char delimiter=',') const
Converts the parameter into a list of strings and keeps empty parts Default style value is an empty s...
QString loadUrl() const
Loads the data associated to the parameter converted into an url.
Provides an interface to retrieve and manipulate WMS parameters received from the client.
bool htmlInfoOnlyMapTip() const
Returns true if only maptip information is requested for HTML feature info response.
QString rule() const
Returns RULE parameter or an empty string if none is defined.
QString layerTitle() const
Returns LAYERTITLE parameter or an empty string if not defined.
double layerSpaceAsDouble() const
Returns LAYERSPACE as a double or its default value if not defined.
QString boxSpace() const
Returns BOXSPACE parameter or an empty string if not defined.
QString wmsPrecision() const
Returns WMS_PRECISION parameter or an empty string if not defined.
double dxfScale() const
Returns the DXF SCALE parameter.
QString featureCount() const
Returns FEATURE_COUNT parameter or an empty string if none is defined.
QFont layerFont() const
Returns the layer font (built thanks to the LAYERFONTFAMILY, LAYERFONTSIZE, LAYERFONTBOLD,...
QList< int > opacitiesAsInt() const
Returns the list of opacities found in OPACITIES parameter as integers.
bool transparentAsBool() const
Returns TRANSPARENT parameter as a bool or its default value if not defined.
QString transparent() const
Returns TRANSPARENT parameter or an empty string if not defined.
QList< int > highlightLabelWeightAsInt() const
Returns HIGHLIGHT_LABELWEIGHT as a list of int.
QString iconLabelSpace() const
Returns ICONLABELSPACE parameter or an empty string if not defined.
QString layerTitleSpace() const
Returns LAYERTITLESPACE parameter or an empty string if not defined.
QString x() const
Returns X parameter or an empty string if not defined.
QString layerSpace() const
Returns LAYERSPACE parameter or an empty string if not defined.
int wmsPrecisionAsInt() const
Returns WMS_PRECISION parameter as an int or its default value if not defined.
QStringList highlightLabelBufferSize() const
Returns HIGHLIGHT_LABELBUFFERSIZE.
QStringList allLayersNickname() const
Returns nickname of layers found in LAYER and LAYERS parameters.
QString formatAsString() const
Returns FORMAT parameter as a string.
double layerFontSizeAsDouble() const
Returns LAYERFONTSIZE as a double.
QString externalWMSUri(const QString &id) const
Returns the external WMS uri.
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
QString scale() const
Returns SCALE parameter or an empty string if none is defined.
QString ruleLabel() const
Returns RULELABEL parameter or an empty string if none is defined.
double scaleAsDouble() const
Returns SCALE as a double.
bool layerFontItalicAsBool() const
Returns LAYERFONTITALIC as a boolean or its default value if not defined.
QgsWmsParametersComposerMap composerMapParameters(int mapId) const
Returns the requested parameters for a composer map parameter.
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
bool withGeometry() const
Returns if the client wants the feature info response with geometry information.
QStringList highlightLabelString() const
Returns HIGHLIGHT_LABELSTRING as a list of string.
QString tiled() const
Returns TILED parameter or an empty string if not defined.
QString layerFontSize() const
Returns LAYERFONTSIZE parameter or an empty string if not defined.
QList< QColor > highlightLabelColorAsColor() const
Returns HIGHLIGHT_LABELCOLOR as a list of color.
bool itemFontBoldAsBool() const
Returns ITEMFONTBOLD as a boolean or its default value if not defined.
QStringList highlightLabelHorizontalAlignment() const
Returns HIGHLIGHT_LABEL_HORIZONTAL_ALIGNMENT as a list of string.
void set(QgsWmsParameter::Name name, const QVariant &value)
Sets a parameter value thanks to its name.
QString pointTolerance() const
Returns FI_POINT_TOLERANCE parameter or an empty string if not defined.
QString filterGeom() const
Returns the filter geometry found in FILTER_GEOM parameter.
QString composerTemplate() const
Returns TEMPLATE parameter or an empty string if not defined.
Format infoFormat() const
Returns infoFormat.
QString dxfCodec() const
Returns the DXF CODEC parameter.
QString y() const
Returns Y parameter or an empty string if not defined.
QString srcHeight() const
Returns SRCHEIGHT parameter or an empty string if not defined.
double dpiAsDouble() const
Returns DPI parameter as an int or its default value if not defined.
QStringList highlightLabelVerticalAlignment() const
Returns HIGHLIGHT_LABEL_VERTICAL_ALIGNMENT as a list of string.
void dump() const
Dumps parameters.
int pointToleranceAsInt() const
Returns FI_POINT_TOLERANCE parameter as an integer.
bool withMapTip() const
withMapTip
QString polygonTolerance() const
Returns FI_POLYGON_TOLERANCE parameter or an empty string if not defined.
QStringList highlightGeom() const
Returns HIGHLIGHT_GEOM as a list of string in WKT.
QString i() const
Returns I parameter or an empty string if not defined.
bool pdfLosslessImageCompression() const
Returns true if images embedded in pdf must be compressed using a lossless algorithm.
QList< QColor > highlightLabelBufferColorAsColor() const
Returns HIGHLIGHT_LABELBUFFERCOLOR as a list of colors.
QString request() const override
Returns REQUEST parameter as a string or an empty string if not defined.
double layerTitleSpaceAsDouble() const
Returns LAYERTITLESPACE as a double.
QList< QgsWmsParametersLayer > layersParameters() const
Returns parameters for each layer found in LAYER/LAYERS.
int lineToleranceAsInt() const
Returns FI_LINE_TOLERANCE parameter as an integer.
QList< double > highlightLabelBufferSizeAsFloat() const
Returns HIGHLIGHT_LABELBUFFERSIZE as a list of float.
QString lineTolerance() const
Returns FI_LINE_TOLERANCE parameter or an empty string if not defined.
bool showFeatureCountAsBool() const
Returns SHOWFEATURECOUNT as a bool.
QStringList pdfExportMapThemes() const
Returns map themes for geospatial PDF export.
bool pdfUseOgcBestPracticeFormatGeoreferencing() const
Returns true if OGC best practice georeferencing shall be used.
QStringList highlightLabelColor() const
Returns HIGHLIGHT_LABELCOLOR as a list of string.
bool pdfExportMetadata() const
Returns true if metadata shall be added to the pdf.
bool versionIsValid(const QString version) const
Returns true if version is valid, false otherwise.
QString j() const
Returns J parameter or an empty string if not defined.
int xAsInt() const
Returns X parameter as an int or its default value if not defined.
QColor layerFontColorAsColor() const
Returns LAYERFONTCOLOR as a color or its defined value if not defined.
QString bbox() const
Returns BBOX if defined or an empty string.
QgsWmsParameters()
Constructor for WMS parameters with default values only.
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
QStringList highlightLabelWeight() const
Returns HIGHLIGHT_LABELWEIGHT as a list of string.
QString backgroundColor() const
Returns BGCOLOR parameter or an empty string if not defined.
QStringList allStyles() const
Returns styles found in STYLE and STYLES parameters.
double symbolWidthAsDouble() const
Returns SYMBOLWIDTH as a double or its default value if not defined.
QColor backgroundColorAsColor() const
Returns BGCOLOR parameter as a QColor or its default value if not defined.
Format format() const
Returns format.
QgsWmsParameter operator[](QgsWmsParameter::Name name) const
Returns the parameter corresponding to name.
QString itemFontSize() const
Returns ITEMFONTSIZE parameter or an empty string if not defined.
QStringList atlasPk() const
Returns the ATLAS_PK parameter.
QList< QgsGeometry > highlightGeomAsGeom() const
Returns HIGHLIGHT_GEOM as a list of geometries.
QString layerFontFamily() const
Returns LAYERFONTFAMILY parameter or an empty string if not defined.
QString withMapTipAsString() const
withMapTipAsString
QList< QgsWmsParametersHighlightLayer > highlightLayersParameters() const
Returns parameters for each highlight layer.
int iAsInt() const
Returns I parameter as an int or its default value if not defined.
QStringList highlightLabelBufferColor() const
Returns HIGHLIGHT_LABELBUFFERCOLOR as a list of string.
bool pdfAppendGeoreference() const
Returns true if georeference info shall be added to the pdf.
int polygonToleranceAsInt() const
Returns FI_POLYGON_TOLERANCE parameter as an integer.
bool ruleLabelAsBool() const
Returns RULELABEL as a bool.
QList< double > highlightLabelDistance() const
Returns HIGHLIGHT_LABEL_DISTANCE as a list of double.
QList< int > highlightLabelSizeAsInt() const
Returns HIGHLIGHT_LABELSIZE as a list of int An exception is raised if an invalid size is found.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
QString sldBody() const
Returns SLD_body if defined or an empty string.
bool itemFontItalicAsBool() const
Returns ITEMFONTITALIC as a boolean or its default value if not defined.
bool pdfDisableTiledRasterRendering() const
Returns true if rasters shall be untiled in the pdf.
QColor itemFontColorAsColor() const
Returns ITEMFONTCOLOR as a color.
double itemFontSizeAsDouble() const
Returns ITEMFONTSIZE as a double.
QString layerFontColor() const
Returns LAYERFONTCOLOR parameter or an empty string if not defined.
QString layoutParameter(const QString &id, bool &ok) const
Returns a layout parameter thanks to its id.
bool dxfUseLayerTitleAsName() const
Returns the DXF USE_TITLE_AS_LAYERNAME parameter.
QString symbolHeight() const
Returns SYMBOLHEIGHT parameter or an empty string if not defined.
int imageQualityAsInt() const
Returns IMAGE_QUALITY parameter as an integer.
bool pdfForceVectorOutput() const
Returns if pdf should be exported as vector.
bool writeGeospatialPdf() const
Returns if a geospatial PDF shall be exported.
bool pdfUseIso32000ExtensionFormatGeoreferencing() const
Returns true, if Iso32000 georeferencing shall be used.
QMap< QString, QString > dimensionValues() const
Returns the dimensions parameter.
QList< QgsWmsParametersExternalLayer > externalLayersParameters() const
Returns parameters for each external layer.
bool withDisplayName() const
withDisplayName
int infoFormatVersion() const
Returns the infoFormat version for GML.
QString layerFontBold() const
Returns LAYERFONTBOLD parameter or an empty string if not defined.
QgsLegendSettings legendSettings() const
Returns legend settings.
int srcHeightAsInt() const
Returns SRCHEIGHT parameter as an int or its default value if not defined.
QString symbolSpace() const
Returns SYMBOLSPACE parameter or an empty string if not defined.
QString itemFontBold() const
Returns ITEMFONTBOLD parameter or an empty string if not defined.
double symbolSpaceAsDouble() const
Returns SYMBOLSPACE as a double or its default value if not defined.
QString infoFormatAsString() const
Returns INFO_FORMAT parameter as a string.
QStringList highlightLabelFont() const
Returns HIGHLIGHT_LABELFONT.
Qgis::TextRenderFormat pdfTextRenderFormat() const
Returns text render format for pdf export.
QString wmtver() const
Returns WMTVER parameter or an empty string if not defined.
QStringList dxfLayerAttributes() const
Returns the DXF LAYERATTRIBUTES parameter.
QString srcWidth() const
Returns SRCWIDTH parameter or an empty string if not defined.
Qgis::FeatureSymbologyExport dxfMode() const
Returns the DXF MODE parameter.
QStringList highlightLabelSize() const
Returns HIGHLIGHT_LABELSIZE as a list of string.
QString imageQuality() const
Returns IMAGE_QUALITY parameter or an empty string if not defined.
QList< double > highlightLabelRotation() const
Returns HIGHLIGHT_LABEL_ROTATION as a list of double.
QString height() const
Returns HEIGHT parameter or an empty string if not defined.
QString crs() const
Returns CRS or an empty string if none is defined.
bool showRuleDetailsAsBool() const
Returns SHOWRULEDETAILS as a bool.
QStringList selections() const
Returns the list of feature selection found in SELECTION parameter.
int featureCountAsInt() const
Returns FEATURE_COUNT as an integer.
int yAsInt() const
Returns Y parameter as an int or its default value if not defined.
bool layerTitleAsBool() const
Returns LAYERTITLE as a bool or its default value if not defined.
QString itemFontColor() const
Returns ITEMFONTCOLOR parameter or an empty string if not defined.
double boxSpaceAsDouble() const
Returns BOXSPACE as a double or its default value if not defined.
bool addLayerGroups() const
Returns true if layer groups shall be added to GetLegendGraphic results.
QString symbolWidth() const
Returns SYMBOLWIDTH parameter or an empty string if not defined.
bool tiledAsBool() const
Returns TILED parameter as a boolean.
Format
Output format for the response.
QString width() const
Returns WIDTH parameter or an empty string if not defined.
QFont itemFont() const
Returns the item font (built thanks to the ITEMFONTFAMILY, ITEMFONTSIZE, ITEMFONTBOLD,...
QStringList opacities() const
Returns the list of opacities found in OPACITIES parameter.
QString version() const override
Returns VERSION parameter as a string or an empty string if not defined.
QString layerFontItalic() const
Returns LAYERFONTITALIC parameter or an empty string if not defined.
QString itemFontItalic() const
Returns ITEMFONTITALIC parameter or an empty string if not defined.
QStringList filters() const
Returns the list of filters found in FILTER parameter.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
QString itemFontFamily() const
Returns ITEMFONTFAMILY parameter or an empty string if not defined.
int jAsInt() const
Returns J parameter as an int or its default value if not defined.
QVector< qreal > pdfPredefinedMapScales() const
Returns list of map scales.
QString showFeatureCount() const
Returns SHOWFEATURECOUNT parameter or an empty string if none is defined.
bool pdfSimplifyGeometries() const
Returns if geometries shall to be simplified.
bool layerFontBoldAsBool() const
Returns LAYERFONTBOLD as a boolean or its default value if not defined.
double iconLabelSpaceAsDouble() const
Returns ICONLABELSPACE as a double or its default value if not defined.
QStringList highlightSymbol() const
Returns HIGHLIGHT_SYMBOL as a list of string.
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
double symbolHeightAsDouble() const
Returns SYMBOLHEIGHT as a double or its default value if not defined.
bool infoFormatIsImage() const
Checks if INFO_FORMAT parameter is one of the image formats (PNG, JPG).
int srcWidthAsInt() const
Returns SRCWIDTH parameter as an int or its default value if not defined.
Median cut implementation.
const QString EXTERNAL_LAYER_PREFIX
QList< QgsWmsParametersLayer > mLayers
QList< QgsWmsParametersHighlightLayer > mHighlightLayers
QgsWmsParametersFilter::Type mType
QgsOgcUtils::FilterVersion mVersion
QList< QgsWmsParametersFilter > mFilter