Skip to content
Permalink
Browse files

Add an invert checkbox for heatmap renderer

  • Loading branch information
nyalldawson committed Nov 22, 2014
1 parent 7277476 commit 802a4acdba0c7d22c138dce3dd6e72cd6f649bd0
@@ -37,6 +37,19 @@ class QgsHeatmapRenderer : QgsFeatureRendererV2
* @see colorRamp
*/
void setColorRamp( QgsVectorColorRampV2* ramp /Transfer/ );

/**Returns whether the ramp is inverted
* @returns true if color ramp is inverted
* @see setInvertRamp
* @see colorRamp
*/
double invertRamp() const;
/**Sets whether the ramp is inverted
* @param invert set to true to invert color ramp
* @see invertRamp
* @see setColorRamp
*/
void setInvertRamp( const bool invert );

/**Returns the radius for the heatmap
* @returns heatmap radius
@@ -34,6 +34,7 @@ QgsHeatmapRenderer::QgsHeatmapRenderer( )
, mRadius( 10 )
, mRadiusUnit( QgsSymbolV2::MM )
, mGradientRamp( 0 )
, mInvertRamp( false )
, mExplicitMax( 0.0 )
, mRenderQuality( 1 )
{
@@ -208,7 +209,7 @@ void QgsHeatmapRenderer::renderImage( QgsRenderContext& context )
pixVal = mValues.at( idx ) > 0 ? qMin(( mValues.at( idx ) / scaleMax ), 1.0 ) : 0;

//convert value to color from ramp
pixColor = mGradientRamp->color( pixVal );
pixColor = mGradientRamp->color( mInvertRamp ? 1 - pixVal : pixVal );

scanLine[widthIndex] = pixColor.rgba();
idx++;
@@ -239,6 +240,7 @@ QgsFeatureRendererV2* QgsHeatmapRenderer::clone() const
{
newRenderer->setColorRamp( mGradientRamp->clone() );
}
newRenderer->setInvertRamp( mInvertRamp );
newRenderer->setRadius( mRadius );
newRenderer->setRadiusUnit( mRadiusUnit );
newRenderer->setRadiusMapUnitScale( mRadiusMapUnitScale );
@@ -286,6 +288,7 @@ QgsFeatureRendererV2* QgsHeatmapRenderer::create( QDomElement& element )
{
r->setColorRamp( QgsSymbolLayerV2Utils::loadColorRamp( sourceColorRampElem ) );
}
r->setInvertRamp( element.attribute( "invert_ramp", "0" ).toInt() );
return r;
}

@@ -303,6 +306,7 @@ QDomElement QgsHeatmapRenderer::save( QDomDocument& doc )
QDomElement colorRampElem = QgsSymbolLayerV2Utils::saveColorRamp( "[source]", mGradientRamp, doc );
rendererElem.appendChild( colorRampElem );
}
rendererElem.setAttribute( "invert_ramp", QString::number( mInvertRamp ) );

return rendererElem;
}
@@ -67,6 +67,19 @@ class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRendererV2
*/
void setColorRamp( QgsVectorColorRampV2* ramp );

/**Returns whether the ramp is inverted
* @returns true if color ramp is inverted
* @see setInvertRamp
* @see colorRamp
*/
double invertRamp() const { return mInvertRamp; }
/**Sets whether the ramp is inverted
* @param invert set to true to invert color ramp
* @see invertRamp
* @see setColorRamp
*/
void setInvertRamp( const bool invert ) { mInvertRamp = invert; }

/**Returns the radius for the heatmap
* @returns heatmap radius
* @see setRadius
@@ -155,6 +168,7 @@ class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRendererV2
QgsMapUnitScale mRadiusMapUnitScale;

QgsVectorColorRampV2* mGradientRamp;
bool mInvertRamp;

double mExplicitMax;
int mRenderQuality;
@@ -97,6 +97,9 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer* layer, QgsSt
mQualitySlider->blockSignals( true );
mQualitySlider->setValue( mRenderer->renderQuality() );
mQualitySlider->blockSignals( false );
mInvertCheckBox->blockSignals( true );
mInvertCheckBox->setChecked( mRenderer->invertRamp() );
mInvertCheckBox->blockSignals( false );
}

QgsFeatureRendererV2* QgsHeatmapRendererWidget::renderer()
@@ -193,3 +196,13 @@ void QgsHeatmapRendererWidget::on_mQualitySlider_valueChanged( int v )

mRenderer->setRenderQuality( v );
}

void QgsHeatmapRendererWidget::on_mInvertCheckBox_toggled( bool v )
{
if ( !mRenderer )
{
return;
}

mRenderer->setInvertRamp( v );
}
@@ -54,6 +54,7 @@ class GUI_EXPORT QgsHeatmapRendererWidget : public QgsRendererV2Widget, private
void on_mRadiusSpinBox_valueChanged( double d );
void on_mMaxSpinBox_valueChanged( double d );
void on_mQualitySlider_valueChanged( int v );
void on_mInvertCheckBox_toggled( bool v );

};

@@ -15,7 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,0">
<item>
<widget class="QgsColorRampComboBox" name="mRampComboBox"/>
</item>
@@ -32,16 +32,23 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mInvertCheckBox">
<property name="text">
<string>Invert</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Radius</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QgsDoubleSpinBox" name="mRadiusSpinBox">
@@ -67,14 +74,14 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Maximum value</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QgsDoubleSpinBox" name="mMaxSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@@ -96,14 +103,14 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Rendering quality</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_4">
@@ -152,7 +159,7 @@
</item>
</layout>
</item>
<item row="4" column="1">
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -188,6 +195,7 @@
<tabstops>
<tabstop>mRampComboBox</tabstop>
<tabstop>mButtonEditRamp</tabstop>
<tabstop>mInvertCheckBox</tabstop>
<tabstop>mRadiusSpinBox</tabstop>
<tabstop>mMaxSpinBox</tabstop>
<tabstop>mQualitySlider</tabstop>

0 comments on commit 802a4ac

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