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