Skip to content
Permalink
Browse files

Merge pull request #1618 from ccrook/GraduatedRendererBugFix11366

Fix #11366 Customised graduated renderer labels ignored
  • Loading branch information
NathanW2 committed Oct 12, 2014
2 parents 62ad5ae + 823b57e commit 1770ec1a6b03cded7ac4a5ed6d833a39338ce9d4
@@ -63,7 +63,7 @@ class QgsRendererRangeV2LabelFormat
void setTrimTrailingZeroes( bool trimTrailingZeroes );

//! @note labelForLowerUpper in python bindings
QString labelForRange( double lower, double upper ) const;
QString labelForRange( double lower, double upper ) const /PyName=labelForLowerUpper/;
QString labelForRange( const QgsRendererRangeV2 &range ) const;
QString formatNumber( double value ) const;

@@ -165,7 +165,7 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
//! @param labelFormat The string appended to classification labels
//! @param updateRanges If true then ranges ending with the old unit string are updated to the new.
//! @note Added in 2.6
void setLabelFormat( const QgsRendererRangeV2LabelFormat &labelFormat, bool updateRanges = true );
void setLabelFormat( const QgsRendererRangeV2LabelFormat &labelFormat, bool updateRanges = false );

//! Reset the label decimal places to a numberbased on the minimum class interval
//! @param updateRanges if true then ranges currently using the default label will be updated
@@ -178,12 +178,14 @@ QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat():
mTrimTrailingZeroes( false ),
mNumberScale( 1.0 ),
mNumberSuffix( "" ),
mReTrailingZeroes( "[.,]?0*$" )
mReTrailingZeroes( "[.,]?0*$" ),
mReNegativeZero("^\\-0(?:[.,]0*)?$")
{
}

QgsRendererRangeV2LabelFormat::QgsRendererRangeV2LabelFormat( QString format, int precision, bool trimTrailingZeroes ):
mReTrailingZeroes( "[.,]?0*$" )
mReTrailingZeroes( "[.,]?0*$" ),
mReNegativeZero("^\\-0(?:[.,]0*)?$")
{
setFormat( format );
setPrecision( precision );
@@ -231,11 +233,13 @@ QString QgsRendererRangeV2LabelFormat::formatNumber( double value ) const
{
QString valueStr=QString::number( value, 'f', mPrecision );
if( mTrimTrailingZeroes ) valueStr=valueStr.replace(mReTrailingZeroes,"");
if( mReNegativeZero.exactMatch(valueStr)) valueStr=valueStr.mid(1);
return valueStr;
}
else
{
QString valueStr=QString::number( value*mNumberScale, 'f', 0 );
if( valueStr == "-0" ) valueStr="0";
if( valueStr != "0" ) valueStr=valueStr+mNumberSuffix;
return valueStr;
}
@@ -935,7 +939,7 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::createRenderer(
r->setSourceColorRamp( ramp->clone() );
r->setInvertedColorRamp( inverted );
r->setMode( mode );
r->setLabelFormat( labelFormat, false );
r->setLabelFormat( labelFormat );
r->updateClasses( vlayer, mode, classes );
return r;
}
@@ -104,6 +104,7 @@ class CORE_EXPORT QgsRendererRangeV2LabelFormat
double mNumberScale;
QString mNumberSuffix;
QRegExp mReTrailingZeroes;
QRegExp mReNegativeZero;
};

class QgsVectorLayer;
@@ -195,7 +196,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
//! @param labelFormat The string appended to classification labels
//! @param updateRanges If true then ranges ending with the old unit string are updated to the new.
//! @note Added in 2.6
void setLabelFormat( const QgsRendererRangeV2LabelFormat &labelFormat, bool updateRanges = true );
void setLabelFormat( const QgsRendererRangeV2LabelFormat &labelFormat, bool updateRanges = false );

//! Reset the label decimal places to a numberbased on the minimum class interval
//! @param updateRanges if true then ranges currently using the default label will be updated

0 comments on commit 1770ec1

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