Skip to content
Permalink
Browse files

[symblogy] migrate heatmap renderer color ramp widget

  • Loading branch information
nirvn committed Dec 3, 2016
1 parent e604fc9 commit 56c55344553831e857d83abb9f84bb1d965bcd54
@@ -40,20 +40,6 @@ class QgsHeatmapRenderer : QgsFeatureRenderer
*/
void setColorRamp( QgsColorRamp* ramp /Transfer/ );

/** Returns whether the ramp is inverted
* @returns true if color ramp is inverted
* @see setInvertRamp
* @see colorRamp
*/
bool 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
* @see setRadius
@@ -40,7 +40,6 @@ QgsHeatmapRenderer::QgsHeatmapRenderer()
, mRadiusUnit( QgsUnitTypes::RenderMillimeters )
, mWeightAttrNum( -1 )
, mGradientRamp( nullptr )
, mInvertRamp( false )
, mExplicitMax( 0.0 )
, mRenderQuality( 3 )
, mFeaturesRendered( 0 )
@@ -255,7 +254,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( mInvertRamp ? 1 - pixVal : pixVal );
pixColor = mGradientRamp->color( pixVal );

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

@@ -356,7 +353,6 @@ QDomElement QgsHeatmapRenderer::save( QDomDocument& doc )
QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), mGradientRamp, doc );
rendererElem.appendChild( colorRampElem );
}
rendererElem.setAttribute( QStringLiteral( "invert_ramp" ), QString::number( mInvertRamp ) );
rendererElem.setAttribute( QStringLiteral( "forceraster" ), ( mForceRaster ? "1" : "0" ) );

if ( mPaintEffect && !QgsPaintEffectRegistry::isDefaultStack( mPaintEffect ) )
@@ -69,20 +69,6 @@ class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRenderer
*/
void setColorRamp( QgsColorRamp* ramp );

/** Returns whether the ramp is inverted
* @returns true if color ramp is inverted
* @see setInvertRamp
* @see colorRamp
*/
bool 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
@@ -192,7 +178,6 @@ class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRenderer
QScopedPointer<QgsExpression> mWeightExpression;

QgsColorRamp* mGradientRamp;
bool mInvertRamp;

double mExplicitMax;
int mRenderQuality;
@@ -21,6 +21,7 @@
#include "qgslogger.h"
#include "qgsvectorlayer.h"
#include "qgscolorramp.h"
#include "qgscolorrampbutton.h"
#include "qgsstyle.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
@@ -95,17 +96,15 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer* layer, QgsSt
mRenderer = new QgsHeatmapRenderer();
}

mRampComboBox->setShowGradientOnly( true );
mRampComboBox->populate( QgsStyle::defaultStyle() );
connect( mRampComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
connect( mRampComboBox, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), mRampComboBox, SLOT( editSourceRamp() ) );
btnColorRamp->setShowGradientOnly( true );

connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsHeatmapRendererWidget::applyColorRamp );

if ( mRenderer->colorRamp() )
{
mRampComboBox->blockSignals( true );
mRampComboBox->setSourceColorRamp( mRenderer->colorRamp() );
mRampComboBox->blockSignals( false );
btnColorRamp->blockSignals( true );
btnColorRamp->setColorRamp( mRenderer->colorRamp() );
btnColorRamp->blockSignals( false );
}
mRadiusSpinBox->blockSignals( true );
mRadiusSpinBox->setValue( mRenderer->radius() );
@@ -120,9 +119,6 @@ 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 );

mWeightExpressionWidget->setLayer( layer );
mWeightExpressionWidget->setField( mRenderer->weightExpression() );
@@ -148,7 +144,7 @@ void QgsHeatmapRendererWidget::applyColorRamp()
return;
}

QgsColorRamp* ramp = mRampComboBox->currentColorRamp();
QgsColorRamp* ramp = btnColorRamp->colorRamp();
if ( !ramp )
return;

@@ -201,17 +197,6 @@ void QgsHeatmapRendererWidget::on_mQualitySlider_valueChanged( int v )
emit widgetChanged();
}

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

mRenderer->setInvertRamp( v );
emit widgetChanged();
}

void QgsHeatmapRendererWidget::weightExpressionChanged( const QString& expression )
{
mRenderer->setWeightExpression( expression );
@@ -61,7 +61,6 @@ class GUI_EXPORT QgsHeatmapRendererWidget : public QgsRendererWidget, private Ui
void on_mRadiusSpinBox_valueChanged( double d );
void on_mMaxSpinBox_valueChanged( double d );
void on_mQualitySlider_valueChanged( int v );
void on_mInvertCheckBox_toggled( bool v );
void weightExpressionChanged( const QString& expression );

};
@@ -112,32 +112,34 @@
</item>
</layout>
</item>
<item row="0" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,0">
<item>
<widget class="QgsColorRampComboBox" name="mRampComboBox"/>
</item>
<item>
<widget class="QPushButton" name="mButtonEditRamp">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mInvertCheckBox">
<property name="text">
<string>Invert</string>
</property>
</widget>
</item>
</layout>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Color ramp</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QgsColorRampButton" name="btnColorRamp">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
@@ -219,15 +221,14 @@
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorRampComboBox</class>
<extends>QComboBox</extends>
<header>qgscolorrampcombobox.h</header>
<class>QgsColorRampButton</class>
<extends>QToolButton</extends>
<header>qgscolorrampbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mRampComboBox</tabstop>
<tabstop>mButtonEditRamp</tabstop>
<tabstop>mInvertCheckBox</tabstop>
<tabstop>btnColorRamp</tabstop>
<tabstop>mRadiusSpinBox</tabstop>
<tabstop>mMaxSpinBox</tabstop>
<tabstop>mWeightExpressionWidget</tabstop>

0 comments on commit 56c5534

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