@@ -23,6 +23,11 @@ namespace QgsWms
23
23
{
24
24
QgsWmsParameters::QgsWmsParameters ()
25
25
{
26
+ // Available version number
27
+ mVersions .append ( QgsProjectVersion ( 1 , 1 , 1 ) );
28
+ mVersions .append ( QgsProjectVersion ( 1 , 3 , 0 ) );
29
+
30
+ // WMS parameters definition
26
31
const Parameter pBoxSpace = { ParameterName::BOXSPACE,
27
32
QVariant::Double,
28
33
QVariant ( 2.0 ),
@@ -184,6 +189,13 @@ namespace QgsWms
184
189
};
185
190
save ( pCRS );
186
191
192
+ const Parameter pSRS = { ParameterName::SRS,
193
+ QVariant::String,
194
+ QVariant ( " " ),
195
+ QVariant ()
196
+ };
197
+ save ( pSRS );
198
+
187
199
const Parameter pFormat = { ParameterName::FORMAT,
188
200
QVariant::String,
189
201
QVariant ( " " ),
@@ -393,6 +405,27 @@ namespace QgsWms
393
405
QVariant ()
394
406
};
395
407
save ( pWmsPrecision );
408
+
409
+ const Parameter pTransparent = { ParameterName::TRANSPARENT,
410
+ QVariant::Bool,
411
+ QVariant ( false ),
412
+ QVariant ()
413
+ };
414
+ save ( pTransparent );
415
+
416
+ const Parameter pBgColor = { ParameterName::BGCOLOR,
417
+ QVariant::String,
418
+ QVariant ( " white" ),
419
+ QVariant ()
420
+ };
421
+ save ( pBgColor );
422
+
423
+ const Parameter pDpi = { ParameterName::DPI,
424
+ QVariant::Int,
425
+ QVariant ( -1 ),
426
+ QVariant ()
427
+ };
428
+ save ( pDpi );
396
429
}
397
430
398
431
QgsWmsParameters::QgsWmsParameters ( const QgsServerRequest::Parameters ¶meters )
@@ -438,6 +471,9 @@ namespace QgsWms
438
471
log ( " - " + name + " : " + value );
439
472
}
440
473
}
474
+
475
+ if ( !version ().isEmpty () )
476
+ log ( " - VERSION : " + version () );
441
477
}
442
478
443
479
void QgsWmsParameters::save ( const Parameter ¶meter )
@@ -490,7 +526,25 @@ namespace QgsWms
490
526
491
527
QString QgsWmsParameters::crs () const
492
528
{
493
- return value ( ParameterName::CRS ).toString ();
529
+ QString rs;
530
+ QString srs = value ( ParameterName::SRS ).toString ();
531
+ QString crs = value ( ParameterName::CRS ).toString ();
532
+
533
+ // both SRS/CRS are supported but there's a priority according to the
534
+ // specified version when both are defined in the request
535
+ if ( !srs.isEmpty () && crs.isEmpty () )
536
+ rs = srs;
537
+ else if ( srs.isEmpty () && !crs.isEmpty () )
538
+ rs = crs;
539
+ else if ( !srs.isEmpty () && !crs.isEmpty () )
540
+ {
541
+ if ( versionAsNumber () >= QgsProjectVersion ( 1 , 3 , 0 ) )
542
+ rs = crs;
543
+ else
544
+ rs = srs;
545
+ }
546
+
547
+ return rs;
494
548
}
495
549
496
550
QString QgsWmsParameters::bbox () const
@@ -552,6 +606,39 @@ namespace QgsWms
552
606
return toInt ( ParameterName::WIDTH );
553
607
}
554
608
609
+ QString QgsWmsParameters::dpi () const
610
+ {
611
+ return value ( ParameterName::DPI ).toString ();
612
+ }
613
+
614
+ int QgsWmsParameters::dpiAsInt () const
615
+ {
616
+ return toInt ( ParameterName::DPI );
617
+ }
618
+
619
+ QString QgsWmsParameters::version () const
620
+ {
621
+ // VERSION parameter is not managed with other parameters because
622
+ // there's a conflict with qgis VERSION defined in qgsconfig.h
623
+ if ( mRequestParameters .contains ( " VERSION" ) )
624
+ return mRequestParameters [" VERSION" ];
625
+ else
626
+ return QString ();
627
+ }
628
+
629
+ QgsProjectVersion QgsWmsParameters::versionAsNumber () const
630
+ {
631
+ QString vStr = version ();
632
+ QgsProjectVersion version;
633
+
634
+ if ( vStr.isEmpty () )
635
+ version = QgsProjectVersion ( 1 , 3 , 0 ); // default value
636
+ else if ( mVersions .contains ( QgsProjectVersion ( vStr ) ) )
637
+ version = QgsProjectVersion ( vStr );
638
+
639
+ return version;
640
+ }
641
+
555
642
double QgsWmsParameters::toDouble ( ParameterName p ) const
556
643
{
557
644
double val = defaultValue ( p ).toDouble ();
@@ -605,6 +692,31 @@ namespace QgsWms
605
692
return val;
606
693
}
607
694
695
+ QColor QgsWmsParameters::toColor ( ParameterName p ) const
696
+ {
697
+ QColor c = defaultValue ( p ).value <QColor>();
698
+
699
+ if ( !value ( p ).toString ().isEmpty () )
700
+ {
701
+ // support hexadecimal notation to define colors
702
+ QString cStr = value ( p ).toString ();
703
+ if ( cStr.startsWith ( " 0x" , Qt::CaseInsensitive ) )
704
+ cStr.replace ( 0 , 2 , " #" );
705
+
706
+ c = QColor ( cStr );
707
+
708
+ if ( !c.isValid () )
709
+ {
710
+ QString val = value ( p ).toString ();
711
+ QString n = name ( p );
712
+ QString msg = n + " ('" + val + " ') cannot be converted into a color" ;
713
+ raiseError ( msg );
714
+ }
715
+ }
716
+
717
+ return c;
718
+ }
719
+
608
720
QStringList QgsWmsParameters::toStringList ( ParameterName name, char delimiter ) const
609
721
{
610
722
return value ( name ).toString ().split ( delimiter, QString::SkipEmptyParts );
@@ -795,6 +907,16 @@ namespace QgsWms
795
907
return toBool ( ParameterName::RULELABEL );
796
908
}
797
909
910
+ QString QgsWmsParameters::transparent () const
911
+ {
912
+ return value ( ParameterName::TRANSPARENT ).toString ();
913
+ }
914
+
915
+ bool QgsWmsParameters::transparentAsBool () const
916
+ {
917
+ return toBool ( ParameterName::TRANSPARENT );
918
+ }
919
+
798
920
QString QgsWmsParameters::scale () const
799
921
{
800
922
return value ( ParameterName::SCALE ).toString ();
@@ -962,23 +1084,7 @@ namespace QgsWms
962
1084
963
1085
QColor QgsWmsParameters::layerFontColorAsColor () const
964
1086
{
965
- ParameterName p = ParameterName::LAYERFONTCOLOR;
966
- QColor c = defaultValue ( p ).value <QColor>();
967
-
968
- if ( !layerFontColor ().isEmpty () )
969
- {
970
- c = QColor ( layerFontColor () );
971
-
972
- if ( !c.isValid () )
973
- {
974
- QString val = value ( p ).toString ();
975
- QString n = name ( p );
976
- QString msg = n + " ('" + val + " ') cannot be converted into a color" ;
977
- raiseError ( msg );
978
- }
979
- }
980
-
981
- return c;
1087
+ return toColor ( ParameterName::LAYERFONTCOLOR );
982
1088
}
983
1089
984
1090
QString QgsWmsParameters::itemFontSize () const
@@ -1301,6 +1407,16 @@ namespace QgsWms
1301
1407
return params;
1302
1408
}
1303
1409
1410
+ QString QgsWmsParameters::backgroundColor () const
1411
+ {
1412
+ return value ( ParameterName::BGCOLOR ).toString ();
1413
+ }
1414
+
1415
+ QColor QgsWmsParameters::backgroundColorAsColor () const
1416
+ {
1417
+ return toColor ( ParameterName::BGCOLOR );
1418
+ }
1419
+
1304
1420
QString QgsWmsParameters::name ( ParameterName name ) const
1305
1421
{
1306
1422
const QMetaEnum metaEnum ( QMetaEnum::fromType<ParameterName>() );
0 commit comments