39 props.insert( QStringLiteral(
"color" ), QStringLiteral(
"white" ) );
40 props.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
41 props.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
42 props.insert( QStringLiteral(
"color_border" ), QStringLiteral(
"black" ) );
43 props.insert( QStringLiteral(
"width_border" ), QStringLiteral(
"0.3" ) );
44 props.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
61 if ( mHasFixedMapPosition == fixed )
64 mHasFixedMapPosition = fixed;
70 mMapPosition = position;
76 mMapPositionCrs =
crs;
82 mRelativePosition = position;
94 return mOffsetFromReferencePoint / 3.7795275;
99 mOffsetFromReferencePoint = offset;
113 return mFrameSize / 3.7795275;
126 mContentsMargins = margins;
132 mFillSymbol.reset( symbol );
138 return mFillSymbol.get();
143 QPainter *painter = context.
painter();
152 drawFrame( context );
153 if ( mHasFixedMapPosition )
155 drawMarkerSymbol( context );
157 if ( mHasFixedMapPosition )
179 mMarkerSymbol.reset( symbol );
222 return QSizeF( 0, 0 );
230 auto scaleSize = [&context](
double size )->
double
235 const QRectF frameRect( mHasFixedMapPosition ? scaleSize( mOffsetFromReferencePoint.x() ) : 0,
236 mHasFixedMapPosition ? scaleSize( mOffsetFromReferencePoint.y() ) : 0,
237 scaleSize( mFrameSize.width() ),
238 scaleSize( mFrameSize.height() ) );
243 mFillSymbol->startRender( context );
244 const QVector<QPolygonF> rings;
245 mFillSymbol->renderPolygon( poly, &rings,
nullptr, context );
246 mFillSymbol->stopRender( context );
258 mMarkerSymbol->startRender( context );
259 mMarkerSymbol->renderPoint( QPointF( 0, 0 ),
nullptr, context );
260 mMarkerSymbol->stopRender( context );
266 if ( itemElem.isNull() )
270 QDomElement annotationElem = doc.createElement( QStringLiteral(
"AnnotationItem" ) );
271 annotationElem.setAttribute( QStringLiteral(
"mapPositionFixed" ), mHasFixedMapPosition );
272 annotationElem.setAttribute( QStringLiteral(
"mapPosX" ),
qgsDoubleToString( mMapPosition.
x() ) );
273 annotationElem.setAttribute( QStringLiteral(
"mapPosY" ),
qgsDoubleToString( mMapPosition.
y() ) );
274 if ( mMapPositionCrs.
isValid() )
275 mMapPositionCrs.
writeXml( annotationElem, doc );
276 annotationElem.setAttribute( QStringLiteral(
"offsetXMM" ),
qgsDoubleToString( mOffsetFromReferencePoint.x() ) );
277 annotationElem.setAttribute( QStringLiteral(
"offsetYMM" ),
qgsDoubleToString( mOffsetFromReferencePoint.y() ) );
278 annotationElem.setAttribute( QStringLiteral(
"frameWidthMM" ),
qgsDoubleToString( mFrameSize.width() ) );
279 annotationElem.setAttribute( QStringLiteral(
"frameHeightMM" ),
qgsDoubleToString( mFrameSize.height() ) );
280 annotationElem.setAttribute( QStringLiteral(
"canvasPosX" ),
qgsDoubleToString( mRelativePosition.x() ) );
281 annotationElem.setAttribute( QStringLiteral(
"canvasPosY" ),
qgsDoubleToString( mRelativePosition.y() ) );
282 annotationElem.setAttribute( QStringLiteral(
"contentsMargin" ), mContentsMargins.
toString() );
283 annotationElem.setAttribute( QStringLiteral(
"visible" ),
isVisible() );
286 annotationElem.setAttribute( QStringLiteral(
"mapLayer" ), mMapLayer->id() );
291 if ( !symbolElem.isNull() )
293 annotationElem.appendChild( symbolElem );
298 QDomElement fillElem = doc.createElement( QStringLiteral(
"fillSymbol" ) );
300 if ( !symbolElem.isNull() )
302 fillElem.appendChild( symbolElem );
303 annotationElem.appendChild( fillElem );
306 itemElem.appendChild( annotationElem );
311 if ( annotationElem.isNull() )
316 pos.setX( annotationElem.attribute( QStringLiteral(
"canvasPosX" ), QStringLiteral(
"0" ) ).toDouble() );
317 pos.setY( annotationElem.attribute( QStringLiteral(
"canvasPosY" ), QStringLiteral(
"0" ) ).toDouble() );
318 if ( pos.x() >= 1 || pos.x() < 0 || pos.y() < 0 || pos.y() >= 1 )
319 mRelativePosition = QPointF();
321 mRelativePosition = pos;
323 mapPos.
setX( annotationElem.attribute( QStringLiteral(
"mapPosX" ), QStringLiteral(
"0" ) ).toDouble() );
324 mapPos.
setY( annotationElem.attribute( QStringLiteral(
"mapPosY" ), QStringLiteral(
"0" ) ).toDouble() );
325 mMapPosition = mapPos;
327 if ( !mMapPositionCrs.
readXml( annotationElem ) )
332 mContentsMargins =
QgsMargins::fromString( annotationElem.attribute( QStringLiteral(
"contentsMargin" ) ) );
334 if ( annotationElem.hasAttribute( QStringLiteral(
"frameWidthMM" ) ) )
335 mFrameSize.setWidth( annotationElem.attribute( QStringLiteral(
"frameWidthMM" ), QStringLiteral(
"5" ) ).toDouble() );
337 mFrameSize.setWidth( dpiScale * annotationElem.attribute( QStringLiteral(
"frameWidth" ), QStringLiteral(
"50" ) ).toDouble() );
338 if ( annotationElem.hasAttribute( QStringLiteral(
"frameHeightMM" ) ) )
339 mFrameSize.setHeight( annotationElem.attribute( QStringLiteral(
"frameHeightMM" ), QStringLiteral(
"3" ) ).toDouble() );
341 mFrameSize.setHeight( dpiScale * annotationElem.attribute( QStringLiteral(
"frameHeight" ), QStringLiteral(
"50" ) ).toDouble() );
343 if ( annotationElem.hasAttribute( QStringLiteral(
"offsetXMM" ) ) )
344 mOffsetFromReferencePoint.setX( annotationElem.attribute( QStringLiteral(
"offsetXMM" ), QStringLiteral(
"0" ) ).toDouble() );
346 mOffsetFromReferencePoint.setX( dpiScale * annotationElem.attribute( QStringLiteral(
"offsetX" ), QStringLiteral(
"0" ) ).toDouble() );
347 if ( annotationElem.hasAttribute( QStringLiteral(
"offsetYMM" ) ) )
348 mOffsetFromReferencePoint.setY( annotationElem.attribute( QStringLiteral(
"offsetYMM" ), QStringLiteral(
"0" ) ).toDouble() );
350 mOffsetFromReferencePoint.setY( dpiScale * annotationElem.attribute( QStringLiteral(
"offsetY" ), QStringLiteral(
"0" ) ).toDouble() );
352 mHasFixedMapPosition = annotationElem.attribute( QStringLiteral(
"mapPositionFixed" ), QStringLiteral(
"1" ) ).toInt();
353 mVisible = annotationElem.attribute( QStringLiteral(
"visible" ), QStringLiteral(
"1" ) ).toInt();
354 if ( annotationElem.hasAttribute( QStringLiteral(
"mapLayer" ) ) )
361 const QDomElement symbolElem = annotationElem.firstChildElement( QStringLiteral(
"symbol" ) );
362 if ( !symbolElem.isNull() )
364 QgsMarkerSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElem, context );
367 mMarkerSymbol.reset( symbol );
372 mFillSymbol.reset(
nullptr );
373 const QDomElement fillElem = annotationElem.firstChildElement( QStringLiteral(
"fillSymbol" ) );
374 if ( !fillElem.isNull() )
376 const QDomElement symbolElem = fillElem.firstChildElement( QStringLiteral(
"symbol" ) );
377 if ( !symbolElem.isNull() )
379 QgsFillSymbol *symbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context );
382 mFillSymbol.reset( symbol );
389 frameColor.setNamedColor( annotationElem.attribute( QStringLiteral(
"frameColor" ), QStringLiteral(
"#000000" ) ) );
390 frameColor.setAlpha( annotationElem.attribute( QStringLiteral(
"frameColorAlpha" ), QStringLiteral(
"255" ) ).toInt() );
391 QColor frameBackgroundColor;
392 frameBackgroundColor.setNamedColor( annotationElem.attribute( QStringLiteral(
"frameBackgroundColor" ) ) );
393 frameBackgroundColor.setAlpha( annotationElem.attribute( QStringLiteral(
"frameBackgroundColorAlpha" ), QStringLiteral(
"255" ) ).toInt() );
394 double frameBorderWidth = annotationElem.attribute( QStringLiteral(
"frameBorderWidth" ), QStringLiteral(
"0.5" ) ).toDouble();
396 frameBorderWidth = frameBorderWidth * 25.4 / 96.0;
398 props.insert( QStringLiteral(
"color" ), frameBackgroundColor.name() );
399 props.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
400 props.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
401 props.insert( QStringLiteral(
"color_border" ), frameColor.name() );
402 props.insert( QStringLiteral(
"width_border" ), QString::number( frameBorderWidth ) );
403 props.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
412 target->mVisible = mVisible;
413 target->mHasFixedMapPosition = mHasFixedMapPosition;
414 target->mMapPosition = mMapPosition;
415 target->mMapPositionCrs = mMapPositionCrs;
416 target->mRelativePosition = mRelativePosition;
417 target->mOffsetFromReferencePoint = mOffsetFromReferencePoint;
418 target->mFrameSize = mFrameSize;
419 target->mMarkerSymbol.reset( mMarkerSymbol ? mMarkerSymbol->clone() :
nullptr );
420 target->mContentsMargins = mContentsMargins;
421 target->mFillSymbol.reset( mFillSymbol ? mFillSymbol->clone() :
nullptr );
422 target->mSegmentPointWidthMm = mSegmentPointWidthMm;
423 target->mMapLayer = mMapLayer;
424 target->mFeature = mFeature;