@@ -428,62 +428,64 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
428
428
return QObject::tr ( " Currently only filebased datasets are supported" );
429
429
}
430
430
QFile myFile ( theURI );
431
- if ( myFile.open (QFile::ReadOnly ) )
431
+ if ( ! myFile.open (QFile::ReadOnly ) )
432
432
{
433
- QDomDocument myDocument ( " qgis" );
434
- // location of problem associated with errorMsg
435
- int line, column;
436
- QString myErrorMessage;
437
- if ( !myDocument.setContent ( &myFile, &myErrorMessage, &line, &column ) )
433
+ return QObject::tr ( " File could not been opened." );
434
+ }
435
+
436
+ QDomDocument myDocument ( " qgis" );
437
+ // location of problem associated with errorMsg
438
+ int line, column;
439
+ QString myErrorMessage;
440
+ if ( !myDocument.setContent ( &myFile, &myErrorMessage, &line, &column ) )
441
+ {
442
+ myFile.close ();
443
+ return myErrorMessage + " at line " + QString::number ( line ) +
444
+ " column " + QString::number ( column );
445
+ }
446
+ else // dom parsed in ok
447
+ {
448
+ myFile.close ();
449
+
450
+ // now get the layer node out and pass it over to the layer
451
+ // to deserialise...
452
+ QDomElement myRoot = myDocument.firstChildElement (" qgis" );
453
+ if (myRoot.isNull ())
454
+ {
455
+ myErrorMessage = " Error: qgis element could not be found in " + theURI;
456
+ return myErrorMessage;
457
+ }
458
+
459
+ QDomElement myLayer = myRoot.firstChildElement (" maplayer" );
460
+ if (myLayer.isNull ())
438
461
{
439
- myFile.close ();
440
- return myErrorMessage + " at line " + QString::number ( line ) +
441
- " column " + QString::number ( column );
462
+ myErrorMessage = " Error: maplayer element could not be found in " + theURI;
463
+ return myErrorMessage;
442
464
}
443
- else // dom parsed in ok
465
+
466
+ //
467
+ // we need to ensure the data source matches the layers
468
+ // current datasource not the one specified in the qml
469
+ //
470
+ QDomElement myDataSource = myLayer.firstChildElement (" datasource" );
471
+ if (myDataSource.isNull ())
444
472
{
445
- myFile.close ();
446
-
447
- // now get the layer node out and pass it over to the layer
448
- // to deserialise...
449
- QDomElement myRoot = myDocument.firstChildElement (" qgis" );
450
- if (myRoot.isNull ())
451
- {
452
- myErrorMessage = " Error: qgis element could not be found in " + theURI;
453
- return myErrorMessage;
454
- }
455
-
456
- QDomElement myLayer = myRoot.firstChildElement (" maplayer" );
457
- if (myLayer.isNull ())
458
- {
459
- myErrorMessage = " Error: maplayer element could not be found in " + theURI;
460
- return myErrorMessage;
461
- }
462
-
463
- //
464
- // we need to ensure the data source matches the layers
465
- // current datasource not the one specified in the qml
466
- //
467
- QDomElement myDataSource = myLayer.firstChildElement (" datasource" );
468
- if (myDataSource.isNull ())
469
- {
470
- myErrorMessage = " Error: datasource element could not be found in " + theURI;
471
- return myErrorMessage;
472
- }
473
- QDomElement myNewDataSource = myDocument.createElement ( " datasource" );
474
- QDomText myDataSourceText = myDocument.createTextNode ( source () );
475
- myNewDataSource.appendChild ( myDataSourceText );
476
- myLayer.replaceChild ( myNewDataSource ,
477
- myLayer.firstChildElement (" datasource" ) );
478
-
479
- //
480
- // Now go on to parse the xml (QDomElement inherits QDomNode
481
- // so we can just pass along the element to readXML)
482
- //
483
- theResultFlag = readXML ( myLayer );
484
-
485
- return QObject::tr ( " Loaded default style file from " ) + theURI;
473
+ myErrorMessage = " Error: datasource element could not be found in " + theURI;
474
+ return myErrorMessage;
486
475
}
476
+ QDomElement myNewDataSource = myDocument.createElement ( " datasource" );
477
+ QDomText myDataSourceText = myDocument.createTextNode ( source () );
478
+ myNewDataSource.appendChild ( myDataSourceText );
479
+ myLayer.replaceChild ( myNewDataSource ,
480
+ myLayer.firstChildElement (" datasource" ) );
481
+
482
+ //
483
+ // Now go on to parse the xml (QDomElement inherits QDomNode
484
+ // so we can just pass along the element to readXML)
485
+ //
486
+ theResultFlag = readXML ( myLayer );
487
+
488
+ return QObject::tr ( " Loaded default style file from " ) + theURI;
487
489
}
488
490
}
489
491
QString QgsMapLayer::saveDefaultStyle ( bool & theResultFlag )
@@ -497,7 +499,6 @@ QString QgsMapLayer::saveDefaultStyle ( bool & theResultFlag )
497
499
}
498
500
QString QgsMapLayer::saveNamedStyle ( const QString theURI , bool & theResultFlag )
499
501
{
500
-
501
502
QFileInfo myFileInfo ( theURI );
502
503
// now check if we can write to the dir where the layer
503
504
// exists...
0 commit comments