Skip to content
Permalink
Browse files

[Server] WMS GetPrint refactoring - Add Highlight layers

  • Loading branch information
rldhont committed Aug 6, 2017
1 parent 7c1d397 commit 0e1d535c78b289c70b13b8dde0feeed5f89bc00b
@@ -1482,21 +1482,66 @@ namespace QgsWms
}

//layers
QList<QgsWmsParametersLayer> parameters;
QStringList layers = composerMapParamToStringList( mapId, "LAYERS", ',' );
QStringList styles = composerMapParamToStringList( mapId, "STYLES", ',' );
QList<QgsWmsParametersLayer> lParams;
QStringList layers = composerMapParamToStringList( mapId, name( ParameterName::LAYERS ), ',' );
QStringList styles = composerMapParamToStringList( mapId, name( ParameterName::STYLES ), ',' );
for ( int i = 0; i < layers.size(); i++ )
{
QString layer = layers[i];
QgsWmsParametersLayer param;
param.mNickname = layer;
QgsWmsParametersLayer lParam;
lParam.mNickname = layer;

if ( i < styles.count() )
param.mStyle = styles[i];
lParam.mStyle = styles[i];

parameters.append( param );
lParams.append( lParam );
}
param.mLayers = lParams;

//highlight layers
QList<QgsWmsParametersHighlightLayer> hParams;
QList<QgsGeometry> geoms = composerMapParamToGeomList( mapId, name( ParameterName::HIGHLIGHT_GEOM ), ';' );
QStringList slds = composerMapParamToStringList( mapId, name( ParameterName::HIGHLIGHT_SYMBOL ), ';' );
QStringList labels = composerMapParamToStringList( mapId, name( ParameterName::HIGHLIGHT_LABELSTRING ), ';' );
QList<QColor> colors = composerMapParamToColorList( mapId, name( ParameterName::HIGHLIGHT_LABELCOLOR ), ';' );
QList<int> sizes = composerMapParamToIntList( mapId, name( ParameterName::HIGHLIGHT_LABELSIZE ), ';' );
QList<int> weights = composerMapParamToIntList( mapId, name( ParameterName::HIGHLIGHT_LABELWEIGHT ), ';' );
QStringList fonts = composerMapParamToStringList( mapId, name( ParameterName::HIGHLIGHT_LABELFONT ), ';' );
QList<QColor> bufferColors = composerMapParamToColorList( mapId, name( ParameterName::HIGHLIGHT_LABELBUFFERCOLOR ), ';' );
QList<float> bufferSizes = composerMapParamToFloatList( mapId, name( ParameterName::HIGHLIGHT_LABELBUFFERSIZE ), ';' );

int nHLayers = qMin( geoms.size(), slds.size() );
for ( int i = 0; i < nHLayers; i++ )
{
QgsWmsParametersHighlightLayer hParam;
hParam.mName = pMapId + "_highlight_" + QString::number( i );
hParam.mGeom = geoms[i];
hParam.mSld = slds[i];

if ( i < labels.count() )
hParam.mLabel = labels[i];

if ( i < colors.count() )
hParam.mColor = colors[i];

if ( i < sizes.count() )
hParam.mSize = sizes[i];

if ( i < weights.count() )
hParam.mWeight = weights[i];

if ( i < fonts.count() )
hParam.mFont = fonts[ i ];

if ( i < bufferColors.count() )
hParam.mBufferColor = bufferColors[i];

if ( i < bufferSizes.count() )
hParam.mBufferSize = bufferSizes[i];

hParams.append( hParam );
}
param.mLayers = parameters;
param.mHighlightLayers = hParams;

return param;
}
@@ -1545,6 +1590,112 @@ namespace QgsWms
return valStr.split( delimiter, QString::SkipEmptyParts );
}

QList<QgsGeometry> QgsWmsParameters::composerMapParamToGeomList( int mapId, QString name, char delimiter ) const
{
QStringList l = composerMapParamToStringList( mapId, name, delimiter );
QList<QgsGeometry> geometries;

Q_FOREACH ( QString wkt, l )
{
QgsGeometry g( QgsGeometry::fromWkt( wkt ) );

if ( g.isGeosValid() )
{
geometries.append( g );
}
else
{
QString pMapId = "MAP" + QString::number( mapId );
QString paramName = pMapId + ":" + name;
QString valStr = l.join( delimiter );
QString msg = paramName + " ('" + valStr + "') cannot be converted into a list of geometries";
raiseError( msg );
}
}

return geometries;
}

QList<QColor> QgsWmsParameters::composerMapParamToColorList( int mapId, QString name, char delimiter ) const
{
QStringList l = composerMapParamToStringList( mapId, name, delimiter );
QList<QColor> elements;

Q_FOREACH ( QString element, l )
{
QColor c = QColor( element );

if ( c.isValid() )
{
elements.append( c );
}
else
{
QString pMapId = "MAP" + QString::number( mapId );
QString paramName = pMapId + ":" + name;
QString valStr = l.join( delimiter );
QString msg = paramName + " ('" + valStr + "') cannot be converted into a list of colors";
raiseError( msg );
}
}

return elements;
}

QList<int> QgsWmsParameters::composerMapParamToIntList( int mapId, QString name, char delimiter ) const
{
QStringList l = composerMapParamToStringList( mapId, name, delimiter );
QList<int> elements;

Q_FOREACH ( QString element, l )
{
bool ok;
int e = element.toInt( &ok );

if ( ok )
{
elements.append( e );
}
else
{
QString pMapId = "MAP" + QString::number( mapId );
QString paramName = pMapId + ":" + name;
QString valStr = l.join( delimiter );
QString msg = paramName + " ('" + valStr + "') cannot be converted into a list of int";
raiseError( msg );
}
}

return elements;
}

QList<float> QgsWmsParameters::composerMapParamToFloatList( int mapId, QString name, char delimiter ) const
{
QStringList l = composerMapParamToStringList( mapId, name, delimiter );
QList<float> elements;

Q_FOREACH ( QString element, l )
{
bool ok;
float e = element.toFloat( &ok );

if ( ok )
{
elements.append( e );
}
else
{
QString pMapId = "MAP" + QString::number( mapId );
QString paramName = pMapId + ":" + name;
QString valStr = l.join( delimiter );
QString msg = paramName + " ('" + valStr + "') cannot be converted into a list of float";
raiseError( msg );
}
}

return elements;
}

QString QgsWmsParameters::name( ParameterName name ) const
{
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );
@@ -69,6 +69,7 @@ namespace QgsWms
float mGridX = 0;
float mGridY = 0;
QList<QgsWmsParametersLayer> mLayers; // list of layers fr this composer map
QList<QgsWmsParametersHighlightLayer> mHighlightLayers; // list of highlight layers fr this composer map
};

class QgsWmsParameters
@@ -810,6 +811,10 @@ namespace QgsWms
* \returns parameter as a string list
*/
QStringList composerMapParamToStringList( int mapId, QString name, char delimiter ) const;
QList<QgsGeometry> composerMapParamToGeomList( int mapId, QString name, char delimiter ) const;
QList<QColor> composerMapParamToColorList( int mapId, QString name, char delimiter ) const;
QList<int> composerMapParamToIntList( int mapId, QString name, char delimiter ) const;
QList<float> composerMapParamToFloatList( int mapId, QString name, char delimiter ) const;

private:
QString name( ParameterName name ) const;
@@ -349,7 +349,7 @@ namespace QgsWms
}

// add highlight layers above others
layers = layers << highlightLayers();
layers = layers << highlightLayers( mWmsParameters.highlightLayersParameters() );

// add layers to map settings (revert order for the rendering)
std::reverse( layers.begin(), layers.end() );
@@ -523,6 +523,7 @@ namespace QgsWms
QStringLiteral( "Layer \"%1\" does not exist" ).arg( nickname ) );
}
}
layerSet << highlightLayers( cMapParams.mHighlightLayers );
std::reverse( layerSet.begin(), layerSet.end() );
map->setLayers( layerSet );
}
@@ -754,7 +755,7 @@ namespace QgsWms
}

// add highlight layers above others
layers = layers << highlightLayers();
layers = layers << highlightLayers( mWmsParameters.highlightLayersParameters() );

// create the output image and the painter
std::unique_ptr<QPainter> painter;
@@ -2871,12 +2872,11 @@ namespace QgsWms
return visible;
}

QList<QgsMapLayer *> QgsRenderer::highlightLayers()
QList<QgsMapLayer *> QgsRenderer::highlightLayers( QList<QgsWmsParametersHighlightLayer> params )
{
QList<QgsMapLayer *> highlightLayers;

// try to create highlight layer for each geometry
QList<QgsWmsParametersHighlightLayer> params = mWmsParameters.highlightLayersParameters();
QString crs = mWmsParameters.crs();
Q_FOREACH ( QgsWmsParametersHighlightLayer param, params )
{
@@ -124,7 +124,7 @@ namespace QgsWms
void initRestrictedLayers();

// Build and returns highlight layers
QList<QgsMapLayer *> highlightLayers();
QList<QgsMapLayer *> highlightLayers( QList<QgsWmsParametersHighlightLayer> params );

// Init a map with nickname for layers' project
void initNicknameLayers();

0 comments on commit 0e1d535

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