bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context ) { QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsMeshLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 ); //process provider key QDomNode pkeyNode = layer_node.namedItem( QStringLiteral( "provider" ) ); if ( pkeyNode.isNull() ) { mProviderKey.clear(); } else { QDomElement pkeyElt = pkeyNode.toElement(); mProviderKey = pkeyElt.text(); } QgsDataProvider::ProviderOptions providerOptions; if ( !setDataProvider( mProviderKey, providerOptions ) ) { return false; } QDomElement elemExtraDatasets = layer_node.firstChildElement( QStringLiteral( "extra-datasets" ) ); if ( !elemExtraDatasets.isNull() ) { QDomElement elemUri = elemExtraDatasets.firstChildElement( QStringLiteral( "uri" ) ); while ( !elemUri.isNull() ) { QString uri = context.pathResolver().readPath( elemUri.text() ); bool res = mDataProvider->addDataset( uri ); #ifdef QGISDEBUG QgsDebugMsg( QStringLiteral( "extra dataset (res %1): %2" ).arg( res ).arg( uri ) ); #else ( void )res; // avoid unused warning in release builds #endif elemUri = elemUri.nextSiblingElement( QStringLiteral( "uri" ) ); } } QString errorMsg; readSymbology( layer_node, errorMsg, context ); return mValid; // should be true if read successfully }
QString QgsMapLayer::loadNamedStyle( const QString &theURI, bool &theResultFlag ) { QgsDebugMsg( QString( "uri = %1 myURI = %2" ).arg( theURI ).arg( publicSource() ) ); theResultFlag = false; QDomDocument myDocument( "qgis" ); // location of problem associated with errorMsg int line, column; QString myErrorMessage; QFile myFile( theURI ); if ( myFile.open( QFile::ReadOnly ) ) { // read file theResultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column ); if ( !theResultFlag ) myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column ); myFile.close(); } else { QFileInfo project( QgsProject::instance()->fileName() ); QgsDebugMsg( QString( "project fileName: %1" ).arg( project.absoluteFilePath() ) ); QString qml; if ( loadNamedStyleFromDb( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( "qgis.qmldb" ), theURI, qml ) || ( project.exists() && loadNamedStyleFromDb( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), theURI, qml ) ) || loadNamedStyleFromDb( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( "resources/qgis.qmldb" ), theURI, qml ) ) { theResultFlag = myDocument.setContent( qml, &myErrorMessage, &line, &column ); if ( !theResultFlag ) { myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column ); } } else { myErrorMessage = tr( "style not found in database" ); } } if ( !theResultFlag ) { return myErrorMessage; } // get style file version string, if any QgsProjectVersion fileVersion( myDocument.firstChildElement( "qgis" ).attribute( "version" ) ); QgsProjectVersion thisVersion( QGis::QGIS_VERSION ); if ( thisVersion > fileVersion ) { QgsLogger::warning( "Loading a style file that was saved with an older " "version of qgis (saved in " + fileVersion.text() + ", loaded in " + QGis::QGIS_VERSION + "). Problems may occur." ); QgsProjectFileTransform styleFile( myDocument, fileVersion ); // styleFile.dump(); styleFile.updateRevision( thisVersion ); // styleFile.dump(); } // now get the layer node out and pass it over to the layer // to deserialise... QDomElement myRoot = myDocument.firstChildElement( "qgis" ); if ( myRoot.isNull() ) { myErrorMessage = tr( "Error: qgis element could not be found in %1" ).arg( theURI ); theResultFlag = false; return myErrorMessage; } // use scale dependent visibility flag toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 ); setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() ); setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() ); #if 0 //read transparency level QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" ); if ( ! transparencyNode.isNull() ) { // set transparency level only if it's in project // (otherwise it sets the layer transparent) QDomElement myElement = transparencyNode.toElement(); setTransparency( myElement.text().toInt() ); } #endif QString errorMsg; theResultFlag = readSymbology( myRoot, errorMsg ); if ( !theResultFlag ) { myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( theURI ).arg( errorMsg ); return myErrorMessage; } return ""; }