Skip to content

Commit ef4b5ea

Browse files
committedNov 21, 2015
Let the test for presence of root element be the first step.
1 parent efeacaa commit ef4b5ea

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed
 

‎src/core/qgsmaplayer.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,15 @@ QString QgsMapLayer::loadNamedStyle( const QString &theURI, bool &theResultFlag
11471147

11481148
bool QgsMapLayer::importNamedStyle( QDomDocument& myDocument, QString& myErrorMessage )
11491149
{
1150+
QDomElement myRoot = myDocument.firstChildElement( "qgis" );
1151+
if ( myRoot.isNull() )
1152+
{
1153+
myErrorMessage = tr( "Root <qgis> element could not be found" );
1154+
return false;
1155+
}
1156+
11501157
// get style file version string, if any
1151-
QgsProjectVersion fileVersion( myDocument.firstChildElement( "qgis" ).attribute( "version" ) );
1158+
QgsProjectVersion fileVersion( myRoot.attribute( "version" ) );
11521159
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );
11531160

11541161
if ( thisVersion > fileVersion )
@@ -1164,15 +1171,6 @@ bool QgsMapLayer::importNamedStyle( QDomDocument& myDocument, QString& myErrorMe
11641171
// styleFile.dump();
11651172
}
11661173

1167-
// now get the layer node out and pass it over to the layer
1168-
// to deserialise...
1169-
QDomElement myRoot = myDocument.firstChildElement( "qgis" );
1170-
if ( myRoot.isNull() )
1171-
{
1172-
myErrorMessage = tr( "Root <qgis> element could not be found" );
1173-
return false;
1174-
}
1175-
11761174
//Test for matching geometry type on vector layers when applying, if geometry type is given in the style
11771175
if ( type() == QgsMapLayer::VectorLayer && !myRoot.firstChildElement( "layerGeometryType" ).isNull() )
11781176
{

0 commit comments

Comments
 (0)
Please sign in to comment.