Skip to content
Permalink
Browse files
Fix inverting ramps with color spec set
  • Loading branch information
nyalldawson committed Nov 10, 2021
1 parent b8e4eee commit 01315d63e94d97bc1b7fa14b28d93319ce3c4a69
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/core/qgscolorrampimpl.cpp
@@ -367,6 +367,7 @@ QString QgsGradientColorRamp::type() const
void QgsGradientColorRamp::invert()
{
QgsGradientStopsList newStops;
newStops.reserve( mStops.size() );

if ( mDiscrete )
{
@@ -388,6 +389,26 @@ void QgsGradientColorRamp::invert()
newStops << QgsGradientStop( 1 - mStops.at( k ).offset, mStops.at( k ).color );
}
}

// transfer color spec, invert directions
if ( mStops.empty() )
{
// reverse direction
mDirection = mDirection == Qgis::AngularDirection::Clockwise ? Qgis::AngularDirection::CounterClockwise : Qgis::AngularDirection::Clockwise;
}
else
{
newStops[0].setColorSpec( mColorSpec );
newStops[0].setDirection( mDirection == Qgis::AngularDirection::Clockwise ? Qgis::AngularDirection::CounterClockwise : Qgis::AngularDirection::Clockwise );
for ( int i = 1, j = mStops.size() - 1; i < mStops.size(); ++i, --j )
{
newStops[i].setColorSpec( mStops.at( j ).colorSpec() );
newStops[i].setDirection( mStops.at( j ).direction() == Qgis::AngularDirection::Clockwise ? Qgis::AngularDirection::CounterClockwise : Qgis::AngularDirection::Clockwise );
}
mColorSpec = mStops.at( 0 ).colorSpec();
mDirection = mStops.at( 0 ).direction() == Qgis::AngularDirection::Clockwise ? Qgis::AngularDirection::CounterClockwise : Qgis::AngularDirection::Clockwise;
}

mStops = newStops;
}

0 comments on commit 01315d6

Please sign in to comment.