bool QgsLayoutItemPicture::writePropertiesToElement( QDomElement &elem, QDomDocument &, const QgsReadWriteContext &context ) const { QString imagePath = mSourcePath; // convert from absolute path to relative. For SVG we also need to consider system SVG paths QgsPathResolver pathResolver = context.pathResolver(); if ( imagePath.endsWith( QLatin1String( ".svg" ), Qt::CaseInsensitive ) ) imagePath = QgsSymbolLayerUtils::svgSymbolPathToName( imagePath, pathResolver ); else imagePath = pathResolver.writePath( imagePath ); elem.setAttribute( QStringLiteral( "file" ), imagePath ); elem.setAttribute( QStringLiteral( "pictureWidth" ), QString::number( mPictureWidth ) ); elem.setAttribute( QStringLiteral( "pictureHeight" ), QString::number( mPictureHeight ) ); elem.setAttribute( QStringLiteral( "resizeMode" ), QString::number( static_cast< int >( mResizeMode ) ) ); elem.setAttribute( QStringLiteral( "anchorPoint" ), QString::number( static_cast< int >( mPictureAnchor ) ) ); elem.setAttribute( QStringLiteral( "svgFillColor" ), QgsSymbolLayerUtils::encodeColor( mSvgFillColor ) ); elem.setAttribute( QStringLiteral( "svgBorderColor" ), QgsSymbolLayerUtils::encodeColor( mSvgStrokeColor ) ); elem.setAttribute( QStringLiteral( "svgBorderWidth" ), QString::number( mSvgStrokeWidth ) ); //rotation elem.setAttribute( QStringLiteral( "pictureRotation" ), QString::number( mPictureRotation ) ); if ( !mRotationMap ) { elem.setAttribute( QStringLiteral( "mapUuid" ), QString() ); } else { elem.setAttribute( QStringLiteral( "mapUuid" ), mRotationMap->uuid() ); } elem.setAttribute( QStringLiteral( "northMode" ), mNorthMode ); elem.setAttribute( QStringLiteral( "northOffset" ), mNorthOffset ); return true; }
QString QgsMeshLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const { QString src( source ); if ( providerType() == QLatin1String( "mdal" ) ) { src = context.pathResolver().writePath( src ); } return src; }
bool QgsLayoutItemPolyline::readPropertiesFromElement( const QDomElement &elmt, const QDomDocument &doc, const QgsReadWriteContext &context ) { mArrowHeadWidth = elmt.attribute( QStringLiteral( "arrowHeadWidth" ), QStringLiteral( "2.0" ) ).toDouble(); mArrowHeadFillColor = QgsSymbolLayerUtils::decodeColor( elmt.attribute( QStringLiteral( "arrowHeadFillColor" ), QStringLiteral( "0,0,0,255" ) ) ); mArrowHeadStrokeColor = QgsSymbolLayerUtils::decodeColor( elmt.attribute( QStringLiteral( "arrowHeadOutlineColor" ), QStringLiteral( "0,0,0,255" ) ) ); mArrowHeadStrokeWidth = elmt.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "1.0" ) ).toDouble(); // relative paths to absolute QString startMarkerPath = elmt.attribute( QStringLiteral( "startMarkerFile" ), QString() ); QString endMarkerPath = elmt.attribute( QStringLiteral( "endMarkerFile" ), QString() ); setStartSvgMarkerPath( QgsSymbolLayerUtils::svgSymbolNameToPath( startMarkerPath, context.pathResolver() ) ); setEndSvgMarkerPath( QgsSymbolLayerUtils::svgSymbolNameToPath( endMarkerPath, context.pathResolver() ) ); mEndMarker = static_cast< QgsLayoutItemPolyline::MarkerMode >( elmt.attribute( QStringLiteral( "markerMode" ), QStringLiteral( "0" ) ).toInt() ); mStartMarker = static_cast< QgsLayoutItemPolyline::MarkerMode >( elmt.attribute( QStringLiteral( "startMarkerMode" ), QStringLiteral( "0" ) ).toInt() ); QgsLayoutNodesItem::readPropertiesFromElement( elmt, doc, context ); updateBoundingRect(); return true; }
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 }
bool QgsLayoutItemPolyline::writePropertiesToElement( QDomElement &elmt, QDomDocument &doc, const QgsReadWriteContext &context ) const { QgsLayoutNodesItem::writePropertiesToElement( elmt, doc, context ); // absolute paths to relative QString startMarkerPath = QgsSymbolLayerUtils::svgSymbolPathToName( mStartMarkerFile, context.pathResolver() ); QString endMarkerPath = QgsSymbolLayerUtils::svgSymbolPathToName( mEndMarkerFile, context.pathResolver() ); elmt.setAttribute( QStringLiteral( "arrowHeadWidth" ), QString::number( mArrowHeadWidth ) ); elmt.setAttribute( QStringLiteral( "arrowHeadFillColor" ), QgsSymbolLayerUtils::encodeColor( mArrowHeadFillColor ) ); elmt.setAttribute( QStringLiteral( "arrowHeadOutlineColor" ), QgsSymbolLayerUtils::encodeColor( mArrowHeadStrokeColor ) ); elmt.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mArrowHeadStrokeWidth ) ); elmt.setAttribute( QStringLiteral( "markerMode" ), mEndMarker ); elmt.setAttribute( QStringLiteral( "startMarkerMode" ), mStartMarker ); elmt.setAttribute( QStringLiteral( "startMarkerFile" ), startMarkerPath ); elmt.setAttribute( QStringLiteral( "endMarkerFile" ), endMarkerPath ); return true; }
bool QgsMeshLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const { // first get the layer element so that we can append the type attribute QDomElement mapLayerNode = layer_node.toElement(); if ( mapLayerNode.isNull() || ( QLatin1String( "maplayer" ) != mapLayerNode.nodeName() ) ) { QgsDebugMsgLevel( QStringLiteral( "can't find <maplayer>" ), 2 ); return false; } mapLayerNode.setAttribute( QStringLiteral( "type" ), QStringLiteral( "mesh" ) ); // add provider node if ( mDataProvider ) { QDomElement provider = document.createElement( QStringLiteral( "provider" ) ); QDomText providerText = document.createTextNode( providerType() ); provider.appendChild( providerText ); layer_node.appendChild( provider ); const QStringList extraDatasetUris = mDataProvider->extraDatasets(); QDomElement elemExtraDatasets = document.createElement( QStringLiteral( "extra-datasets" ) ); for ( const QString &uri : extraDatasetUris ) { QString path = context.pathResolver().writePath( uri ); QDomElement elemUri = document.createElement( QStringLiteral( "uri" ) ); elemUri.appendChild( document.createTextNode( path ) ); elemExtraDatasets.appendChild( elemUri ); } layer_node.appendChild( elemExtraDatasets ); } // renderer specific settings QString errorMsg; return writeSymbology( layer_node, document, errorMsg, context ); }
bool QgsLayoutItemPicture::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &, const QgsReadWriteContext &context ) { mPictureWidth = itemElem.attribute( QStringLiteral( "pictureWidth" ), QStringLiteral( "10" ) ).toDouble(); mPictureHeight = itemElem.attribute( QStringLiteral( "pictureHeight" ), QStringLiteral( "10" ) ).toDouble(); mResizeMode = QgsLayoutItemPicture::ResizeMode( itemElem.attribute( QStringLiteral( "resizeMode" ), QStringLiteral( "0" ) ).toInt() ); //when loading from xml, default to anchor point of middle to match pre 2.4 behavior mPictureAnchor = static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral( "anchorPoint" ), QString::number( QgsLayoutItem::Middle ) ).toInt() ); mSvgFillColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "svgFillColor" ), QgsSymbolLayerUtils::encodeColor( QColor( 255, 255, 255 ) ) ) ); mSvgStrokeColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "svgBorderColor" ), QgsSymbolLayerUtils::encodeColor( QColor( 0, 0, 0 ) ) ) ); mSvgStrokeWidth = itemElem.attribute( QStringLiteral( "svgBorderWidth" ), QStringLiteral( "0.2" ) ).toDouble(); QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral( "ComposerItem" ) ); if ( !composerItemList.isEmpty() ) { QDomElement composerItemElem = composerItemList.at( 0 ).toElement(); if ( !qgsDoubleNear( composerItemElem.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble(), 0.0 ) ) { //in versions prior to 2.1 picture rotation was stored in the rotation attribute mPictureRotation = composerItemElem.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble(); } } mDefaultSvgSize = QSize( 0, 0 ); if ( itemElem.hasAttribute( QStringLiteral( "sourceExpression" ) ) ) { //update pre 2.5 picture expression to use data defined expression QString sourceExpression = itemElem.attribute( QStringLiteral( "sourceExpression" ), QLatin1String( "" ) ); QString useExpression = itemElem.attribute( QStringLiteral( "useExpression" ) ); bool expressionActive; expressionActive = ( useExpression.compare( QLatin1String( "true" ), Qt::CaseInsensitive ) == 0 ); mDataDefinedProperties.setProperty( QgsLayoutObject::PictureSource, QgsProperty::fromExpression( sourceExpression, expressionActive ) ); } QString imagePath = itemElem.attribute( QStringLiteral( "file" ) ); // convert from relative path to absolute. For SVG we also need to consider system SVG paths QgsPathResolver pathResolver = context.pathResolver(); if ( imagePath.endsWith( QLatin1String( ".svg" ), Qt::CaseInsensitive ) ) imagePath = QgsSymbolLayerUtils::svgSymbolNameToPath( imagePath, pathResolver ); else imagePath = pathResolver.readPath( imagePath ); mSourcePath = imagePath; //picture rotation if ( !qgsDoubleNear( itemElem.attribute( QStringLiteral( "pictureRotation" ), QStringLiteral( "0" ) ).toDouble(), 0.0 ) ) { mPictureRotation = itemElem.attribute( QStringLiteral( "pictureRotation" ), QStringLiteral( "0" ) ).toDouble(); } //rotation map mNorthMode = static_cast< NorthMode >( itemElem.attribute( QStringLiteral( "northMode" ), QStringLiteral( "0" ) ).toInt() ); mNorthOffset = itemElem.attribute( QStringLiteral( "northOffset" ), QStringLiteral( "0" ) ).toDouble(); mRotationMap = nullptr; mRotationMapId = -1; mRotationMapUuid.clear(); mRotationMapId = itemElem.attribute( QStringLiteral( "mapId" ), QStringLiteral( "-1" ) ).toInt(); mRotationMapUuid = itemElem.attribute( QStringLiteral( "mapUuid" ) ); return true; }