Skip to content

Commit

Permalink
Live widget updates in graduated symbol renderer when symbol, breaks,
Browse files Browse the repository at this point in the history
break type, field, or ramp changes.
  • Loading branch information
NathanW2 committed Feb 27, 2012
1 parent b86bb6f commit cda3693
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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


Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit cda3693

Please sign in to comment.