24 #include <QDomElement> 25 #include <QTextStream> 35 return !mXmlData.isEmpty();
54 if ( !errorMsg.isEmpty() )
56 QgsDebugMsg(
"Failed to export style from layer: " + errorMsg );
61 QTextStream stream( &mXmlData );
62 doc.documentElement().save( stream, 0 );
72 QDomDocument doc( QStringLiteral(
"qgis" ) );
73 if ( !doc.setContent( mXmlData ) )
75 QgsDebugMsg( QStringLiteral(
"Failed to parse XML of previously stored XML data - this should not happen!" ) );
82 QgsDebugMsg(
"Failed to import style to layer: " + errorMsg );
89 QTextStream stream( &mXmlData );
90 styleElement.firstChildElement().save( stream, 0 );
100 docX.setContent( mXmlData );
101 styleElement.appendChild( docX.documentElement() );
106 if ( mLayer && mStyleOverridden )
107 mLayer->styleManager()->restoreOverrideStyle();
114 if ( mStyleOverridden )
115 mLayer->styleManager()->restoreOverrideStyle();
117 mLayer->styleManager()->setOverrideStyle( style );
118 mStyleOverridden =
true;
The class is used as a container of context for various read/write operations on other objects...
void clear()
Remove any stored style data (will get invalid)
Base class for all map layer types.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
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.
QgsMapLayerStyle()=default
construct invalid style
QString xmlData() const
Returns XML content of the style.
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)
~QgsMapLayerStyleOverride()
void writeToLayer(QgsMapLayer *layer) const
Apply stored layer's style information to the layer.
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.
void setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.