27using namespace Qt::StringLiterals;
36 return !mXmlData.isEmpty();
55 if ( !errorMsg.isEmpty() )
57 QgsDebugError(
"Failed to export style from layer: " + errorMsg );
62 QTextStream stream( &mXmlData );
63 doc.documentElement().save( stream, 0 );
73 QDomDocument doc( u
"qgis"_s );
74 if ( !doc.setContent( mXmlData ) )
76 QgsDebugError( u
"Failed to parse XML of previously stored XML data - this should not happen!"_s );
83 QgsDebugError(
"Failed to import style to layer: " + errorMsg );
90 QTextStream stream( &mXmlData );
91 styleElement.firstChildElement().save( stream, 0 );
101 docX.setContent( mXmlData );
102 styleElement.appendChild( docX.documentElement() );
107 if ( mLayer && mStyleOverridden )
108 mLayer->styleManager()->restoreOverrideStyle();
115 if ( mStyleOverridden )
116 mLayer->styleManager()->restoreOverrideStyle();
118 mLayer->styleManager()->setOverrideStyle( style );
119 mStyleOverridden =
true;
void setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.
~QgsMapLayerStyleOverride()
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading).
void readFromLayer(QgsMapLayer *layer)
Store layer's active style information in the instance.
void clear()
Remove any stored style data (will get invalid).
void writeToLayer(QgsMapLayer *layer) const
Apply stored layer's style information to the layer.
bool isValid() const
Tell whether the style is valid (i.e. there is something stored in it).
void writeXml(QDomElement &styleElement) const
Write style configuration (for project file writing).
QString xmlData() const
Returns XML content of the style.
QgsMapLayerStyle()=default
construct invalid style
Base class for all map layer types.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
Export the properties of this layer as named style in a QDomDocument.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
A container for the context for various read/write operations on objects.
#define QgsDebugError(str)