Skip to content

Commit

Permalink
Add support for setting the color model to use when interpolating a
Browse files Browse the repository at this point in the history
gradient ramp

Some gradients will pass through murky grey mid-tones when interpolating
using red/green/blue channels. Interpolating via
hue/saturation/lightness/value channels can avoid these desaturated
mid tones, resulting in more visually pleasing gradients.

The color spec can be set per stop in a multi-stop gradient, and there's
also an option to control the direction which interpolation should
follow for the Hue component of a HSL/HSV color spec interpolation.

Sponsored by North Road, thanks to SLYR
  • Loading branch information
nyalldawson committed Nov 10, 2021
1 parent aaca87c commit acabfb3
Show file tree
Hide file tree
Showing 10 changed files with 770 additions and 54 deletions.
109 changes: 109 additions & 0 deletions python/core/auto_generated/qgscolorrampimpl.sip.in
Expand Up @@ -8,6 +8,7 @@




class QgsGradientStop
{
%Docstring(signature="appended")
Expand All @@ -33,6 +34,61 @@ Constructor for QgsGradientStop
QColor color;

bool operator==( const QgsGradientStop &other ) const;

bool operator!=( const QgsGradientStop &other ) const;

QColor::Spec colorSpec() const;
%Docstring
Returns the color specification in which the color component interpolation will occur.

For multi-stop gradients this color spec will be used for the portion of the color ramp
leading into the current stop.

.. seealso:: :py:func:`setColorSpec`

.. versionadded:: 3.24
%End

void setColorSpec( QColor::Spec spec );
%Docstring
Sets the color specification in which the color component interpolation will occur.

Only QColor.Spec.Rgb, QColor.Spec.Hsv and QColor.Spec.Hsl are currently supported.

For multi-stop gradients this color spec will be used for the portion of the color ramp
leading into the current stop.

.. seealso:: :py:func:`colorSpec`

.. versionadded:: 3.24
%End

Qgis::AngularDirection direction() const;
%Docstring
Returns the direction to traverse the color wheel using when interpolating hue-based color
specifications.

For multi-stop gradients this direction will be used for the portion of the color ramp
leading into the current stop.

.. seealso:: :py:func:`setDirection`

.. versionadded:: 3.24
%End

void setDirection( Qgis::AngularDirection direction );
%Docstring
Sets the ``direction`` to traverse the color wheel using when interpolating hue-based color
specifications.

For multi-stop gradients this direction will be used for the portion of the color ramp
leading into the current stop.

.. seealso:: :py:func:`direction`

.. versionadded:: 3.24
%End

};

typedef QList<QgsGradientStop> QgsGradientStopsList;
Expand Down Expand Up @@ -207,9 +263,62 @@ Copy color ramp stops to a QGradient
by this factor before adding to the gradient.

.. versionadded:: 2.1
%End

QColor::Spec colorSpec() const;
%Docstring
Returns the color specification in which the color component interpolation will occur.

For multi-stop gradients this color spec will be used for the portion of the color ramp
leading into the final stop (i.e. :py:func:`~QgsGradientColorRamp.color2`).

.. seealso:: :py:func:`setColorSpec`

.. versionadded:: 3.24
%End

void setColorSpec( QColor::Spec spec );
%Docstring
Sets the color specification in which the color component interpolation will occur.

Only QColor.Spec.Rgb, QColor.Spec.Hsv and QColor.Spec.Hsl are currently supported.

For multi-stop gradients this color spec will be used for the portion of the color ramp
leading into the final stop (i.e. :py:func:`~QgsGradientColorRamp.color2`).

.. seealso:: :py:func:`colorSpec`

.. versionadded:: 3.24
%End

Qgis::AngularDirection direction() const;
%Docstring
Returns the direction to traverse the color wheel using when interpolating hue-based color
specifications.

For multi-stop gradients this direction will be used for the portion of the color ramp
leading into the final stop (i.e. :py:func:`~QgsGradientColorRamp.color2`).

.. seealso:: :py:func:`setDirection`

.. versionadded:: 3.24
%End

void setDirection( Qgis::AngularDirection direction );
%Docstring
Sets the ``direction`` to traverse the color wheel using when interpolating hue-based color
specifications.

For multi-stop gradients this direction will be used for the portion of the color ramp
leading into the final stop (i.e. :py:func:`~QgsGradientColorRamp.color2`).

.. seealso:: :py:func:`direction`

.. versionadded:: 3.24
%End

protected:

};


Expand Down
14 changes: 14 additions & 0 deletions python/gui/auto_generated/qgsgradientstopeditor.sip.in
Expand Up @@ -96,6 +96,20 @@ first or last stop is selected, as they cannot be repositioned.
.. seealso:: :py:func:`setSelectedStopColor`

.. seealso:: :py:func:`setSelectedStopDetails`
%End

void setSelectedStopColorSpec( QColor::Spec spec );
%Docstring
Sets the color ``spec`` for the current selected stop.

.. versionadded:: 3.24
%End

void setSelectedStopDirection( Qgis::AngularDirection direction );
%Docstring
Sets the hue angular direction for the current selected stop.

.. versionadded:: 3.24
%End

void setSelectedStopDetails( const QColor &color, double offset );
Expand Down

0 comments on commit acabfb3

Please sign in to comment.