Skip to content
Permalink
Browse files
Live widget updates in graduated symbol renderer when symbol, breaks,
break type, field, or ramp changes.
  • Loading branch information
NathanW2 committed Feb 27, 2012
1 parent b86bb6f commit cda3693d584e02d076a4b28a6570af75d5c425db
@@ -1017,6 +1017,33 @@ void QgsGraduatedSymbolRendererV2::setSourceColorRamp( QgsVectorColorRampV2* ram
mSourceColorRamp = ramp;
}

void QgsGraduatedSymbolRendererV2::updateColorRamp( QgsVectorColorRampV2 *ramp )
{
int i = 0;
foreach( QgsRendererRangeV2 range, mRanges )
{
QgsSymbolV2* symbol = range.symbol()->clone();
double colorValue = ( mRanges.count() > 1 ? ( double ) i / ( mRanges.count() - 1 ) : 0 );
symbol->setColor( ramp->color( colorValue ) );
updateRangeSymbol( i, symbol );
++i;
}
this->setSourceColorRamp( ramp );
}

void QgsGraduatedSymbolRendererV2::updateSymbols( QgsSymbolV2 *sym )
{
int i = 0;
foreach( QgsRendererRangeV2 range, mRanges )
{
QgsSymbolV2* symbol = sym->clone();
symbol->setColor( range.symbol()->color() );
updateRangeSymbol( i, symbol );
++i;
}
this->setSourceSymbol( sym->clone() );
}

void QgsGraduatedSymbolRendererV2::addClass( QgsSymbolV2* symbol )
{
QgsSymbolV2* newSymbol = symbol->clone();
@@ -114,6 +114,14 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
QgsVectorColorRampV2* sourceColorRamp();
void setSourceColorRamp( QgsVectorColorRampV2* ramp );

/** Update the color ramp used. Also updates all symbols colors.
* Doesn't alter current breaks.
*/
void updateColorRamp( QgsVectorColorRampV2* ramp );

/** Update the all symbols but leave breaks and colors. */
void updateSymbols( QgsSymbolV2* sym );

//! @note added in 1.6
void setRotationField( QString fieldName ) { mRotationField = fieldName; }
//! @note added in 1.6
@@ -65,11 +65,13 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
connect( btnGraduatedDelete, SIGNAL( clicked() ), this, SLOT( deleteCurrentClass() ) );
connect( btnGraduatedAdd, SIGNAL( clicked() ), this, SLOT( addClass() ) );



// initialize from previously set renderer
updateUiFromRenderer();

connect( spinGraduatedClasses, SIGNAL( valueChanged( int ) ) , this, SLOT( classifyGraduated() ) );
connect( cboGraduatedMode, SIGNAL( currentIndexChanged( int ) ) , this, SLOT( classifyGraduated() ) );
connect( cboGraduatedColorRamp, SIGNAL( currentIndexChanged( int ) ) , this, SLOT( reapplyColorRamp() ) );

// menus for data-defined rotation/size
QMenu* advMenu = new QMenu;

@@ -145,6 +147,7 @@ void QgsGraduatedSymbolRendererV2Widget::populateColumns()
void QgsGraduatedSymbolRendererV2Widget::graduatedColumnChanged()
{
mRenderer->setClassAttribute( cboGraduatedColumn->currentText() );
classifyGraduated();
}


@@ -194,13 +197,25 @@ void QgsGraduatedSymbolRendererV2Widget::classifyGraduated()
populateRanges();
}

void QgsGraduatedSymbolRendererV2Widget::reapplyColorRamp()
{
QgsVectorColorRampV2* ramp = cboGraduatedColorRamp->currentColorRamp();
if ( ramp == NULL )
return;

mRenderer->updateColorRamp( ramp );
refreshSymbolView();
}

void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
{
QgsSymbolV2SelectorDialog dlg( mGraduatedSymbol, mStyle, mLayer, this );
if ( !dlg.exec() )
return;

updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol );
refreshSymbolView();
}

void QgsGraduatedSymbolRendererV2Widget::updateGraduatedSymbolIcon()
@@ -24,6 +24,7 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void changeGraduatedSymbol();
void graduatedColumnChanged();
void classifyGraduated();
void reapplyColorRamp();
void rangesDoubleClicked( const QModelIndex & idx );
void rangesClicked( const QModelIndex & idx );
void changeCurrentValue( QStandardItem * item );

0 comments on commit cda3693

Please sign in to comment.