Skip to content

Commit

Permalink
Add an edit button for shapeburst and gradient color ramps
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 25, 2014
1 parent 8224a16 commit 1f6dd8e
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 16 deletions.
2 changes: 2 additions & 0 deletions python/gui/symbology-ng/qgssymbollayerv2widget.sip
Expand Up @@ -134,6 +134,7 @@ class QgsGradientFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void setColor( const QColor& color );
void setColor2( const QColor& color );
void applyColorRamp();
void on_mButtonEditRamp_clicked();
void setGradientType( int index );
void setCoordinateMode( int index );
void setGradientSpread( int index );
Expand Down Expand Up @@ -170,6 +171,7 @@ class QgsShapeburstFillSymbolLayerV2Widget : QgsSymbolLayerV2Widget
void on_mDistanceUnitWidget_changed( );
void on_mRadioUseWholeShape_toggled( bool value );
void applyColorRamp();
void on_mButtonEditRamp_clicked();
void offsetChanged();
void on_mOffsetUnitWidget_changed( );
void on_mDataDefinedPropertiesButton_clicked();
Expand Down
48 changes: 48 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp 100755 → 100644
Expand Up @@ -26,6 +26,8 @@
#include "qgssymbolv2selectordialog.h"
#include "qgssvgcache.h"
#include "qgssymbollayerv2utils.h"
#include "qgsvectorcolorrampv2.h"
#include "qgsvectorgradientcolorrampv2dialog.h"

#include "qgsstylev2.h" //for symbol selector dialog

Expand Down Expand Up @@ -959,6 +961,29 @@ void QgsGradientFillSymbolLayerV2Widget::applyColorRamp()
emit changed();
}

void QgsGradientFillSymbolLayerV2Widget::on_mButtonEditRamp_clicked()
{
if ( mLayer->colorRamp()->type() == "gradient" )
{
QgsVectorColorRampV2* ramp = mLayer->colorRamp()->clone();
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );

if ( dlg.exec() && gradRamp )
{
mLayer->setColorRamp( gradRamp );
cboGradientColorRamp->blockSignals( true );
cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
cboGradientColorRamp->blockSignals( false );
emit changed();
}
else
{
delete ramp;
}
}
}

void QgsGradientFillSymbolLayerV2Widget::setGradientType( int index )
{
switch ( index )
Expand Down Expand Up @@ -1325,6 +1350,29 @@ void QgsShapeburstFillSymbolLayerV2Widget::applyColorRamp()
emit changed();
}

void QgsShapeburstFillSymbolLayerV2Widget::on_mButtonEditRamp_clicked()
{
if ( mLayer->colorRamp()->type() == "gradient" )
{
QgsVectorColorRampV2* ramp = mLayer->colorRamp()->clone();
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );

if ( dlg.exec() && gradRamp )
{
mLayer->setColorRamp( gradRamp );
cboGradientColorRamp->blockSignals( true );
cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
cboGradientColorRamp->blockSignals( false );
emit changed();
}
else
{
delete ramp;
}
}
}

void QgsShapeburstFillSymbolLayerV2Widget::offsetChanged()
{
if ( mLayer )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -182,6 +182,7 @@ class GUI_EXPORT QgsGradientFillSymbolLayerV2Widget : public QgsSymbolLayerV2Wid
void setColor( const QColor& color );
void setColor2( const QColor& color );
void applyColorRamp();
void on_mButtonEditRamp_clicked();
void setGradientType( int index );
void setCoordinateMode( int index );
void setGradientSpread( int index );
Expand Down Expand Up @@ -224,6 +225,7 @@ class GUI_EXPORT QgsShapeburstFillSymbolLayerV2Widget : public QgsSymbolLayerV2W
void on_mDistanceUnitWidget_changed( );
void on_mRadioUseWholeShape_toggled( bool value );
void applyColorRamp();
void on_mButtonEditRamp_clicked();
void offsetChanged();
void on_mOffsetUnitWidget_changed( );
void on_mDataDefinedPropertiesButton_clicked();
Expand Down
38 changes: 23 additions & 15 deletions src/ui/symbollayer/widget_gradientfill.ui
Expand Up @@ -14,21 +14,12 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<property name="horizontalSpacing">
<number>28</number>
</property>
<property name="margin">
<number>1</number>
</property>
<item row="0" column="0">
<widget class="QRadioButton" name="radioTwoColor">
<property name="text">
Expand Down Expand Up @@ -102,7 +93,24 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorRampComboBox" name="cboGradientColorRamp"/>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QgsColorRampComboBox" name="cboGradientColorRamp"/>
</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>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
Expand Down Expand Up @@ -408,7 +416,7 @@
</widget>
</item>
<item>
<widget class="QgsUnitSelectionWidget" name="mOffsetUnitWidget"/>
<widget class="QgsUnitSelectionWidget" name="mOffsetUnitWidget" native="true"/>
</item>
</layout>
</item>
Expand Down Expand Up @@ -448,7 +456,7 @@
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QComboBox</extends>
<extends>QWidget</extends>
<header>qgsunitselectionwidget.h</header>
<container>1</container>
</customwidget>
Expand Down
19 changes: 18 additions & 1 deletion src/ui/symbollayer/widget_shapeburstfill.ui
Expand Up @@ -90,7 +90,24 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorRampComboBox" name="cboGradientColorRamp"/>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QgsColorRampComboBox" name="cboGradientColorRamp"/>
</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>
</layout>
</item>
</layout>
</widget>
Expand Down

0 comments on commit 1f6dd8e

Please sign in to comment.