QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
QgsColorUtils Class Reference

Contains utility functions for working with colors. More...

#include <qgscolorutils.h>

Static Public Member Functions

static QColor colorFromString (const QString &string)
 Decodes a string into a color value.
 
static QString colorToString (const QColor &color)
 Encodes a color into a string value.
 
static QColorSpace iccProfile (const QString &iccProfileFilePath, QString &errorMsg)
 Loads an ICC profile from iccProfileFilePath and returns associated color space.
 
static QColor readXml (const QDomElement &element, const QString &identifier, const QgsReadWriteContext &context)
 Reads a color from an XML element, matching the specified identifier string.
 
static QString saveIccProfile (const QColorSpace &colorSpace, const QString &iccProfileFilePath)
 Save color space colorSpace to an ICC profile file iccProfileFilePath.
 
static Qgis::ColorModel toColorModel (QColorSpace::ColorModel colorModel, bool *ok=nullptr)
 Convert and returns Qt colorModel to Qgis::ColorModel.
 
static void writeXml (const QColor &color, const QString &identifier, QDomDocument &document, QDomElement &element, const QgsReadWriteContext &context)
 Writes a color to an XML element, storing it under the specified identifier.
 

Detailed Description

Contains utility functions for working with colors.

Since
QGIS 3.28

Definition at line 37 of file qgscolorutils.h.

Member Function Documentation

◆ colorFromString()

QColor QgsColorUtils::colorFromString ( const QString &  string)
static

Decodes a string into a color value.

This method losslessly retrieves a color's definition from a string value. All properties of the color are restored, including the color specification and original values of the color's components. It is therefore suitable for restoring high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.

An invalid color will be returned if the color could not be read.

See also
colorToString()

Definition at line 296 of file qgscolorutils.cpp.

◆ colorToString()

QString QgsColorUtils::colorToString ( const QColor &  color)
static

Encodes a color into a string value.

This method losslessly stores a color's definition into a single string value. All properties of the color are stored, including the color specification and original values of the color's components. It is therefore suitable for storing high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.

See also
colorFromString()

Definition at line 193 of file qgscolorutils.cpp.

◆ iccProfile()

QColorSpace QgsColorUtils::iccProfile ( const QString &  iccProfileFilePath,
QString &  errorMsg 
)
static

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

Parameters
iccProfileFilePathICC profile file path
errorMsgWill be set to a user-friendly message if an error occurs while loading the ICC profile file
Returns
loaded color space
Since
QGIS 3.40

Definition at line 358 of file qgscolorutils.cpp.

◆ readXml()

QColor QgsColorUtils::readXml ( const QDomElement &  element,
const QString &  identifier,
const QgsReadWriteContext context 
)
static

Reads a color from an XML element, matching the specified identifier string.

This method losslessly retrieves a color's definition from an XML element. All properties of the color are restored, including the color specification and original values of the color's components. It is therefore suitable for restoring high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.

An invalid color will be returned if the color could not be read.

See also
writeXml()

Definition at line 142 of file qgscolorutils.cpp.

◆ saveIccProfile()

QString QgsColorUtils::saveIccProfile ( const QColorSpace &  colorSpace,
const QString &  iccProfileFilePath 
)
static

Save color space colorSpace to an ICC profile file iccProfileFilePath.

Returns
error message if an error occurred else empty string.
Since
QGIS 3.40

Definition at line 381 of file qgscolorutils.cpp.

◆ toColorModel()

Qgis::ColorModel QgsColorUtils::toColorModel ( QColorSpace::ColorModel  colorModel,
bool *  ok = nullptr 
)
static

Convert and returns Qt colorModel to Qgis::ColorModel.

ok is set to true if colorModel is a valid Qgis::ColorModel.

Note
Not available in Python bindings
Since
QGIS 3.40

Definition at line 398 of file qgscolorutils.cpp.

◆ writeXml()

void QgsColorUtils::writeXml ( const QColor &  color,
const QString &  identifier,
QDomDocument &  document,
QDomElement &  element,
const QgsReadWriteContext context 
)
static

Writes a color to an XML element, storing it under the specified identifier.

This method losslessly stores a color's definition in an XML element. All properties of the color are stored, including the color specification and original values of the color's components. It is therefore suitable for storing high color depth colors (such as 16 bit colors), or colors using alternative specifications such as CMYK colors.

The identifier string is used to specify the element name for the stored color, allowing for multiple color definitions to be stored in a single element (assuming each uses a unique identifier string).

See also
readXml()

Definition at line 27 of file qgscolorutils.cpp.


The documentation for this class was generated from the following files: