Skip to content

Commit a8f6dbc

Browse files
authoredAug 1, 2017
Merge pull request #4945 from pblottiere/server_smallclean
[server] Small clean-up in WMS renderer
2 parents 0db8a58 + e44a5ce commit a8f6dbc

File tree

5 files changed

+244
-84
lines changed

5 files changed

+244
-84
lines changed
 

‎src/core/qgsprojectversion.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ bool QgsProjectVersion::operator!=( const QgsProjectVersion &other ) const
6969

7070
bool QgsProjectVersion::operator>=( const QgsProjectVersion &other ) const
7171
{
72-
return ( ( mMajor >= other.mMajor ) ||
73-
( ( mMajor == other.mMajor ) && ( mMinor >= other.mMinor ) ) ||
74-
( ( mMajor == other.mMajor ) && ( mMinor == other.mMinor ) && ( mSub >= other.mSub ) ) );
72+
return ( *this == other ) || ( *this > other );
7573
}
7674

7775
bool QgsProjectVersion::operator>( const QgsProjectVersion &other ) const

‎src/server/services/wms/qgswmsparameters.cpp

Lines changed: 134 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ namespace QgsWms
2323
{
2424
QgsWmsParameters::QgsWmsParameters()
2525
{
26+
// Available version number
27+
mVersions.append( QgsProjectVersion( 1, 1, 1 ) );
28+
mVersions.append( QgsProjectVersion( 1, 3, 0 ) );
29+
30+
// WMS parameters definition
2631
const Parameter pBoxSpace = { ParameterName::BOXSPACE,
2732
QVariant::Double,
2833
QVariant( 2.0 ),
@@ -184,6 +189,13 @@ namespace QgsWms
184189
};
185190
save( pCRS );
186191

192+
const Parameter pSRS = { ParameterName::SRS,
193+
QVariant::String,
194+
QVariant( "" ),
195+
QVariant()
196+
};
197+
save( pSRS );
198+
187199
const Parameter pFormat = { ParameterName::FORMAT,
188200
QVariant::String,
189201
QVariant( "" ),
@@ -393,6 +405,27 @@ namespace QgsWms
393405
QVariant()
394406
};
395407
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 );
396429
}
397430

398431
QgsWmsParameters::QgsWmsParameters( const QgsServerRequest::Parameters &parameters )
@@ -438,6 +471,9 @@ namespace QgsWms
438471
log( " - " + name + " : " + value );
439472
}
440473
}
474+
475+
if ( !version().isEmpty() )
476+
log( " - VERSION : " + version() );
441477
}
442478

443479
void QgsWmsParameters::save( const Parameter &parameter )
@@ -490,7 +526,25 @@ namespace QgsWms
490526

491527
QString QgsWmsParameters::crs() const
492528
{
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;
494548
}
495549

496550
QString QgsWmsParameters::bbox() const
@@ -552,6 +606,39 @@ namespace QgsWms
552606
return toInt( ParameterName::WIDTH );
553607
}
554608

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+
555642
double QgsWmsParameters::toDouble( ParameterName p ) const
556643
{
557644
double val = defaultValue( p ).toDouble();
@@ -605,6 +692,31 @@ namespace QgsWms
605692
return val;
606693
}
607694

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+
608720
QStringList QgsWmsParameters::toStringList( ParameterName name, char delimiter ) const
609721
{
610722
return value( name ).toString().split( delimiter, QString::SkipEmptyParts );
@@ -795,6 +907,16 @@ namespace QgsWms
795907
return toBool( ParameterName::RULELABEL );
796908
}
797909

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+
798920
QString QgsWmsParameters::scale() const
799921
{
800922
return value( ParameterName::SCALE ).toString();
@@ -962,23 +1084,7 @@ namespace QgsWms
9621084

9631085
QColor QgsWmsParameters::layerFontColorAsColor() const
9641086
{
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 );
9821088
}
9831089

9841090
QString QgsWmsParameters::itemFontSize() const
@@ -1301,6 +1407,16 @@ namespace QgsWms
13011407
return params;
13021408
}
13031409

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+
13041420
QString QgsWmsParameters::name( ParameterName name ) const
13051421
{
13061422
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );

‎src/server/services/wms/qgswmsparameters.h

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
#include <QObject>
2323
#include <QMetaEnum>
2424
#include <QColor>
25+
2526
#include "qgsrectangle.h"
2627
#include "qgswmsserviceexception.h"
2728
#include "qgsserverrequest.h"
2829
#include "qgslegendsettings.h"
2930
#include "qgsgeometry.h"
31+
#include "qgsprojectversion.h"
3032

3133
/** QgsWmsParameters provides an interface to retrieve and manipulate WMS
3234
* parameters received from the client.
@@ -66,7 +68,7 @@ namespace QgsWms
6668
{
6769
BOXSPACE,
6870
CRS, // instead of SRS for WMS 1.3.0
69-
// SRS, // for WMS 1.1.1
71+
SRS, // for WMS 1.1.1
7072
WIDTH,
7173
HEIGHT,
7274
BBOX,
@@ -117,7 +119,10 @@ namespace QgsWms
117119
HIGHLIGHT_LABELCOLOR,
118120
HIGHLIGHT_LABELBUFFERCOLOR,
119121
HIGHLIGHT_LABELBUFFERSIZE,
120-
WMS_PRECISION
122+
WMS_PRECISION,
123+
TRANSPARENT,
124+
BGCOLOR,
125+
DPI
121126
};
122127
Q_ENUM( ParameterName )
123128

@@ -189,6 +194,17 @@ namespace QgsWms
189194
*/
190195
int heightAsInt() const;
191196

197+
/** Returns VERSION parameter as a string or an empty string if not
198+
* defined.
199+
* \returns version
200+
*/
201+
QString version() const;
202+
203+
/** Returns VERSION parameter if defined or its default value.
204+
* \returns version
205+
*/
206+
QgsProjectVersion versionAsNumber() const;
207+
192208
/** Returns BBOX if defined or an empty string.
193209
* \returns bbox parameter
194210
*/
@@ -712,6 +728,45 @@ namespace QgsWms
712728
*/
713729
int wmsPrecisionAsInt() const;
714730

731+
/** Returns TRANSPARENT parameter or an empty string if not defined.
732+
* \returns TRANSPARENT parameter
733+
*/
734+
QString transparent() const;
735+
736+
/** Returns TRANSPARENT parameter as a bool or its default value if not
737+
* defined. An exception is raised if TRANSPARENT is defined and cannot
738+
* be converted.
739+
* \returns transparent parameter
740+
* \throws QgsBadRequestException
741+
*/
742+
bool transparentAsBool() const;
743+
744+
/** Returns BGCOLOR parameter or an empty string if not defined.
745+
* \returns BGCOLOR parameter
746+
*/
747+
QString backgroundColor() const;
748+
749+
/** Returns BGCOLOR parameter as a QColor or its default value if not
750+
* defined. An exception is raised if BGCOLOR is defined and cannot
751+
* be converted.
752+
* \returns background color parameter
753+
* \throws QgsBadRequestException
754+
*/
755+
QColor backgroundColorAsColor() const;
756+
757+
/** Returns DPI parameter or an empty string if not defined.
758+
* \returns DPI parameter
759+
*/
760+
QString dpi() const;
761+
762+
/** Returns DPI parameter as an int or its default value if not
763+
* defined. An exception is raised if DPI is defined and cannot
764+
* be converted.
765+
* \returns dpi parameter
766+
* \throws QgsBadRequestException
767+
*/
768+
int dpiAsInt() const;
769+
715770
private:
716771
QString name( ParameterName name ) const;
717772
void raiseError( ParameterName name ) const;
@@ -724,13 +779,15 @@ namespace QgsWms
724779
double toDouble( ParameterName name ) const;
725780
bool toBool( ParameterName name ) const;
726781
int toInt( ParameterName name ) const;
782+
QColor toColor( ParameterName name ) const;
727783
QStringList toStringList( ParameterName name, char delimiter = ',' ) const;
728784
QList<int> toIntList( QStringList l, ParameterName name ) const;
729785
QList<float> toFloatList( QStringList l, ParameterName name ) const;
730786
QList<QColor> toColorList( QStringList l, ParameterName name ) const;
731787

732788
QgsServerRequest::Parameters mRequestParameters;
733789
QMap<ParameterName, Parameter> mParameters;
790+
QList<QgsProjectVersion> mVersions;
734791
};
735792
}
736793

0 commit comments

Comments
 (0)
Please sign in to comment.