Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 745f91d
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 118 deletions.
15 changes: 15 additions & 0 deletions python/gui/symbology-ng/qgscolorrampcombobox.sip
Expand Up @@ -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();
};
2 changes: 0 additions & 2 deletions python/gui/symbology-ng/qgssymbollayerv2widget.sip
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
32 changes: 3 additions & 29 deletions src/gui/effects/qgspainteffectwidget.cpp
Expand Up @@ -24,7 +24,6 @@
#include "qgscoloreffect.h"
#include "qgsstylev2.h"
#include "qgsvectorcolorrampv2.h"
#include "qgsvectorgradientcolorrampv2dialog.h"

//
// draw source
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
//
Expand Down
2 changes: 1 addition & 1 deletion src/gui/effects/qgspainteffectwidget.h
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Expand Up @@ -46,6 +46,7 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(

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

if ( !mRasterLayer )
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Expand Up @@ -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;
Expand Down
55 changes: 55 additions & 0 deletions src/gui/symbology-ng/qgscolorrampcombobox.cpp
Expand Up @@ -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 ) :
Expand Down Expand Up @@ -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();
}
}
}
15 changes: 15 additions & 0 deletions src/gui/symbology-ng/qgscolorrampcombobox.h
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Expand Up @@ -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() ) );
Expand All @@ -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() ) );
Expand Down
26 changes: 3 additions & 23 deletions src/gui/symbology-ng/qgsheatmaprendererwidget.cpp
Expand Up @@ -21,7 +21,6 @@
#include "qgslogger.h"
#include "qgsvectorlayer.h"
#include "qgsvectorcolorrampv2.h"
#include "qgsvectorgradientcolorrampv2dialog.h"
#include "qgsstylev2.h"
#include "qgsproject.h"
#include <QGridLayout>
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
Expand Down
1 change: 0 additions & 1 deletion src/gui/symbology-ng/qgsheatmaprendererwidget.h
Expand Up @@ -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 );
Expand Down
52 changes: 5 additions & 47 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -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 ) ) );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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 )
Expand Down
2 changes: 0 additions & 2 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 8 additions & 0 deletions src/ui/qgscategorizedsymbolrendererv2widget.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -203,6 +210,7 @@
<tabstops>
<tabstop>btnChangeCategorizedSymbol</tabstop>
<tabstop>cboCategorizedColorRamp</tabstop>
<tabstop>mButtonEditRamp</tabstop>
<tabstop>cbxInvertedColorRamp</tabstop>
<tabstop>viewCategories</tabstop>
<tabstop>btnAddCategories</tabstop>
Expand Down

0 comments on commit 745f91d

Please sign in to comment.