QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
49
51 {
52 const QString msg = QString( "%1 ('%2') cannot be converted into %3" ).arg( name( mName ), toString(), typeName() );
54 }
55
56 QStringList QgsWmsParameter::toStyleList( const char delimiter, bool skipEmptyParts ) const
57 {
58 return QgsServerParameterDefinition::toStringList( delimiter, skipEmptyParts );
59 }
60
61 QList<QgsGeometry> QgsWmsParameter::toGeomList( const char delimiter, bool skipEmptyParts ) const
62 {
63 bool ok = true;
64 const QList<QgsGeometry> geoms = QgsServerParameterDefinition::toGeomList( ok, delimiter, skipEmptyParts );
65
66 if ( !ok )
67 {
68 const QString msg = QString( "%1 ('%2') cannot be converted into a list of geometries" ).arg( name( mName ), toString() );
70 }
71
72 return geoms;
73 }
74
76 {
77 bool ok = true;
79
80 if ( !ok )
81 {
82 const QString msg = QString( "%1 ('%2') cannot be converted into a rectangle" ).arg( name( mName ), toString() );
84 }
85
86 return rect;
87 }
88
90 {
91 bool ok = false;
92 const int val = QgsServerParameterDefinition::toInt( ok );
93
94 if ( !ok )
95 {
96 raiseError();
97 }
98
99 return val;
100 }
101
103 {
104 // Check URL -- it will be used in error messages
105 const QUrl url = toUrl();
106
107 bool ok = false;
108 const QString content = QgsServerParameterDefinition::loadUrl( ok );
109
110 if ( !ok )
111 {
112 const QString msg = QString( "%1 request error for %2" ).arg( name( mName ), url.toString() );
114 }
115
116 return content;
117 }
118
120 {
121 bool ok = false;
122 const QUrl url = QgsServerParameterDefinition::toUrl( ok );
123
124 if ( !ok )
125 {
126 raiseError();
127 }
128
129 return url;
130 }
131
133 {
134 bool ok = false;
135 const QColor col = QgsServerParameterDefinition::toColor( ok );
136
137 if ( !ok )
138 {
139 raiseError();
140 }
141
142 return col;
143 }
144
145 QList<QColor> QgsWmsParameter::toColorList( const char delimiter, bool skipEmptyParts ) const
146 {
147 bool ok = false;
148 const QList<QColor> vals = QgsServerParameterDefinition::toColorList( ok, delimiter, skipEmptyParts );
149
150 if ( !ok )
151 {
152 const QString msg = QString( "%1 ('%2') cannot be converted into a list of colors" ).arg( name( mName ), toString() );
154 }
155
156 return vals;
157 }
158
159 QList<int> QgsWmsParameter::toIntList( const char delimiter, bool skipEmptyParts ) const
160 {
161 bool ok = false;
162 const QList<int> vals = QgsServerParameterDefinition::toIntList( ok, delimiter, skipEmptyParts );
163
164 if ( !ok )
165 {
166 const QString msg = QString( "%1 ('%2') cannot be converted into a list of int" ).arg( name( mName ), toString() );
168 }
169
170 return vals;
171 }
172
173 QList<double> QgsWmsParameter::toDoubleList( const char delimiter, bool skipEmptyParts ) const
174 {
175 bool ok = false;
176 const QList<double> vals = QgsServerParameterDefinition::toDoubleList( ok, delimiter, skipEmptyParts );
177
178 if ( !ok )
179 {
180 const QString msg = QString( "%1 ('%2') cannot be converted into a list of float" ).arg( name( mName ), toString() );
182 }
183
184 return vals;
185 }
186
188 {
189 bool ok = false;
190 const double val = QgsServerParameterDefinition::toDouble( ok );
191
192 if ( !ok )
193 {
194 raiseError();
195 }
196
197 return val;
198 }
199
200 QString QgsWmsParameter::name() const
201 {
203 }
204
206 {
207 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
208 return metaEnum.valueToKey( name );
209 }
210
212 {
213 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
214 return ( QgsWmsParameter::Name ) metaEnum.keyToValue( name.toUpper().toStdString().c_str() );
215 }
216
217 //
218 // QgsWmsParameters
219 //
222 {
223 // Available version number
224 mVersions.append( QgsProjectVersion( 1, 1, 1 ) );
225 mVersions.append( QgsProjectVersion( 1, 3, 0 ) );
226
227 // WMS parameters definition
228 const QgsWmsParameter pQuality( QgsWmsParameter::IMAGE_QUALITY, QMetaType::Type::Int, QVariant( 0 ) );
229 save( pQuality );
230
231 const QgsWmsParameter pTiled( QgsWmsParameter::TILED, QMetaType::Type::Bool, QVariant( false ) );
232 save( pTiled );
233
234 const QgsWmsParameter pBoxSpace( QgsWmsParameter::BOXSPACE, QMetaType::Type::Double, QVariant( 2.0 ) );
235 save( pBoxSpace );
236
237 const QgsWmsParameter pSymbSpace( QgsWmsParameter::SYMBOLSPACE, QMetaType::Type::Double, QVariant( 2.0 ) );
238 save( pSymbSpace );
239
240 const QgsWmsParameter pLayerSpace( QgsWmsParameter::LAYERSPACE, QMetaType::Type::Double, QVariant( 3.0 ) );
241 save( pLayerSpace );
242
243 const QgsWmsParameter pTitleSpace( QgsWmsParameter::LAYERTITLESPACE, QMetaType::Type::Double, QVariant( 3.0 ) );
244 save( pTitleSpace );
245
246 const QgsWmsParameter pSymbHeight( QgsWmsParameter::SYMBOLHEIGHT, QMetaType::Type::Double, QVariant( 4.0 ) );
247 save( pSymbHeight );
248
249 const QgsWmsParameter pSymbWidth( QgsWmsParameter::SYMBOLWIDTH, QMetaType::Type::Double, QVariant( 7.0 ) );
250 save( pSymbWidth );
251
252 const QgsWmsParameter pIcLabelSpace( QgsWmsParameter::ICONLABELSPACE, QMetaType::Type::Double, QVariant( 2.0 ) );
253 save( pIcLabelSpace );
254
256 save( pItFontFamily );
257
258 const QgsWmsParameter pItFontBold( QgsWmsParameter::ITEMFONTBOLD, QMetaType::Type::Bool, QVariant( false ) );
259 save( pItFontBold );
260
261 const QgsWmsParameter pItFontItalic( QgsWmsParameter::ITEMFONTITALIC, QMetaType::Type::Bool, QVariant( false ) );
262 save( pItFontItalic );
263
264 const QgsWmsParameter pItFontSize( QgsWmsParameter::ITEMFONTSIZE, QMetaType::Type::Double, QVariant( -1 ) );
265 save( pItFontSize );
266
267 const QgsWmsParameter pItFontColor( QgsWmsParameter::ITEMFONTCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
268 save( pItFontColor );
269
270 const QgsWmsParameter pHighlightGeom( QgsWmsParameter::HIGHLIGHT_GEOM );
271 save( pHighlightGeom );
272
273 const QgsWmsParameter pShowFeatureCount( QgsWmsParameter::SHOWFEATURECOUNT, QMetaType::Type::Bool, QVariant( false ) );
274 save( pShowFeatureCount );
275
276 const QgsWmsParameter pHighlightSymbol( QgsWmsParameter::HIGHLIGHT_SYMBOL );
277 save( pHighlightSymbol );
278
280 save( pHighlightLabel );
281
282 const QgsWmsParameter pHighlightColor( QgsWmsParameter::HIGHLIGHT_LABELCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
283 save( pHighlightColor );
284
285 const QgsWmsParameter pHighlightFontSize( QgsWmsParameter::HIGHLIGHT_LABELSIZE );
286 save( pHighlightFontSize );
287
288 const QgsWmsParameter pHighlightFontWeight( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT );
289 save( pHighlightFontWeight );
290
292 save( pHighlightFont );
293
294 const QgsWmsParameter pHighlightBufferColor( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
295 save( pHighlightBufferColor );
296
298 save( pHighlightBufferSize );
299
300 const QgsWmsParameter pLabelRotation( QgsWmsParameter::HIGHLIGHT_LABEL_ROTATION, QMetaType::Type::Double );
301 save( pLabelRotation );
302
303 const QgsWmsParameter pLabelDistance( QgsWmsParameter::HIGHLIGHT_LABEL_DISTANCE, QMetaType::Type::Double );
304 save( pLabelDistance );
305
307 save( pLabelHali );
308
310 save( pLabelVali );
311
313 save( pCRS );
314
316 save( pSRS );
317
318 const QgsWmsParameter pFormat( QgsWmsParameter::FORMAT, QMetaType::Type::QString, QVariant( "png" ) );
319 save( pFormat );
320
322 save( pInfoFormat );
323
324 const QgsWmsParameter pI( QgsWmsParameter::I, QMetaType::Type::Int, QVariant( -1 ) );
325 save( pI );
326
327 const QgsWmsParameter pJ( QgsWmsParameter::J, QMetaType::Type::Int, QVariant( -1 ) );
328 save( pJ );
329
330 const QgsWmsParameter pX( QgsWmsParameter::X, QMetaType::Type::Int, QVariant( -1 ) );
331 save( pX );
332
333 const QgsWmsParameter pY( QgsWmsParameter::Y, QMetaType::Type::Int, QVariant( -1 ) );
334 save( pY );
335
337 save( pRule );
338
339 const QgsWmsParameter pRuleLabel( QgsWmsParameter::RULELABEL, QMetaType::Type::Bool, QVariant( true ) );
340 save( pRuleLabel );
341
342 const QgsWmsParameter pShowRuleDetails( QgsWmsParameter::SHOWRULEDETAILS, QMetaType::Type::Bool, QVariant( false ) );
343 save( pShowRuleDetails );
344
345 const QgsWmsParameter pScale( QgsWmsParameter::SCALE, QMetaType::Type::Double, QVariant( -1 ) );
346 save( pScale );
347
348 const QgsWmsParameter pHeight( QgsWmsParameter::HEIGHT, QMetaType::Type::Int, QVariant( 0 ) );
349 save( pHeight );
350
351 const QgsWmsParameter pWidth( QgsWmsParameter::WIDTH, QMetaType::Type::Int, QVariant( 0 ) );
352 save( pWidth );
353
354 const QgsWmsParameter pSrcHeight( QgsWmsParameter::SRCHEIGHT, QMetaType::Type::Int, QVariant( 0 ) );
355 save( pSrcHeight );
356
357 const QgsWmsParameter pSrcWidth( QgsWmsParameter::SRCWIDTH, QMetaType::Type::Int, QVariant( 0 ) );
358 save( pSrcWidth );
359
361 save( pBbox );
362
364 save( pSld );
365
367 save( pSldBody );
368
370 save( pLayer );
371
373 save( pLayers );
374
376 save( pQueryLayers );
377
378 const QgsWmsParameter pFeatureCount( QgsWmsParameter::FEATURE_COUNT, QMetaType::Type::Int, QVariant( 1 ) );
379 save( pFeatureCount );
380
381 const QgsWmsParameter pLayerTitle( QgsWmsParameter::LAYERTITLE, QMetaType::Type::Bool, QVariant( true ) );
382 save( pLayerTitle );
383
385 save( pLayerFtFamily );
386
387 const QgsWmsParameter pLayerFtBold( QgsWmsParameter::LAYERFONTBOLD, QMetaType::Type::Bool, QVariant( false ) );
388 save( pLayerFtBold );
389
390 const QgsWmsParameter pLayerFtItalic( QgsWmsParameter::LAYERFONTITALIC, QMetaType::Type::Bool, QVariant( false ) );
391 save( pLayerFtItalic );
392
393 const QgsWmsParameter pLayerFtSize( QgsWmsParameter::LAYERFONTSIZE, QMetaType::Type::Double, QVariant( -1 ) );
394 save( pLayerFtSize );
395
396 const QgsWmsParameter pLayerFtColor( QgsWmsParameter::LAYERFONTCOLOR, QMetaType::Type::QString, QVariant( "black" ) );
397 save( pLayerFtColor );
398
400 save( pStyle );
401
403 save( pStyles );
404
406 save( pOpacities );
407
409 save( pFilter );
410
412 save( pFilterGeom );
413
414 const QgsWmsParameter pPolygTol( QgsWmsParameter::FI_POLYGON_TOLERANCE, QMetaType::Type::Double, QVariant( 0.0 ) );
415 save( pPolygTol );
416
417 const QgsWmsParameter pLineTol( QgsWmsParameter::FI_LINE_TOLERANCE, QMetaType::Type::Double, QVariant( 0.0 ) );
418 save( pLineTol );
419
420 const QgsWmsParameter pPointTol( QgsWmsParameter::FI_POINT_TOLERANCE, QMetaType::Type::Double, QVariant( 0.0 ) );
421 save( pPointTol );
422
424 save( pSelection );
425
426 const QgsWmsParameter pWmsPrecision( QgsWmsParameter::WMS_PRECISION, QMetaType::Type::Int, QVariant( -1 ) );
427 save( pWmsPrecision );
428
429 const QgsWmsParameter pTransparent( QgsWmsParameter::TRANSPARENT, QMetaType::Type::Bool, QVariant( false ) );
430 save( pTransparent );
431
432 const QgsWmsParameter pBgColor( QgsWmsParameter::BGCOLOR, QMetaType::Type::QString, QVariant( "white" ) );
433 save( pBgColor );
434
435 const QgsWmsParameter pDpi( QgsWmsParameter::DPI, QMetaType::Type::Int, QVariant( -1 ) );
436 save( pDpi );
437
439 save( pTemplate );
440
442 save( pExtent );
443
444 const QgsWmsParameter pRotation( QgsWmsParameter::ROTATION, QMetaType::Type::Double, QVariant( 0.0 ) );
445 save( pRotation );
446
447 const QgsWmsParameter pGridX( QgsWmsParameter::GRID_INTERVAL_X, QMetaType::Type::Double, QVariant( 0.0 ) );
448 save( pGridX );
449
450 const QgsWmsParameter pGridY( QgsWmsParameter::GRID_INTERVAL_Y, QMetaType::Type::Double, QVariant( 0.0 ) );
451 save( pGridY );
452
453 const QgsWmsParameter pWithGeometry( QgsWmsParameter::WITH_GEOMETRY, QMetaType::Type::Bool, QVariant( false ) );
454 save( pWithGeometry );
455
456 const QgsWmsParameter pWithMapTip( QgsWmsParameter::WITH_MAPTIP, QMetaType::Type::QString );
457 save( pWithMapTip );
458
459 const QgsWmsParameter pWithDisplayName( QgsWmsParameter::WITH_DISPLAY_NAME, QMetaType::Type::Bool, QVariant( false ) );
460 save( pWithDisplayName );
461
463 save( pWmtver );
464
465 const QgsWmsParameter pAtlasPk( QgsWmsParameter::ATLAS_PK, QMetaType::Type::QStringList );
466 save( pAtlasPk );
467
468 const QgsWmsParameter pFormatOpts( QgsWmsParameter::FORMAT_OPTIONS, QMetaType::Type::QString );
469 save( pFormatOpts );
470
471 const QgsWmsParameter pAddLayerGroups( QgsWmsParameter::ADDLAYERGROUPS, QMetaType::Type::Bool, QVariant( false ) );
472 save( pAddLayerGroups );
473 }
474
477 {
478 load( parameters.urlQuery() );
479
480 auto it = mWmsParameters.constFind( QgsWmsParameter::SLD );
481 if ( it != mWmsParameters.constEnd() && !it->toString().isEmpty() )
482 {
483 const QString sldBody = it->loadUrl();
484 if ( !sldBody.isEmpty() )
485 {
487 }
488 }
489 }
490
492 {
493 return mWmsParameters.value( name );
494 }
495
497 {
498 auto it = mWmsParameters.find( name );
499 if ( it == mWmsParameters.end() )
500 {
501 it = mWmsParameters.insert( name, QgsWmsParameter() );
502 }
503
504 it->mValue = value;
505 }
506
507 bool QgsWmsParameters::loadParameter( const QString &key, const QString &value )
508 {
509 bool loaded = false;
510
511 const thread_local QRegularExpression composerParamRegExp( u"^MAP\\d+:"_s, QRegularExpression::CaseInsensitiveOption );
512 if ( key.contains( composerParamRegExp ) )
513 {
514 const int mapId = QStringView { key }.mid( 3, key.indexOf( ':' ) - 3 ).toInt();
515 const QString theKey = key.mid( key.indexOf( ':' ) + 1 );
516 const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey );
517
518 if ( name >= 0 )
519 {
520 QgsWmsParameter param = mWmsParameters.value( name );
521 param.mValue = value;
522 param.mMapId = mapId;
523
524 if ( !param.isValid() )
525 {
526 param.raiseError();
527 }
528
529 save( param, true ); // multi MAP parameters for composer
530 loaded = true;
531 }
532 }
533 else
534 {
536 if ( name >= 0 )
537 {
538 auto it = mWmsParameters.find( name );
539 if ( it == mWmsParameters.end() )
540 it = mWmsParameters.insert( name, QgsWmsParameter() );
541
542 it->mValue = value;
543 if ( !it->isValid() )
544 {
545 it->raiseError();
546 }
547
548 loaded = true;
549 }
550 else //maybe an external wms parameter?
551 {
552 int separator = key.indexOf( ':'_L1 );
553 if ( separator >= 1 )
554 {
555 QString id = key.left( separator );
556 QString param = key.right( key.length() - separator - 1 );
557 mExternalWMSParameters[id].insert( param, value );
558
559 loaded = true;
560 }
561 }
562 }
563
564 return loaded;
565 }
566
568 {
569 ( void ) log( u"WMS Request parameters:"_s );
570 for ( auto it = mWmsParameters.constBegin(); it != mWmsParameters.constEnd(); ++it )
571 {
572 const QString value = it->toString();
573
574 if ( !value.isEmpty() )
575 {
576 QString name = QgsWmsParameter::name( it.key() );
577
578 if ( it->mMapId >= 0 )
579 {
580 name = u"%1:%2"_s.arg( QString::number( it->mMapId ), name );
581 }
582
583 log( u" - %1 : %2"_s.arg( name, value ) );
584 }
585 }
586
587 if ( !version().isEmpty() )
588 log( u" - VERSION : %1"_s.arg( version() ) );
589 }
590
591 void QgsWmsParameters::save( const QgsWmsParameter &parameter, bool multi )
592 {
593 if ( multi )
594 {
595 mWmsParameters.insert( parameter.mName, parameter );
596 }
597 else
598 {
599 mWmsParameters.replace( parameter.mName, parameter );
600 }
601 }
602
604 {
605 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_GEOM ).toStringList( ';' );
606 }
607
608 QList<QgsGeometry> QgsWmsParameters::highlightGeomAsGeom() const
609 {
610 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_GEOM ).toGeomList( ';' );
611 }
612
614 {
615 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_SYMBOL ).toStringList( ';' );
616 }
617
618 QString QgsWmsParameters::crs() const
619 {
620 QString rs;
621 const QString srs = mWmsParameters.value( QgsWmsParameter::SRS ).toString();
622 const QString crs = mWmsParameters.value( QgsWmsParameter::CRS ).toString();
623
624 // both SRS/CRS are supported but there's a priority according to the
625 // specified version when both are defined in the request
626 if ( !srs.isEmpty() && crs.isEmpty() )
627 rs = srs;
628 else if ( srs.isEmpty() && !crs.isEmpty() )
629 rs = crs;
630 else if ( !srs.isEmpty() && !crs.isEmpty() )
631 {
632 if ( versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
633 rs = crs;
634 else
635 rs = srs;
636 }
637
638 return rs;
639 }
640
642 {
643 return mWmsParameters.value( QgsWmsParameter::BBOX ).toString();
644 }
645
647 {
648 return mWmsParameters.value( QgsWmsParameter::BBOX ).toRectangle();
649 }
650
652 {
653 return mWmsParameters.value( QgsWmsParameter::HEIGHT ).toString();
654 }
655
657 {
658 return mWmsParameters.value( QgsWmsParameter::WIDTH ).toString();
659 }
660
662 {
663 return mWmsParameters.value( QgsWmsParameter::HEIGHT ).toInt();
664 }
665
667 {
668 return mWmsParameters.value( QgsWmsParameter::WIDTH ).toInt();
669 }
670
672 {
673 return mWmsParameters.value( QgsWmsParameter::SRCHEIGHT ).toString();
674 }
675
677 {
678 return mWmsParameters.value( QgsWmsParameter::SRCWIDTH ).toString();
679 }
680
682 {
683 return mWmsParameters.value( QgsWmsParameter::SRCHEIGHT ).toInt();
684 }
685
687 {
688 return mWmsParameters.value( QgsWmsParameter::SRCWIDTH ).toInt();
689 }
690
691 QString QgsWmsParameters::dpi() const
692 {
693 return mWmsParameters.value( QgsWmsParameter::DPI ).toString();
694 }
695
697 {
698 return mWmsParameters.value( QgsWmsParameter::DPI ).toDouble();
699 }
700
702 {
704
705 if ( QgsServerParameters::request().compare( "GetProjectSettings"_L1, Qt::CaseInsensitive ) == 0 )
706 {
707 version = u"1.3.0"_s;
708 }
709 else if ( version.isEmpty() )
710 {
711 if ( !wmtver().isEmpty() )
712 {
713 version = wmtver();
714 }
715 else
716 {
717 version = u"1.3.0"_s;
718 }
719 }
720 else if ( !mVersions.contains( QgsProjectVersion( version ) ) )
721 {
722 // WMS 1.3.0 specification: If a version lower than any of those
723 // known to the server is requested, then the server shall send the
724 // lowest version it supports.
725 if ( QgsProjectVersion( 1, 1, 1 ) > QgsProjectVersion( version ) )
726 {
727 version = u"1.1.1"_s;
728 }
729 else
730 {
731 version = u"1.3.0"_s;
732 }
733 }
734
735 return version;
736 }
737
739 {
740 QString req = QgsServerParameters::request();
741
742 if ( version().compare( "1.1.1"_L1 ) == 0 && req.compare( "capabilities"_L1, Qt::CaseInsensitive ) == 0 )
743 {
744 req = u"GetCapabilities"_s;
745 }
746
747 return req;
748 }
749
754
755 bool QgsWmsParameters::versionIsValid( const QString version ) const
756 {
757 return mVersions.contains( QgsProjectVersion( version ) );
758 }
759
761 {
762 return mWmsParameters.value( QgsWmsParameter::FORMAT ).toString( true );
763 }
764
766 {
767 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameters::Format>() );
768 return metaEnum.valueToKey( format );
769 }
770
772 {
773 const QString fStr = formatAsString();
774
776 if ( fStr.compare( "image/png"_L1, Qt::CaseInsensitive ) == 0 || fStr.compare( "png"_L1, Qt::CaseInsensitive ) == 0 )
777 {
778 f = Format::PNG;
779 }
780 else if ( fStr.compare( "jpg"_L1, Qt::CaseInsensitive ) == 0 || fStr.compare( "jpeg"_L1, Qt::CaseInsensitive ) == 0 || fStr.compare( "image/jpeg"_L1, Qt::CaseInsensitive ) == 0 )
781 {
782 f = Format::JPG;
783 }
784 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 )
785 {
786 f = Format::SVG;
787 }
788 else if ( fStr.compare( "application/pdf"_L1, Qt::CaseInsensitive ) == 0 || fStr.compare( "pdf"_L1, Qt::CaseInsensitive ) == 0 )
789 {
790 f = Format::PDF;
791 }
792 else if ( fStr.compare( "application/json"_L1, Qt::CaseInsensitive ) == 0 || fStr.compare( "json"_L1, Qt::CaseInsensitive ) == 0 )
793 {
794 f = Format::JSON;
795 }
796 return f;
797 }
798
800 {
801 return mWmsParameters.value( QgsWmsParameter::INFO_FORMAT ).toString();
802 }
803
805 {
806 return infoFormat() == Format::PNG || infoFormat() == Format::JPG;
807 }
808
810 {
811 QString fStr = infoFormatAsString();
812
814 if ( fStr.isEmpty() )
815 return f;
816
817 if ( fStr.startsWith( "text/xml"_L1, Qt::CaseInsensitive ) )
818 f = Format::XML;
819 else if ( fStr.startsWith( "text/html"_L1, Qt::CaseInsensitive ) )
820 f = Format::HTML;
821 else if ( fStr.startsWith( "text/plain"_L1, Qt::CaseInsensitive ) )
822 f = Format::TEXT;
823 else if ( fStr.startsWith( "application/vnd.ogc.gml"_L1, Qt::CaseInsensitive ) )
824 f = Format::GML;
825 else if ( fStr.startsWith( "application/json"_L1, Qt::CaseInsensitive ) || fStr.startsWith( "application/geo+json"_L1, 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( "application/vnd.ogc.gml/3"_L1, 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( Qgis::LegendComponent::Group ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() );
1231 settings.rstyle( Qgis::LegendComponent::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( ';', false );
1275 }
1276
1278 {
1279 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELSIZE ).toIntList( ';', false );
1280 }
1281
1283 {
1284 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELCOLOR ).toStringList( ';', false );
1285 }
1286
1288 {
1289 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELCOLOR ).toColorList( ';', false );
1290 }
1291
1293 {
1294 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT ).toStringList( ';', false );
1295 }
1296
1298 {
1299 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT ).toIntList( ';', false );
1300 }
1301
1303 {
1304 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELFONT ).toStringList( ';', false );
1305 }
1306
1308 {
1309 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR ).toStringList( ';', false );
1310 }
1311
1313 {
1314 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR ).toColorList( ';', false );
1315 }
1316
1318 {
1319 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE ).toStringList( ';', false );
1320 }
1321
1323 {
1324 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE ).toDoubleList( ';', false );
1325 }
1326
1328 {
1329 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_ROTATION ).toDoubleList( ';', false );
1330 }
1331
1333 {
1334 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_DISTANCE ).toDoubleList( ';', false );
1335 }
1336
1338 {
1339 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_HORIZONTAL_ALIGNMENT ).toStringList( ';', false );
1340 }
1341
1343 {
1344 return mWmsParameters.value( QgsWmsParameter::HIGHLIGHT_LABEL_VERTICAL_ALIGNMENT ).toStringList( ';', false );
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 = u"http://www.opengis.net/fes/2.0"_s;
1440 const QString prefixWfs2 = u"<fes:"_s;
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( '<'_L1 ) && f.endsWith( "Filter>"_L1 ) && i < layers.size() )
1448 {
1450 filter.mFilter = f;
1453
1454 if ( filter.mFilter.contains( nsWfs2 ) || filter.mFilter.contains( prefixWfs2 ) )
1455 {
1457 }
1458
1459 filters.insert( layers[i], filter );
1460 }
1461 else if ( !f.isEmpty() )
1462 {
1463 // filter format: "LayerName,LayerName2:filterString;LayerName3:filterString2;..."
1464 // several filters can be defined for one layer
1465 const int colonIndex = f.indexOf( ':' );
1466 if ( colonIndex != -1 )
1467 {
1468 const QString layers = f.section( ':', 0, 0 );
1469 const QString filter = f.section( ':', 1 );
1470 const QStringList layersList = layers.split( ',' );
1471 for ( const QString &layer : layersList )
1472 {
1473 QgsWmsParametersFilter parametersFilter;
1474 parametersFilter.mFilter = filter;
1475 parametersFilter.mType = QgsWmsParametersFilter::SQL;
1476 filters.insert( layer, parametersFilter );
1477 }
1478 }
1479 else
1480 {
1481 QString filterStr = mWmsParameters.value( QgsWmsParameter::FILTER ).toString();
1482 raiseError( u"FILTER ('"_s + filterStr + u"') is not properly formatted"_s );
1483 }
1484 }
1485 }
1486 return filters;
1487 }
1488
1490 {
1491 bool force2D = false;
1492 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
1493
1494 if ( options.contains( DxfFormatOption::FORCE_2D ) )
1495 {
1496 force2D = QVariant( options[DxfFormatOption::FORCE_2D] ).toBool();
1497 }
1498
1499 return force2D;
1500 }
1501
1503 {
1504 bool zeroWidth = false;
1505 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
1506
1507 if ( options.contains( DxfFormatOption::EXPORT_LINES_WITH_ZERO_WIDTH ) )
1508 {
1509 zeroWidth = QVariant( options[DxfFormatOption::EXPORT_LINES_WITH_ZERO_WIDTH] ).toBool();
1510 }
1511
1512 return zeroWidth;
1513 }
1514
1516 {
1517 bool noMText = false;
1518 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
1519
1520 if ( options.contains( DxfFormatOption::NO_MTEXT ) )
1521 {
1522 noMText = QVariant( options[DxfFormatOption::NO_MTEXT] ).toBool();
1523 }
1524
1525 return noMText;
1526 }
1527
1528
1529 QList<QgsWmsParametersLayer> QgsWmsParameters::layersParameters() const
1530 {
1531 const QStringList layers = allLayersNickname();
1532 const QStringList styles = allStyles();
1533 const QStringList selection = selections();
1534 const QList<int> opacities = opacitiesAsInt();
1535 const QMultiMap<QString, QgsWmsParametersFilter> filters = layerFilters( layers );
1536
1537 // selection format: "LayerName:id0,id1;LayerName2:id0,id1;..."
1538 // several filters can be defined for one layer
1539 QMultiMap<QString, QString> layerSelections;
1540 for ( const QString &s : selection )
1541 {
1542 const QStringList splits = s.split( ':' );
1543 if ( splits.size() == 2 )
1544 {
1545 layerSelections.insert( splits[0], splits[1] );
1546 }
1547 else
1548 {
1549 QString selStr = mWmsParameters.value( QgsWmsParameter::SELECTION ).toString();
1550 raiseError( u"SELECTION ('"_s + selStr + u"') is not properly formatted"_s );
1551 }
1552 }
1553
1554 QList<QgsWmsParametersLayer> parameters;
1555 for ( int i = 0; i < layers.size(); i++ )
1556 {
1557 QString layer = layers[i];
1558
1560 param.mNickname = layer;
1561
1562 if ( i < opacities.count() )
1563 param.mOpacity = opacities[i];
1564
1565 if ( isExternalLayer( layer ) )
1566 {
1567 const QgsWmsParametersExternalLayer extParam = externalLayerParameter( layer );
1568 param.mNickname = extParam.mName;
1569 param.mExternalUri = extParam.mUri;
1570 }
1571 else
1572 {
1573 if ( i < styles.count() )
1574 param.mStyle = styles[i];
1575
1576 if ( filters.contains( layer ) )
1577 {
1578 auto it = filters.find( layer );
1579 while ( it != filters.end() && it.key() == layer )
1580 {
1581 param.mFilter.append( it.value() );
1582 ++it;
1583 }
1584 }
1585
1586 if ( layerSelections.contains( layer ) )
1587 {
1588 QMultiMap<QString, QString>::const_iterator it;
1589 it = layerSelections.constFind( layer );
1590 while ( it != layerSelections.constEnd() && it.key() == layer )
1591 {
1592 param.mSelection << it.value().split( ',' );
1593 ++it;
1594 }
1595 }
1596 }
1597
1598 parameters.append( param );
1599 }
1600
1601 return parameters;
1602 }
1603
1604 QList<QgsWmsParametersHighlightLayer> QgsWmsParameters::highlightLayersParameters() const
1605 {
1606 QList<QgsWmsParametersHighlightLayer> params;
1607 const QList<QgsGeometry> geoms = highlightGeomAsGeom();
1608 const QStringList slds = highlightSymbol();
1609 const QStringList labels = highlightLabelString();
1610 const QList<QColor> colors = highlightLabelColorAsColor();
1611 const QList<int> sizes = highlightLabelSizeAsInt();
1612 const QList<int> weights = highlightLabelWeightAsInt();
1613 const QStringList fonts = highlightLabelFont();
1614 const QList<QColor> bufferColors = highlightLabelBufferColorAsColor();
1615 const QList<double> bufferSizes = highlightLabelBufferSizeAsFloat();
1616 const QList<double> rotation = highlightLabelRotation();
1617 const QList<double> distance = highlightLabelDistance();
1618 const QStringList hali = highlightLabelHorizontalAlignment();
1619 const QStringList vali = highlightLabelVerticalAlignment();
1620
1621 int nLayers = std::min( geoms.size(), slds.size() );
1622 for ( int i = 0; i < nLayers; i++ )
1623 {
1625 param.mName = u"highlight_"_s + QString::number( i );
1626 param.mGeom = geoms[i];
1627 param.mSld = slds[i];
1628
1629 if ( i < labels.count() )
1630 param.mLabel = labels[i];
1631
1632 if ( i < colors.count() )
1633 param.mColor = colors[i];
1634
1635 if ( i < sizes.count() )
1636 param.mSize = sizes[i];
1637
1638 if ( i < weights.count() )
1639 param.mWeight = weights[i];
1640
1641 if ( i < fonts.count() )
1642 param.mFont = fonts[i];
1643
1644 if ( i < bufferColors.count() )
1645 param.mBufferColor = bufferColors[i];
1646
1647 if ( i < bufferSizes.count() )
1648 param.mBufferSize = bufferSizes[i];
1649
1650 if ( i < rotation.count() )
1651 param.mLabelRotation = rotation[i];
1652
1653 if ( i < distance.count() )
1654 param.mLabelDistance = distance[i];
1655
1656 if ( i < hali.count() )
1657 param.mHali = hali[i];
1658
1659 if ( i < vali.count() )
1660 param.mVali = vali[i];
1661
1662
1663 params.append( param );
1664 }
1665
1666 return params;
1667 }
1668
1669 QList<QgsWmsParametersExternalLayer> QgsWmsParameters::externalLayersParameters() const
1670 {
1671 auto notExternalLayer = []( const QString &name ) { return !QgsWmsParameters::isExternalLayer( name ); };
1672
1673 QList<QgsWmsParametersExternalLayer> externalLayers;
1674
1675 QStringList layers = allLayersNickname();
1676 QStringList::iterator rit = std::remove_if( layers.begin(), layers.end(), notExternalLayer );
1677
1678 for ( QStringList::iterator it = layers.begin(); it != rit; ++it )
1679 {
1680 externalLayers << externalLayerParameter( *it );
1681 }
1682
1683 return externalLayers;
1684 }
1685
1687 {
1688 return mWmsParameters.value( QgsWmsParameter::BGCOLOR ).toString();
1689 }
1690
1692 {
1693 return mWmsParameters.value( QgsWmsParameter::BGCOLOR ).toColor();
1694 }
1695
1697 {
1698 return mWmsParameters.value( QgsWmsParameter::TEMPLATE ).toString();
1699 }
1700
1702 {
1703 QgsWmsParameter wmsParam;
1705 param.mId = mapId;
1706
1707 QString pMapId = u"MAP"_s + QString::number( mapId );
1708
1709 wmsParam = idParameter( QgsWmsParameter::EXTENT, mapId );
1710 QgsRectangle extent;
1711 if ( wmsParam.isValid() )
1712 {
1713 extent = wmsParam.toRectangle();
1714 }
1715
1716 param.mHasExtent = !extent.isEmpty();
1717 param.mExtent = extent;
1718
1719 // scale
1720 wmsParam = idParameter( QgsWmsParameter::SCALE, mapId );
1721 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1722 {
1723 param.mScale = wmsParam.toDouble();
1724 }
1725
1726 // rotation
1727 wmsParam = idParameter( QgsWmsParameter::ROTATION, mapId );
1728 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1729 {
1730 param.mRotation = wmsParam.toDouble();
1731 }
1732
1733 //grid space x / y
1734 double gridx( -1 ), gridy( -1 );
1735
1736 wmsParam = idParameter( QgsWmsParameter::GRID_INTERVAL_X, mapId );
1737 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1738 {
1739 gridx = wmsParam.toDouble();
1740 }
1741
1742 wmsParam = idParameter( QgsWmsParameter::GRID_INTERVAL_Y, mapId );
1743 if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1744 {
1745 gridy = wmsParam.toDouble();
1746 }
1747
1748 if ( gridx >= 0 && gridy >= 0 )
1749 {
1750 param.mGridX = gridx;
1751 param.mGridY = gridy;
1752 }
1753
1754 //layers
1755 QStringList allLayers;
1756 wmsParam = idParameter( QgsWmsParameter::LAYERS, mapId );
1757 if ( wmsParam.isValid() )
1758 {
1759 allLayers = wmsParam.toStringList();
1760 }
1761
1762 // external layers
1763 QStringList layers;
1764
1765 for ( const auto &layer : std::as_const( allLayers ) )
1766 {
1767 if ( isExternalLayer( layer ) )
1768 {
1769 const QgsWmsParametersExternalLayer extParam = externalLayerParameter( layer );
1770 layers << extParam.mName;
1771 }
1772 else
1773 {
1774 layers << layer;
1775 }
1776 }
1777
1778 QStringList styles;
1779 wmsParam = idParameter( QgsWmsParameter::STYLES, mapId );
1780 if ( wmsParam.isValid() )
1781 {
1782 styles = wmsParam.toStyleList();
1783 }
1784
1785 QList<QgsWmsParametersLayer> lParams;
1786 for ( int i = 0; i < layers.size(); i++ )
1787 {
1788 QString layer = layers[i];
1789 QgsWmsParametersLayer lParam;
1790 lParam.mNickname = layer;
1791
1792 if ( i < styles.count() )
1793 lParam.mStyle = styles[i];
1794
1795 lParams.append( lParam );
1796 }
1797 param.mLayers = lParams;
1798
1799 //highlight layers
1800 QList<QgsWmsParametersHighlightLayer> hParams;
1801
1802 QList<QgsGeometry> geoms;
1803 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_GEOM, mapId );
1804 if ( wmsParam.isValid() )
1805 {
1806 geoms = wmsParam.toGeomList( ';', false );
1807 }
1808
1809 QStringList slds;
1810 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_SYMBOL, mapId );
1811 if ( wmsParam.isValid() )
1812 {
1813 slds = wmsParam.toStringList( ';', false );
1814 }
1815
1816 QStringList labels;
1817 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELSTRING, mapId );
1818 if ( wmsParam.isValid() )
1819 {
1820 labels = wmsParam.toStringList( ';', false );
1821 }
1822
1823 QStringList fonts;
1824 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELFONT, mapId );
1825 if ( wmsParam.isValid() )
1826 {
1827 fonts = wmsParam.toStringList( ';', false );
1828 }
1829
1830 QList<QColor> colors;
1831 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELCOLOR, mapId );
1832 if ( wmsParam.isValid() )
1833 {
1834 colors = wmsParam.toColorList( ';', false );
1835 }
1836
1837 QList<int> sizes;
1838 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELSIZE, mapId );
1839 if ( wmsParam.isValid() )
1840 {
1841 sizes = wmsParam.toIntList( ';', false );
1842 }
1843
1844 QList<int> weights;
1845 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT, mapId );
1846 if ( wmsParam.isValid() )
1847 {
1848 weights = wmsParam.toIntList( ';', false );
1849 }
1850
1851 QList<QColor> bufferColors;
1852 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR, mapId );
1853 if ( wmsParam.isValid() )
1854 {
1855 bufferColors = wmsParam.toColorList( ';', false );
1856 }
1857
1858 QList<double> bufferSizes;
1859 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE, mapId );
1860 if ( wmsParam.isValid() )
1861 {
1862 bufferSizes = wmsParam.toDoubleList( ';', false );
1863 }
1864
1865 QList<double> rotations;
1866 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_ROTATION, mapId );
1867 if ( wmsParam.isValid() )
1868 {
1869 rotations = wmsParam.toDoubleList( ';', false );
1870 }
1871
1872 QList<double> distances;
1873 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_DISTANCE, mapId );
1874 if ( wmsParam.isValid() )
1875 {
1876 distances = wmsParam.toDoubleList( ';', false );
1877 }
1878
1879 QStringList halis;
1880 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_HORIZONTAL_ALIGNMENT, mapId );
1881 if ( wmsParam.isValid() )
1882 {
1883 halis = wmsParam.toStringList( ';', false );
1884 }
1885
1886 QStringList valis;
1887 wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABEL_VERTICAL_ALIGNMENT, mapId );
1888 if ( wmsParam.isValid() )
1889 {
1890 valis = wmsParam.toStringList( ';', false );
1891 }
1892
1893 int nHLayers = std::min( geoms.size(), slds.size() );
1894 for ( int i = 0; i < nHLayers; i++ )
1895 {
1897 hParam.mName = pMapId + u"_highlight_"_s + QString::number( i );
1898 hParam.mGeom = geoms[i];
1899 hParam.mSld = slds[i];
1900
1901 if ( i < labels.count() )
1902 hParam.mLabel = labels[i];
1903
1904 if ( i < colors.count() )
1905 hParam.mColor = colors[i];
1906
1907 if ( i < sizes.count() )
1908 hParam.mSize = sizes[i];
1909
1910 if ( i < weights.count() )
1911 hParam.mWeight = weights[i];
1912
1913 if ( i < fonts.count() )
1914 hParam.mFont = fonts[i];
1915
1916 if ( i < bufferColors.count() )
1917 hParam.mBufferColor = bufferColors[i];
1918
1919 if ( i < bufferSizes.count() )
1920 hParam.mBufferSize = bufferSizes[i];
1921
1922 if ( i < rotations.count() )
1923 hParam.mLabelRotation = rotations[i];
1924
1925 if ( i < distances.count() )
1926 hParam.mLabelDistance = distances[i];
1927
1928 if ( i < halis.count() )
1929 hParam.mHali = halis[i];
1930
1931 if ( i < valis.count() )
1932 hParam.mVali = valis[i];
1933
1934 hParams.append( hParam );
1935 }
1936 param.mHighlightLayers = hParams;
1937
1938 return param;
1939 }
1940
1941 QString QgsWmsParameters::externalWMSUri( const QString &layerId ) const
1942 {
1943 // Param names may be uppercased.
1944 QString id { layerId };
1945
1946 for ( auto it = mExternalWMSParameters.cbegin(); it != mExternalWMSParameters.cend(); ++it )
1947 {
1948 if ( it.key().compare( id, Qt::CaseSensitivity::CaseInsensitive ) == 0 )
1949 {
1950 id = it.key();
1951 break;
1952 }
1953 }
1954
1955 if ( !mExternalWMSParameters.contains( id ) )
1956 {
1957 return QString();
1958 }
1959
1960 QgsDataSourceUri wmsUri;
1961 const QMap<QString, QString> &paramMap = mExternalWMSParameters[id];
1962 QMap<QString, QString>::const_iterator paramIt = paramMap.constBegin();
1963 for ( ; paramIt != paramMap.constEnd(); ++paramIt )
1964 {
1965 QString paramName = paramIt.key().toLower();
1966 if ( paramName == "layers"_L1 || paramName == "styles"_L1 || paramName == "opacities"_L1 )
1967 {
1968 const QStringList values = paramIt.value().split( ',' );
1969 for ( const QString &value : values )
1970 wmsUri.setParam( paramName, value );
1971 }
1972 else if ( paramName == "ignorereportedlayerextents"_L1 )
1973 {
1974 wmsUri.setParam( u"IgnoreReportedLayerExtents"_s, paramIt.value() );
1975 }
1976 else if ( paramName == "smoothpixmaptransform"_L1 )
1977 {
1978 wmsUri.setParam( u"SmoothPixmapTransform"_s, paramIt.value() );
1979 }
1980 else if ( paramName == "ignoregetmapurl"_L1 )
1981 {
1982 wmsUri.setParam( u"IgnoreGetMapUrl"_s, paramIt.value() );
1983 }
1984 else if ( paramName == "ignoregetfeatureinfourl"_L1 )
1985 {
1986 wmsUri.setParam( u"IgnoreGetFeatureInfoUrl"_s, paramIt.value() );
1987 }
1988 else if ( paramName == "ignoreaxisorientation"_L1 )
1989 {
1990 wmsUri.setParam( u"IgnoreAxisOrientation"_s, paramIt.value() );
1991 }
1992 else if ( paramName == "invertaxisorientation"_L1 )
1993 {
1994 wmsUri.setParam( u"InvertAxisOrientation"_s, paramIt.value() );
1995 }
1996 else if ( paramName == "dpimode"_L1 )
1997 {
1998 wmsUri.setParam( u"dpiMode"_s, paramIt.value() );
1999 }
2000 else if ( paramName == "stepwidth"_L1 )
2001 {
2002 wmsUri.setParam( u"stepWidth"_s, paramIt.value() );
2003 }
2004 else if ( paramName == "stepheight"_L1 )
2005 {
2006 wmsUri.setParam( u"stepHeight"_s, paramIt.value() );
2007 }
2008 else
2009 {
2010 wmsUri.setParam( paramName, paramIt.value() );
2011 }
2012 }
2013 return wmsUri.encodedUri();
2014 }
2015
2017 {
2018 return mWmsParameters.value( QgsWmsParameter::WITH_GEOMETRY ).toBool();
2019 }
2020
2022 {
2023 return mWmsParameters.value( QgsWmsParameter::WITH_MAPTIP ).toString();
2024 }
2025
2027 {
2028 const QString mStr = withMapTipAsString();
2029
2030 if ( mStr.startsWith( "true"_L1, Qt::CaseInsensitive ) || mStr.startsWith( "on"_L1, Qt::CaseInsensitive ) || mStr.startsWith( "yes"_L1, Qt::CaseInsensitive ) || mStr.startsWith( '1'_L1 ) )
2031 return true;
2032 else
2033 return false;
2034 }
2035
2037 {
2038 const QString mStr = withMapTipAsString();
2039
2040 if ( mStr.startsWith( "html_fi_only_maptip"_L1, Qt::CaseInsensitive ) )
2041 return true;
2042 else
2043 return false;
2044 }
2045
2047 {
2048 return mWmsParameters.value( QgsWmsParameter::WITH_DISPLAY_NAME ).toBool();
2049 }
2050
2052 {
2053 return mWmsParameters.value( QgsWmsParameter::WMTVER ).toString();
2054 }
2055
2056 void QgsWmsParameters::log( const QString &msg, const char *file, const char *function, int line ) const
2057 {
2058 QgsMessageLog::logMessage( msg, u"Server"_s, Qgis::MessageLevel::Info, true, file, function, line );
2059 }
2060
2061 void QgsWmsParameters::raiseError( const QString &msg ) const
2062 {
2064 }
2065
2066 QgsWmsParameter QgsWmsParameters::idParameter( const QgsWmsParameter::Name name, const int id ) const
2067 {
2068 QgsWmsParameter p;
2069
2070 for ( const auto &param : mWmsParameters.values( name ) )
2071 {
2072 if ( param.mMapId == id )
2073 {
2074 p = param;
2075 }
2076 }
2077
2078 return p;
2079 }
2080
2081 QgsWmsParametersExternalLayer QgsWmsParameters::externalLayerParameter( const QString &name ) const
2082 {
2083 QgsWmsParametersExternalLayer param;
2084
2085 param.mName = name;
2086 param.mName.remove( 0, EXTERNAL_LAYER_PREFIX.size() );
2087 param.mUri = externalWMSUri( param.mName );
2088
2089 return param;
2090 }
2091
2092 bool QgsWmsParameters::isExternalLayer( const QString &name )
2093 {
2094 return name.startsWith( EXTERNAL_LAYER_PREFIX );
2095 }
2096
2098 {
2099 QStringList attributes;
2100 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2101
2102 if ( options.contains( DxfFormatOption::LAYERATTRIBUTES ) )
2103 {
2104 attributes = options[DxfFormatOption::LAYERATTRIBUTES].split( ',' );
2105 }
2106
2107 return attributes;
2108 }
2109
2111 {
2112 bool use = false;
2113 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2114
2115 if ( options.contains( DxfFormatOption::USE_TITLE_AS_LAYERNAME ) )
2116 {
2117 use = QVariant( options[DxfFormatOption::USE_TITLE_AS_LAYERNAME] ).toBool();
2118 }
2119
2120 return use;
2121 }
2122
2124 {
2125 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2126
2127 double scale = -1;
2128 if ( options.contains( DxfFormatOption::SCALE ) )
2129 {
2130 scale = options[DxfFormatOption::SCALE].toDouble();
2131 }
2132
2133 return scale;
2134 }
2135
2137 {
2138 const QMap<DxfFormatOption, QString> options = formatOptions<QgsWmsParameters::DxfFormatOption>();
2139
2141
2142 if ( !options.contains( DxfFormatOption::MODE ) )
2143 {
2144 return symbol;
2145 }
2146
2147 const QString mode = options[DxfFormatOption::MODE];
2148 if ( mode.compare( "SymbolLayerSymbology"_L1, Qt::CaseInsensitive ) == 0 )
2149 {
2151 }
2152 else if ( mode.compare( "FeatureSymbology"_L1, Qt::CaseInsensitive ) == 0 )
2153 {
2155 }
2156
2157 return symbol;
2158 }
2159
2161 {
2162 QString codec = u"ISO-8859-1"_s;
2163
2165 {
2167 }
2168
2169 return codec;
2170 }
2171
2173 {
2174 bool geospatialPdf = false;
2175 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2176 if ( options.contains( PdfFormatOption::WRITE_GEO_PDF ) )
2177 {
2178 geospatialPdf = QVariant( options[PdfFormatOption::WRITE_GEO_PDF] ).toBool();
2179 }
2180 return geospatialPdf;
2181 }
2182
2184 {
2185 bool forceVector = false;
2186 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2187 if ( options.contains( PdfFormatOption::FORCE_VECTOR_OUTPUT ) )
2188 {
2189 forceVector = QVariant( options[PdfFormatOption::FORCE_VECTOR_OUTPUT] ).toBool();
2190 }
2191 return forceVector;
2192 }
2193
2195 {
2196 bool appendGeoref = true;
2197 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2198 if ( options.contains( PdfFormatOption::APPEND_GEOREFERENCE ) )
2199 {
2200 appendGeoref = QVariant( options[PdfFormatOption::APPEND_GEOREFERENCE] ).toBool();
2201 }
2202 return appendGeoref;
2203 }
2204
2206 {
2207 bool simplify = true;
2208 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2209 if ( options.contains( PdfFormatOption::SIMPLIFY_GEOMETRY ) )
2210 {
2211 simplify = QVariant( options[PdfFormatOption::SIMPLIFY_GEOMETRY] ).toBool();
2212 }
2213 return simplify;
2214 }
2215
2217 {
2218 bool exportMetadata = false;
2219 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2220 if ( options.contains( PdfFormatOption::EXPORT_METADATA ) )
2221 {
2222 exportMetadata = QVariant( options[PdfFormatOption::EXPORT_METADATA] ).toBool();
2223 }
2224 return exportMetadata;
2225 }
2226
2228 {
2230 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2231 if ( options.contains( PdfFormatOption::TEXT_RENDER_FORMAT ) )
2232 {
2233 if ( options[PdfFormatOption::TEXT_RENDER_FORMAT].compare( u"AlwaysText"_s, Qt::CaseInsensitive ) == 0 )
2234 {
2236 }
2237 else if ( options[PdfFormatOption::TEXT_RENDER_FORMAT].compare( u"PreferText"_s, Qt::CaseInsensitive ) == 0 )
2238 {
2240 }
2241 }
2242 return format;
2243 }
2244
2246 {
2247 bool losslessCompression = false;
2248 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2249 if ( options.contains( PdfFormatOption::LOSSLESS_IMAGE_COMPRESSION ) )
2250 {
2251 losslessCompression = QVariant( options[PdfFormatOption::LOSSLESS_IMAGE_COMPRESSION] ).toBool();
2252 }
2253 return losslessCompression;
2254 }
2255
2257 {
2258 bool disableTiledRaster = false;
2259 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2260 if ( options.contains( PdfFormatOption::DISABLE_TILED_RASTER_RENDERING ) )
2261 {
2262 disableTiledRaster = QVariant( options[PdfFormatOption::DISABLE_TILED_RASTER_RENDERING] ).toBool();
2263 }
2264 return disableTiledRaster;
2265 }
2266
2268 {
2269 bool useIso32000 = true;
2270 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2272 {
2273 useIso32000 = QVariant( options[PdfFormatOption::USE_ISO_32000_EXTENSION_FORMAT_GEOREFERENCING] ).toBool();
2274 }
2275 return useIso32000;
2276 }
2277
2279 {
2280 return false;
2281 }
2282
2284 {
2285 QStringList themes;
2286 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2287 if ( options.contains( PdfFormatOption::EXPORT_THEMES ) )
2288 {
2289 themes = options[PdfFormatOption::EXPORT_THEMES].split( ',' );
2290 }
2291 return themes;
2292 }
2293
2295 {
2296 QVector<qreal> scales;
2297 const QMap<QgsWmsParameters::PdfFormatOption, QString> options = formatOptions<QgsWmsParameters::PdfFormatOption>();
2298 if ( options.contains( PdfFormatOption::PREDEFINED_MAP_SCALES ) )
2299 {
2300 const QStringList scaleList = options[PdfFormatOption::PREDEFINED_MAP_SCALES].split( ',' );
2301 for ( const QString &it : std::as_const( scaleList ) )
2302 {
2303 bool ok = false;
2304 qreal scale = it.toDouble( &ok );
2305 if ( ok )
2306 {
2307 scales.append( scale );
2308 }
2309 }
2310 }
2311 return scales;
2312 }
2313
2314 QMap<QString, QString> QgsWmsParameters::dimensionValues() const
2315 {
2316 QMap<QString, QString> dimValues;
2317 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
2318 const QStringList unmanagedNames = mUnmanagedParameters.keys();
2319 for ( const QString &key : unmanagedNames )
2320 {
2321 if ( key.startsWith( "DIM_"_L1 ) )
2322 {
2323 dimValues[key.mid( 4 )] = mUnmanagedParameters[key];
2324 }
2325 else if ( pnMetaEnum.keyToValue( key.toUpper().toStdString().c_str() ) != -1 )
2326 {
2327 dimValues[key] = mUnmanagedParameters[key];
2328 }
2329 }
2330 return dimValues;
2331 }
2332} // namespace QgsWms
@ Symbol
Symbol icon (excluding label).
Definition qgis.h:4725
@ Group
Legend group title.
Definition qgis.h:4723
@ Subgroup
Legend subgroup title.
Definition qgis.h:4724
@ Title
Legend title.
Definition qgis.h:4722
@ SymbolLabel
Symbol label (excluding icon).
Definition qgis.h:4726
@ Info
Information message.
Definition qgis.h:161
TextRenderFormat
Options for rendering text.
Definition qgis.h:2923
@ PreferText
Render text as text objects, unless doing so results in rendering artifacts or poor quality rendering...
Definition qgis.h:2930
@ AlwaysOutlines
Always render text using path objects (AKA outlines/curves). This setting guarantees the best quality...
Definition qgis.h:2924
@ AlwaysText
Always render text as text objects. While this mode preserves text objects as text for post-processin...
Definition qgis.h:2927
FeatureSymbologyExport
Options for exporting features considering their symbology.
Definition qgis.h:5913
@ PerFeature
Keeps the number of features and export symbology per feature.
Definition qgis.h:5915
@ PerSymbolLayer
Exports one feature per symbol layer (considering symbol levels).
Definition qgis.h:5916
@ NoSymbology
Export only data.
Definition qgis.h:5914
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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 rounded to the spec...
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