QGIS API Documentation  3.6.0-Noosa (5873452)
qgswmsparameters.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswmsparameters.cpp
3  --------------------
4  begin : March 17, 2017
5  copyright : (C) 2017 by Paul Blottiere
6  email : paul dot blottiere at oslandia dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgswmsparameters.h"
19 #include "qgsdatasourceuri.h"
20 #include "qgsmessagelog.h"
21 
22 namespace QgsWms
23 {
24  //
25  // QgsWmsParameter
26  //
28  const QVariant::Type type,
29  const QVariant defaultValue )
30  : QgsServerParameterDefinition( type, defaultValue )
31  , mName( name )
32  {
33  }
34 
36  {
38  }
39 
41  {
42  const QString msg = QString( "%1 ('%2') cannot be converted into %3" ).arg( name( mName ), toString(), typeName() );
44  }
45 
46  QList<QgsGeometry> QgsWmsParameter::toGeomList( const char delimiter ) const
47  {
48  bool ok = true;
49  const QList<QgsGeometry> geoms = QgsServerParameterDefinition::toGeomList( ok, delimiter );
50 
51  if ( !ok )
52  {
53  const QString msg = QString( "%1 ('%2') cannot be converted into a list of geometries" ).arg( name( mName ), toString(), typeName() );
55  }
56 
57  return geoms;
58  }
59 
61  {
62  bool ok = true;
64 
65  if ( !ok )
66  {
67  const QString msg = QString( "%1 ('%2') cannot be converted into a rectangle" ).arg( name( mName ), toString(), typeName() );
69  }
70 
71  return rect;
72  }
73 
75  {
76  bool ok = false;
77  const int val = QgsServerParameterDefinition::toInt( ok );
78 
79  if ( !ok )
80  {
81  raiseError();
82  }
83 
84  return val;
85  }
86 
87  QString QgsWmsParameter::loadUrl() const
88  {
89  // Check URL -- it will be used in error messages
90  const QUrl url = toUrl();
91 
92  bool ok = false;
93  const QString content = QgsServerParameterDefinition::loadUrl( ok );
94 
95  if ( !ok )
96  {
97  const QString msg = QString( "%1 request error for %2" ).arg( name( mName ), url.toString() );
99  }
100 
101  return content;
102  }
103 
105  {
106  bool ok = false;
107  const QUrl url = QgsServerParameterDefinition::toUrl( ok );
108 
109  if ( !ok )
110  {
111  raiseError();
112  }
113 
114  return url;
115  }
116 
118  {
119  bool ok = false;
120  const QColor col = QgsServerParameterDefinition::toColor( ok );
121 
122  if ( !ok )
123  {
124  raiseError();
125  }
126 
127  return col;
128  }
129 
130  QList<QColor> QgsWmsParameter::toColorList( const char delimiter ) const
131  {
132  bool ok = false;
133  const QList<QColor> vals = QgsServerParameterDefinition::toColorList( ok, delimiter );
134 
135  if ( !ok )
136  {
137  const QString msg = QString( "%1 ('%2') cannot be converted into a list of colors" ).arg( name( mName ), toString(), typeName() );
139  }
140 
141  return vals;
142  }
143 
144  QList<int> QgsWmsParameter::toIntList( const char delimiter ) const
145  {
146  bool ok = false;
147  const QList<int> vals = QgsServerParameterDefinition::toIntList( ok, delimiter );
148 
149  if ( !ok )
150  {
151  const QString msg = QString( "%1 ('%2') cannot be converted into a list of int" ).arg( name( mName ), toString(), typeName() );
153  }
154 
155  return vals;
156  }
157 
158  QList<double> QgsWmsParameter::toDoubleList( const char delimiter ) const
159  {
160  bool ok = false;
161  const QList<double> vals = QgsServerParameterDefinition::toDoubleList( ok, delimiter );
162 
163  if ( !ok )
164  {
165  const QString msg = QString( "%1 ('%2') cannot be converted into a list of float" ).arg( name( mName ), toString(), typeName() );
167  }
168 
169  return vals;
170  }
171 
173  {
174  bool ok = false;
175  const double val = QgsServerParameterDefinition::toDouble( ok );
176 
177  if ( !ok )
178  {
179  raiseError();
180  }
181 
182  return val;
183  }
184 
186  {
187  const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
188  return metaEnum.valueToKey( name );
189  }
190 
192  {
193  const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameter::Name>() );
194  return ( QgsWmsParameter::Name ) metaEnum.keyToValue( name.toUpper().toStdString().c_str() );
195  }
196 
197  //
198  // QgsWmsParameters
199  //
202  {
203  // Available version number
204  mVersions.append( QgsProjectVersion( 1, 1, 1 ) );
205  mVersions.append( QgsProjectVersion( 1, 3, 0 ) );
206 
207  // WMS parameters definition
209  QVariant::Int,
210  QVariant( 0 ) );
211  save( pQuality );
212 
214  QVariant::Double,
215  QVariant( 2.0 ) );
216  save( pBoxSpace );
217 
219  QVariant::Double,
220  QVariant( 2.0 ) );
221  save( pSymbSpace );
222 
223  const QgsWmsParameter pLayerSpace( QgsWmsParameter::LAYERSPACE,
224  QVariant::Double,
225  QVariant( 3.0 ) );
226  save( pLayerSpace );
227 
229  QVariant::Double,
230  QVariant( 3.0 ) );
231  save( pTitleSpace );
232 
234  QVariant::Double,
235  QVariant( 4.0 ) );
236  save( pSymbHeight );
237 
239  QVariant::Double,
240  QVariant( 7.0 ) );
241  save( pSymbWidth );
242 
244  QVariant::Double,
245  QVariant( 2.0 ) );
246  save( pIcLabelSpace );
247 
248  const QgsWmsParameter pItFontFamily( QgsWmsParameter::ITEMFONTFAMILY );
249  save( pItFontFamily );
250 
252  QVariant::Bool,
253  QVariant( false ) );
254  save( pItFontBold );
255 
257  QVariant::Bool,
258  QVariant( false ) );
259  save( pItFontItalic );
260 
262  QVariant::Double,
263  QVariant( -1 ) );
264  save( pItFontSize );
265 
267  QVariant::String,
268  QVariant( "black" ) );
269  save( pItFontColor );
270 
271  const QgsWmsParameter pHighlightGeom( QgsWmsParameter::HIGHLIGHT_GEOM );
272  save( pHighlightGeom );
273 
274  const QgsWmsParameter pShowFeatureCount( QgsWmsParameter::SHOWFEATURECOUNT,
275  QVariant::Bool,
276  QVariant( false ) );
277  save( pShowFeatureCount );
278 
279  const QgsWmsParameter pHighlightSymbol( QgsWmsParameter::HIGHLIGHT_SYMBOL );
280  save( pHighlightSymbol );
281 
283  save( pHighlightLabel );
284 
286  QVariant::String,
287  QVariant( "black" ) );
288  save( pHighlightColor );
289 
290  const QgsWmsParameter pHighlightFontSize( QgsWmsParameter::HIGHLIGHT_LABELSIZE );
291  save( pHighlightFontSize );
292 
293  const QgsWmsParameter pHighlightFontWeight( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT );
294  save( pHighlightFontWeight );
295 
297  save( pHighlightFont );
298 
300  QVariant::String,
301  QVariant( "black" ) );
302  save( pHighlightBufferColor );
303 
304  const QgsWmsParameter pHighlightBufferSize( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE );
305  save( pHighlightBufferSize );
306 
308  save( pCRS );
309 
311  save( pSRS );
312 
313  const QgsWmsParameter pFormat( QgsWmsParameter::FORMAT );
314  save( pFormat );
315 
316  const QgsWmsParameter pInfoFormat( QgsWmsParameter::INFO_FORMAT );
317  save( pInfoFormat );
318 
320  QVariant::Int,
321  QVariant( -1 ) );
322  save( pI );
323 
325  QVariant::Int,
326  QVariant( -1 ) );
327  save( pJ );
328 
330  QVariant::Int,
331  QVariant( -1 ) );
332  save( pX );
333 
335  QVariant::Int,
336  QVariant( -1 ) );
337  save( pY );
338 
339  const QgsWmsParameter pRule( QgsWmsParameter::RULE );
340  save( pRule );
341 
343  QVariant::Bool,
344  QVariant( true ) );
345  save( pRuleLabel );
346 
348  QVariant::Double,
349  QVariant( -1 ) );
350  save( pScale );
351 
353  QVariant::Int,
354  QVariant( 0 ) );
355  save( pHeight );
356 
358  QVariant::Int,
359  QVariant( 0 ) );
360  save( pWidth );
361 
362  const QgsWmsParameter pBbox( QgsWmsParameter::BBOX );
363  save( pBbox );
364 
366  save( pSld );
367 
368  const QgsWmsParameter pSldBody( QgsWmsParameter::SLD_BODY );
369  save( pSldBody );
370 
371  const QgsWmsParameter pLayer( QgsWmsParameter::LAYER );
372  save( pLayer );
373 
374  const QgsWmsParameter pLayers( QgsWmsParameter::LAYERS );
375  save( pLayers );
376 
377  const QgsWmsParameter pQueryLayers( QgsWmsParameter::QUERY_LAYERS );
378  save( pQueryLayers );
379 
380  const QgsWmsParameter pFeatureCount( QgsWmsParameter::FEATURE_COUNT,
381  QVariant::Int,
382  QVariant( 1 ) );
383  save( pFeatureCount );
384 
385  const QgsWmsParameter pLayerTitle( QgsWmsParameter::LAYERTITLE,
386  QVariant::Bool,
387  QVariant( true ) );
388  save( pLayerTitle );
389 
390  const QgsWmsParameter pLayerFtFamily( QgsWmsParameter::LAYERFONTFAMILY );
391  save( pLayerFtFamily );
392 
394  QVariant::Bool,
395  QVariant( false ) );
396  save( pLayerFtBold );
397 
399  QVariant::Bool,
400  QVariant( false ) );
401  save( pLayerFtItalic );
402 
404  QVariant::Double,
405  QVariant( -1 ) );
406  save( pLayerFtSize );
407 
409  QVariant::String,
410  QVariant( "black" ) );
411  save( pLayerFtColor );
412 
413  const QgsWmsParameter pStyle( QgsWmsParameter::STYLE );
414  save( pStyle );
415 
416  const QgsWmsParameter pStyles( QgsWmsParameter::STYLES );
417  save( pStyles );
418 
419  const QgsWmsParameter pOpacities( QgsWmsParameter::OPACITIES );
420  save( pOpacities );
421 
422  const QgsWmsParameter pFilter( QgsWmsParameter::FILTER );
423  save( pFilter );
424 
425  const QgsWmsParameter pFilterGeom( QgsWmsParameter::FILTER_GEOM );
426  save( pFilterGeom );
427 
429  QVariant::Double,
430  QVariant( 0.0 ) );
431  save( pPolygTol );
432 
434  QVariant::Double,
435  QVariant( 0.0 ) );
436  save( pLineTol );
437 
439  QVariant::Double,
440  QVariant( 0.0 ) );
441  save( pPointTol );
442 
443  const QgsWmsParameter pSelection( QgsWmsParameter::SELECTION );
444  save( pSelection );
445 
446  const QgsWmsParameter pWmsPrecision( QgsWmsParameter::WMS_PRECISION,
447  QVariant::Int,
448  QVariant( -1 ) );
449  save( pWmsPrecision );
450 
451  const QgsWmsParameter pTransparent( QgsWmsParameter::TRANSPARENT,
452  QVariant::Bool,
453  QVariant( false ) );
454  save( pTransparent );
455 
457  QVariant::String,
458  QVariant( "white" ) );
459  save( pBgColor );
460 
462  QVariant::Int,
463  QVariant( -1 ) );
464  save( pDpi );
465 
466  const QgsWmsParameter pTemplate( QgsWmsParameter::TEMPLATE );
467  save( pTemplate );
468 
469  const QgsWmsParameter pExtent( QgsWmsParameter::EXTENT );
470  save( pExtent );
471 
473  QVariant::Double,
474  QVariant( 0.0 ) );
475  save( pRotation );
476 
478  QVariant::Double,
479  QVariant( 0.0 ) );
480  save( pGridX );
481 
483  QVariant::Double,
484  QVariant( 0.0 ) );
485  save( pGridY );
486 
487  const QgsWmsParameter pWithGeometry( QgsWmsParameter::WITH_GEOMETRY,
488  QVariant::Bool,
489  QVariant( false ) );
490  save( pWithGeometry );
491 
493  QVariant::Bool,
494  QVariant( false ) );
495  save( pWithMapTip );
496 
497  const QgsWmsParameter pWmtver( QgsWmsParameter::WMTVER );
498  save( pWmtver );
499 
501  QVariant::StringList );
502  save( pAtlasPk );
503  }
504 
506  : QgsWmsParameters()
507  {
508  load( parameters.urlQuery() );
509 
510  const QString sld = mWmsParameters[ QgsWmsParameter::SLD ].toString();
511  if ( !sld.isEmpty() )
512  {
513  const QString sldBody = mWmsParameters[ QgsWmsParameter::SLD ].loadUrl();
514  if ( !sldBody.isEmpty() )
515  {
516  loadParameter( QgsWmsParameter::name( QgsWmsParameter::SLD_BODY ), sldBody );
517  }
518  }
519  }
520 
521  bool QgsWmsParameters::loadParameter( const QString &key, const QString &value )
522  {
523  bool loaded = false;
524 
525  const QRegExp composerParamRegExp( QStringLiteral( "^MAP\\d+:" ), Qt::CaseInsensitive );
526  if ( key.contains( composerParamRegExp ) )
527  {
528  const int mapId = key.midRef( 3, key.indexOf( ':' ) - 3 ).toInt();
529  const QString theKey = key.mid( key.indexOf( ':' ) + 1 );
530  const QgsWmsParameter::Name name = QgsWmsParameter::name( theKey );
531 
532  if ( name >= 0 )
533  {
534  QgsWmsParameter param = mWmsParameters[name];
535  param.mValue = value;
536  param.mId = mapId;
537 
538  if ( ! param.isValid() )
539  {
540  param.raiseError();
541  }
542 
543  save( param, true ); // multi MAP parameters for composer
544  loaded = true;
545  }
546  }
547  else
548  {
549  const QgsWmsParameter::Name name = QgsWmsParameter::name( key );
550  if ( name >= 0 )
551  {
552  mWmsParameters[name].mValue = value;
553  if ( ! mWmsParameters[name].isValid() )
554  {
555  mWmsParameters[name].raiseError();
556  }
557 
558  loaded = true;
559  }
560  else //maybe an external wms parameter?
561  {
562  int separator = key.indexOf( QStringLiteral( ":" ) );
563  if ( separator >= 1 )
564  {
565  QString id = key.left( separator );
566  QString param = key.right( key.length() - separator - 1 );
567  mExternalWMSParameters[id].insert( param, value );
568 
569  loaded = true;
570  }
571  }
572  }
573 
574  return loaded;
575  }
576 
578  {
579  log( QStringLiteral( "WMS Request parameters:" ) );
580  for ( auto parameter : mWmsParameters.toStdMap() )
581  {
582  const QString value = parameter.second.toString();
583 
584  if ( ! value.isEmpty() )
585  {
586  QString name = QgsWmsParameter::name( parameter.first );
587 
588  if ( parameter.second.mId >= 0 )
589  {
590  name = QStringLiteral( "%1:%2" ).arg( QString::number( parameter.second.mId ), name );
591  }
592 
593  log( QStringLiteral( " - %1 : %2" ).arg( name, value ) );
594  }
595  }
596 
597  if ( !version().isEmpty() )
598  log( QStringLiteral( " - VERSION : %1" ).arg( version() ) );
599  }
600 
601  void QgsWmsParameters::save( const QgsWmsParameter &parameter, bool multi )
602  {
603  if ( multi )
604  {
605  mWmsParameters.insertMulti( parameter.mName, parameter );
606  }
607  else
608  {
609  mWmsParameters[ parameter.mName ] = parameter;
610  }
611  }
612 
614  {
615  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_GEOM ].toStringList( ';' );
616  }
617 
618  QList<QgsGeometry> QgsWmsParameters::highlightGeomAsGeom() const
619  {
620  return mWmsParameters[QgsWmsParameter::HIGHLIGHT_GEOM].toGeomList( ';' );
621  }
622 
624  {
625  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_SYMBOL ].toStringList( ';' );
626  }
627 
628  QString QgsWmsParameters::crs() const
629  {
630  QString rs;
631  const QString srs = mWmsParameters[ QgsWmsParameter::SRS ].toString();
632  const QString crs = mWmsParameters[ QgsWmsParameter::CRS ].toString();
633 
634  // both SRS/CRS are supported but there's a priority according to the
635  // specified version when both are defined in the request
636  if ( !srs.isEmpty() && crs.isEmpty() )
637  rs = srs;
638  else if ( srs.isEmpty() && !crs.isEmpty() )
639  rs = crs;
640  else if ( !srs.isEmpty() && !crs.isEmpty() )
641  {
642  if ( versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
643  rs = crs;
644  else
645  rs = srs;
646  }
647 
648  return rs;
649  }
650 
651  QString QgsWmsParameters::bbox() const
652  {
653  return mWmsParameters[ QgsWmsParameter::BBOX ].toString();
654  }
655 
657  {
658  return mWmsParameters[ QgsWmsParameter::BBOX ].toRectangle();
659  }
660 
661  QString QgsWmsParameters::height() const
662  {
663  return mWmsParameters[ QgsWmsParameter::HEIGHT ].toString();
664  }
665 
666  QString QgsWmsParameters::width() const
667  {
668  return mWmsParameters[ QgsWmsParameter::WIDTH ].toString();
669  }
670 
672  {
673  return mWmsParameters[ QgsWmsParameter::HEIGHT ].toInt();
674  }
675 
677  {
678  return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
679  }
680 
681  QString QgsWmsParameters::dpi() const
682  {
683  return mWmsParameters[ QgsWmsParameter::DPI ].toString();
684  }
685 
687  {
688  return mWmsParameters[ QgsWmsParameter::DPI ].toDouble();
689  }
690 
692  {
693  const QString vStr = version();
694 
696 
697  if ( vStr.isEmpty() )
698  {
699  version = QgsProjectVersion( 1, 3, 0 ); // default value
700  }
701  else if ( mVersions.contains( QgsProjectVersion( vStr ) ) )
702  {
703  version = QgsProjectVersion( vStr );
704  }
705 
706  return version;
707  }
708 
709  bool QgsWmsParameters::versionIsValid( const QString version ) const
710  {
711  return mVersions.contains( QgsProjectVersion( version ) );
712  }
713 
715  {
716  return mWmsParameters[ QgsWmsParameter::FORMAT ].toString();
717  }
718 
720  {
721  QString fStr = formatAsString();
722 
723  if ( fStr.isEmpty() )
724  return Format::NONE;
725 
726  Format f = Format::PNG;
727  if ( fStr.compare( QLatin1String( "jpg" ), Qt::CaseInsensitive ) == 0
728  || fStr.compare( QLatin1String( "jpeg" ), Qt::CaseInsensitive ) == 0
729  || fStr.compare( QLatin1String( "image/jpeg" ), Qt::CaseInsensitive ) == 0 )
730  f = Format::JPG;
731 
732  return f;
733  }
734 
736  {
737  return mWmsParameters[ QgsWmsParameter::INFO_FORMAT ].toString();
738  }
739 
741  {
742  return infoFormat() == Format::PNG || infoFormat() == Format::JPG;
743  }
744 
746  {
747  QString fStr = infoFormatAsString();
748 
749  Format f = Format::TEXT;
750  if ( fStr.isEmpty() )
751  return f;
752 
753  if ( fStr.startsWith( QLatin1String( "text/xml" ), Qt::CaseInsensitive ) )
754  f = Format::XML;
755  else if ( fStr.startsWith( QLatin1String( "text/html" ), Qt::CaseInsensitive ) )
756  f = Format::HTML;
757  else if ( fStr.startsWith( QLatin1String( "text/plain" ), Qt::CaseInsensitive ) )
758  f = Format::TEXT;
759  else if ( fStr.startsWith( QLatin1String( "application/vnd.ogc.gml" ), Qt::CaseInsensitive ) )
760  f = Format::GML;
761  else if ( fStr.startsWith( QLatin1String( "application/json" ), Qt::CaseInsensitive )
762  || fStr.startsWith( QLatin1String( "application/geo+json" ), Qt::CaseInsensitive ) )
763  f = Format::JSON;
764  else
765  f = Format::NONE;
766 
767  return f;
768  }
769 
771  {
772  if ( infoFormat() != Format::GML )
773  return -1;
774 
775  QString fStr = infoFormatAsString();
776  if ( fStr.startsWith( QLatin1String( "application/vnd.ogc.gml/3" ), Qt::CaseInsensitive ) )
777  return 3;
778  else
779  return 2;
780  }
781 
782  QString QgsWmsParameters::i() const
783  {
784  return mWmsParameters[ QgsWmsParameter::I ].toString();
785  }
786 
787  QString QgsWmsParameters::j() const
788  {
789  return mWmsParameters[ QgsWmsParameter::J ].toString();
790  }
791 
793  {
794  return mWmsParameters[ QgsWmsParameter::I ].toInt();
795  }
796 
798  {
799  return mWmsParameters[ QgsWmsParameter::J ].toInt();
800  }
801 
802  QString QgsWmsParameters::x() const
803  {
804  return mWmsParameters[ QgsWmsParameter::X ].toString();
805  }
806 
807  QString QgsWmsParameters::y() const
808  {
809  return mWmsParameters[ QgsWmsParameter::Y ].toString();
810  }
811 
813  {
814  return mWmsParameters[ QgsWmsParameter::X ].toInt();
815  }
816 
818  {
819  return mWmsParameters[ QgsWmsParameter::Y ].toInt();
820  }
821 
822  QString QgsWmsParameters::rule() const
823  {
824  return mWmsParameters[ QgsWmsParameter::RULE ].toString();
825  }
826 
828  {
829  return mWmsParameters[ QgsWmsParameter::RULELABEL ].toString();
830  }
831 
833  {
834  return mWmsParameters[ QgsWmsParameter::RULELABEL ].toBool();
835  }
836 
838  {
839  return mWmsParameters[ QgsWmsParameter::TRANSPARENT ].toString();
840  }
841 
843  {
844  return mWmsParameters[ QgsWmsParameter::TRANSPARENT ].toBool();
845  }
846 
847  QString QgsWmsParameters::scale() const
848  {
849  return mWmsParameters[ QgsWmsParameter::SCALE ].toString();
850  }
851 
853  {
854  return mWmsParameters[ QgsWmsParameter::SCALE ].toDouble();
855  }
856 
858  {
859  return mWmsParameters[ QgsWmsParameter::IMAGE_QUALITY ].toString();
860  }
861 
863  {
864  return mWmsParameters[ QgsWmsParameter::IMAGE_QUALITY ].toInt();
865  }
866 
868  {
869  return mWmsParameters[ QgsWmsParameter::SHOWFEATURECOUNT ].toString();
870  }
871 
873  {
874  return mWmsParameters[ QgsWmsParameter::SHOWFEATURECOUNT ].toBool();
875  }
876 
878  {
879  return mWmsParameters[ QgsWmsParameter::FEATURE_COUNT ].toString();
880  }
881 
883  {
884  return mWmsParameters[ QgsWmsParameter::FEATURE_COUNT ].toInt();
885  }
886 
888  {
889  return mWmsParameters[ QgsWmsParameter::BOXSPACE ].toString();
890  }
891 
893  {
894  return mWmsParameters[ QgsWmsParameter::BOXSPACE ].toDouble();
895  }
896 
898  {
899  return mWmsParameters[ QgsWmsParameter::LAYERSPACE ].toString();
900  }
901 
903  {
904  return mWmsParameters[ QgsWmsParameter::LAYERSPACE ].toDouble();
905  }
906 
908  {
909  return mWmsParameters[ QgsWmsParameter::LAYERTITLESPACE ].toString();
910  }
911 
913  {
914  return mWmsParameters[ QgsWmsParameter::LAYERTITLESPACE ].toDouble();
915  }
916 
918  {
919  return mWmsParameters[ QgsWmsParameter::SYMBOLSPACE ].toString();
920  }
921 
923  {
924  return mWmsParameters[ QgsWmsParameter::SYMBOLSPACE ].toDouble();
925  }
926 
928  {
929  return mWmsParameters[ QgsWmsParameter::SYMBOLHEIGHT ].toString();
930  }
931 
933  {
934  return mWmsParameters[ QgsWmsParameter::SYMBOLHEIGHT ].toDouble();
935  }
936 
938  {
939  return mWmsParameters[ QgsWmsParameter::SYMBOLWIDTH ].toString();
940  }
941 
943  {
944  return mWmsParameters[ QgsWmsParameter::SYMBOLWIDTH ].toDouble();
945  }
946 
948  {
949  return mWmsParameters[ QgsWmsParameter::ICONLABELSPACE ].toString();
950  }
951 
953  {
954  return mWmsParameters[ QgsWmsParameter::ICONLABELSPACE ].toDouble();
955  }
956 
958  {
959  return mWmsParameters[ QgsWmsParameter::LAYERFONTFAMILY ].toString();
960  }
961 
963  {
964  return mWmsParameters[ QgsWmsParameter::ITEMFONTFAMILY ].toString();
965  }
966 
968  {
969  return mWmsParameters[ QgsWmsParameter::LAYERFONTBOLD ].toString();
970  }
971 
973  {
974  return mWmsParameters[ QgsWmsParameter::LAYERFONTBOLD ].toBool();
975  }
976 
978  {
979  return mWmsParameters[ QgsWmsParameter::ITEMFONTBOLD ].toString();
980  }
981 
983  {
984  return mWmsParameters[ QgsWmsParameter::FI_POLYGON_TOLERANCE ].toString();
985  }
986 
988  {
989  return mWmsParameters[ QgsWmsParameter::FI_LINE_TOLERANCE ].toString();
990  }
991 
993  {
994  return mWmsParameters[ QgsWmsParameter::FI_POINT_TOLERANCE ].toString();
995  }
996 
998  {
999  return mWmsParameters[ QgsWmsParameter::FI_POLYGON_TOLERANCE ].toInt();
1000  }
1001 
1003  {
1004  return mWmsParameters[ QgsWmsParameter::FI_LINE_TOLERANCE ].toInt();
1005  }
1006 
1008  {
1009  return mWmsParameters[ QgsWmsParameter::FI_POINT_TOLERANCE ].toInt();
1010  }
1011 
1013  {
1014  return mWmsParameters[ QgsWmsParameter::ITEMFONTBOLD ].toBool();
1015  }
1016 
1018  {
1019  return mWmsParameters[ QgsWmsParameter::LAYERFONTITALIC ].toString();
1020  }
1021 
1023  {
1024  return mWmsParameters[ QgsWmsParameter::LAYERFONTITALIC ].toBool();
1025  }
1026 
1028  {
1029  return mWmsParameters[ QgsWmsParameter::ITEMFONTITALIC ].toString();
1030  }
1031 
1033  {
1034  return mWmsParameters[ QgsWmsParameter::ITEMFONTITALIC ].toBool();
1035  }
1036 
1038  {
1039  return mWmsParameters[ QgsWmsParameter::LAYERFONTSIZE ].toString();
1040  }
1041 
1043  {
1044  return mWmsParameters[ QgsWmsParameter::LAYERFONTSIZE ].toDouble();
1045  }
1046 
1048  {
1049  return mWmsParameters[ QgsWmsParameter::LAYERFONTCOLOR ].toString();
1050  }
1051 
1053  {
1054  return mWmsParameters[ QgsWmsParameter::LAYERFONTCOLOR ].toColor();
1055  }
1056 
1058  {
1059  return mWmsParameters[ QgsWmsParameter::ITEMFONTSIZE ].toString();
1060  }
1061 
1063  {
1064  return mWmsParameters[ QgsWmsParameter::ITEMFONTSIZE ].toDouble();
1065  }
1066 
1068  {
1069  QFont font;
1070  font.fromString( "" );
1071  font.setBold( layerFontBoldAsBool() );
1072  font.setItalic( layerFontItalicAsBool() );
1073 
1074  if ( ! layerFontSize().isEmpty() )
1075  font.setPointSizeF( layerFontSizeAsDouble() );
1076 
1077  if ( !layerFontFamily().isEmpty() )
1078  font.setFamily( layerFontFamily() );
1079 
1080  return font;
1081  }
1082 
1084  {
1085  QFont font;
1086  font.fromString( "" );
1087 
1088  font.setBold( itemFontBoldAsBool() );
1089  font.setItalic( itemFontItalicAsBool() );
1090 
1091  if ( ! itemFontSize().isEmpty() )
1092  font.setPointSizeF( itemFontSizeAsDouble() );
1093 
1094  if ( !itemFontFamily().isEmpty() )
1095  font.setFamily( itemFontFamily() );
1096 
1097  return font;
1098  }
1099 
1101  {
1102  return mWmsParameters[ QgsWmsParameter::LAYERTITLE ].toString();
1103  }
1104 
1106  {
1107  return mWmsParameters[ QgsWmsParameter::LAYERTITLE ].toBool();
1108  }
1109 
1111  {
1112  QgsLegendSettings settings;
1113  settings.setTitle( QString() );
1114  settings.setBoxSpace( boxSpaceAsDouble() );
1115  settings.setSymbolSize( QSizeF( symbolWidthAsDouble(), symbolHeightAsDouble() ) );
1116 
1117  settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Top, layerSpaceAsDouble() );
1118  settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Bottom, layerTitleSpaceAsDouble() );
1119  settings.rstyle( QgsLegendStyle::Style::Subgroup ).setFont( layerFont() );
1120 
1121  settings.rstyle( QgsLegendStyle::Style::SymbolLabel ).setFont( itemFont() );
1122  settings.rstyle( QgsLegendStyle::Style::Symbol ).setMargin( QgsLegendStyle::Side::Top, symbolSpaceAsDouble() );
1123  settings.rstyle( QgsLegendStyle::Style::SymbolLabel ).setMargin( QgsLegendStyle::Side::Left, iconLabelSpaceAsDouble() );
1124 
1125  return settings;
1126  }
1127 
1128  QString QgsWmsParameters::layoutParameter( const QString &id, bool &ok ) const
1129  {
1130  QString label;
1131  ok = false;
1132 
1133  if ( mUnmanagedParameters.contains( id.toUpper() ) )
1134  {
1135  label = mUnmanagedParameters[id.toUpper()];
1136  ok = true;
1137  }
1138 
1139  return label;
1140  }
1141 
1142  QStringList QgsWmsParameters::atlasPk() const
1143  {
1144  return mWmsParameters[ QgsWmsParameter::ATLAS_PK ].toStringList();
1145  }
1146 
1148  {
1149  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELSTRING ].toStringList( ';' );
1150  }
1151 
1153  {
1154  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELSIZE ].toStringList( ';' );
1155  }
1156 
1158  {
1159  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELSIZE ].toIntList( ';' );
1160  }
1161 
1163  {
1164  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELCOLOR ].toStringList( ';' );
1165  }
1166 
1168  {
1169  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELCOLOR ].toColorList( ';' );
1170  }
1171 
1173  {
1174  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELWEIGHT ].toStringList( ';' );
1175  }
1176 
1178  {
1179  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELWEIGHT ].toIntList( ';' );
1180  }
1181 
1183  {
1184  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELFONT ].toStringList( ';' );
1185  }
1186 
1188  {
1189  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR ].toStringList( ';' );
1190  }
1191 
1193  {
1194  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR ].toColorList( ';' );
1195  }
1196 
1198  {
1199  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE ].toStringList( ';' );
1200  }
1201 
1203  {
1204  return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE ].toDoubleList( ';' );
1205  }
1206 
1208  {
1209  return mWmsParameters[ QgsWmsParameter::WMS_PRECISION ].toString();
1210  }
1211 
1213  {
1214  return mWmsParameters[ QgsWmsParameter::WMS_PRECISION ].toInt();
1215  }
1216 
1218  {
1219  return mWmsParameters[ QgsWmsParameter::SLD_BODY ].toString();
1220  }
1221 
1222  QStringList QgsWmsParameters::filters() const
1223  {
1224  const QString filter = mWmsParameters[ QgsWmsParameter::FILTER ].toString();
1225  QStringList results;
1226  int pos = 0;
1227  while ( pos < filter.size() )
1228  {
1229  if ( pos + 1 < filter.size() && filter[pos] == '(' && filter[pos + 1] == '<' )
1230  {
1231  // OGC filter on multiple layers
1232  int posEnd = filter.indexOf( "Filter>)", pos );
1233  if ( posEnd < 0 )
1234  {
1235  posEnd = filter.size();
1236  }
1237  results.append( filter.mid( pos + 1, posEnd - pos + 6 ) );
1238  pos = posEnd + 8;
1239  }
1240  else if ( pos + 1 < filter.size() && filter[pos] == '(' && filter[pos + 1] == ')' )
1241  {
1242  // empty OGC filter
1243  results.append( "" );
1244  pos += 2;
1245  }
1246  else if ( filter[pos] == '<' )
1247  {
1248  // Single OGC filter
1249  results.append( filter.mid( pos ) );
1250  break;
1251  }
1252  else
1253  {
1254  // QGIS specific filter
1255  int posEnd = filter.indexOf( ';', pos + 1 );
1256  if ( posEnd < 0 )
1257  {
1258  posEnd = filter.size();
1259  }
1260  results.append( filter.mid( pos, posEnd - pos ) );
1261  pos = posEnd + 1;
1262  }
1263  }
1264  return results;
1265  }
1266 
1268  {
1269  return mWmsParameters[ QgsWmsParameter::FILTER_GEOM ].toString();
1270  }
1271 
1272  QStringList QgsWmsParameters::selections() const
1273  {
1274  return mWmsParameters[ QgsWmsParameter::SELECTION ].toStringList( ';' );
1275  }
1276 
1277  QStringList QgsWmsParameters::opacities() const
1278  {
1279  return mWmsParameters[ QgsWmsParameter::OPACITIES ].toStringList();
1280  }
1281 
1283  {
1284  return mWmsParameters[ QgsWmsParameter::OPACITIES ].toIntList();
1285  }
1286 
1288  {
1289  QStringList layer = mWmsParameters[ QgsWmsParameter::LAYER ].toStringList();
1290  const QStringList layers = mWmsParameters[ QgsWmsParameter::LAYERS ].toStringList();
1291  return layer << layers;
1292  }
1293 
1295  {
1296  return mWmsParameters[ QgsWmsParameter::QUERY_LAYERS ].toStringList();
1297  }
1298 
1299  QStringList QgsWmsParameters::allStyles() const
1300  {
1301  QStringList style = mWmsParameters[ QgsWmsParameter::STYLE ].toStringList();
1302  const QStringList styles = mWmsParameters[ QgsWmsParameter::STYLES ].toStringList();
1303  return style << styles;
1304  }
1305 
1306  QMultiMap<QString, QgsWmsParametersFilter> QgsWmsParameters::layerFilters( const QStringList &layers ) const
1307  {
1308  const QString nsWfs2 = QStringLiteral( "http://www.opengis.net/fes/2.0" );
1309  const QString prefixWfs2 = QStringLiteral( "<fes:" );
1310 
1311  const QStringList rawFilters = filters();
1312  QMultiMap<QString, QgsWmsParametersFilter> filters;
1313  for ( int i = 0; i < rawFilters.size(); i++ )
1314  {
1315  const QString f = rawFilters[i];
1316  if ( f.startsWith( QLatin1String( "<" ) ) \
1317  && f.endsWith( QLatin1String( "Filter>" ) ) \
1318  && i < layers.size() )
1319  {
1320  QgsWmsParametersFilter filter;
1321  filter.mFilter = f;
1324 
1325  if ( filter.mFilter.contains( nsWfs2 ) \
1326  || filter.mFilter.contains( prefixWfs2 ) )
1327  {
1329  }
1330 
1331  filters.insert( layers[i], filter );
1332  }
1333  else if ( !f.isEmpty() )
1334  {
1335  // filter format: "LayerName:filterString;LayerName2:filterString2;..."
1336  // several filters can be defined for one layer
1337  const QStringList splits = f.split( ':' );
1338  if ( splits.size() == 2 )
1339  {
1340  QgsWmsParametersFilter filter;
1341  filter.mFilter = splits[1];
1343  filters.insert( splits[0], filter );
1344  }
1345  else
1346  {
1347  QString filterStr = mWmsParameters[ QgsWmsParameter::FILTER ].toString();
1348  raiseError( QStringLiteral( "FILTER ('" ) + filterStr + QStringLiteral( "') is not properly formatted" ) );
1349  }
1350  }
1351  }
1352  return filters;
1353  }
1354 
1355  QList<QgsWmsParametersLayer> QgsWmsParameters::layersParameters() const
1356  {
1357  const QStringList layers = allLayersNickname();
1358  const QStringList styles = allStyles();
1359  const QStringList selection = selections();
1360  const QList<int> opacities = opacitiesAsInt();
1361  const QMultiMap<QString, QgsWmsParametersFilter> filters = layerFilters( layers );
1362 
1363  // selection format: "LayerName:id0,id1;LayerName2:id0,id1;..."
1364  // several filters can be defined for one layer
1365  QMultiMap<QString, QString> layerSelections;
1366  for ( const QString &s : selection )
1367  {
1368  const QStringList splits = s.split( ':' );
1369  if ( splits.size() == 2 )
1370  {
1371  layerSelections.insert( splits[0], splits[1] );
1372  }
1373  else
1374  {
1375  QString selStr = mWmsParameters[ QgsWmsParameter::SELECTION ].toString();
1376  raiseError( QStringLiteral( "SELECTION ('" ) + selStr + QStringLiteral( "') is not properly formatted" ) );
1377  }
1378  }
1379 
1380  QList<QgsWmsParametersLayer> parameters;
1381  for ( int i = 0; i < layers.size(); i++ )
1382  {
1383  QString layer = layers[i];
1384  QgsWmsParametersLayer param;
1385  param.mNickname = layer;
1386 
1387  if ( i < styles.count() )
1388  param.mStyle = styles[i];
1389 
1390  if ( i < opacities.count() )
1391  param.mOpacity = opacities[i];
1392 
1393  if ( filters.contains( layer ) )
1394  {
1395  auto it = filters.find( layer );
1396  while ( it != filters.end() && it.key() == layer )
1397  {
1398  param.mFilter.append( it.value() );
1399  ++it;
1400  }
1401  }
1402 
1403  if ( layerSelections.contains( layer ) )
1404  {
1405  QMultiMap<QString, QString>::const_iterator it;
1406  it = layerSelections.find( layer );
1407  while ( it != layerSelections.end() && it.key() == layer )
1408  {
1409  param.mSelection << it.value().split( ',' );
1410  ++it;
1411  }
1412  }
1413 
1414  parameters.append( param );
1415  }
1416 
1417  return parameters;
1418  }
1419 
1420  QList<QgsWmsParametersHighlightLayer> QgsWmsParameters::highlightLayersParameters() const
1421  {
1422  QList<QgsWmsParametersHighlightLayer> params;
1423  QList<QgsGeometry> geoms = highlightGeomAsGeom();
1424  QStringList slds = highlightSymbol();
1425  QStringList labels = highlightLabelString();
1426  QList<QColor> colors = highlightLabelColorAsColor();
1427  QList<int> sizes = highlightLabelSizeAsInt();
1428  QList<int> weights = highlightLabelWeightAsInt();
1429  QStringList fonts = highlightLabelFont();
1430  QList<QColor> bufferColors = highlightLabelBufferColorAsColor();
1431  QList<double> bufferSizes = highlightLabelBufferSizeAsFloat();
1432 
1433  int nLayers = std::min( geoms.size(), slds.size() );
1434  for ( int i = 0; i < nLayers; i++ )
1435  {
1437  param.mName = QStringLiteral( "highlight_" ) + QString::number( i );
1438  param.mGeom = geoms[i];
1439  param.mSld = slds[i];
1440 
1441  if ( i < labels.count() )
1442  param.mLabel = labels[i];
1443 
1444  if ( i < colors.count() )
1445  param.mColor = colors[i];
1446 
1447  if ( i < sizes.count() )
1448  param.mSize = sizes[i];
1449 
1450  if ( i < weights.count() )
1451  param.mWeight = weights[i];
1452 
1453  if ( i < fonts.count() )
1454  param.mFont = fonts[ i ];
1455 
1456  if ( i < bufferColors.count() )
1457  param.mBufferColor = bufferColors[i];
1458 
1459  if ( i < bufferSizes.count() )
1460  param.mBufferSize = bufferSizes[i];
1461 
1462  params.append( param );
1463  }
1464 
1465  return params;
1466  }
1467 
1469  {
1470  return mWmsParameters[ QgsWmsParameter::BGCOLOR ].toString();
1471  }
1472 
1474  {
1475  return mWmsParameters[ QgsWmsParameter::BGCOLOR ].toColor();
1476  }
1477 
1479  {
1480  return mWmsParameters[ QgsWmsParameter::TEMPLATE ].toString();
1481  }
1482 
1484  {
1485  QgsWmsParameter wmsParam;
1487  param.mId = mapId;
1488 
1489  //map extent is mandatory
1490  QString extentStr;
1491  wmsParam = idParameter( QgsWmsParameter::EXTENT, mapId );
1492  if ( wmsParam.isValid() )
1493  {
1494  extentStr = wmsParam.toString();
1495  }
1496 
1497  if ( extentStr.isEmpty() )
1498  {
1499  return param;
1500  }
1501 
1502  QString pMapId = QStringLiteral( "MAP" ) + QString::number( mapId );
1503 
1504  wmsParam = idParameter( QgsWmsParameter::EXTENT, mapId );
1505  QgsRectangle extent;
1506  if ( wmsParam.isValid() )
1507  {
1508  extent = wmsParam.toRectangle();
1509  }
1510 
1511  if ( extent.isEmpty() )
1512  return param;
1513 
1514  param.mHasExtent = !extent.isEmpty();
1515  param.mExtent = extent;
1516 
1517  // scale
1518  wmsParam = idParameter( QgsWmsParameter::SCALE, mapId );
1519  if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1520  {
1521  param.mScale = wmsParam.toDouble();
1522  }
1523 
1524  // rotation
1525  wmsParam = idParameter( QgsWmsParameter::ROTATION, mapId );
1526  if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1527  {
1528  param.mRotation = wmsParam.toDouble();
1529  }
1530 
1531  //grid space x / y
1532  double gridx( -1 ), gridy( -1 );
1533 
1534  wmsParam = idParameter( QgsWmsParameter::GRID_INTERVAL_X, mapId );
1535  if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1536  {
1537  gridx = wmsParam.toDouble();
1538  }
1539 
1540  wmsParam = idParameter( QgsWmsParameter::GRID_INTERVAL_Y, mapId );
1541  if ( wmsParam.isValid() && !wmsParam.toString().isEmpty() )
1542  {
1543  gridy = wmsParam.toDouble();
1544  }
1545 
1546  if ( gridx != -1 && gridy != -1 )
1547  {
1548  param.mGridX = gridx;
1549  param.mGridY = gridy;
1550  }
1551 
1552  //layers
1553  QStringList layers;
1554  wmsParam = idParameter( QgsWmsParameter::LAYERS, mapId );
1555  if ( wmsParam.isValid() )
1556  {
1557  layers = wmsParam.toStringList();
1558  }
1559 
1560  QStringList styles;
1561  wmsParam = idParameter( QgsWmsParameter::STYLES, mapId );
1562  if ( wmsParam.isValid() )
1563  {
1564  styles = wmsParam.toStringList();
1565  }
1566 
1567  QList<QgsWmsParametersLayer> lParams;
1568  for ( int i = 0; i < layers.size(); i++ )
1569  {
1570  QString layer = layers[i];
1571  QgsWmsParametersLayer lParam;
1572  lParam.mNickname = layer;
1573 
1574  if ( i < styles.count() )
1575  lParam.mStyle = styles[i];
1576 
1577  lParams.append( lParam );
1578  }
1579  param.mLayers = lParams;
1580 
1581  //highlight layers
1582  QList<QgsWmsParametersHighlightLayer> hParams;
1583 
1584  QList<QgsGeometry> geoms;
1585  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_GEOM, mapId );
1586  if ( wmsParam.isValid() )
1587  {
1588  geoms = wmsParam.toGeomList( ';' );
1589  }
1590 
1591  QStringList slds;
1592  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_SYMBOL, mapId );
1593  if ( wmsParam.isValid() )
1594  {
1595  slds = wmsParam.toStringList( ';' );
1596  }
1597 
1598  QStringList labels;
1599  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELSTRING, mapId );
1600  if ( wmsParam.isValid() )
1601  {
1602  labels = wmsParam.toStringList( ';' );
1603  }
1604 
1605  QStringList fonts;
1606  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELFONT, mapId );
1607  if ( wmsParam.isValid() )
1608  {
1609  fonts = wmsParam.toStringList( ';' );
1610  }
1611 
1612  QList<QColor> colors;
1613  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELCOLOR, mapId );
1614  if ( wmsParam.isValid() )
1615  {
1616  colors = wmsParam.toColorList( ';' );
1617  }
1618 
1619  QList<int> sizes;
1620  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELSIZE, mapId );
1621  if ( wmsParam.isValid() )
1622  {
1623  sizes = wmsParam.toIntList( ';' );
1624  }
1625 
1626  QList<int> weights;
1627  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELWEIGHT, mapId );
1628  if ( wmsParam.isValid() )
1629  {
1630  weights = wmsParam.toIntList( ';' );
1631  }
1632 
1633  QList<QColor> bufferColors;
1634  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELBUFFERCOLOR, mapId );
1635  if ( wmsParam.isValid() )
1636  {
1637  bufferColors = wmsParam.toColorList( ';' );
1638  }
1639 
1640  QList<double> bufferSizes;
1641  wmsParam = idParameter( QgsWmsParameter::HIGHLIGHT_LABELBUFFERSIZE, mapId );
1642  if ( wmsParam.isValid() )
1643  {
1644  bufferSizes = wmsParam.toDoubleList( ';' );
1645  }
1646 
1647  int nHLayers = std::min( geoms.size(), slds.size() );
1648  for ( int i = 0; i < nHLayers; i++ )
1649  {
1651  hParam.mName = pMapId + QStringLiteral( "_highlight_" ) + QString::number( i );
1652  hParam.mGeom = geoms[i];
1653  hParam.mSld = slds[i];
1654 
1655  if ( i < labels.count() )
1656  hParam.mLabel = labels[i];
1657 
1658  if ( i < colors.count() )
1659  hParam.mColor = colors[i];
1660 
1661  if ( i < sizes.count() )
1662  hParam.mSize = sizes[i];
1663 
1664  if ( i < weights.count() )
1665  hParam.mWeight = weights[i];
1666 
1667  if ( i < fonts.count() )
1668  hParam.mFont = fonts[ i ];
1669 
1670  if ( i < bufferColors.count() )
1671  hParam.mBufferColor = bufferColors[i];
1672 
1673  if ( i < bufferSizes.count() )
1674  hParam.mBufferSize = bufferSizes[i];
1675 
1676  hParams.append( hParam );
1677  }
1678  param.mHighlightLayers = hParams;
1679 
1680  return param;
1681  }
1682 
1683  QString QgsWmsParameters::externalWMSUri( const QString &id ) const
1684  {
1685  if ( !mExternalWMSParameters.contains( id ) )
1686  {
1687  return QString();
1688  }
1689 
1690  QgsDataSourceUri wmsUri;
1691  const QMap<QString, QString> &paramMap = mExternalWMSParameters[ id ];
1692  QMap<QString, QString>::const_iterator paramIt = paramMap.constBegin();
1693  for ( ; paramIt != paramMap.constEnd(); ++paramIt )
1694  {
1695  wmsUri.setParam( paramIt.key().toLower(), paramIt.value() );
1696  }
1697  return wmsUri.encodedUri();
1698  }
1699 
1701  {
1702  return mWmsParameters[ QgsWmsParameter::WITH_GEOMETRY ].toBool();
1703  }
1704 
1706  {
1707  return mWmsParameters[ QgsWmsParameter::WITH_MAPTIP ].toBool();
1708  }
1709 
1711  {
1712  return mWmsParameters[ QgsWmsParameter::WMTVER ].toString();
1713  }
1714 
1715  void QgsWmsParameters::log( const QString &msg ) const
1716  {
1717  QgsMessageLog::logMessage( msg, QStringLiteral( "Server" ), Qgis::Info );
1718  }
1719 
1720  void QgsWmsParameters::raiseError( const QString &msg ) const
1721  {
1722  throw QgsBadRequestException( QStringLiteral( "Invalid WMS Parameter" ), msg );
1723  }
1724 
1725  QgsWmsParameter QgsWmsParameters::idParameter( const QgsWmsParameter::Name name, const int id ) const
1726  {
1727  QgsWmsParameter p;
1728 
1729  for ( const auto &param : mWmsParameters.values( name ) )
1730  {
1731  if ( param.mId == id )
1732  {
1733  p = param;
1734  }
1735  }
1736 
1737  return p;
1738  }
1739 }
bool versionIsValid(const QString version) const
Returns true if version is valid, false otherwise.
QList< QgsWmsParametersHighlightLayer > highlightLayersParameters() const
Returns parameters for each highlight layer.
QFont layerFont() const
Returns the layer font (built thanks to the LAYERFONTFAMILY, LAYERFONTSIZE, LAYERFONTBOLD, ...
QString layerFontSize() const
Returns LAYERFONTSIZE parameter or an empty string if not defined.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
void dump() const
Dumps parameters.
int imageQualityAsInt() const
Returns IMAGE_QUALITY parameter as an integer.
QStringList highlightLabelWeight() const
Returns HIGHLIGHT_LABELWEIGHT as a list of string.
void setBoxSpace(double s)
QgsRectangle toRectangle() const
Converts the parameter into a rectangle.
QList< double > highlightLabelBufferSizeAsFloat() const
Returns HIGHLIGHT_LABELBUFFERSIZE as a list of float.
QString typeName() const
Returns the type of the parameter as a string.
double symbolHeightAsDouble() const
Returns SYMBOLHEIGHT as a double or its default value if not defined.
QUrl toUrl() const
Converts the parameter into an url.
QString transparent() const
Returns TRANSPARENT parameter or an empty string if not defined.
QString i() const
Returns I parameter or an empty string if not defined.
QList< QColor > highlightLabelColorAsColor() const
Returns HIGHLIGHT_LABELCOLOR as a list of color.
QMap< QString, QString > mUnmanagedParameters
int featureCountAsInt() const
Returns FEATURE_COUNT as an integer.
QStringList filters() const
Returns the list of filters found in FILTER parameter.
QString itemFontSize() const
Returns ITEMFONTSIZE parameter or an empty string if not defined.
QgsRectangle bboxAsRectangle() const
Returns BBOX as a rectangle if defined and valid.
QString j() const
Returns J parameter or an empty string if not defined.
QStringList highlightLabelBufferSize() const
Returns HIGHLIGHT_LABELBUFFERSIZE.
QString backgroundColor() const
Returns BGCOLOR parameter or an empty string if not defined.
QgsWmsParameter::Name mName
QList< QgsWmsParametersLayer > mLayers
int toInt() const
Converts the parameter into an integer.
QString scale() const
Returns SCALE parameter or an empty string if none is defined.
void setSymbolSize(QSizeF s)
QList< QColor > toColorList(const char delimiter=',') const
Converts the parameter into a list of colors.
QString layerFontBold() const
Returns LAYERFONTBOLD parameter or an empty string if not defined.
QString value(const QString &key) const
Returns the value of a parameter.
static QString name(const QgsWmsParameter::Name)
Converts a parameter&#39;s name into its string representation.
QgsLegendSettings legendSettings() const
Returns legend settings.
QList< QgsGeometry > toGeomList(const char delimiter=',') const
Converts the parameter into a list of geometries.
QString sldBody() const
Returns SLD_body if defined or an empty string.
static void raiseError(const QString &msg)
Raises an exception in case of an invalid parameters.
int yAsInt() const
Returns Y parameter as an int or its default value if not defined.
double symbolSpaceAsDouble() const
Returns SYMBOLSPACE as a double or its default value if not defined.
double dpiAsDouble() const
Returns DPI parameter as an int or its default value if not defined.
double toDouble() const
Converts the parameter into a double.
QString loadUrl(bool &ok) const
Loads the data associated to the parameter converted into an url.
bool isValid() const override
Returns true if the parameter is valid, false otherwise.
Format
Output format for the response.
QList< int > highlightLabelWeightAsInt() const
Returns HIGHLIGHT_LABELWEIGHT as a list of int.
int widthAsInt() const
Returns WIDTH parameter as an int or its default value if not defined.
void load(const QUrlQuery &query)
Loads new parameters.
double layerTitleSpaceAsDouble() const
Returns LAYERTITLESPACE as a double.
QString layerTitle() const
Returns LAYERTITLE parameter or an empty string if not defined.
QString symbolSpace() const
Returns SYMBOLSPACE parameter or an empty string if not defined.
QString layerFontColor() const
Returns LAYERFONTCOLOR parameter or an empty string if not defined.
Exception thrown in case of malformed request.
Format infoFormat() const
Returns infoFormat.
double layerSpaceAsDouble() const
Returns LAYERSPACE as a double or its default value if not defined.
QString featureCount() const
Returns FEATURE_COUNT parameter or an empty string if none is defined.
bool transparentAsBool() const
Returns TRANSPARENT parameter as a bool or its default value if not defined.
QString layerFontFamily() const
Returns LAYERFONTFAMILY parameter or an empty string if not defined.
QString symbolWidth() const
Returns SYMBOLWIDTH parameter or an empty string if not defined.
QStringList selections() const
Returns the list of feature selection found in SELECTION parameter.
bool withMapTip() const
withMapTip
QString bbox() const
Returns BBOX if defined or an empty string.
double iconLabelSpaceAsDouble() const
Returns ICONLABELSPACE as a double or its default value if not defined.
bool ruleLabelAsBool() const
Returns RULELABEL as a bool.
void raiseError() const
Raises an error in case of an invalid conversion.
bool showFeatureCountAsBool() const
Returns SHOWFEATURECOUNT as a bool.
QStringList highlightSymbol() const
Returns HIGHLIGHT_SYMBOL as a list of string.
QList< int > highlightLabelSizeAsInt() const
Returns HIGHLIGHT_LABELSIZE as a list of int An exception is raised if an invalid size is found...
double itemFontSizeAsDouble() const
Returns ITEMFONTSIZE as a double.
double toDouble(bool &ok) const
Converts the parameter into a double.
QStringList allLayersNickname() const
Returns nickname of layers found in LAYER and LAYERS parameters.
int lineToleranceAsInt() const
Returns FI_LINE_TOLERANCE parameter as an integer.
QUrl toUrl(bool &ok) const
Converts the parameter into an url.
void setFont(const QFont &font)
The font for this style.
QStringList opacities() const
Returns the list of opacities found in OPACITIES parameter.
QString x() const
Returns X parameter or an empty string if not defined.
QString layoutParameter(const QString &id, bool &ok) const
Returns a layout parameter thanks to its id.
QList< double > toDoubleList(bool &ok, char delimiter=',') const
Converts the parameter into a list of doubles.
QString itemFontItalic() const
Returns ITEMFONTITALIC parameter or an empty string if not defined.
QStringList highlightLabelString() const
Returns HIGHLIGHT_LABELSTRING as a list of string.
QString crs() const
Returns CRS or an empty string if none is defined.
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:426
QList< int > toIntList(bool &ok, char delimiter=',') const
Converts the parameter into a list of integers.
QgsRectangle toRectangle(bool &ok) const
Converts the parameter into a rectangle.
QString filterGeom() const
Returns the filter geometry found in FILTER_GEOM parameter.
QString layerSpace() const
Returns LAYERSPACE parameter or an empty string if not defined.
A class to describe the version of a project.
QStringList highlightLabelSize() const
Returns HIGHLIGHT_LABELSIZE as a list of string.
Provides an interface to retrieve and manipulate WMS parameters received from the client...
int infoFormatVersion() const
Returns the infoFormat version for GML.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QStringList highlightLabelBufferColor() const
Returns HIGHLIGHT_LABELBUFFERCOLOR as a list of string.
QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
QUrlQuery urlQuery() const
Returns a url query with underlying parameters.
QString imageQuality() const
Returns IMAGE_QUALITY parameter or an empty string if not defined.
QList< QgsWmsParametersHighlightLayer > mHighlightLayers
QString loadUrl() const
Loads the data associated to the parameter converted into an url.
void setTitle(const QString &t)
QString composerTemplate() const
Returns TEMPLATE parameter or an empty string if not defined.
QgsProjectVersion versionAsNumber() const
Returns VERSION parameter if defined or its default value.
QgsWmsParameters()
Constructor for WMS parameters with default values only.
void setMargin(Side side, double margin)
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
QColor toColor(bool &ok) const
Converts the parameter into a color.
QStringList queryLayersNickname() const
Returns nickname of layers found in QUERY_LAYERS parameter.
QgsWmsParametersFilter::Type mType
int pointToleranceAsInt() const
Returns FI_POINT_TOLERANCE parameter as an integer.
Format format() const
Returns format.
QgsOgcUtils::FilterVersion mVersion
bool itemFontItalicAsBool() const
Returns ITEMFONTITALIC as a boolean or its default value if not defined.
int polygonToleranceAsInt() const
Returns FI_POLYGON_TOLERANCE parameter as an integer.
QList< double > toDoubleList(const char delimiter=',') const
Converts the parameter into a list of doubles.
bool layerTitleAsBool() const
Returns LAYERTITLE as a bool or its default value if not defined.
Median cut implementation.
bool withGeometry() const
Returns if the client wants the feature info response with geometry information.
double symbolWidthAsDouble() const
Returns SYMBOLWIDTH as a double or its default value if not defined.
int heightAsInt() const
Returns HEIGHT parameter as an int or its default value if not defined.
QString layerTitleSpace() const
Returns LAYERTITLESPACE 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.
double boxSpaceAsDouble() const
Returns BOXSPACE as a double or its default value if not defined.
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable style.
int toInt(bool &ok) const
Converts the parameter into an integer.
QStringList allStyles() const
Returns styles found in STYLE and STYLES parameters.
int jAsInt() const
Returns J parameter as an int or its default value if not defined.
double scaleAsDouble() const
Returns SCALE as a double.
QFont itemFont() const
Returns the item font (built thanks to the ITEMFONTFAMILY, ITEMFONTSIZE, ITEMFONTBOLD, ...
QColor layerFontColorAsColor() const
Returns LAYERFONTCOLOR as a color or its defined value if not defined.
QString pointTolerance() const
Returns FI_POINT_TOLERANCE parameter or an empty string if not defined.
QgsServerParameters provides an interface to retrieve and manipulate global parameters received from ...
QByteArray encodedUri() const
Returns complete encoded uri (generic mode)
QString boxSpace() const
Returns BOXSPACE parameter or an empty string if not defined.
QString width() const
Returns WIDTH parameter or an empty string if not defined.
virtual bool isValid() const
Returns true if the parameter is valid, false otherwise.
QString toString() const
Converts the parameter into a string.
bool itemFontBoldAsBool() const
Returns ITEMFONTBOLD as a boolean or its default value if not defined.
QgsWmsParameter(const QgsWmsParameter::Name name=QgsWmsParameter::UNKNOWN, const QVariant::Type type=QVariant::String, const QVariant defaultValue=QVariant(""))
Constructor for QgsWmsParameter.
QString polygonTolerance() const
Returns FI_POLYGON_TOLERANCE parameter or an empty string if not defined.
QString symbolHeight() const
Returns SYMBOLHEIGHT parameter or an empty string if not defined.
QStringList atlasPk() const
Returns the ATLAS_PK parameter.
QList< int > opacitiesAsInt() const
Returns the list of opacities found in OPACITIES parameter as integers.
QList< int > toIntList(const char delimiter=',') const
Converts the parameter into a list of integers.
QString formatAsString() const
Returns FORMAT parameter as a string.
bool layerFontBoldAsBool() const
Returns LAYERFONTBOLD as a boolean or its default value if not defined.
QString lineTolerance() const
Returns FI_LINE_TOLERANCE parameter or an empty string if not defined.
QString height() const
Returns HEIGHT parameter or an empty string if not defined.
QString rule() const
Returns RULE parameter or an empty string if none is defined.
QString y() const
Returns Y parameter or an empty string if not defined.
QColor backgroundColorAsColor() const
Returns BGCOLOR parameter as a QColor or its default value if not defined.
QList< QgsGeometry > toGeomList(bool &ok, char delimiter=',') const
Converts the parameter into a list of geometries.
QString layerFontItalic() const
Returns LAYERFONTITALIC parameter or an empty string if not defined.
QString wmtver() const
Returns WMTVER parameter or an empty string if not defined.
QString showFeatureCount() const
Returns SHOWFEATURECOUNT parameter or an empty string if none is defined.
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
QString dpi() const
Returns DPI parameter or an empty string if not defined.
QString infoFormatAsString() const
Returns INFO_FORMAT parameter as a string.
int iAsInt() const
Returns I parameter as an int or its default value if not defined.
bool layerFontItalicAsBool() const
Returns LAYERFONTITALIC as a boolean or its default value if not defined.
QList< QgsWmsParametersLayer > layersParameters() const
Returns parameters for each layer found in LAYER/LAYERS.
bool infoFormatIsImage() const
Checks if INFO_FORMAT parameter is one of the image formats (PNG, JPG).
QString itemFontBold() const
Returns ITEMFONTBOLD parameter or an empty string if not defined.
QgsWmsParametersComposerMap composerMapParameters(int mapId) const
Returns the requested parameters for a composer map parameter.
QString iconLabelSpace() const
Returns ICONLABELSPACE parameter or an empty string if not defined.
QList< QColor > toColorList(bool &ok, char delimiter=',') const
Converts the parameter into a list of colors.
QList< QgsWmsParametersFilter > mFilter
QStringList highlightLabelColor() const
Returns HIGHLIGHT_LABELCOLOR as a list of string.
QColor toColor() const
Converts the parameter into a color.
WMS parameter received from the client.
double layerFontSizeAsDouble() const
Returns LAYERFONTSIZE as a double.
QStringList highlightGeom() const
Returns HIGHLIGHT_GEOM as a list of string in WKT.
QList< QgsGeometry > highlightGeomAsGeom() const
Returns HIGHLIGHT_GEOM as a list of geometries.
QList< QColor > highlightLabelBufferColorAsColor() const
Returns HIGHLIGHT_LABELBUFFERCOLOR as a list of colors.
QString ruleLabel() const
Returns RULELABEL parameter or an empty string if none is defined.
QStringList toStringList(char delimiter=',') const
Converts the parameter into a list of strings.
QString externalWMSUri(const QString &id) const
Returns the external WMS uri.
QString itemFontFamily() const
Returns ITEMFONTFAMILY parameter or an empty string if not defined.
QString wmsPrecision() const
Returns WMS_PRECISION parameter or an empty string if not defined.
int xAsInt() const
Returns X parameter as an int or its default value if not defined.
QStringList highlightLabelFont() const
Returns HIGHLIGHT_LABELFONT.
Name
Available parameters for WMS requests.
Definition of a parameter with basic conversion methods.