QgsColorSchemeRegistry class

Registry of color schemes.

A registry of QgsColorScheme color schemes. This class can be created directly, or accessed via a QgsApplication::colorSchemeRegistry().

Constructors, destructors, conversion operators

QgsColorSchemeRegistry() defaulted
Constructor for an empty color scheme registry.

Public functions

void addColorScheme(QgsColorScheme* scheme)
Adds a color scheme to the registry.
void addDefaultSchemes()
Adds all default color schemes to this color scheme.
void addUserSchemes()
Creates schemes for all gpl palettes in the user's palettes folder.
auto fetchRandomStyleColor() const -> QColor
Returns a random color for use with a new symbol style (e.g.
void initStyleScheme()
Initializes the default random style color scheme for the user.
void populateFromInstance()
Adds all color schemes from the global instance to this color scheme.
auto randomStyleColorScheme() -> QgsColorScheme*
Returns the color scheme used when fetching random colors to use for symbol styles.
auto removeColorScheme(QgsColorScheme* scheme) -> bool
Removes all matching color schemes from the registry.
auto schemes() const -> QList<QgsColorScheme*>
Returns all color schemes in the registry.
auto schemes(QgsColorScheme::SchemeFlag flag) const -> QList<QgsColorScheme*>
Returns all color schemes in the registry which have a specified flag set.
template<class T>
void schemes(QList<T*>& schemeList)
Returns color schemes of a specific type.
void setRandomStyleColorScheme(QgsColorScheme* scheme)
Sets the color scheme to use when fetching random colors to use for symbol styles.

Function documentation

void QgsColorSchemeRegistry::addColorScheme(QgsColorScheme* scheme)

Adds a color scheme to the registry.

Parameters
scheme color scheme to add

Ownership of the scheme is transferred to the registry.

void QgsColorSchemeRegistry::addDefaultSchemes()

Adds all default color schemes to this color scheme.

void QgsColorSchemeRegistry::addUserSchemes()

Creates schemes for all gpl palettes in the user's palettes folder.

QColor QgsColorSchemeRegistry::fetchRandomStyleColor() const

Returns a random color for use with a new symbol style (e.g.

for a newly created map layer).

If a randomStyleColorScheme() is set then this color will be randomly taken from that color scheme. If no randomStyleColorScheme() is set then a totally random color will be generated.

Note that calling setRandomStyleColorScheme() takes a snapshot of the colors from the scheme's QgsColorScheme::fetchColors() list. Accordingly, any future changes to the colors in the scheme are not automatically reflected by calls to fetchRandomStyleColor(). If the scheme is updated, then another call to setRandomStyleColorScheme() must be made in order to update the cached list of available style colors from which fetchRandomStyleColor() selects colors.

This method is thread safe.

void QgsColorSchemeRegistry::initStyleScheme()

Initializes the default random style color scheme for the user.

void QgsColorSchemeRegistry::populateFromInstance()

Adds all color schemes from the global instance to this color scheme.

QgsColorScheme* QgsColorSchemeRegistry::randomStyleColorScheme()

Returns the color scheme used when fetching random colors to use for symbol styles.

This may be nullptr, in which case totally random colors are used for styles.

bool QgsColorSchemeRegistry::removeColorScheme(QgsColorScheme* scheme)

Removes all matching color schemes from the registry.

Parameters
scheme color scheme to remove
Returns true if scheme was found and removed

QList<QgsColorScheme*> QgsColorSchemeRegistry::schemes() const

Returns all color schemes in the registry.

Returns list of color schemes

QList<QgsColorScheme*> QgsColorSchemeRegistry::schemes(QgsColorScheme::SchemeFlag flag) const

Returns all color schemes in the registry which have a specified flag set.

Parameters
flag flag to match
Returns list of color schemes with flag set

template<class T>
void QgsColorSchemeRegistry::schemes(QList<T*>& schemeList)

Returns color schemes of a specific type.

Parameters
schemeList destination list for matching schemes

void QgsColorSchemeRegistry::setRandomStyleColorScheme(QgsColorScheme* scheme)

Sets the color scheme to use when fetching random colors to use for symbol styles.

scheme should match a color scheme which is already present in the registry.

Note that calling this method takes a snapshot of the colors from the scheme's QgsColorScheme::fetchColors() list. Accordingly, any future changes to the colors in scheme are not automatically reflected by calls to fetchRandomStyleColor(). If scheme is updated, then another call to setRandomStyleColorScheme() must be made in order to update the cached list of available style colors.