Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix bad alloc when styling raster with random color ramp (fix #13112)
(cherry-picked from 688ac16)
  • Loading branch information
nyalldawson committed Aug 4, 2015
1 parent 3bcc2bc commit 5502222
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsvectorcolorrampv2.cpp
Expand Up @@ -374,7 +374,7 @@ QgsRandomColorsV2::~QgsRandomColorsV2()

int QgsRandomColorsV2::count() const
{
return INT_MAX;
return -1;
}

double QgsRandomColorsV2::value( int index ) const
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgsvectorcolorrampv2.h
Expand Up @@ -28,10 +28,12 @@ class CORE_EXPORT QgsVectorColorRampV2

virtual ~QgsVectorColorRampV2() {}

// Number of defined colors
/** Returns number of defined colors, or -1 if undefined
*/
virtual int count() const = 0;

// Relative value (0,1) of color at index
/** Returns relative value between [0,1] of color at specified index
*/
virtual double value( int index ) const = 0;

virtual QColor color( double value ) const = 0;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -350,6 +350,17 @@ void QgsSingleBandPseudoColorRendererWidget::on_mColorRampComboBox_currentIndexC
Q_UNUSED( index );
QSettings settings;
settings.setValue( "/Raster/defaultPalette", mColorRampComboBox->currentText() );

QgsVectorColorRampV2* ramp = mColorRampComboBox->currentColorRamp();
if ( !ramp )
return;

bool enableContinuous = ( ramp->count() > 0 );
mClassificationModeComboBox->setEnabled( enableContinuous );
if ( !enableContinuous )
{
mClassificationModeComboBox->setCurrentIndex( mClassificationModeComboBox->findData( EqualInterval ) );
}
}

void QgsSingleBandPseudoColorRendererWidget::populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems )
Expand Down

0 comments on commit 5502222

Please sign in to comment.