Skip to content
Permalink
Browse files

Save readOnly state and default values to style

They should be handled equal to the edit form config.
Fix #15931
  • Loading branch information
m-kuhn committed Jan 19, 2017
1 parent c84b51f commit 72cffa68b9fd996620d076e1df5fbbdad92e4ecd
Showing with 37 additions and 37 deletions.
  1. +37 −37 src/core/qgsvectorlayer.cpp
@@ -1630,10 +1630,6 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node )
return false;
}

QDomElement mapLayerNode = layer_node.toElement();
if ( mapLayerNode.attribute( "readOnly", "0" ).toInt() == 1 )
mReadOnly = true;

QDomElement pkeyElem = pkeyNode.toElement();
if ( !pkeyElem.isNull() )
{
@@ -1679,24 +1675,6 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node )

readStyleManager( layer_node );

// default expressions
mDefaultExpressionMap.clear();
QDomNode defaultsNode = layer_node.namedItem( "defaults" );
if ( !defaultsNode.isNull() )
{
QDomNodeList defaultNodeList = defaultsNode.toElement().elementsByTagName( "default" );
for ( int i = 0; i < defaultNodeList.size(); ++i )
{
QDomElement defaultElem = defaultNodeList.at( i ).toElement();

QString field = defaultElem.attribute( "field", QString() );
QString expression = defaultElem.attribute( "expression", QString() );
if ( field.isEmpty() || expression.isEmpty() )
continue;

mDefaultExpressionMap.insert( field, expression );
}
}
updateFields();

setLegend( QgsMapLayerLegend::defaultVectorLegend( this ) );
@@ -1874,9 +1852,6 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,
layer_node.appendChild( provider );
}

// save readonly state
mapLayerNode.setAttribute( "readOnly", mReadOnly );

// save preview expression
QDomElement prevExpElem = document.createElement( "previewExpression" );
QDomText prevExpText = document.createTextNode( mDisplayExpression );
@@ -1899,17 +1874,6 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,
// save expression fields
mExpressionFieldBuffer->writeXml( layer_node, document );

//default expressions
QDomElement defaultsElem = document.createElement( "defaults" );
Q_FOREACH ( const QgsField& field, mUpdatedFields )
{
QDomElement defaultElem = document.createElement( "default" );
defaultElem.setAttribute( "field", field.name() );
defaultElem.setAttribute( "expression", field.defaultValueExpression() );
defaultsElem.appendChild( defaultElem );
}
layer_node.appendChild( defaultsElem );

writeStyleManager( layer_node, document );

// renderer specific settings
@@ -1963,6 +1927,24 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mAttributeAliasMap.insert( field, aliasElem.attribute( "name" ) );
}
}
// default expressions
mDefaultExpressionMap.clear();
QDomNode defaultsNode = node.namedItem( "defaults" );
if ( !defaultsNode.isNull() )
{
QDomNodeList defaultNodeList = defaultsNode.toElement().elementsByTagName( "default" );
for ( int i = 0; i < defaultNodeList.size(); ++i )
{
QDomElement defaultElem = defaultNodeList.at( i ).toElement();

QString field = defaultElem.attribute( "field", QString() );
QString expression = defaultElem.attribute( "expression", QString() );
if ( field.isEmpty() || expression.isEmpty() )
continue;

mDefaultExpressionMap.insert( field, expression );
}
}
updateFields();

//Attributes excluded from WMS and WFS
@@ -1996,6 +1978,11 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage

readCustomProperties( node, "variable" );

QDomElement mapLayerNode = node.toElement();
if ( mapLayerNode.attribute( "readOnly", "0" ).toInt() == 1 )
mReadOnly = true;


return true;
}

@@ -2101,7 +2088,6 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage )

if ( !labelattributesnode.isNull() && mLabel )
{
QgsDebugMsg( "calling readXML" );
mLabel->readXML( labelattributesnode );
}

@@ -2193,6 +2179,20 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
mEditFormConfig->writeXml( node );
mConditionalStyles->writeXml( node, doc );

// save readonly state
node.toElement().setAttribute( "readOnly", mReadOnly );

//default expressions
QDomElement defaultsElem = node.ownerDocument().createElement( "defaults" );
Q_FOREACH ( const QgsField& field, mUpdatedFields )
{
QDomElement defaultElem = doc.createElement( "default" );
defaultElem.setAttribute( "field", field.name() );
defaultElem.setAttribute( "expression", field.defaultValueExpression() );
defaultsElem.appendChild( defaultElem );
}
node.appendChild( defaultsElem );

return true;
}

0 comments on commit 72cffa6

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