Skip to content

Commit

Permalink
fix(CMYK): treat review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Jul 11, 2024
1 parent 7e527d1 commit 43062c8
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 77 deletions.
4 changes: 2 additions & 2 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5145,8 +5145,8 @@
# --
Qgis.SensorThingsEntity.baseClass = Qgis
# monkey patching scoped based enum
Qgis.ColorModel.Rgb.__doc__ = ""
Qgis.ColorModel.Cmyk.__doc__ = ""
Qgis.ColorModel.Rgb.__doc__ = "RGB color model"
Qgis.ColorModel.Cmyk.__doc__ = "CMYK color model"
Qgis.ColorModel.__doc__ = "Color model types\n\n.. versionadded:: 3.40\n\n" + '* ``Rgb``: ' + Qgis.ColorModel.Rgb.__doc__ + '\n' + '* ``Cmyk``: ' + Qgis.ColorModel.Cmyk.__doc__
# --
Qgis.ColorModel.baseClass = Qgis
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,17 @@ Returns the style database to use for project specific styles.

void setColorModel( Qgis::ColorModel colorModel );
%Docstring
Set project ``colorModel``
Set the project's color model to ``colorModel``

It would serve as default color model when selecting a color in the whole application.
This sets the default color model used when selecting a color in the whole application.
Any color defined in a different color model than the one specified here will be converted to
this color model when exporting a layout.

If a color space has already been set and its color model differs from ``colorModel``, project
color space is set to invalid one. :py:func:`setColorSpace` colorSpace()
If a color space has already been set and its color model differs from ``colorModel``, the project
color space will be reset to invalid one (This is only true if QGIS is built against
Qt 6.8.0 or greater). :py:func:`setColorSpace` colorSpace()

defaults to :py:class:`Qgis`.ColorModel.Rgb
The color model defaults to :py:class:`Qgis`.ColorModel.Rgb

.. seealso:: :py:func:`colorModel`

Expand All @@ -161,13 +162,13 @@ defaults to :py:class:`Qgis`.ColorModel.Rgb

Qgis::ColorModel colorModel() const;
%Docstring
Returns project color model
Returns the project's color model

Used as default color model when selecting a color in the whole application.
Any color defined in a different color model than the returned will be converted to
this color model when exporting a layout
This model is used as the default color model when selecting a color in the whole application.
Any color defined in a different color model than the returned model will be converted to
this color model when exporting a layout.

defaults to :py:class:`Qgis`.ColorModel.Rgb
The color model defaults to :py:class:`Qgis`.ColorModel.Rgb

.. seealso:: :py:func:`setColorModel`

Expand All @@ -176,16 +177,17 @@ defaults to :py:class:`Qgis`.ColorModel.Rgb

void setColorSpace( const QColorSpace &colorSpace );
%Docstring
Set project current ``colorSpace``. ``colorSpace`` must be a valid RGB or CMYK color space.
Color space ICC profile will be added as a project attached file.
Set the project's current color space to ``colorSpace``. ``colorSpace`` must be a valid RGB or CMYK color space.
The color space's ICC profile will be added as a project attached file.

Project color space will be added to PDF layout export if defined (meaning different from
The project color's space will be added to PDF layout exports when it is defined (i.e. it is different from
the default invalid QColorSpace).

If a color model has already been set and it differs from ``colorSpace`` color model, project
color model is set to ``colorSpace`` one. :py:func:`setColorModel` colorModel()
If a color model has already been set and it differs from ``colorSpace``'s color model, the project's
color model is set to match the color space's color model (This is only true if QGIS is built against
Qt 6.8.0 or greater). :py:func:`setColorModel` colorModel()

defaults to invalid color space
The color space defaults to an invalid color space.

.. seealso:: :py:func:`colorSpace`

Expand All @@ -194,12 +196,12 @@ defaults to invalid color space

QColorSpace colorSpace() const;
%Docstring
Returns current project color space.
Returns the project's color space.

Project color space will be added to PDF layout export if defined (meaning different from
The project color's space will be added to PDF layout exports when it is defined (i.e. it is different from
the default invalid QColorSpace).

defaults to invalid color space
The color space defaults to an invalid color space.

.. seealso:: :py:func:`setColorSpace`

Expand Down
2 changes: 1 addition & 1 deletion python/PyQt6/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ The development version
enum class ColorModel /BaseType=IntEnum/
{
Rgb,
Cmyk
Cmyk,
};

static const double DEFAULT_SEARCH_RADIUS_MM;
Expand Down
11 changes: 9 additions & 2 deletions python/PyQt6/core/auto_generated/qgscolorutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@ An invalid color will be returned if the color could not be read.
.. seealso:: :py:func:`colorToString`
%End

static QColorSpace iccProfile( const QString &iccProfileFilePath, QString &errorMsg );
static QColorSpace iccProfile( const QString &iccProfileFilePath, QString &errorMsg /Out/ );
%Docstring
Load ``iccProfileFilePath`` and returns associated color space.
Loads an ICC profile from ``iccProfileFilePath`` and returns associated color space.
If an error occurred, an invalid color space is returned and ``errorMsg`` is updated with error
message

:param iccProfileFilePath: ICC profile file path

:return: - loaded color space
- errorMsg: Will be set to a user-friendly message if an error occurs while loading the ICC profile file

.. versionadded:: 3.40
%End


Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5063,8 +5063,8 @@
# --
Qgis.SensorThingsEntity.baseClass = Qgis
# monkey patching scoped based enum
Qgis.ColorModel.Rgb.__doc__ = ""
Qgis.ColorModel.Cmyk.__doc__ = ""
Qgis.ColorModel.Rgb.__doc__ = "RGB color model"
Qgis.ColorModel.Cmyk.__doc__ = "CMYK color model"
Qgis.ColorModel.__doc__ = "Color model types\n\n.. versionadded:: 3.40\n\n" + '* ``Rgb``: ' + Qgis.ColorModel.Rgb.__doc__ + '\n' + '* ``Cmyk``: ' + Qgis.ColorModel.Cmyk.__doc__
# --
Qgis.ColorModel.baseClass = Qgis
Expand Down
40 changes: 21 additions & 19 deletions python/core/auto_generated/project/qgsprojectstylesettings.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,17 @@ Returns the style database to use for project specific styles.

void setColorModel( Qgis::ColorModel colorModel );
%Docstring
Set project ``colorModel``
Set the project's color model to ``colorModel``

It would serve as default color model when selecting a color in the whole application.
This sets the default color model used when selecting a color in the whole application.
Any color defined in a different color model than the one specified here will be converted to
this color model when exporting a layout.

If a color space has already been set and its color model differs from ``colorModel``, project
color space is set to invalid one. :py:func:`setColorSpace` colorSpace()
If a color space has already been set and its color model differs from ``colorModel``, the project
color space will be reset to invalid one (This is only true if QGIS is built against
Qt 6.8.0 or greater). :py:func:`setColorSpace` colorSpace()

defaults to :py:class:`Qgis`.ColorModel.Rgb
The color model defaults to :py:class:`Qgis`.ColorModel.Rgb

.. seealso:: :py:func:`colorModel`

Expand All @@ -161,13 +162,13 @@ defaults to :py:class:`Qgis`.ColorModel.Rgb

Qgis::ColorModel colorModel() const;
%Docstring
Returns project color model
Returns the project's color model

Used as default color model when selecting a color in the whole application.
Any color defined in a different color model than the returned will be converted to
this color model when exporting a layout
This model is used as the default color model when selecting a color in the whole application.
Any color defined in a different color model than the returned model will be converted to
this color model when exporting a layout.

defaults to :py:class:`Qgis`.ColorModel.Rgb
The color model defaults to :py:class:`Qgis`.ColorModel.Rgb

.. seealso:: :py:func:`setColorModel`

Expand All @@ -176,16 +177,17 @@ defaults to :py:class:`Qgis`.ColorModel.Rgb

void setColorSpace( const QColorSpace &colorSpace );
%Docstring
Set project current ``colorSpace``. ``colorSpace`` must be a valid RGB or CMYK color space.
Color space ICC profile will be added as a project attached file.
Set the project's current color space to ``colorSpace``. ``colorSpace`` must be a valid RGB or CMYK color space.
The color space's ICC profile will be added as a project attached file.

Project color space will be added to PDF layout export if defined (meaning different from
The project color's space will be added to PDF layout exports when it is defined (i.e. it is different from
the default invalid QColorSpace).

If a color model has already been set and it differs from ``colorSpace`` color model, project
color model is set to ``colorSpace`` one. :py:func:`setColorModel` colorModel()
If a color model has already been set and it differs from ``colorSpace``'s color model, the project's
color model is set to match the color space's color model (This is only true if QGIS is built against
Qt 6.8.0 or greater). :py:func:`setColorModel` colorModel()

defaults to invalid color space
The color space defaults to an invalid color space.

.. seealso:: :py:func:`colorSpace`

Expand All @@ -194,12 +196,12 @@ defaults to invalid color space

QColorSpace colorSpace() const;
%Docstring
Returns current project color space.
Returns the project's color space.

Project color space will be added to PDF layout export if defined (meaning different from
The project color's space will be added to PDF layout exports when it is defined (i.e. it is different from
the default invalid QColorSpace).

defaults to invalid color space
The color space defaults to an invalid color space.

.. seealso:: :py:func:`setColorSpace`

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -2889,7 +2889,7 @@ The development version
enum class ColorModel
{
Rgb,
Cmyk
Cmyk,
};

static const double DEFAULT_SEARCH_RADIUS_MM;
Expand Down
11 changes: 9 additions & 2 deletions python/core/auto_generated/qgscolorutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@ An invalid color will be returned if the color could not be read.
.. seealso:: :py:func:`colorToString`
%End

static QColorSpace iccProfile( const QString &iccProfileFilePath, QString &errorMsg );
static QColorSpace iccProfile( const QString &iccProfileFilePath, QString &errorMsg /Out/ );
%Docstring
Load ``iccProfileFilePath`` and returns associated color space.
Loads an ICC profile from ``iccProfileFilePath`` and returns associated color space.
If an error occurred, an invalid color space is returned and ``errorMsg`` is updated with error
message

:param iccProfileFilePath: ICC profile file path

:return: - loaded color space
- errorMsg: Will be set to a user-friendly message if an error occurs while loading the ICC profile file

.. versionadded:: 3.40
%End


Expand Down
14 changes: 9 additions & 5 deletions src/core/project/qgsprojectstylesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ bool QgsProjectStyleSettings::readXml( const QDomElement &element, const QgsRead
{
mRandomizeDefaultSymbolColor = element.attribute( QStringLiteral( "RandomizeDefaultSymbolColor" ), QStringLiteral( "0" ) ).toInt();
mDefaultSymbolOpacity = element.attribute( QStringLiteral( "DefaultSymbolOpacity" ), QStringLiteral( "1.0" ) ).toDouble();
mColorModel = QgsXmlUtils::readFlagAttribute( element, QStringLiteral( "colorModel" ), Qgis::ColorModel::Rgb );
mColorModel = qgsEnumKeyToValue( element.attribute( QStringLiteral( "colorModel" ) ), Qgis::ColorModel::Rgb );

QDomElement elem = element.firstChildElement( QStringLiteral( "markerSymbol" ) );
if ( !elem.isNull() )
Expand Down Expand Up @@ -268,6 +268,9 @@ bool QgsProjectStyleSettings::readXml( const QDomElement &element, const QgsRead
{
QString errorMsg;
QColorSpace colorSpace = QgsColorUtils::iccProfile( mIccProfileFilePath, errorMsg );
if ( !errorMsg.isEmpty() )
context.pushMessage( errorMsg );

setColorSpace( colorSpace );
}

Expand All @@ -283,9 +286,7 @@ QDomElement QgsProjectStyleSettings::writeXml( QDomDocument &doc, const QgsReadW
element.setAttribute( QStringLiteral( "RandomizeDefaultSymbolColor" ), mRandomizeDefaultSymbolColor ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
element.setAttribute( QStringLiteral( "DefaultSymbolOpacity" ), QString::number( mDefaultSymbolOpacity ) );

const QMetaEnum metaEnum = QMetaEnum::fromType<Qgis::ColorModel>();
const QString colorModel( metaEnum.valueToKeys( static_cast<int>( mColorModel ) ) );
element.setAttribute( QStringLiteral( "colorModel" ), colorModel );
element.setAttribute( QStringLiteral( "colorModel" ), qgsEnumValueToKey( mColorModel ) );

if ( mDefaultMarkerSymbol )
{
Expand Down Expand Up @@ -336,7 +337,10 @@ QDomElement QgsProjectStyleSettings::writeXml( QDomDocument &doc, const QgsReadW
element.setAttribute( QStringLiteral( "projectStyleId" ), mProject->attachmentIdentifier( mProjectStyle->fileName() ) );
}

element.setAttribute( QStringLiteral( "iccProfileId" ), mProject->attachmentIdentifier( mIccProfileFilePath ) );
if ( mProject )
{
element.setAttribute( QStringLiteral( "iccProfileId" ), mProject->attachmentIdentifier( mIccProfileFilePath ) );
}

return element;
}
Expand Down
40 changes: 21 additions & 19 deletions src/core/project/qgsprojectstylesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,60 +146,62 @@ class CORE_EXPORT QgsProjectStyleSettings : public QObject
QgsStyle *projectStyle();

/**
* Set project \a colorModel
* Set the project's color model to \a colorModel
*
* It would serve as default color model when selecting a color in the whole application.
* This sets the default color model used when selecting a color in the whole application.
* Any color defined in a different color model than the one specified here will be converted to
* this color model when exporting a layout.
*
* If a color space has already been set and its color model differs from \a colorModel, project
* color space is set to invalid one. \see setColorSpace() colorSpace()
* If a color space has already been set and its color model differs from \a colorModel, the project
* color space will be reset to invalid one (This is only true if QGIS is built against
* Qt 6.8.0 or greater). \see setColorSpace() colorSpace()
*
* defaults to Qgis::ColorModel::Rgb
* The color model defaults to Qgis::ColorModel::Rgb
*
* \see colorModel()
* \since QGIS 3.40
*/
void setColorModel( Qgis::ColorModel colorModel );

/**
* Returns project color model
* Returns the project's color model
*
* Used as default color model when selecting a color in the whole application.
* Any color defined in a different color model than the returned will be converted to
* this color model when exporting a layout
* This model is used as the default color model when selecting a color in the whole application.
* Any color defined in a different color model than the returned model will be converted to
* this color model when exporting a layout.
*
* defaults to Qgis::ColorModel::Rgb
* The color model defaults to Qgis::ColorModel::Rgb
*
* \see setColorModel()
* \since QGIS 3.40
*/
Qgis::ColorModel colorModel() const;

/**
* Set project current \a colorSpace. \a colorSpace must be a valid RGB or CMYK color space.
* Color space ICC profile will be added as a project attached file.
* Set the project's current color space to \a colorSpace. \a colorSpace must be a valid RGB or CMYK color space.
* The color space's ICC profile will be added as a project attached file.
*
* Project color space will be added to PDF layout export if defined (meaning different from
* The project color's space will be added to PDF layout exports when it is defined (i.e. it is different from
* the default invalid QColorSpace).
*
* If a color model has already been set and it differs from \a colorSpace color model, project
* color model is set to \a colorSpace one. \see setColorModel() colorModel()
* If a color model has already been set and it differs from \a colorSpace's color model, the project's
* color model is set to match the color space's color model (This is only true if QGIS is built against
* Qt 6.8.0 or greater). \see setColorModel() colorModel()
*
* defaults to invalid color space
* The color space defaults to an invalid color space.
*
* \see colorSpace()
* \since QGIS 3.40
*/
void setColorSpace( const QColorSpace &colorSpace );

/**
* Returns current project color space.
* Returns the project's color space.
*
* Project color space will be added to PDF layout export if defined (meaning different from
* The project color's space will be added to PDF layout exports when it is defined (i.e. it is different from
* the default invalid QColorSpace).
*
* defaults to invalid color space
* The color space defaults to an invalid color space.
*
* \see setColorSpace()
* \since QGIS 3.40
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -5137,8 +5137,8 @@ class CORE_EXPORT Qgis
*/
enum class ColorModel : int
{
Rgb,
Cmyk
Rgb, //!< RGB color model
Cmyk, //!< CMYK color model
};
Q_ENUM( ColorModel )

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscolorutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ QColorSpace QgsColorUtils::iccProfile( const QString &iccProfileFilePath, QStrin

Qgis::ColorModel QgsColorUtils::toColorModel( QColorSpace::ColorModel colorModel, bool *ok )
{
bool lok;
bool lok = false;
Qgis::ColorModel res;
switch ( colorModel )
{
Expand Down
Loading

0 comments on commit 43062c8

Please sign in to comment.