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