Skip to content
Permalink
Browse files

Merge pull request #4945 from pblottiere/server_smallclean

[server] Small clean-up in WMS renderer
  • Loading branch information
rldhont committed Aug 1, 2017
2 parents 0db8a58 + e44a5ce commit a8f6dbc3b7b87f7a2bf673b70f8e16211abdd564
@@ -69,9 +69,7 @@ bool QgsProjectVersion::operator!=( const QgsProjectVersion &other ) const

bool QgsProjectVersion::operator>=( const QgsProjectVersion &other ) const
{
return ( ( mMajor >= other.mMajor ) ||
( ( mMajor == other.mMajor ) && ( mMinor >= other.mMinor ) ) ||
( ( mMajor == other.mMajor ) && ( mMinor == other.mMinor ) && ( mSub >= other.mSub ) ) );
return ( *this == other ) || ( *this > other );
}

bool QgsProjectVersion::operator>( const QgsProjectVersion &other ) const
@@ -23,6 +23,11 @@ namespace QgsWms
{
QgsWmsParameters::QgsWmsParameters()
{
// Available version number
mVersions.append( QgsProjectVersion( 1, 1, 1 ) );
mVersions.append( QgsProjectVersion( 1, 3, 0 ) );

// WMS parameters definition
const Parameter pBoxSpace = { ParameterName::BOXSPACE,
QVariant::Double,
QVariant( 2.0 ),
@@ -184,6 +189,13 @@ namespace QgsWms
};
save( pCRS );

const Parameter pSRS = { ParameterName::SRS,
QVariant::String,
QVariant( "" ),
QVariant()
};
save( pSRS );

const Parameter pFormat = { ParameterName::FORMAT,
QVariant::String,
QVariant( "" ),
@@ -393,6 +405,27 @@ namespace QgsWms
QVariant()
};
save( pWmsPrecision );

const Parameter pTransparent = { ParameterName::TRANSPARENT,
QVariant::Bool,
QVariant( false ),
QVariant()
};
save( pTransparent );

const Parameter pBgColor = { ParameterName::BGCOLOR,
QVariant::String,
QVariant( "white" ),
QVariant()
};
save( pBgColor );

const Parameter pDpi = { ParameterName::DPI,
QVariant::Int,
QVariant( -1 ),
QVariant()
};
save( pDpi );
}

QgsWmsParameters::QgsWmsParameters( const QgsServerRequest::Parameters &parameters )
@@ -438,6 +471,9 @@ namespace QgsWms
log( " - " + name + " : " + value );
}
}

if ( !version().isEmpty() )
log( " - VERSION : " + version() );
}

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

QString QgsWmsParameters::crs() const
{
return value( ParameterName::CRS ).toString();
QString rs;
QString srs = value( ParameterName::SRS ).toString();
QString crs = value( ParameterName::CRS ).toString();

// both SRS/CRS are supported but there's a priority according to the
// specified version when both are defined in the request
if ( !srs.isEmpty() && crs.isEmpty() )
rs = srs;
else if ( srs.isEmpty() && !crs.isEmpty() )
rs = crs;
else if ( !srs.isEmpty() && !crs.isEmpty() )
{
if ( versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
rs = crs;
else
rs = srs;
}

return rs;
}

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

QString QgsWmsParameters::dpi() const
{
return value( ParameterName::DPI ).toString();
}

int QgsWmsParameters::dpiAsInt() const
{
return toInt( ParameterName::DPI );
}

QString QgsWmsParameters::version() const
{
// VERSION parameter is not managed with other parameters because
// there's a conflict with qgis VERSION defined in qgsconfig.h
if ( mRequestParameters.contains( "VERSION" ) )
return mRequestParameters["VERSION"];
else
return QString();
}

QgsProjectVersion QgsWmsParameters::versionAsNumber() const
{
QString vStr = version();
QgsProjectVersion version;

if ( vStr.isEmpty() )
version = QgsProjectVersion( 1, 3, 0 ); // default value
else if ( mVersions.contains( QgsProjectVersion( vStr ) ) )
version = QgsProjectVersion( vStr );

return version;
}

double QgsWmsParameters::toDouble( ParameterName p ) const
{
double val = defaultValue( p ).toDouble();
@@ -605,6 +692,31 @@ namespace QgsWms
return val;
}

QColor QgsWmsParameters::toColor( ParameterName p ) const
{
QColor c = defaultValue( p ).value<QColor>();

if ( !value( p ).toString().isEmpty() )
{
// support hexadecimal notation to define colors
QString cStr = value( p ).toString();
if ( cStr.startsWith( "0x", Qt::CaseInsensitive ) )
cStr.replace( 0, 2, "#" );

c = QColor( cStr );

if ( !c.isValid() )
{
QString val = value( p ).toString();
QString n = name( p );
QString msg = n + " ('" + val + "') cannot be converted into a color";
raiseError( msg );
}
}

return c;
}

QStringList QgsWmsParameters::toStringList( ParameterName name, char delimiter ) const
{
return value( name ).toString().split( delimiter, QString::SkipEmptyParts );
@@ -795,6 +907,16 @@ namespace QgsWms
return toBool( ParameterName::RULELABEL );
}

QString QgsWmsParameters::transparent() const
{
return value( ParameterName::TRANSPARENT ).toString();
}

bool QgsWmsParameters::transparentAsBool() const
{
return toBool( ParameterName::TRANSPARENT );
}

QString QgsWmsParameters::scale() const
{
return value( ParameterName::SCALE ).toString();
@@ -962,23 +1084,7 @@ namespace QgsWms

QColor QgsWmsParameters::layerFontColorAsColor() const
{
ParameterName p = ParameterName::LAYERFONTCOLOR;
QColor c = defaultValue( p ).value<QColor>();

if ( !layerFontColor().isEmpty() )
{
c = QColor( layerFontColor() );

if ( !c.isValid() )
{
QString val = value( p ).toString();
QString n = name( p );
QString msg = n + " ('" + val + "') cannot be converted into a color";
raiseError( msg );
}
}

return c;
return toColor( ParameterName::LAYERFONTCOLOR );
}

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

QString QgsWmsParameters::backgroundColor() const
{
return value( ParameterName::BGCOLOR ).toString();
}

QColor QgsWmsParameters::backgroundColorAsColor() const
{
return toColor( ParameterName::BGCOLOR );
}

QString QgsWmsParameters::name( ParameterName name ) const
{
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );
@@ -22,11 +22,13 @@
#include <QObject>
#include <QMetaEnum>
#include <QColor>

#include "qgsrectangle.h"
#include "qgswmsserviceexception.h"
#include "qgsserverrequest.h"
#include "qgslegendsettings.h"
#include "qgsgeometry.h"
#include "qgsprojectversion.h"

/** QgsWmsParameters provides an interface to retrieve and manipulate WMS
* parameters received from the client.
@@ -66,7 +68,7 @@ namespace QgsWms
{
BOXSPACE,
CRS, // instead of SRS for WMS 1.3.0
// SRS, // for WMS 1.1.1
SRS, // for WMS 1.1.1
WIDTH,
HEIGHT,
BBOX,
@@ -117,7 +119,10 @@ namespace QgsWms
HIGHLIGHT_LABELCOLOR,
HIGHLIGHT_LABELBUFFERCOLOR,
HIGHLIGHT_LABELBUFFERSIZE,
WMS_PRECISION
WMS_PRECISION,
TRANSPARENT,
BGCOLOR,
DPI
};
Q_ENUM( ParameterName )

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

/** Returns VERSION parameter as a string or an empty string if not
* defined.
* \returns version
*/
QString version() const;

/** Returns VERSION parameter if defined or its default value.
* \returns version
*/
QgsProjectVersion versionAsNumber() const;

/** Returns BBOX if defined or an empty string.
* \returns bbox parameter
*/
@@ -712,6 +728,45 @@ namespace QgsWms
*/
int wmsPrecisionAsInt() const;

/** Returns TRANSPARENT parameter or an empty string if not defined.
* \returns TRANSPARENT parameter
*/
QString transparent() const;

/** Returns TRANSPARENT parameter as a bool or its default value if not
* defined. An exception is raised if TRANSPARENT is defined and cannot
* be converted.
* \returns transparent parameter
* \throws QgsBadRequestException
*/
bool transparentAsBool() const;

/** Returns BGCOLOR parameter or an empty string if not defined.
* \returns BGCOLOR parameter
*/
QString backgroundColor() const;

/** Returns BGCOLOR parameter as a QColor or its default value if not
* defined. An exception is raised if BGCOLOR is defined and cannot
* be converted.
* \returns background color parameter
* \throws QgsBadRequestException
*/
QColor backgroundColorAsColor() const;

/** Returns DPI parameter or an empty string if not defined.
* \returns DPI parameter
*/
QString dpi() const;

/** Returns DPI parameter as an int or its default value if not
* defined. An exception is raised if DPI is defined and cannot
* be converted.
* \returns dpi parameter
* \throws QgsBadRequestException
*/
int dpiAsInt() const;

private:
QString name( ParameterName name ) const;
void raiseError( ParameterName name ) const;
@@ -724,13 +779,15 @@ namespace QgsWms
double toDouble( ParameterName name ) const;
bool toBool( ParameterName name ) const;
int toInt( ParameterName name ) const;
QColor toColor( ParameterName name ) const;
QStringList toStringList( ParameterName name, char delimiter = ',' ) const;
QList<int> toIntList( QStringList l, ParameterName name ) const;
QList<float> toFloatList( QStringList l, ParameterName name ) const;
QList<QColor> toColorList( QStringList l, ParameterName name ) const;

QgsServerRequest::Parameters mRequestParameters;
QMap<ParameterName, Parameter> mParameters;
QList<QgsProjectVersion> mVersions;
};
}

0 comments on commit a8f6dbc

Please sign in to comment.
You can’t perform that action at this time.