Skip to content

Commit

Permalink
Fix for bug 11366
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrook committed Oct 8, 2014
1 parent bb72302 commit 823b57e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class CORE_EXPORT QgsRendererRangeV2LabelFormat
double mNumberScale;
QString mNumberSuffix;
QRegExp mReTrailingZeroes;
QRegExp mReNegativeZero;
};

class QgsVectorLayer;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 823b57e

Please sign in to comment.