31 QgsLayerSettings settings;
32 settings.name = layer->name();
34 QString style = layer->styleManager()->currentStyle();
35 settings.mNamedStyle = layer->styleManager()->currentStyle();
39 layer->setCustomProperty(
"readSLD",
false );
42 QDomDocument styleDoc( QStringLiteral(
"style" ) );
43 QDomElement styleXml = styleDoc.createElement( QStringLiteral(
"style" ) );
44 styleDoc.appendChild( styleXml );
47 QgsMessageLog::logMessage( QStringLiteral(
"QGIS Style has not been added to layer restorer for layer %1: %2" ).arg( layer->name(), errMsg ) );
49 ( void )settings.mQgisStyle.setContent( styleDoc.toString() );
51 if ( layer->type() == QgsMapLayer::LayerType::VectorLayer )
57 settings.mOpacity = vLayer->
opacity();
62 else if ( layer->type() == QgsMapLayer::LayerType::RasterLayer )
72 mLayerSettings[layer] = settings;
80 QgsLayerSettings settings = mLayerSettings[layer];
81 layer->styleManager()->setCurrentStyle( settings.mNamedStyle );
82 layer->setName( mLayerSettings[layer].name );
85 if ( layer->customProperty(
"readSLD",
false ).toBool() )
88 QDomElement root = settings.mQgisStyle.documentElement();
90 if ( !layer->readStyle( root, errMsg, context ) )
92 QgsMessageLog::logMessage( QStringLiteral(
"QGIS Style has not been read from layer restorer for layer %1: %2" ).arg( layer->name(), errMsg ) );
95 layer->removeCustomProperty(
"readSLD" );
97 if ( layer->type() == QgsMapLayer::LayerType::VectorLayer )
104 vLayer->
selectByIds( settings.mSelectedFeatureIds );
108 else if ( layer->type() == QgsMapLayer::LayerType::RasterLayer )
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
void selectByIds(const QgsFeatureIds &ids, SelectBehavior behavior=SetSelection)
Select matching features using a list of feature IDs.
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
QgsLayerRestorer(const QList< QgsMapLayer * > &layers)
Constructor for QgsLayerRestorer.
QgsRasterRenderer * renderer() const
~QgsLayerRestorer()
Destructor.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
virtual bool setSubsetString(const QString &subset)
Set the string (typically sql) used to define a subset of the layer.
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1...
Represents a vector layer which manages a vector based data sets.
void setOpacity(double opacity)
Sets the opacity for the vector layer, where opacity is a value between 0 (totally transparent) and 1...