Skip to content
Permalink
Browse files

Nyall's comments

  • Loading branch information
pierreloicq authored and nyalldawson committed Sep 14, 2018
1 parent c921d2e commit 6443df655890dd7820162c1d9e0b2c23fc0a7d9b
@@ -325,27 +325,27 @@ Reset the label decimal places to a numberbased on the minimum class interval
const QString &attrName,
int classes,
Mode mode,
bool useSymmetricMode,
double symmetryPoint,
QStringList listForCboPrettyBreaks,
bool astride,
QgsSymbol *symbol /Transfer/,
QgsColorRamp *ramp /Transfer/,
const QgsRendererRangeLabelFormat &legendFormat = QgsRendererRangeLabelFormat() );
const QgsRendererRangeLabelFormat &legendFormat = QgsRendererRangeLabelFormat(),
bool useSymmetricMode = false,
double symmetryPoint = 0.0,
QStringList listForCboPrettyBreaks = {},
bool astride = false);
%Docstring
Creates a new graduated renderer.

:param vlayer: vector layer
:param attrName: attribute to classify
:param classes: number of classes
:param mode: classification mode
:param symbol: base symbol
:param ramp: color ramp for classes
:param legendFormat:
:param useSymmetricMode: A bool indicating if we want to have classes and hence colors ramp symmetric around a value
:param symmetryPoint: The value around which the classes will be symmetric if useSymmetricMode is checked
:param listForCboPrettyBreaks: The list of potential pivot values for symmetric mode with prettybreaks mode
:param astride: A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
:param symbol: base symbol
:param ramp: color ramp for classes
:param legendFormat:

:return: new QgsGraduatedSymbolRenderer object
%End
@@ -518,7 +518,9 @@ Gets the symbol which is used to represent ``value``.
Returns the matching legend key for a value.
%End



QStringList mListForCboPrettyBreaks = {};

private:
QgsGraduatedSymbolRenderer( const QgsGraduatedSymbolRenderer & );
QgsGraduatedSymbolRenderer &operator=( const QgsGraduatedSymbolRenderer & );
@@ -288,8 +288,6 @@ QgsGraduatedSymbolRenderer::QgsGraduatedSymbolRenderer( const QString &attrName,
{
mRanges << range;
}
mUseSymmetricMode = false;
mAstride = false;
}

QgsGraduatedSymbolRenderer::~QgsGraduatedSymbolRenderer()
@@ -555,7 +553,7 @@ static void _makeBreaksSymmetric( QList<double> &breaks, double symmetryPoint, b
}
}
// remove symmetry point
if ( true == astride ) // && breaks.indexOf( symmetryPoint ) != -1) // if symmetryPoint is found
if ( astride ) // && breaks.indexOf( symmetryPoint ) != -1) // if symmetryPoint is found
{
breaks.removeAt( breaks.indexOf( symmetryPoint ) );
}
@@ -567,7 +565,7 @@ static QList<double> _calcEqualIntervalBreaks( double minimum, double maximum, i
// Equal interval algorithm
// Returns breaks based on dividing the range ('minimum' to 'maximum') into 'classes' parts.
QList<double> breaks;
if ( false == useSymmetricMode ) // nomal mode
if ( !useSymmetricMode ) // nomal mode
{
double step = ( maximum - minimum ) / classes;

@@ -582,24 +580,25 @@ static QList<double> _calcEqualIntervalBreaks( double minimum, double maximum, i
// set the last break to be exactly maximum so we do not miss it
breaks[classes - 1] = maximum;
}
else if ( true == useSymmetricMode ) // symmetric mode
else if ( useSymmetricMode ) // symmetric mode
{
double distBelowSymmetricValue = std::abs( minimum - symmetryPoint );
double distAboveSymmetricValue = std::abs( maximum - symmetryPoint ) ;

if ( true == astride )
if ( astride )
{
( 0 == classes % 2 ) ? ++classes : classes; // we want odd number of classes
if ( classes % 2 == 0 ) // we want odd number of classes
++classes;
}
else
{
( 1 == classes % 2 ) ? ++classes : classes; // we want even number of classes
if ( classes % 2 == 1 ) // we want even number of classes
++classes;
}
double step = 2 * std::min( distBelowSymmetricValue, distAboveSymmetricValue ) / classes;

double value;
breaks.reserve( classes );
value = ( distBelowSymmetricValue < distAboveSymmetricValue ) ? minimum : maximum - classes * step;
double value = ( distBelowSymmetricValue < distAboveSymmetricValue ) ? minimum : maximum - classes * step;

for ( int i = 0; i < classes; i++ )
{
@@ -689,7 +688,7 @@ static QList<double> _calcStdDevBreaks( QList<double> values, int classes, QList
}
stdDev = std::sqrt( stdDev / n );

if ( false == useSymmetricMode )
if ( !useSymmetricMode )
symmetryPoint = mean; // otherwise symmetryPoint = symmetryPoint

QList<double> breaks = QgsSymbolLayerUtils::prettyBreaks( ( minimum - symmetryPoint ) / stdDev, ( maximum - symmetryPoint ) / stdDev, classes );
@@ -833,28 +832,28 @@ static QList<double> _calcJenksBreaks( QList<double> values, int classes,
return breaks.toList();
} //_calcJenksBreaks

static QStringList _breaksAsStrings( QList<double> breaks ) // get QStringList from QList<double> without maxi break (min is not in)
static QStringList _breaksAsStrings( const QList<double> &breaks ) // get QStringList from QList<double> without maxi break (min is not in)
{
QStringList breaksAsTrings;
QStringList breaksAsStrings;
for ( int i = 0; i < breaks.count() - 1; i++ )
{
breaksAsTrings << QString::number( breaks.at( i ), 'f', 2 );
breaksAsStrings << QString::number( breaks.at( i ), 'f', 2 );
}
return breaksAsTrings;
return breaksAsStrings;
}

QgsGraduatedSymbolRenderer *QgsGraduatedSymbolRenderer::createRenderer(
QgsVectorLayer *vlayer,
const QString &attrName,
int classes,
Mode mode,
QgsSymbol *symbol,
QgsColorRamp *ramp,
const QgsRendererRangeLabelFormat &labelFormat,
bool useSymmetricMode,
double symmetryPoint,
QStringList listForCboPrettyBreaks,
bool astride,
QgsSymbol *symbol,
QgsColorRamp *ramp,
const QgsRendererRangeLabelFormat &labelFormat
bool astride
)
{
QgsRangeList ranges;
@@ -926,7 +925,7 @@ void QgsGraduatedSymbolRenderer::updateClasses( QgsVectorLayer *vlayer, Mode mod
breaks = QgsSymbolLayerUtils::prettyBreaks( minimum, maximum, nclasses );
setListForCboPrettyBreaks( _breaksAsStrings( breaks ) );

if ( true == useSymmetricMode )
if ( useSymmetricMode )
_makeBreaksSymmetric( breaks, symmetryPoint, astride );
}
else if ( mode == Quantile || mode == Jenks || mode == StdDev )
@@ -1082,7 +1081,7 @@ QgsFeatureRenderer *QgsGraduatedSymbolRenderer::create( QDomElement &element, co
QString symmetricPointString = symmetricModeElem.attribute( QStringLiteral( "symmetryPoint" ) );
r->setSymmetryPoint( symmetricPointString.toDouble() );
QString breaksForPretty = symmetricModeElem.attribute( QStringLiteral( "valueForCboPrettyBreaks" ) );
r->setListForCboPrettyBreaks( breaksForPretty.split( "/" ) );
r->setListForCboPrettyBreaks( breaksForPretty.split( '/' ) );

QString astrideEnabled = symmetricModeElem.attribute( QStringLiteral( "astride" ) );
astrideEnabled == QLatin1String( "true" ) ? r->setAstride( true ) : r->setAstride( false );
@@ -1215,7 +1214,7 @@ QDomElement QgsGraduatedSymbolRenderer::save( QDomDocument &doc, const QgsReadWr
for ( int i = 0; i < mListForCboPrettyBreaks.size() - 1; i++ ) // -1 to write 1/2/3 instead of 1/2/3/
{
breaks.append( mListForCboPrettyBreaks.at( i ) );
breaks.append( QStringLiteral( "/" ) );
breaks.append( '/' );
}
if ( mListForCboPrettyBreaks.size() > 0 ) //make sure we can go at size-1
breaks.append( mListForCboPrettyBreaks.at( mListForCboPrettyBreaks.size() - 1 ) ); //add the last break
@@ -309,26 +309,26 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer : public QgsFeatureRenderer
* \param attrName attribute to classify
* \param classes number of classes
* \param mode classification mode
* \param symbol base symbol
* \param ramp color ramp for classes
* \param legendFormat
* \param useSymmetricMode A bool indicating if we want to have classes and hence colors ramp symmetric around a value
* \param symmetryPoint The value around which the classes will be symmetric if useSymmetricMode is checked
* \param listForCboPrettyBreaks The list of potential pivot values for symmetric mode with prettybreaks mode
* \param astride A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
* \param symbol base symbol
* \param ramp color ramp for classes
* \param legendFormat
* \returns new QgsGraduatedSymbolRenderer object
*/
static QgsGraduatedSymbolRenderer *createRenderer( QgsVectorLayer *vlayer,
const QString &attrName,
int classes,
Mode mode,
bool useSymmetricMode,
double symmetryPoint,
QStringList listForCboPrettyBreaks,
bool astride,
QgsSymbol *symbol SIP_TRANSFER,
QgsColorRamp *ramp SIP_TRANSFER,
const QgsRendererRangeLabelFormat &legendFormat = QgsRendererRangeLabelFormat() );
const QgsRendererRangeLabelFormat &legendFormat = QgsRendererRangeLabelFormat(),
bool useSymmetricMode = false,
double symmetryPoint = 0.0,
QStringList listForCboPrettyBreaks = {},
bool astride = false );

//! create renderer from XML element
static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
@@ -455,10 +455,6 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer : public QgsFeatureRenderer
QString mAttrName;
QgsRangeList mRanges;
Mode mMode = Custom;
bool mUseSymmetricMode;
double mSymmetryPoint;
QStringList mListForCboPrettyBreaks;
bool mAstride;
std::unique_ptr<QgsSymbol> mSourceSymbol;
std::unique_ptr<QgsColorRamp> mSourceColorRamp;
QgsRendererRangeLabelFormat mLabelFormat;
@@ -485,6 +481,11 @@ class CORE_EXPORT QgsGraduatedSymbolRenderer : public QgsFeatureRenderer
//! \note not available in Python bindings
static const char *graduatedMethodStr( GraduatedMethod method ) SIP_SKIP;

bool mUseSymmetricMode = false;
double mSymmetryPoint = 0.0;
QStringList mListForCboPrettyBreaks = {};
bool mAstride = false;

private:

/**
@@ -641,7 +641,7 @@ void QgsGraduatedSymbolRendererWidget::updateUiFromRenderer( bool updateCount )
spinSymmetryPointForOtherMethods->setValue( mRenderer->symmetryPoint() );
}

if ( true == mRenderer->useSymmetricMode() )
if ( mRenderer->useSymmetricMode() )
{
cbxClassifySymmetric->setChecked( true );
spinSymmetryPointForOtherMethods->setEnabled( true );
@@ -656,12 +656,11 @@ void QgsGraduatedSymbolRendererWidget::updateUiFromRenderer( bool updateCount )
cboSymmetryPointForPretty->setEnabled( false );
}

if ( true == mRenderer->astride() )
if ( mRenderer->astride() )
cbxAstride->setChecked( true );
else
cbxAstride->setChecked( false );


// Only update class count if different - otherwise typing value gets very messy
int nclasses = mRenderer->ranges().count();
if ( nclasses && updateCount )
@@ -886,7 +885,7 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
{
useSymmetricMode = true;
symmetryPoint = spinSymmetryPointForOtherMethods->value();
cbxAstride->isChecked() ? astride = true : astride = false;
astride = cbxAstride->isChecked();
}
}
else if ( cboGraduatedMode->currentIndex() == 2 ) // Jenks
@@ -905,7 +904,7 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
{
useSymmetricMode = true;
symmetryPoint = spinSymmetryPointForOtherMethods->value();
cbxAstride->isChecked() ? astride = true : astride = false;
astride = cbxAstride->isChecked();
}
}
else if ( cboGraduatedMode->currentIndex() == 4 ) // Pretty
@@ -914,7 +913,7 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
if ( cbxClassifySymmetric->isChecked() )
{
useSymmetricMode = true;
cbxAstride->isChecked() ? astride = true : astride = false;
astride = cbxAstride->isChecked();
symmetryPoint = cboSymmetryPointForPretty->currentText().toDouble(); //selected number
}
}

0 comments on commit 6443df6

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