Skip to content
Permalink
Browse files

[3d] Fix style copy/paste for 3D renderer (fixes #17540)

  • Loading branch information
wonder-sk committed Dec 1, 2017
1 parent be76e23 commit f8788b9185c2741b2dc5ea560ffd6a5f9fdd65bb
@@ -1155,6 +1155,18 @@ Read style manager's configuration (if any). To be called by subclasses.
Write style manager's configuration (if exists). To be called by subclasses.
%End

void writeCommonStyle( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
%Docstring
Write style data common to all layer types
.. versionadded:: 3.0
%End

void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context );
%Docstring
Read style data common to all layer types
.. versionadded:: 3.0
%End


void appendError( const QgsErrorMessage &error );
%Docstring
@@ -547,19 +547,6 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, const QgsReadWr
QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral( "resourceMetadata" ) );
mMetadata.readMetadataXml( metadataElem );

QgsAbstract3DRenderer *r3D = nullptr;
QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
if ( !renderer3DElem.isNull() )
{
QString type3D = renderer3DElem.attribute( QStringLiteral( "type" ) );
Qgs3DRendererAbstractMetadata *meta3D = QgsApplication::renderer3DRegistry()->rendererMetadata( type3D );
if ( meta3D )
{
r3D = meta3D->createRenderer( renderer3DElem, context );
}
}
setRenderer3D( r3D );

return true;
} // bool QgsMapLayer::readLayerXML

@@ -832,14 +819,6 @@ bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &docume
mMetadata.writeMetadataXml( myMetadataElem, document );
layerElement.appendChild( myMetadataElem );

if ( m3DRenderer )
{
QDomElement renderer3DElem = document.createElement( QStringLiteral( "renderer-3d" ) );
renderer3DElem.setAttribute( QStringLiteral( "type" ), m3DRenderer->type() );
m3DRenderer->writeXml( renderer3DElem, context );
layerElement.appendChild( renderer3DElem );
}

// now append layer node to map layer node

writeCustomProperties( layerElement, document );
@@ -1597,6 +1576,35 @@ bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorM
}


void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const
{
if ( m3DRenderer )
{
QDomElement renderer3DElem = document.createElement( QStringLiteral( "renderer-3d" ) );
renderer3DElem.setAttribute( QStringLiteral( "type" ), m3DRenderer->type() );
m3DRenderer->writeXml( renderer3DElem, context );
layerElement.appendChild( renderer3DElem );
}
}


void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context )
{
QgsAbstract3DRenderer *r3D = nullptr;
QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
if ( !renderer3DElem.isNull() )
{
QString type3D = renderer3DElem.attribute( QStringLiteral( "type" ) );
Qgs3DRendererAbstractMetadata *meta3D = QgsApplication::renderer3DRegistry()->rendererMetadata( type3D );
if ( meta3D )
{
r3D = meta3D->createRenderer( renderer3DElem, context );
}
}
setRenderer3D( r3D );
}


QUndoStack *QgsMapLayer::undoStack()
{
return &mUndoStack;
@@ -1095,6 +1095,18 @@ class CORE_EXPORT QgsMapLayer : public QObject
//! Write style manager's configuration (if exists). To be called by subclasses.
void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;

/**
* Write style data common to all layer types
* \since QGIS 3.0
*/
void writeCommonStyle( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;

/**
* Read style data common to all layer types
* \since QGIS 3.0
*/
void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context );

#ifndef SIP_RUN
#if 0
//! Debugging member - invoked when a connect() is made to this object
@@ -1712,6 +1712,9 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes

updateFields();

QDomElement layerElement = layerNode.toElement();
readCommonStyle( layerElement, context );

readStyle( layerNode, errorMessage, context );

mDisplayExpression = layerNode.namedItem( QStringLiteral( "previewExpression" ) ).toElement().text();
@@ -2052,8 +2055,12 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
return result;
}


bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const
{
QDomElement layerElement = node.toElement();
writeCommonStyle( layerElement, doc, context );

( void )writeStyle( node, doc, errorMessage, context );

QDomElement fieldConfigurationElement = doc.createElement( QStringLiteral( "fieldConfiguration" ) );
@@ -1294,9 +1294,11 @@ QImage QgsRasterLayer::previewAsImage( QSize size, const QColor &bgColor, QImage
bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMessage, const QgsReadWriteContext &context )
{
Q_UNUSED( errorMessage );
Q_UNUSED( context );
QDomElement rasterRendererElem;

QDomElement layerElement = layer_node.toElement();
readCommonStyle( layerElement, context );

// pipe element was introduced in the end of 1.9 development when there were
// already many project files in use so we support 1.9 backward compatibility
// even it was never officially released -> use pipe element if present, otherwise
@@ -1536,7 +1538,9 @@ bool QgsRasterLayer::readXml( const QDomNode &layer_node, const QgsReadWriteCont
bool QgsRasterLayer::writeSymbology( QDomNode &layer_node, QDomDocument &document, QString &errorMessage, const QgsReadWriteContext &context ) const
{
Q_UNUSED( errorMessage );
Q_UNUSED( context );

QDomElement layerElement = layer_node.toElement();
writeCommonStyle( layerElement, document, context );

// Store pipe members (except provider) into pipe element, in future, it will be
// possible to add custom filters into the pipe

0 comments on commit f8788b9

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