Skip to content
Permalink
Browse files

store and restore layer extents in projects

  • Loading branch information
jef-n committed Mar 30, 2016
1 parent 402ee9d commit d690d721c27f359b2f106de986ff0517e1864b24
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/core/qgsmaplayer.cpp
@@ -48,6 +48,7 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsmaplayerregistry.h"
#include "qgsxmlutils.h"


QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
@@ -531,6 +532,11 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
layerElement.setAttribute( "minimumScale", QString::number( minimumScale() ) );
layerElement.setAttribute( "maximumScale", QString::number( maximumScale() ) );

if ( !mExtent.isNull() )
{
layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document ) );
}

// ID
QDomElement layerId = document.createElement( "id" );
QDomText layerIdText = document.createTextNode( id() );
@@ -1212,6 +1218,12 @@ bool QgsMapLayer::importNamedStyle( QDomDocument& myDocument, QString& myErrorMe
setMinimumScale( myRoot.attribute( "minimumScale" ).toDouble() );
setMaximumScale( myRoot.attribute( "maximumScale" ).toDouble() );

QDomNode extentNode = myRoot.namedItem( "extent" );
if ( !extentNode.isNull() )
{
setExtent( QgsXmlUtils::readRectangle( extentNode.toElement() ) );
}

#if 0
//read transparency level
QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );

2 comments on commit d690d72

@rldhont

This comment has been minimized.

Copy link
Contributor

@rldhont rldhont replied May 26, 2016

Can we backport this code to 2.14 ?

Can we add read extent in readLayerXml and not only in importNamedStyle ?

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Jun 14, 2016

@jef-n , this created the following regression: http://hub.qgis.org/issues/15026

Basically, copy / pasting style for raster layers broken as a pasting a style onto a raster layer leads to that layer getting extent of the copied style's raster.

Please sign in to comment.
You can’t perform that action at this time.