Skip to content
Permalink
Browse files

fixed AStyle with astyle-all.sh

  • Loading branch information
luipir committed Feb 1, 2019
1 parent 82e48f9 commit 0e9af791651a69a72c3e993ecbd79415f0d60e41
@@ -128,7 +128,7 @@ By default it will be generated.

void toSld( QDomDocument &doc, QDomElement &element ) const;
%Docstring
! Write ContrastEnhancement tags following SLD v1.0 specs
Write ContrastEnhancement tags following SLD v1.0 specs
SLD1.0 is limited to the parameters listed in:
https://docs.geoserver.org/stable/en/user/styling/sld/reference/rastersymbolizer.html#contrastenhancement
Btw only <Normalize> + vendor options are supported because there is no clear mapping
@@ -115,7 +115,7 @@ Sets origin of min/max values

virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const;
%Docstring
! Used from subclasses to create SLD Rule elements following SLD v1.0 specs
Used from subclasses to create SLD Rule elements following SLD v1.0 specs

.. versionadded:: 3.6
%End
@@ -1394,7 +1394,7 @@ void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg )

const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>( this );
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( this );
if (!vlayer && !rlayer)
if ( !vlayer && !rlayer )
{
errorMsg = tr( "Could not save symbology because:\n%1" )
.arg( QStringLiteral( "Non vector or raster layers are supported yet" ) );
@@ -1441,7 +1441,7 @@ void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg )
props[ QStringLiteral( "scaleMaxDenom" ) ] = QString::number( mMaxScale );
}

if (vlayer)
if ( vlayer )
{
if ( !vlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
{
@@ -1450,7 +1450,7 @@ void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg )
}
}

if (rlayer)
if ( rlayer )
{
if ( !rlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
{
@@ -383,7 +383,7 @@ void QgsContrastEnhancement::toSld( QDomDocument &doc, QDomElement &element ) co
return;

QString algName;
switch( contrastEnhancementAlgorithm() )
switch ( contrastEnhancementAlgorithm() )
{
case StretchToMinimumMaximum:
algName = QStringLiteral( "StretchToMinimumMaximum" );
@@ -159,7 +159,8 @@ class CORE_EXPORT QgsContrastEnhancement

void readXml( const QDomElement &elem );

/*! Write ContrastEnhancement tags following SLD v1.0 specs
/**
* Write ContrastEnhancement tags following SLD v1.0 specs
* SLD1.0 is limited to the parameters listed in:
* https://docs.geoserver.org/stable/en/user/styling/sld/reference/rastersymbolizer.html#contrastenhancement
* Btw only <Normalize> + vendor options are supported because there is no clear mapping
@@ -552,29 +552,29 @@ void QgsHillshadeRenderer::toSld( QDomDocument &doc, QDomElement &element, const

// look for RasterSymbolizer tag
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
if ( elements.size() == 0)
if ( elements.size() == 0 )
return;

// there SHOULD be only one
QDomElement rasterSymbolizerElem = elements.at(0).toElement();
QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();

// add Channel Selection tags (if band is not default 1)
// Need to insert channelSelection in the correct sequence as in SLD standard e.g.
// after opacity or geometry or as first element after sld:RasterSymbolizer
if ( band() != 1)
if ( band() != 1 )
{
QDomElement channelSelectionElem = doc.createElement( QStringLiteral( "sld:ChannelSelection" ) );
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Opacity" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at(0) );
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Geometry" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at(0) );
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
@@ -476,7 +476,7 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element,
return;

// there SHOULD be only one
QDomElement rasterSymbolizerElem = elements.at(0).toElement();
QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();

// add Channel Selection tags
// Need to insert channelSelection in the correct sequence as in SLD standard e.g.
@@ -485,14 +485,14 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element,
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Opacity" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at(0) );
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Geometry" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at(0) );
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
@@ -504,16 +504,16 @@ void QgsMultiBandColorRenderer::toSld( QDomDocument &doc, QDomElement &element,
QStringList tags;
tags << QStringLiteral( "sld:RedChannel" ) << QStringLiteral( "sld:GreenChannel" ) << QStringLiteral( "sld:BlueChannel" );

QList<QgsContrastEnhancement*> contrastEnhancements;
QList<QgsContrastEnhancement *> contrastEnhancements;
contrastEnhancements.append( mRedContrastEnhancement );
contrastEnhancements.append( mGreenContrastEnhancement );
contrastEnhancements.append( mBlueContrastEnhancement );

QList<int> bands = usesBands();
QList<int>::const_iterator bandIt = bands.constBegin();
for ( int tagCounter = 0 ; bandIt != bands.constEnd(); ++bandIt, ++tagCounter)
for ( int tagCounter = 0 ; bandIt != bands.constEnd(); ++bandIt, ++tagCounter )
{
if ( *bandIt < 0)
if ( *bandIt < 0 )
continue;

QDomElement channelElem = doc.createElement( tags[ tagCounter ] );
@@ -254,11 +254,11 @@ void QgsPalettedRasterRenderer::toSld( QDomDocument &doc, QDomElement &element,

// look for RasterSymbolizer tag
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
if ( elements.size() == 0)
if ( elements.size() == 0 )
return;

// there SHOULD be only one
QDomElement rasterSymbolizerElem = elements.at(0).toElement();
QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();

// add Channel Selection tags
QDomElement channelSelectionElem = doc.createElement( QStringLiteral( "sld:ChannelSelection" ) );
@@ -284,7 +284,7 @@ void QgsPalettedRasterRenderer::toSld( QDomDocument &doc, QDomElement &element,
// e.g. <ColorMapEntry color="#EEBE2F" quantity="-300" label="label" opacity="0"/>
QList<QgsPalettedRasterRenderer::Class> classes = this->classes();
QList<QgsPalettedRasterRenderer::Class>::const_iterator classDataIt = classes.constBegin();
for (; classDataIt != classes.constEnd(); ++classDataIt )
for ( ; classDataIt != classes.constEnd(); ++classDataIt )
{
QDomElement colorMapEntryElem = doc.createElement( QStringLiteral( "sld:ColorMapEntry" ) );
colorMapElem.appendChild( colorMapEntryElem );
@@ -1348,15 +1348,15 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
if ( hasScaleBasedVisibility() )
{
// note that denominator is the inverted value of scale
if ( maximumScale() != 0.0)
if ( maximumScale() != 0.0 )
{
QDomElement minScaleElem = doc.createElement( QStringLiteral( "sld:MinScaleDenominator" ) );
minScaleElem.appendChild( doc.createTextNode( QString::number( maximumScale() ) ) );
typeStyleRuleElem.appendChild( minScaleElem );
}

QDomElement maxScaleElem = doc.createElement( QStringLiteral( "sld:MaxScaleDenominator" ) );
maxScaleElem.appendChild( doc.createTextNode( QString::number( minimumScale() ) ) );
maxScaleElem.appendChild( doc.createTextNode( QString::number( minimumScale() ) ) );
typeStyleRuleElem.appendChild( maxScaleElem );
}

@@ -1370,10 +1370,10 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
if ( elements.size() != 0 )
{
// there SHOULD be only one
QDomElement rasterSymbolizerElem = elements.at(0).toElement();
QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();

// lamda helper used below to reduce code redundancy
auto vendorOptionWriter = [&](QString name, QString value)
auto vendorOptionWriter = [&]( QString name, QString value )
{
QDomElement vendorOptionElem = doc.createElement( QStringLiteral( "sld:VendorOption" ) );
vendorOptionElem.setAttribute( QStringLiteral( "name" ), name );
@@ -1385,19 +1385,19 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
if ( hueSaturationFilter()->grayscaleMode() != QgsHueSaturationFilter::GrayscaleOff )
{
QString property;
switch( hueSaturationFilter()->grayscaleMode() )
switch ( hueSaturationFilter()->grayscaleMode() )
{
case (QgsHueSaturationFilter::GrayscaleLightness):
property = QStringLiteral( "lightness" );
break;
case (QgsHueSaturationFilter::GrayscaleLuminosity):
property = QStringLiteral( "luminosity" );
break;
case (QgsHueSaturationFilter::GrayscaleAverage):
property = QStringLiteral( "average" );
break;
default:
break;
case ( QgsHueSaturationFilter::GrayscaleLightness ):
property = QStringLiteral( "lightness" );
break;
case ( QgsHueSaturationFilter::GrayscaleLuminosity ):
property = QStringLiteral( "luminosity" );
break;
case ( QgsHueSaturationFilter::GrayscaleAverage ):
property = QStringLiteral( "average" );
break;
default:
break;
}
if ( !property.isEmpty() )
vendorOptionWriter( QStringLiteral( "grayScale" ), property );
@@ -1421,7 +1421,7 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
{
// normlize value [-100:100] -> [0:1]
int s = hueSaturationFilter()->saturation();
double sF = ( s - (-100.0) ) / (100.0 - (-100.0) );
double sF = ( s - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
vendorOptionWriter( QStringLiteral( "saturation" ), QString::number( sF ) );
}
}
@@ -1431,7 +1431,7 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
{
// normalize value [-255:255] -> [0:1]
int b = brightnessFilter()->brightness();
double bF = ( b - (-255.0) ) / (255.0 - (-255.0) );
double bF = ( b - ( -255.0 ) ) / ( 255.0 - ( -255.0 ) );
vendorOptionWriter( QStringLiteral( "brightness" ), QString::number( bF ) );
}

@@ -1440,8 +1440,8 @@ bool QgsRasterLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
{
// normlize value [-100:100] -> [0:1]
int c = brightnessFilter()->contrast();
double cF = ( c - (-100.0) ) / (100.0 - (-100.0) );
vendorOptionWriter( QStringLiteral( "contrast" ), QString::number(cF ) );
double cF = ( c - ( -100.0 ) ) / ( 100.0 - ( -100.0 ) );
vendorOptionWriter( QStringLiteral( "contrast" ), QString::number( cF ) );
}

// TODO: check if the below mapping formula make sense to map QGIS contrast with SLD gamma value
@@ -113,7 +113,8 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
//! Sets origin of min/max values
void setMinMaxOrigin( const QgsRasterMinMaxOrigin &origin ) { mMinMaxOrigin = origin; }

/*! Used from subclasses to create SLD Rule elements following SLD v1.0 specs
/**
* Used from subclasses to create SLD Rule elements following SLD v1.0 specs
* \since QGIS 3.6 */
virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const;

@@ -228,11 +228,11 @@ void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element,

// look for RasterSymbolizer tag
QDomNodeList elements = element.elementsByTagName( QStringLiteral( "sld:RasterSymbolizer" ) );
if ( elements.size() == 0)
if ( elements.size() == 0 )
return;

// there SHOULD be only one
QDomElement rasterSymbolizerElem = elements.at(0).toElement();
QDomElement rasterSymbolizerElem = elements.at( 0 ).toElement();

// add Channel Selection tags
// Need to insert channelSelection in the correct sequence as in SLD standard e.g.
@@ -241,14 +241,14 @@ void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element,
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Opacity" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at(0) );
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
elements = rasterSymbolizerElem.elementsByTagName( QStringLiteral( "sld:Geometry" ) );
if ( elements.size() != 0 )
{
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at(0) );
rasterSymbolizerElem.insertAfter( channelSelectionElem, elements.at( 0 ) );
}
else
{
@@ -289,12 +289,12 @@ void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element,
QDomNodeList elements = contrastEnhancementElem.elementsByTagName( QStringLiteral( "sld:VendorOption" ) );
for ( int i = 0; i < elements.size(); ++i )
{
QDomElement vendorOption = elements.at(i).toElement();
if ( vendorOption.attribute( QStringLiteral( "name" ) ) != QStringLiteral( "minValue" ))
QDomElement vendorOption = elements.at( i ).toElement();
if ( vendorOption.attribute( QStringLiteral( "name" ) ) != QStringLiteral( "minValue" ) )
continue;

// remove old value and add the new one
vendorOption.removeChild(vendorOption.firstChild());
vendorOption.removeChild( vendorOption.firstChild() );
vendorOption.appendChild( doc.createTextNode( QString::number( myRasterBandStats.minimumValue ) ) );
}
}
@@ -325,27 +325,27 @@ void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element,
// each ContrastEnhancementAlgorithm need a specfic management.
// set type of ColorMap ramp [ramp, intervals, values]
// basing on interpolation algorithm of the raster shader
QList< QPair< QString, QColor > > colorMapping(classes);
QList< QPair< QString, QColor > > colorMapping( classes );
switch ( contrastEnhancement()->contrastEnhancementAlgorithm() )
{
case ( QgsContrastEnhancement::StretchAndClipToMinimumMaximum ):
case ( QgsContrastEnhancement::ClipToMinimumMaximum ):
{
QString lowValue = classes[0].first;
QColor lowColor = classes[0].second;
lowColor.setAlpha(0);
lowColor.setAlpha( 0 );
QString highValue = classes[1].first;
QColor highColor = classes[1].second;
highColor.setAlpha(0);
highColor.setAlpha( 0 );

colorMapping.prepend( QPair< QString, QColor >( lowValue, lowColor));
colorMapping.append( QPair< QString, QColor >( highValue, highColor));
colorMapping.prepend( QPair< QString, QColor >( lowValue, lowColor ) );
colorMapping.append( QPair< QString, QColor >( highValue, highColor ) );
break;
}
case ( QgsContrastEnhancement::NoEnhancement ):
break;
case ( QgsContrastEnhancement::StretchToMinimumMaximum ):
// use default
// use default
default:
{
colorMapping[0].first = QStringLiteral( "0" );
@@ -356,7 +356,7 @@ void QgsSingleBandGrayRenderer::toSld( QDomDocument &doc, QDomElement &element,

// create tags
QList< QPair< QString, QColor > >::ConstIterator it;
for ( it = colorMapping.begin(); it != colorMapping.constEnd() ; ++it)
for ( it = colorMapping.begin(); it != colorMapping.constEnd() ; ++it )
{
// set low level color mapping
QDomElement lowColorMapEntryElem = doc.createElement( QStringLiteral( "sld:ColorMapEntry" ) );

0 comments on commit 0e9af79

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