QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
Classes | Signals | Public Member Functions | Static Public Member Functions | Properties | List of all members
QgsMapThemeCollection Class Reference

Container class that allows storage of map themes consisting of visible map layers and layer styles. More...

#include <qgsmapthemecollection.h>

Inheritance diagram for QgsMapThemeCollection:
Inheritance graph
[legend]

Classes

class  MapThemeLayerRecord
 Individual record of a visible layer in a map theme record. More...
 
class  MapThemeRecord
 Individual map theme record of visible layers and styles. More...
 

Signals

void mapThemeChanged (const QString &theme)
 Emitted when a map theme changes definition.
 
void mapThemeRenamed (const QString &name, const QString &newName)
 Emitted when a map theme within the collection is renamed.
 
void mapThemesChanged ()
 Emitted when map themes within the collection are changed.
 
void projectChanged ()
 Emitted when the project changes.
 

Public Member Functions

 QgsMapThemeCollection (QgsProject *project=nullptr)
 Create map theme collection that handles themes of the given project.
 
void applyTheme (const QString &name, QgsLayerTreeGroup *root, QgsLayerTreeModel *model)
 Apply theme given by its name and modify layer tree, current style of layers and checked legend items of passed layer tree model.
 
void clear ()
 Removes all map themes from the collection.
 
bool hasMapTheme (const QString &name) const
 Returns whether a map theme with a matching name exists.
 
void insert (const QString &name, const QgsMapThemeCollection::MapThemeRecord &state)
 Inserts a new map theme to the collection.
 
QStringList mapThemes () const
 Returns a list of existing map theme names.
 
QgsMapThemeCollection::MapThemeRecord mapThemeState (const QString &name) const
 Returns the recorded state of a map theme.
 
QMap< QString, QString > mapThemeStyleOverrides (const QString &name)
 Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
 
QStringList mapThemeVisibleLayerIds (const QString &name) const
 Returns the list of layer IDs that are visible for the specified map theme.
 
QList< QgsMapLayer * > mapThemeVisibleLayers (const QString &name) const
 Returns the list of layers that are visible for the specified map theme.
 
QList< QgsMapLayer * > masterLayerOrder () const
 Returns the master layer order (this will always match the project's QgsProject::layerOrder() ).
 
QList< QgsMapLayer * > masterVisibleLayers () const
 Returns the master list of visible layers.
 
QgsProjectproject ()
 Returns the QgsProject on which this map theme collection works.
 
void readXml (const QDomDocument &doc)
 Reads the map theme collection state from XML.
 
void removeMapTheme (const QString &name)
 Removes an existing map theme from collection.
 
bool renameMapTheme (const QString &name, const QString &newName)
 Renames the existing map theme called name to newName.
 
void setProject (QgsProject *project)
 Sets the project on which this map theme collection works.
 
void update (const QString &name, const QgsMapThemeCollection::MapThemeRecord &state)
 Updates a map theme within the collection.
 
void writeXml (QDomDocument &doc) const
 Writes the map theme collection state to XML.
 

Static Public Member Functions

static QgsMapThemeCollection::MapThemeRecord createThemeFromCurrentState (QgsLayerTreeGroup *root, QgsLayerTreeModel *model)
 Static method to create theme from the current state of layer visibilities in layer tree, current style of layers and check state of legend items (from a layer tree model).
 

Properties

QStringList mapThemes
 
QgsProjectproject
 

Detailed Description

Container class that allows storage of map themes consisting of visible map layers and layer styles.

Definition at line 43 of file qgsmapthemecollection.h.

Constructor & Destructor Documentation

◆ QgsMapThemeCollection()

QgsMapThemeCollection::QgsMapThemeCollection ( QgsProject project = nullptr)

Create map theme collection that handles themes of the given project.

Definition at line 27 of file qgsmapthemecollection.cpp.

Member Function Documentation

◆ applyTheme()

void QgsMapThemeCollection::applyTheme ( const QString &  name,
QgsLayerTreeGroup root,
QgsLayerTreeModel model 
)

Apply theme given by its name and modify layer tree, current style of layers and checked legend items of passed layer tree model.

Definition at line 202 of file qgsmapthemecollection.cpp.

◆ clear()

void QgsMapThemeCollection::clear ( )

Removes all map themes from the collection.

Definition at line 307 of file qgsmapthemecollection.cpp.

◆ createThemeFromCurrentState()

QgsMapThemeCollection::MapThemeRecord QgsMapThemeCollection::createThemeFromCurrentState ( QgsLayerTreeGroup root,
QgsLayerTreeModel model 
)
static

Static method to create theme from the current state of layer visibilities in layer tree, current style of layers and check state of legend items (from a layer tree model).

Definition at line 102 of file qgsmapthemecollection.cpp.

◆ hasMapTheme()

bool QgsMapThemeCollection::hasMapTheme ( const QString &  name) const

Returns whether a map theme with a matching name exists.

Definition at line 257 of file qgsmapthemecollection.cpp.

◆ insert()

void QgsMapThemeCollection::insert ( const QString &  name,
const QgsMapThemeCollection::MapThemeRecord state 
)

Inserts a new map theme to the collection.

See also
update()

Definition at line 262 of file qgsmapthemecollection.cpp.

◆ mapThemeChanged

void QgsMapThemeCollection::mapThemeChanged ( const QString &  theme)
signal

Emitted when a map theme changes definition.

◆ mapThemeRenamed

void QgsMapThemeCollection::mapThemeRenamed ( const QString &  name,
const QString &  newName 
)
signal

Emitted when a map theme within the collection is renamed.

Since
QGIS 3.14

◆ mapThemes()

QStringList QgsMapThemeCollection::mapThemes ( ) const

Returns a list of existing map theme names.

Definition at line 315 of file qgsmapthemecollection.cpp.

◆ mapThemesChanged

void QgsMapThemeCollection::mapThemesChanged ( )
signal

Emitted when map themes within the collection are changed.

◆ mapThemeState()

QgsMapThemeCollection::MapThemeRecord QgsMapThemeCollection::mapThemeState ( const QString &  name) const
inline

Returns the recorded state of a map theme.

Definition at line 296 of file qgsmapthemecollection.h.

◆ mapThemeStyleOverrides()

QMap< QString, QString > QgsMapThemeCollection::mapThemeStyleOverrides ( const QString &  name)

Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.

Definition at line 385 of file qgsmapthemecollection.cpp.

◆ mapThemeVisibleLayerIds()

QStringList QgsMapThemeCollection::mapThemeVisibleLayerIds ( const QString &  name) const

Returns the list of layer IDs that are visible for the specified map theme.

Note
The order of the returned list is not guaranteed to reflect the order of layers in the canvas.

Definition at line 320 of file qgsmapthemecollection.cpp.

◆ mapThemeVisibleLayers()

QList< QgsMapLayer * > QgsMapThemeCollection::mapThemeVisibleLayers ( const QString &  name) const

Returns the list of layers that are visible for the specified map theme.

Note
The order of the returned list is not guaranteed to reflect the order of layers in the canvas.

Definition at line 331 of file qgsmapthemecollection.cpp.

◆ masterLayerOrder()

QList< QgsMapLayer * > QgsMapThemeCollection::masterLayerOrder ( ) const

Returns the master layer order (this will always match the project's QgsProject::layerOrder() ).

All map themes will maintain the same layer order as the master layer order.

See also
masterVisibleLayers()

Definition at line 226 of file qgsmapthemecollection.cpp.

◆ masterVisibleLayers()

QList< QgsMapLayer * > QgsMapThemeCollection::masterVisibleLayers ( ) const

Returns the master list of visible layers.

The order of returned layers will always match those of masterLayerOrder(), but the returned layers are filtered to only include those visible in the project's layer tree.

See also
masterLayerOrder()

Definition at line 234 of file qgsmapthemecollection.cpp.

◆ project()

QgsProject * QgsMapThemeCollection::project ( )

Returns the QgsProject on which this map theme collection works.

See also
setProject()
projectChanged()

◆ projectChanged

void QgsMapThemeCollection::projectChanged ( )
signal

Emitted when the project changes.

See also
project()
setProject()

◆ readXml()

void QgsMapThemeCollection::readXml ( const QDomDocument &  doc)

Reads the map theme collection state from XML.

Parameters
docDOM document
See also
writeXml

Definition at line 436 of file qgsmapthemecollection.cpp.

◆ removeMapTheme()

void QgsMapThemeCollection::removeMapTheme ( const QString &  name)

Removes an existing map theme from collection.

Definition at line 296 of file qgsmapthemecollection.cpp.

◆ renameMapTheme()

bool QgsMapThemeCollection::renameMapTheme ( const QString &  name,
const QString &  newName 
)

Renames the existing map theme called name to newName.

Returns true if the rename was successful, or false if it failed (e.g. due to a duplicate name for newName).

Since
QGIS 3.14

Definition at line 283 of file qgsmapthemecollection.cpp.

◆ setProject()

void QgsMapThemeCollection::setProject ( QgsProject project)

Sets the project on which this map theme collection works.

See also
project()
projectChanged()

Definition at line 215 of file qgsmapthemecollection.cpp.

◆ update()

void QgsMapThemeCollection::update ( const QString &  name,
const QgsMapThemeCollection::MapThemeRecord state 
)

Updates a map theme within the collection.

Parameters
namename of map theme to update
statemap theme record to replace existing map theme
See also
insert()

Definition at line 271 of file qgsmapthemecollection.cpp.

◆ writeXml()

void QgsMapThemeCollection::writeXml ( QDomDocument &  doc) const

Writes the map theme collection state to XML.

Parameters
docDOM document
See also
readXml

Definition at line 458 of file qgsmapthemecollection.cpp.

Property Documentation

◆ mapThemes

QStringList QgsMapThemeCollection::mapThemes
read

Definition at line 47 of file qgsmapthemecollection.h.

◆ project

QgsProject * QgsMapThemeCollection::project
readwrite

Definition at line 48 of file qgsmapthemecollection.h.


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