Skip to content
Permalink
Browse files

Add 'edit' buttons to remaining gradient combo boxes

Also consolidate code for easier maintenance.
  • Loading branch information
nyalldawson committed Aug 4, 2015
1 parent 688ac16 commit 745f91d24932d3b4d836507cfd36c5a13b3661b8
@@ -33,4 +33,19 @@ class QgsColorRampComboBox : QComboBox

public slots:
void colorRampChanged( int index );

/** Triggers a dialog which allows users to edit the current source
* ramp for the combo box.
* @see sourceRampEdited
* @note added in QGIS 2.12
*/
void editSourceRamp();

signals:

/** Emitted when the user has edited the current source ramp.
* @see editSourceRamp
* @note added in QGIS 2.12
*/
void sourceRampEdited();
};
@@ -146,7 +146,6 @@ 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 );
@@ -182,7 +181,6 @@ 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_mIgnoreRingsCheckBox_stateChanged( int state );
@@ -24,7 +24,6 @@
#include "qgscoloreffect.h"
#include "qgsstylev2.h"
#include "qgsvectorcolorrampv2.h"
#include "qgsvectorgradientcolorrampv2dialog.h"

//
// draw source
@@ -425,6 +424,9 @@ QgsGlowWidget::QgsGlowWidget( QWidget *parent )
mRampComboBox->populate( QgsStyleV2::defaultStyle() );
mRampComboBox->setShowGradientOnly( true );
connect( mRampComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
connect( mRampComboBox, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), mRampComboBox, SLOT( editSourceRamp() ) );

connect( radioSingleColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );

initGui();
@@ -601,34 +603,6 @@ void QgsGlowWidget::applyColorRamp()
emit changed();
}

void QgsGlowWidget::on_mButtonEditRamp_clicked()
{
if ( !mEffect )
{
return;
}

if ( mEffect->ramp() && mEffect->ramp()->type() == "gradient" )
{
QgsVectorColorRampV2* ramp = mEffect->ramp()->clone();
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );

if ( dlg.exec() && gradRamp )
{
mEffect->setRamp( gradRamp );
mRampComboBox->blockSignals( true );
mRampComboBox->setSourceColorRamp( mEffect->ramp() );
mRampComboBox->blockSignals( false );
emit changed();
}
else
{
delete ramp;
}
}
}

//
// transform
//
@@ -184,7 +184,7 @@ class GUI_EXPORT QgsGlowWidget : public QgsPaintEffectWidget, private Ui::Widget
void on_mBlurRadiusSpnBx_valueChanged( int value );
void on_mTranspSlider_valueChanged( int value );
void applyColorRamp();
void on_mButtonEditRamp_clicked();

};

#include "ui_widget_transform.h"
@@ -46,6 +46,7 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(

QgsDebugMsg( "defaultPalette = " + defaultPalette );
mColorRampComboBox->setCurrentIndex( mColorRampComboBox->findText( defaultPalette ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), mColorRampComboBox, SLOT( editSourceRamp() ) );

if ( !mRasterLayer )
{
@@ -440,6 +440,8 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
connect( btnAddCategory, SIGNAL( clicked() ), this, SLOT( addCategory() ) );
connect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ), this, SLOT( applyColorRamp() ) );
connect( cboCategorizedColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
connect( cboCategorizedColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), cboCategorizedColorRamp, SLOT( editSourceRamp() ) );

// menus for data-defined rotation/size
QMenu* advMenu = new QMenu;
@@ -19,6 +19,11 @@
#include "qgsstylev2.h"
#include "qgsstylev2managerdialog.h"

#include "qgsvectorgradientcolorrampv2dialog.h"
#include "qgsvectorrandomcolorrampv2dialog.h"
#include "qgsvectorcolorbrewercolorrampv2dialog.h"
#include "qgscptcitycolorrampv2dialog.h"

QSize QgsColorRampComboBox::rampIconSize( 50, 16 );

QgsColorRampComboBox::QgsColorRampComboBox( QWidget *parent ) :
@@ -126,3 +131,53 @@ void QgsColorRampComboBox::colorRampChanged( int index )
// make sure the color ramp is stored
mStyle->save();
}

void QgsColorRampComboBox::editSourceRamp()
{
QgsVectorColorRampV2* currentRamp = currentColorRamp();
if ( !currentRamp )
return;

QScopedPointer<QgsVectorColorRampV2> newRamp( currentRamp->clone() );

if ( newRamp->type() == "gradient" )
{
QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( newRamp.data() );
QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );
if ( dlg.exec() && gradRamp )
{
setSourceColorRamp( gradRamp );
emit sourceRampEdited();
}
}
else if ( newRamp->type() == "random" )
{
QgsVectorRandomColorRampV2* randRamp = static_cast<QgsVectorRandomColorRampV2*>( newRamp.data() );
QgsVectorRandomColorRampV2Dialog dlg( randRamp, this );
if ( dlg.exec() && randRamp )
{
setSourceColorRamp( randRamp );
emit sourceRampEdited();
}
}
else if ( newRamp->type() == "colorbrewer" )
{
QgsVectorColorBrewerColorRampV2* brewerRamp = static_cast<QgsVectorColorBrewerColorRampV2*>( newRamp.data() );
QgsVectorColorBrewerColorRampV2Dialog dlg( brewerRamp, this );
if ( dlg.exec() && brewerRamp )
{
setSourceColorRamp( brewerRamp );
emit sourceRampEdited();
}
}
else if ( newRamp->type() == "cpt-city" )
{
QgsCptCityColorRampV2* cptCityRamp = static_cast<QgsCptCityColorRampV2*>( newRamp.data() );
QgsCptCityColorRampV2Dialog dlg( cptCityRamp, this );
if ( dlg.exec() && cptCityRamp )
{
setSourceColorRamp( cptCityRamp );
emit sourceRampEdited();
}
}
}
@@ -54,6 +54,21 @@ class GUI_EXPORT QgsColorRampComboBox : public QComboBox
public slots:
void colorRampChanged( int index );

/** Triggers a dialog which allows users to edit the current source
* ramp for the combo box.
* @see sourceRampEdited
* @note added in QGIS 2.12
*/
void editSourceRamp();

signals:

/** Emitted when the user has edited the current source ramp.
* @see editSourceRamp
* @note added in QGIS 2.12
*/
void sourceRampEdited();

protected:
QgsStyleV2* mStyle;
QgsVectorColorRampV2* mSourceColorRamp; // owns the copy
@@ -507,6 +507,8 @@ void QgsGraduatedSymbolRendererV2Widget::connectUpdateHandlers()
connect( spinGraduatedClasses, SIGNAL( valueChanged( int ) ), this, SLOT( classifyGraduated() ) );
connect( cboGraduatedMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( classifyGraduated() ) );
connect( cboGraduatedColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( reapplyColorRamp() ) );
connect( cboGraduatedColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( reapplyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), cboGraduatedColorRamp, SLOT( editSourceRamp() ) );
connect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ), this, SLOT( reapplyColorRamp() ) );
connect( spinPrecision, SIGNAL( valueChanged( int ) ), this, SLOT( labelFormatChanged() ) );
connect( cbxTrimTrailingZeroes, SIGNAL( toggled( bool ) ), this, SLOT( labelFormatChanged() ) );
@@ -525,6 +527,8 @@ void QgsGraduatedSymbolRendererV2Widget::disconnectUpdateHandlers()
disconnect( spinGraduatedClasses, SIGNAL( valueChanged( int ) ), this, SLOT( classifyGraduated() ) );
disconnect( cboGraduatedMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( classifyGraduated() ) );
disconnect( cboGraduatedColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( reapplyColorRamp() ) );
disconnect( cboGraduatedColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( reapplyColorRamp() ) );
disconnect( mButtonEditRamp, SIGNAL( clicked() ), cboGraduatedColorRamp, SLOT( editSourceRamp() ) );
disconnect( cbxInvertedColorRamp, SIGNAL( toggled( bool ) ), this, SLOT( reapplyColorRamp() ) );
disconnect( spinPrecision, SIGNAL( valueChanged( int ) ), this, SLOT( labelFormatChanged() ) );
disconnect( cbxTrimTrailingZeroes, SIGNAL( toggled( bool ) ), this, SLOT( labelFormatChanged() ) );
@@ -21,7 +21,6 @@
#include "qgslogger.h"
#include "qgsvectorlayer.h"
#include "qgsvectorcolorrampv2.h"
#include "qgsvectorgradientcolorrampv2dialog.h"
#include "qgsstylev2.h"
#include "qgsproject.h"
#include <QGridLayout>
@@ -68,6 +67,9 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer* layer, QgsSt
mRampComboBox->setShowGradientOnly( true );
mRampComboBox->populate( QgsStyleV2::defaultStyle() );
connect( mRampComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
connect( mRampComboBox, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), mRampComboBox, SLOT( editSourceRamp() ) );

if ( mRenderer->colorRamp() )
{
mRampComboBox->blockSignals( true );
@@ -115,28 +117,6 @@ void QgsHeatmapRendererWidget::applyColorRamp()
mRenderer->setColorRamp( ramp );
}

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

if ( dlg.exec() && gradRamp )
{
mRenderer->setColorRamp( gradRamp );
mRampComboBox->blockSignals( true );
mRampComboBox->setSourceColorRamp( mRenderer->colorRamp() );
mRampComboBox->blockSignals( false );
}
else
{
delete ramp;
}
}
}

void QgsHeatmapRendererWidget::on_mRadiusUnitWidget_changed()
{
if ( !mRenderer )
@@ -49,7 +49,6 @@ class GUI_EXPORT QgsHeatmapRendererWidget : public QgsRendererV2Widget, private
private slots:

void applyColorRamp();
void on_mButtonEditRamp_clicked();
void on_mRadiusUnitWidget_changed();
void on_mRadiusSpinBox_valueChanged( double d );
void on_mMaxSpinBox_valueChanged( double d );
@@ -755,6 +755,8 @@ QgsGradientFillSymbolLayerV2Widget::QgsGradientFillSymbolLayerV2Widget( const Qg
connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
connect( cboGradientType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientType( int ) ) );
connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
connect( cboGradientSpread, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientSpread( int ) ) );
@@ -948,29 +950,6 @@ 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 )
@@ -1102,10 +1081,12 @@ QgsShapeburstFillSymbolLayerV2Widget::QgsShapeburstFillSymbolLayerV2Widget( cons
spinOffsetX->setClearValue( 0.0 );
spinOffsetY->setClearValue( 0.0 );

cboGradientColorRamp->setShowGradientOnly( true );
cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );

connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );

connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
@@ -1297,29 +1278,6 @@ 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 )
@@ -197,7 +197,6 @@ 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 );
@@ -239,7 +238,6 @@ 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_mIgnoreRingsCheckBox_stateChanged( int state );
@@ -90,6 +90,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mButtonEditRamp">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxInvertedColorRamp">
<property name="text">
@@ -203,6 +210,7 @@
<tabstops>
<tabstop>btnChangeCategorizedSymbol</tabstop>
<tabstop>cboCategorizedColorRamp</tabstop>
<tabstop>mButtonEditRamp</tabstop>
<tabstop>cbxInvertedColorRamp</tabstop>
<tabstop>viewCategories</tabstop>
<tabstop>btnAddCategories</tabstop>

0 comments on commit 745f91d

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