25#include "moc_qgsmapthemecollection.cpp"
35 MapThemeLayerRecord layerRec( nodeLayer->
layer() );
36 layerRec.isVisible = nodeLayer->
isVisible();
37 layerRec.usingCurrentStyle =
true;
39 layerRec.expandedLayerNode = nodeLayer->
isExpanded();
40 const QStringList expandedLegendNodes = nodeLayer->
customProperty( QStringLiteral(
"expandedLegendNodes" ) ).toStringList();
41 layerRec.expandedLegendItems = QSet<QString>( expandedLegendNodes.begin(), expandedLegendNodes.end() );
44 bool hasCheckableItems =
false;
45 bool someItemsUnchecked =
false;
46 QSet<QString> checkedItems;
47 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = model->
layerLegendNodes( nodeLayer,
true );
50 if ( legendNode->
flags() & Qt::ItemIsUserCheckable )
52 hasCheckableItems =
true;
54 if ( legendNode->
data( Qt::CheckStateRole ).toInt() == Qt::Checked )
57 someItemsUnchecked =
true;
61 if ( hasCheckableItems && someItemsUnchecked )
63 layerRec.usingLegendItems =
true;
64 layerRec.checkedLegendItems = checkedItems;
74 lst.prepend( node->
name() );
77 return lst.join(
'/' );
82 const QList<QgsLayerTreeNode *> constChildren = parent->
children();
89 rec.mExpandedGroupNodes.insert( _groupId( node ) );
91 rec.mCheckedGroupNodes.insert( _groupId( node ) );
97 rec.mLayerRecords << createThemeLayerRecord( nodeLayer, model );
115 if ( lr.layer() == layer )
126 MapThemeLayerRecord layerRec;
127 const bool recordExists = findRecordForLayer( nodeLayer->
layer(), rec, layerRec );
143 if ( layerRec.usingCurrentStyle )
149 if ( layerRec.usingLegendItems )
152 const QList<QgsLayerTreeModelLegendNode *> constLayerLegendNodes = model->
layerLegendNodes( nodeLayer,
true );
156 Qt::CheckState shouldHaveState = layerRec.checkedLegendItems.contains( ruleKey ) ? Qt::Checked : Qt::Unchecked;
158 legendNode->
data( Qt::CheckStateRole ).toInt() != shouldHaveState )
165 const QList<QgsLayerTreeModelLegendNode *> constLayerLegendNodes = model->
layerLegendNodes( nodeLayer,
true );
177 nodeLayer->
setExpanded( layerRec.expandedLayerNode );
178 nodeLayer->
setCustomProperty( QStringLiteral(
"expandedLegendNodes" ), QStringList( layerRec.expandedLegendItems.constBegin(), layerRec.expandedLegendItems.constEnd() ) );
185 const QList<QgsLayerTreeNode *> constChildren = parent->
children();
229 return QList< QgsMapLayer * >();
239 if ( allLayers.isEmpty() )
242 return visibleLayers;
246 QList< QgsMapLayer * > orderedVisibleLayers;
249 if ( visibleLayers.contains( layer ) )
250 orderedVisibleLayers << layer;
252 return orderedVisibleLayers;
259 return mMapThemes.contains( name );
264 mMapThemes.insert( name, state );
266 reconnectToLayersStyleManager();
273 if ( !mMapThemes.contains( name ) )
276 mMapThemes[name] = state;
278 reconnectToLayersStyleManager();
285 if ( !mMapThemes.contains( name ) || mMapThemes.contains( newName ) )
290 insert( newName, newState );
298 if ( !mMapThemes.contains( name ) )
301 mMapThemes.remove( name );
303 reconnectToLayersStyleManager();
311 reconnectToLayersStyleManager();
317 return mMapThemes.keys();
322 QStringList layerIds;
324 for (
QgsMapLayer *layer : constMapThemeVisibleLayers )
326 layerIds << layer->
id();
333 QList<QgsMapLayer *> layers;
334 const QList<MapThemeLayerRecord> recs = mMapThemes.value( name ).mLayerRecords;
336 if ( layerOrder.isEmpty() )
339 const QList<MapThemeLayerRecord> records { mMapThemes.value( name ).mLayerRecords };
342 if ( layerRec.isVisible && layerRec.layer() )
343 layers << layerRec.layer();
352 if ( layerRec.isVisible && layerRec.layer() == layer )
353 layers << layerRec.layer();
362void QgsMapThemeCollection::applyMapThemeCheckedLegendNodesToLayer(
const MapThemeLayerRecord &layerRec,
QgsMapLayer *layer )
365 if ( !vlayer || !vlayer->
renderer() )
372 bool someNodesUnchecked = layerRec.usingLegendItems;
378 bool shouldBeChecked = someNodesUnchecked ? layerRec.checkedLegendItems.contains( item.ruleKey() ) :
true;
379 if ( checked != shouldBeChecked )
387 QMap<QString, QString> styleOverrides;
388 if ( !mMapThemes.contains( presetName ) )
389 return styleOverrides;
391 const QList<MapThemeLayerRecord> records {mMapThemes.value( presetName ).mLayerRecords};
394 if ( !layerRec.layer() )
397 if ( layerRec.usingCurrentStyle )
404 applyMapThemeCheckedLegendNodesToLayer( layerRec, layer );
409 styleOverrides[layer->
id()] = layerStyle.
xmlData();
412 return styleOverrides;
415void QgsMapThemeCollection::reconnectToLayersStyleManager()
419 QSet<QgsMapLayer *> layers;
420 for (
const MapThemeRecord &rec : std::as_const( mMapThemes ) )
422 for (
const MapThemeLayerRecord &layerRec : std::as_const( rec.mLayerRecords ) )
424 if (
auto *lLayer = layerRec.layer() )
429 const QSet<QgsMapLayer *> constLayers = layers;
440 QDomElement visPresetsElem = doc.firstChildElement( QStringLiteral(
"qgis" ) ).firstChildElement( QStringLiteral(
"visibility-presets" ) );
441 if ( visPresetsElem.isNull() )
444 QDomElement visPresetElem = visPresetsElem.firstChildElement( QStringLiteral(
"visibility-preset" ) );
445 while ( !visPresetElem.isNull() )
447 QString presetName = visPresetElem.attribute( QStringLiteral(
"name" ) );
449 mMapThemes.insert( presetName, rec );
451 visPresetElem = visPresetElem.nextSiblingElement( QStringLiteral(
"visibility-preset" ) );
454 reconnectToLayersStyleManager();
460 QDomElement visPresetsElem = doc.createElement( QStringLiteral(
"visibility-presets" ) );
462 QList< QString > keys = mMapThemes.keys();
464 std::sort( keys.begin(), keys.end() );
466 for (
const QString &grpName : std::as_const( keys ) )
469 QDomElement visPresetElem = doc.createElement( QStringLiteral(
"visibility-preset" ) );
471 visPresetElem.setAttribute( QStringLiteral(
"name" ), grpName );
474 visPresetsElem.appendChild( visPresetElem );
477 doc.firstChildElement( QStringLiteral(
"qgis" ) ).appendChild( visPresetsElem );
480void QgsMapThemeCollection::registryLayersRemoved(
const QStringList &layerIDs )
484 QSet< QString > changedThemes;
485 MapThemeRecordMap::iterator it = mMapThemes.begin();
486 for ( ; it != mMapThemes.end(); ++it )
488 MapThemeRecord &rec = it.value();
489 for (
int i = 0; i < rec.mLayerRecords.count(); ++i )
491 MapThemeLayerRecord &layerRec = rec.mLayerRecords[i];
492 if ( layerRec.layer() && layerIDs.contains( layerRec.layer()->id() ) )
494 rec.mLayerRecords.removeAt( i-- );
495 changedThemes << it.key();
500 for (
const QString &theme : std::as_const( changedThemes ) )
507void QgsMapThemeCollection::layerStyleRenamed(
const QString &oldName,
const QString &newName )
513 QSet< QString > changedThemes;
515 MapThemeRecordMap::iterator it = mMapThemes.begin();
516 for ( ; it != mMapThemes.end(); ++it )
518 MapThemeRecord &rec = it.value();
519 for (
int i = 0; i < rec.mLayerRecords.count(); ++i )
521 MapThemeLayerRecord &layerRec = rec.mLayerRecords[i];
522 if ( layerRec.layer() == styleMgr->
layer() )
524 if ( layerRec.currentStyle == oldName )
526 layerRec.currentStyle = newName;
527 changedThemes << it.key();
533 for (
const QString &theme : std::as_const( changedThemes ) )
542 for (
int i = 0; i < mLayerRecords.length(); ++i )
544 if ( mLayerRecords.at( i ).layer() == layer )
545 mLayerRecords.removeAt( i );
551 mLayerRecords.append( record );
556 QHash<QgsMapLayer *, MapThemeLayerRecord> validSet;
559 if (
auto *lLayer = layerRec.layer() )
560 validSet.insert( lLayer, layerRec );
567 QHash<QString, MapThemeLayerRecord> layerRecords;
569 bool expandedStateInfo =
false;
570 if ( element.hasAttribute( QStringLiteral(
"has-expanded-info" ) ) )
571 expandedStateInfo = element.attribute( QStringLiteral(
"has-expanded-info" ) ).toInt();
573 bool checkedStateInfo =
false;
574 if ( element.hasAttribute( QStringLiteral(
"has-checked-group-info" ) ) )
575 checkedStateInfo = element.attribute( QStringLiteral(
"has-checked-group-info" ) ).toInt();
577 QDomElement visPresetLayerElem = element.firstChildElement( QStringLiteral(
"layer" ) );
578 while ( !visPresetLayerElem.isNull() )
580 QString layerID = visPresetLayerElem.attribute( QStringLiteral(
"id" ) );
584 layerRecords[layerID].isVisible = visPresetLayerElem.attribute( QStringLiteral(
"visible" ), QStringLiteral(
"1" ) ).toInt();
586 if ( visPresetLayerElem.hasAttribute( QStringLiteral(
"style" ) ) )
588 layerRecords[layerID].usingCurrentStyle =
true;
589 layerRecords[layerID].currentStyle = visPresetLayerElem.attribute( QStringLiteral(
"style" ) );
592 if ( visPresetLayerElem.hasAttribute( QStringLiteral(
"expanded" ) ) )
593 layerRecords[layerID].expandedLayerNode = visPresetLayerElem.attribute( QStringLiteral(
"expanded" ) ).toInt();
595 visPresetLayerElem = visPresetLayerElem.nextSiblingElement( QStringLiteral(
"layer" ) );
598 QDomElement checkedLegendNodesElem = element.firstChildElement( QStringLiteral(
"checked-legend-nodes" ) );
599 while ( !checkedLegendNodesElem.isNull() )
601 QSet<QString> checkedLegendNodes;
603 QDomElement checkedLegendNodeElem = checkedLegendNodesElem.firstChildElement( QStringLiteral(
"checked-legend-node" ) );
604 while ( !checkedLegendNodeElem.isNull() )
606 checkedLegendNodes << checkedLegendNodeElem.attribute( QStringLiteral(
"id" ) );
607 checkedLegendNodeElem = checkedLegendNodeElem.nextSiblingElement( QStringLiteral(
"checked-legend-node" ) );
610 QString layerID = checkedLegendNodesElem.attribute( QStringLiteral(
"id" ) );
613 layerRecords[layerID].usingLegendItems =
true;
614 layerRecords[layerID].checkedLegendItems = checkedLegendNodes;
616 checkedLegendNodesElem = checkedLegendNodesElem.nextSiblingElement( QStringLiteral(
"checked-legend-nodes" ) );
619 QSet<QString> expandedGroupNodes;
620 if ( expandedStateInfo )
623 QDomElement expandedLegendNodesElem = element.firstChildElement( QStringLiteral(
"expanded-legend-nodes" ) );
624 while ( !expandedLegendNodesElem.isNull() )
626 QSet<QString> expandedLegendNodes;
628 QDomElement expandedLegendNodeElem = expandedLegendNodesElem.firstChildElement( QStringLiteral(
"expanded-legend-node" ) );
629 while ( !expandedLegendNodeElem.isNull() )
631 expandedLegendNodes << expandedLegendNodeElem.attribute( QStringLiteral(
"id" ) );
632 expandedLegendNodeElem = expandedLegendNodeElem.nextSiblingElement( QStringLiteral(
"expanded-legend-node" ) );
635 QString layerID = expandedLegendNodesElem.attribute( QStringLiteral(
"id" ) );
638 layerRecords[layerID].expandedLegendItems = expandedLegendNodes;
640 expandedLegendNodesElem = expandedLegendNodesElem.nextSiblingElement( QStringLiteral(
"expanded-legend-nodes" ) );
644 QDomElement expandedGroupNodesElem = element.firstChildElement( QStringLiteral(
"expanded-group-nodes" ) );
645 if ( !expandedGroupNodesElem.isNull() )
647 QDomElement expandedGroupNodeElem = expandedGroupNodesElem.firstChildElement( QStringLiteral(
"expanded-group-node" ) );
648 while ( !expandedGroupNodeElem.isNull() )
650 expandedGroupNodes << expandedGroupNodeElem.attribute( QStringLiteral(
"id" ) );
651 expandedGroupNodeElem = expandedGroupNodeElem.nextSiblingElement( QStringLiteral(
"expanded-group-node" ) );
656 QSet<QString> checkedGroupNodes;
657 if ( checkedStateInfo )
660 QDomElement checkedGroupNodesElem = element.firstChildElement( QStringLiteral(
"checked-group-nodes" ) );
661 if ( !checkedGroupNodesElem.isNull() )
663 QDomElement checkedGroupNodeElem = checkedGroupNodesElem.firstChildElement( QStringLiteral(
"checked-group-node" ) );
664 while ( !checkedGroupNodeElem.isNull() )
666 checkedGroupNodes << checkedGroupNodeElem.attribute( QStringLiteral(
"id" ) );
667 checkedGroupNodeElem = checkedGroupNodeElem.nextSiblingElement( QStringLiteral(
"checked-group-node" ) );
684 if ( hasExpandedStateInfo() )
685 element.setAttribute( QStringLiteral(
"has-expanded-info" ), QStringLiteral(
"1" ) );
686 if ( hasCheckedStateInfo() )
687 element.setAttribute( QStringLiteral(
"has-checked-group-info" ), QStringLiteral(
"1" ) );
690 if ( !layerRec.layer() )
692 QString layerID = layerRec.layer()->id();
693 QDomElement layerElem = document.createElement( QStringLiteral(
"layer" ) );
694 layerElem.setAttribute( QStringLiteral(
"id" ), layerID );
695 layerElem.setAttribute( QStringLiteral(
"visible" ), layerRec.isVisible ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
696 if ( layerRec.usingCurrentStyle )
697 layerElem.setAttribute( QStringLiteral(
"style" ), layerRec.currentStyle );
698 element.appendChild( layerElem );
700 if ( layerRec.usingLegendItems )
702 QDomElement checkedLegendNodesElem = document.createElement( QStringLiteral(
"checked-legend-nodes" ) );
703 checkedLegendNodesElem.setAttribute( QStringLiteral(
"id" ), layerID );
704 for (
const QString &checkedLegendNode : std::as_const( layerRec.checkedLegendItems ) )
706 QDomElement checkedLegendNodeElem = document.createElement( QStringLiteral(
"checked-legend-node" ) );
707 checkedLegendNodeElem.setAttribute( QStringLiteral(
"id" ), checkedLegendNode );
708 checkedLegendNodesElem.appendChild( checkedLegendNodeElem );
710 element.appendChild( checkedLegendNodesElem );
713 if ( hasExpandedStateInfo() )
715 layerElem.setAttribute( QStringLiteral(
"expanded" ), layerRec.expandedLayerNode ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
717 QDomElement expandedLegendNodesElem = document.createElement( QStringLiteral(
"expanded-legend-nodes" ) );
718 expandedLegendNodesElem.setAttribute( QStringLiteral(
"id" ), layerID );
719 for (
const QString &expandedLegendNode : std::as_const( layerRec.expandedLegendItems ) )
721 QDomElement expandedLegendNodeElem = document.createElement( QStringLiteral(
"expanded-legend-node" ) );
722 expandedLegendNodeElem.setAttribute( QStringLiteral(
"id" ), expandedLegendNode );
723 expandedLegendNodesElem.appendChild( expandedLegendNodeElem );
725 element.appendChild( expandedLegendNodesElem );
729 if ( hasCheckedStateInfo() )
731 QDomElement checkedGroupElems = document.createElement( QStringLiteral(
"checked-group-nodes" ) );
732 const QSet<QString> _checkedGroupNodes = checkedGroupNodes();
733 for (
const QString &groupId : _checkedGroupNodes )
735 QDomElement checkedGroupElem = document.createElement( QStringLiteral(
"checked-group-node" ) );
736 checkedGroupElem.setAttribute( QStringLiteral(
"id" ), groupId );
737 checkedGroupElems.appendChild( checkedGroupElem );
739 element.appendChild( checkedGroupElems );
742 if ( hasExpandedStateInfo() )
744 QDomElement expandedGroupElems = document.createElement( QStringLiteral(
"expanded-group-nodes" ) );
745 const QSet<QString> _expandedGroupNodes = expandedGroupNodes();
746 for (
const QString &groupId : _expandedGroupNodes )
748 QDomElement expandedGroupElem = document.createElement( QStringLiteral(
"expanded-group-node" ) );
749 expandedGroupElem.setAttribute( QStringLiteral(
"id" ), groupId );
750 expandedGroupElems.appendChild( expandedGroupElem );
752 element.appendChild( expandedGroupElems );
Abstract base class for all 2D vector feature renderers.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
virtual bool legendSymbolItemsCheckable() const
Returns true if symbology items in legend are checkable.
virtual bool legendSymbolItemChecked(const QString &key)
Returns true if the legend symbology item with the specified key is checked.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
Sets whether the legend symbology item with the specified ley should be checked.
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
@ RuleKey
Rule key of the node (QString)
virtual Qt::ItemFlags flags() const
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
virtual bool setData(const QVariant &value, int role)
Sets some data associated with the item. Default implementation does nothing and returns false.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QList< QgsLayerTreeModelLegendNode * > layerLegendNodes(QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent=false)
Returns filtered list of active legend nodes attached to a particular layer node (by default it retur...
This class is a base class for nodes in a layer tree.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well)
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
virtual QString name() const =0
Returns name of the node.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
QList< QgsMapLayer * > checkedLayers() const
Returns a list of any checked layers which belong to this node or its children.
bool itemVisibilityChecked() const
Returns whether a node is checked (independently of its ancestors or children)
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Management of styles for use with one map layer.
QString currentStyle() const
Returns name of the current style.
bool setCurrentStyle(const QString &name)
Set a different style as the current style - will apply it to the layer.
void styleRenamed(const QString &oldName, const QString &newName)
Emitted when a style has been renamed.
QgsMapLayer * layer() const
Gets pointer to the associated map layer.
Restore overridden layer style on destruction.
void setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.
Stores style information (renderer, opacity, labeling, diagrams etc.) applicable to a map layer.
void readFromLayer(QgsMapLayer *layer)
Store layer's active style information in the instance.
QString xmlData() const
Returns XML content of the style.
Base class for all map layer types.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
Individual record of a visible layer in a map theme record.
void setLayer(QgsMapLayer *layer)
Sets the map layer for this record.
Individual map theme record of visible layers and styles.
void setExpandedGroupNodes(const QSet< QString > &expandedGroupNodes)
Sets a set of group identifiers for group nodes that should have expanded state.
void writeXml(QDomElement element, QDomDocument &document) const
Writes the map theme record to XML.
void removeLayerRecord(QgsMapLayer *layer)
Removes a record for layer if present.
QSet< QString > expandedGroupNodes() const
Returns a set of group identifiers for group nodes that should have expanded state (other group nodes...
void setCheckedGroupNodes(const QSet< QString > &checkedGroupNodes)
Sets a set of group identifiers for group nodes that should have checked state.
void setHasExpandedStateInfo(bool hasInfo)
Sets whether the map theme contains valid expanded/collapsed state of nodes.
bool hasExpandedStateInfo() const
Returns whether information about expanded/collapsed state of nodes has been recorded and thus whethe...
QSet< QString > checkedGroupNodes() const
Returns a set of group identifiers for group nodes that should have checked state (other group nodes ...
void setLayerRecords(const QList< QgsMapThemeCollection::MapThemeLayerRecord > &records)
Sets layer records for the theme.
static MapThemeRecord readXml(const QDomElement &element, const QgsProject *project)
Reads the map theme record from XML.
void setHasCheckedStateInfo(bool hasInfo)
Sets whether the map theme contains valid checked/unchecked state of group nodes.
QHash< QgsMapLayer *, QgsMapThemeCollection::MapThemeLayerRecord > validLayerRecords() const
Returns set with only records for valid layers.
void addLayerRecord(const QgsMapThemeCollection::MapThemeLayerRecord &record)
Add a new record for a layer.
bool hasCheckedStateInfo() const
Returns whether information about checked/unchecked state of groups has been recorded and thus whethe...
void mapThemesChanged()
Emitted when map themes within the collection are changed.
static QgsMapThemeCollection::MapThemeRecord createThemeFromCurrentState(QgsLayerTreeGroup *root, QgsLayerTreeModel *model)
Static method to create theme from the current state of layer visibilities in layer tree,...
void insert(const QString &name, const QgsMapThemeCollection::MapThemeRecord &state)
Inserts a new map theme to the collection.
bool renameMapTheme(const QString &name, const QString &newName)
Renames the existing map theme called name to newName.
void mapThemeRenamed(const QString &name, const QString &newName)
Emitted when a map theme within the collection is renamed.
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.
QList< QgsMapLayer * > mapThemeVisibleLayers(const QString &name) const
Returns the list of layers that are visible for the specified map theme.
void removeMapTheme(const QString &name)
Removes an existing map theme from collection.
QgsMapThemeCollection::MapThemeRecord mapThemeState(const QString &name) const
Returns the recorded state of a map theme.
void setProject(QgsProject *project)
Sets the project on which this map theme collection works.
QList< QgsMapLayer * > masterLayerOrder() const
Returns the master layer order (this will always match the project's QgsProject::layerOrder() ).
void writeXml(QDomDocument &doc) const
Writes the map theme collection state to XML.
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...
QMap< QString, QString > mapThemeStyleOverrides(const QString &name)
Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
QList< QgsMapLayer * > masterVisibleLayers() const
Returns the master list of visible layers.
QStringList mapThemeVisibleLayerIds(const QString &name) const
Returns the list of layer IDs that are visible for the specified map theme.
void update(const QString &name, const QgsMapThemeCollection::MapThemeRecord &state)
Updates a map theme within the collection.
void mapThemeChanged(const QString &theme)
Emitted when a map theme changes definition.
QgsMapThemeCollection(QgsProject *project=nullptr)
Create map theme collection that handles themes of the given project.
void projectChanged()
Emitted when the project changes.
void readXml(const QDomDocument &doc)
Reads the map theme collection state from XML.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
Represents a vector layer which manages a vector based data sets.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)