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();
    }
  }
}
void QgsGraduatedSymbolRendererV2::updateColorRamp( QgsVectorColorRampV2 *ramp, bool inverted )
{
  int i = 0;
  if ( ramp )
  {
    setSourceColorRamp( ramp );
    setInvertedColorRamp( inverted );
  }

  if ( mSourceColorRamp )
  {
    foreach ( QgsRendererRangeV2 range, mRanges )
    {
      QgsSymbolV2 *symbol = range.symbol() ? range.symbol()->clone() : 0;
      if ( symbol )
      {
        double colorValue;
        if ( inverted )
          colorValue = ( mRanges.count() > 1 ? ( double )( mRanges.count() - i - 1 ) / ( mRanges.count() - 1 ) : 0 );
        else
          colorValue = ( mRanges.count() > 1 ? ( double ) i / ( mRanges.count() - 1 ) : 0 );
        symbol->setColor( mSourceColorRamp->color( colorValue ) );
      }
      updateRangeSymbol( i, symbol );
      ++i;
    }
  }
void QgsCategorizedSymbolRendererV2::updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted )
{
  setSourceColorRamp( ramp );
  setInvertedColorRamp( inverted );
  double num = mCategories.count() - 1;
  double count = 0;

  QgsRandomColorsV2* randomRamp = dynamic_cast<QgsRandomColorsV2*>( ramp );
  if ( randomRamp )
  {
    //ramp is a random colors ramp, so inform it of the total number of required colors
    //this allows the ramp to pregenerate a set of visually distinctive colors
    randomRamp->setTotalColorCount( mCategories.count() );
  }

  foreach ( const QgsRendererCategoryV2 &cat, mCategories )
  {
    double value = count / num;
    if ( mInvertedColorRamp ) value = 1.0 - value;
    cat.symbol()->setColor( mSourceColorRamp->color( value ) );
    count += 1;
  }