QgsMapThemeCollection class
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Contents
Public types
- class MapThemeLayerRecord
- Individual record of a visible layer in a map theme record.
- class MapThemeRecord
- Individual map theme record of visible layers and styles.
Public static functions
-
static auto createThemeFromCurrentState(QgsLayerTreeGroup* root,
QgsLayerTreeModel* model) -> QgsMapThemeCollection::
MapThemeRecord - 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).
Constructors, destructors, conversion operators
- QgsMapThemeCollection(QgsProject* project = nullptr)
- Create map theme collection that handles themes of the given project.
Public functions
- 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()
- Remove all map themes from the collection.
- auto hasMapTheme(const QString& name) const -> bool
- 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.
- auto mapThemes() const -> QStringList
- Returns a list of existing map theme names.
-
auto mapThemeState(const QString& name) const -> QgsMapThemeCollection::
MapThemeRecord - Returns the recorded state of a map theme.
- auto mapThemeStyleOverrides(const QString& name) -> QMap<QString, QString>
- Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
- auto mapThemeVisibleLayerIds(const QString& name) const -> QStringList
- Returns the list of layer IDs that are visible for the specified map theme.
- auto mapThemeVisibleLayers(const QString& name) const -> QList<QgsMapLayer*>
- Returns the list of layers that are visible for the specified map theme.
- auto masterLayerOrder() const -> QList<QgsMapLayer*>
- Returns the master layer order (this will always match the project's QgsProject::layerOrder() ).
- auto masterVisibleLayers() const -> QList<QgsMapLayer*>
- Returns the master list of visible layers.
- auto project() -> QgsProject*
- 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)
- Remove an existing map theme from collection.
- void setProject(QgsProject* project)
- The QgsProject 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)
- Writes the map theme collection state to XML.
Signals
- void mapThemeChanged(const QString& theme)
- Emitted when a map theme changes definition.
- void mapThemesChanged()
- Emitted when map themes within the collection are changed.
- void projectChanged()
- Emitted when the project changes.
Function documentation
static QgsMapThemeCollection:: MapThemeRecord QgsMapThemeCollection:: 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).
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.
bool QgsMapThemeCollection:: hasMapTheme(const QString& name) const
Returns whether a map theme with a matching name exists.
void QgsMapThemeCollection:: insert(const QString& name,
const QgsMapThemeCollection:: MapThemeRecord& state)
Inserts a new map theme to the collection.
QStringList QgsMapThemeCollection:: mapThemes() const
Returns a list of existing map theme names.
QgsMapThemeCollection:: MapThemeRecord QgsMapThemeCollection:: mapThemeState(const QString& name) const
Returns the recorded state of a map theme.
QMap<QString, QString> QgsMapThemeCollection:: mapThemeStyleOverrides(const QString& name)
Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
QStringList QgsMapThemeCollection:: mapThemeVisibleLayerIds(const QString& name) const
Returns the list of layer IDs that are visible for the specified map theme.
QList<QgsMapLayer*> QgsMapThemeCollection:: mapThemeVisibleLayers(const QString& name) const
Returns the list of layers that are visible for the specified map theme.
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.
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.
QgsProject* QgsMapThemeCollection:: project()
The QgsProject on which this map theme collection works.
void QgsMapThemeCollection:: readXml(const QDomDocument& doc)
Reads the map theme collection state from XML.
| Parameters | |
|---|---|
| doc | DOM document |
void QgsMapThemeCollection:: removeMapTheme(const QString& name)
Remove an existing map theme from collection.
void QgsMapThemeCollection:: setProject(QgsProject* project)
The QgsProject on which this map theme collection works.
void QgsMapThemeCollection:: update(const QString& name,
const QgsMapThemeCollection:: MapThemeRecord& state)
Updates a map theme within the collection.
| Parameters | |
|---|---|
| name | name of map theme to update |
| state | map theme record to replace existing map theme |
void QgsMapThemeCollection:: writeXml(QDomDocument& doc)
Writes the map theme collection state to XML.
| Parameters | |
|---|---|
| doc | DOM document |
void QgsMapThemeCollection:: mapThemeChanged(const QString& theme) signal
Emitted when a map theme changes definition.
void QgsMapThemeCollection:: mapThemesChanged() signal
Emitted when map themes within the collection are changed.
void QgsMapThemeCollection:: projectChanged() signal
Emitted when the project changes.
The QgsProject on which this map theme collection works.