59 void QgsCompositionConverter::initPropertyDefinitions()
61 if ( !sPropertyDefinitions.isEmpty() )
69 "|<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>" 70 "|<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>" 71 "|<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]" 115 QgsCompositionConverter::initPropertyDefinitions();
116 return sPropertyDefinitions;
122 initPropertyDefinitions();
124 QDomElement parentElement = composerElement.parentNode().toElement();
126 std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( project );
127 layout->undoStack()->blockCommands(
true );
129 layout->mCustomProperties.readXml( composerElement );
132 layout->guides().setVisible( composerElement.attribute( QStringLiteral(
"guidesVisible" ), QStringLiteral(
"1" ) ).toInt() != 0 );
134 int printResolution = composerElement.attribute( QStringLiteral(
"printResolution" ), QStringLiteral(
"300" ) ).toInt();
135 layout->renderContext().setDpi( printResolution );
138 int pages = composerElement.attribute( QStringLiteral(
"numPages" ) ).toInt( );
139 float paperHeight = composerElement.attribute( QStringLiteral(
"paperHeight" ) ).toDouble( );
140 float paperWidth = composerElement.attribute( QStringLiteral(
"paperWidth" ) ).toDouble( );
142 QString name = composerElement.attribute( QStringLiteral(
"name" ) );
144 if ( name.isEmpty() )
145 name = composerElement.attribute( QStringLiteral(
"title" ) );
147 if ( name.isEmpty() )
148 name = parentElement.attribute( QStringLiteral(
"title" ) );
149 layout->setName( name );
151 for (
int j = 0; j < pages; j++ )
155 layout->pageCollection()->addPage( page );
157 QDomNodeList snapLineNodes = composerElement.elementsByTagName( QStringLiteral(
"SnapLine" ) );
158 for (
int i = 0; i < snapLineNodes.size(); ++i )
160 QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
161 double x1 = snapLineElem.attribute( QStringLiteral(
"x1" ) ).toDouble();
162 double y1 = snapLineElem.attribute( QStringLiteral(
"y1" ) ).toDouble();
163 double x2 = snapLineElem.attribute( QStringLiteral(
"x2" ) ).toDouble();
165 Qt::Orientation orientation( x1 == x2 ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal );
167 std::unique_ptr< QgsLayoutGuide > guide = qgis::make_unique< QgsLayoutGuide >( orientation, position, page );
168 layout->guides().addGuide( guide.release() );
173 if ( composerElement.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
175 QDomElement symbolElement = composerElement.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
179 std::unique_ptr< QgsFillSymbol > symbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context ) );
181 layout->pageCollection()->setPageStyleSymbol( symbol.get() );
187 if ( parentElement.elementsByTagName( QStringLiteral(
"Atlas" ) ).size() )
189 QDomElement atlasElement = parentElement.elementsByTagName( QStringLiteral(
"Atlas" ) ).at( 0 ).toElement();
190 readAtlasXml( layout->atlas(), atlasElement, layout->project() );
193 layout->undoStack()->blockCommands(
false );
198 void QgsCompositionConverter::adjustPos(
QgsPrintLayout *layout,
QgsLayoutItem *layoutItem, QPointF *position,
bool &pasteInPlace,
int zOrderOffset, QPointF &pasteShiftPos,
int &pageNumber )
208 layoutItem->
attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
212 if ( !layoutItem->scene() )
214 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
217 void QgsCompositionConverter::restoreGeneralComposeItemProperties(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
220 QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral(
"ComposerItem" ) );
221 if ( !composerItemList.isEmpty() )
223 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
226 if ( !
qgsDoubleNear( composerItemElem.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
229 layoutItem->
setItemRotation( composerItemElem.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble(), false );
231 QgsCompositionConverter::readXml( layoutItem, composerItemElem );
235 QRectF QgsCompositionConverter::itemPosition(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
238 double x, y, pagex, pagey, width, height;
239 bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOk;
241 x = itemElem.attribute( QStringLiteral(
"x" ) ).toDouble( &xOk );
242 y = itemElem.attribute( QStringLiteral(
"y" ) ).toDouble( &yOk );
243 page = itemElem.attribute( QStringLiteral(
"page" ) ).toInt( &pageOk );
244 pagex = itemElem.attribute( QStringLiteral(
"pagex" ) ).toDouble( &pagexOk );
245 pagey = itemElem.attribute( QStringLiteral(
"pagey" ) ).toDouble( &pageyOk );
246 width = itemElem.attribute( QStringLiteral(
"width" ) ).toDouble( &widthOk );
247 height = itemElem.attribute( QStringLiteral(
"height" ) ).toDouble( &heightOk );
250 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"positionMode" ) ).toInt( &positionModeOk ) );
251 if ( !positionModeOk )
256 if ( pageOk && pagexOk && pageyOk )
262 if ( page <= layoutItem->layout()->pageCollection()->pageCount() )
275 return QRectF( x, y, width, height );
278 QPointF QgsCompositionConverter::minPointFromXml(
const QDomElement &elem )
280 double minX = std::numeric_limits<double>::max();
281 double minY = std::numeric_limits<double>::max();
282 QDomNodeList composerItemList = elem.elementsByTagName( QStringLiteral(
"ComposerItem" ) );
283 for (
int i = 0; i < composerItemList.size(); ++i )
285 QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
288 x = currentComposerItemElem.attribute( QStringLiteral(
"x" ) ).toDouble( &xOk );
289 y = currentComposerItemElem.attribute( QStringLiteral(
"y" ) ).toDouble( &yOk );
294 minX = std::min( minX, x );
295 minY = std::min( minY, y );
297 if ( minX < std::numeric_limits<double>::max() )
299 return QPointF( minX, minY );
303 return QPointF( 0, 0 );
310 initPropertyDefinitions();
312 QList< QgsLayoutObject * > newItems;
317 int zOrderOffset = layout->mItemsModel->zOrderListSize();
319 QPointF pasteShiftPos;
326 QPointF minItemPos = minPointFromXml( parentElement );
329 pasteShiftPos = *position - minItemPos;
332 pageNumber = layout->mPageCollection->pageNumberForPoint( *position );
339 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerMap" ) ).size(); i++ )
341 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerMap" ) ).at( i ) );
343 readMapXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
344 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
345 newItems << layoutItem ;
349 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerLabel" ) ).size(); i++ )
351 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerLabel" ) ).at( i ) );
353 readLabelXml( layoutItem, itemNode.toElement(), layout->
project() );
354 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
355 newItems << layoutItem ;
359 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerShape" ) ).size(); i++ )
361 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerShape" ) ).at( i ) );
363 readShapeXml( layoutItem, itemNode.toElement(), layout->
project() );
364 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
365 newItems << layoutItem ;
369 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPicture" ) ).size(); i++ )
371 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPicture" ) ).at( i ) );
373 readPictureXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
374 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
375 newItems << layoutItem ;
379 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPolygon" ) ).size(); i++ )
381 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPolygon" ) ).at( i ) );
383 readPolyXml<QgsLayoutItemPolygon, QgsFillSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
384 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
385 newItems << layoutItem ;
389 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPolyline" ) ).size(); i++ )
391 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPolyline" ) ).at( i ) );
393 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
394 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
395 newItems << layoutItem ;
399 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerArrow" ) ).size(); i++ )
401 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerArrow" ) ).at( i ) );
403 readArrowXml( layoutItem, itemNode.toElement(), layout->
project() );
404 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
405 newItems << layoutItem ;
409 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerScaleBar" ) ).size(); i++ )
411 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerScaleBar" ) ).at( i ) );
413 readScaleBarXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
414 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
415 newItems << layoutItem ;
419 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerLegend" ) ).size(); i++ )
421 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerLegend" ) ).at( i ) );
423 readLegendXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
424 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
425 newItems << layoutItem ;
429 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerHtml" ) ).size(); i++ )
431 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerHtml" ) ).at( i ) );
433 readHtmlXml( layoutItem, itemNode.toElement(), layout->
project() );
435 const QList<QgsLayoutFrame *> framesList( layoutItem->frames() );
436 for (
const auto &frame : framesList )
438 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
440 newItems << layoutItem ;
444 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerAttributeTableV2" ) ).size(); i++ )
446 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerAttributeTableV2" ) ).at( i ) );
448 readTableXml( layoutItem, itemNode.toElement(), layout->
project() );
450 const QList<QgsLayoutFrame *> framesList( layoutItem->frames() );
451 for (
const auto &frame : framesList )
453 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
455 newItems << layoutItem ;
463 return document.elementsByTagName( QStringLiteral(
"Composition" ) ).count() > 0;
472 if ( document.elementsByTagName( QStringLiteral(
"Composition" ) ).count( ) > 0 )
474 QDomElement composerElem = document.elementsByTagName( QStringLiteral(
"Composition" ) ).at( 0 ).toElement( );
478 QDomElement elem = layout->writeXml( doc, context );
479 doc.appendChild( elem );
487 if ( itemElem.isNull() )
492 restoreGeneralComposeItemProperties( layoutItem, itemElem );
495 layoutItem->
setText( itemElem.attribute( QStringLiteral(
"labelText" ) ) );
498 layoutItem->
setMode( itemElem.attribute( QStringLiteral(
"htmlState" ) ).toInt() == Qt::Checked ? QgsLayoutItemLabel::Mode::ModeHtml : QgsLayoutItemLabel::Mode::ModeFont );
501 bool marginXOk =
false;
502 bool marginYOk =
false;
503 double marginX = itemElem.attribute( QStringLiteral(
"marginX" ) ).toDouble( &marginXOk );
504 double marginY = itemElem.attribute( QStringLiteral(
"marginY" ) ).toDouble( &marginYOk );
505 if ( !marginXOk || !marginYOk )
508 double margin = itemElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"1.0" ) ).toDouble();
516 layoutItem->
setHAlign( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral(
"halign" ) ).toInt() ) );
519 layoutItem->
setVAlign( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral(
"valign" ) ).toInt() ) );
528 QDomNodeList fontColorList = itemElem.elementsByTagName( QStringLiteral(
"FontColor" ) );
529 if ( !fontColorList.isEmpty() )
531 QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
532 int red = fontColorElem.attribute( QStringLiteral(
"red" ), QStringLiteral(
"0" ) ).toInt();
533 int green = fontColorElem.attribute( QStringLiteral(
"green" ), QStringLiteral(
"0" ) ).toInt();
534 int blue = fontColorElem.attribute( QStringLiteral(
"blue" ), QStringLiteral(
"0" ) ).toInt();
548 layoutItem->
setShapeType( static_cast<QgsLayoutItemShape::Shape>( itemElem.attribute( QStringLiteral(
"shapeType" ), QStringLiteral(
"0" ) ).toInt() ) );
551 restoreGeneralComposeItemProperties( layoutItem, itemElem );
557 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
559 QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
560 QgsFillSymbol *shapeStyleSymbol = QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context );
561 if ( shapeStyleSymbol )
562 layoutItem->
setSymbol( shapeStyleSymbol );
571 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
575 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"no" ) );
579 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
583 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"no" ) );
586 properties.insert( QStringLiteral(
"width_border" ), QString::number( layoutItem->pen().widthF() ) );
589 QDomNodeList outlineColorList = itemElem.elementsByTagName( QStringLiteral(
"OutlineColor" ) );
590 if ( !outlineColorList.isEmpty() )
592 QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
593 bool redOk, greenOk, blueOk, alphaOk, widthOk;
594 int penRed, penGreen, penBlue, penAlpha;
597 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
598 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toInt( &redOk );
599 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toInt( &greenOk );
600 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toInt( &blueOk );
601 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toInt( &alphaOk );
603 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
606 properties.insert( QStringLiteral(
"width_border" ), QString::number( penWidth ) );
609 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"FillColor" ) );
610 if ( !fillColorList.isEmpty() )
612 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
613 bool redOk, greenOk, blueOk, alphaOk;
614 int fillRed, fillGreen, fillBlue, fillAlpha;
616 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toInt( &redOk );
617 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toInt( &greenOk );
618 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toInt( &blueOk );
619 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toInt( &alphaOk );
621 if ( redOk && greenOk && blueOk && alphaOk )
624 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
627 if ( itemElem.hasAttribute( QStringLiteral(
"transparentFill" ) ) )
630 bool hasOldTransparentFill = itemElem.attribute( QStringLiteral(
"transparentFill" ), QStringLiteral(
"0" ) ).toInt();
631 if ( hasOldTransparentFill )
633 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"no" ) );
648 restoreGeneralComposeItemProperties( layoutItem, itemElem );
652 bool positionModeOk =
false;
653 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"positionMode" ) ).toInt( &positionModeOk ) );
654 if ( !positionModeOk )
656 layoutItem->mReferencePoint = QgsLayoutItem::ReferencePoint::UpperLeft;
658 bool anchorPointOk =
false;
660 layoutItem->
setPictureAnchor( static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"anchorPoint" ), QString::number( QgsLayoutItem::ReferencePoint::Middle ) ).toInt( &anchorPointOk ) ) );
661 if ( !anchorPointOk )
663 layoutItem->mPictureAnchor = QgsLayoutItem::ReferencePoint::UpperLeft;
667 layoutItem->mSvgStrokeWidth = itemElem.attribute( QStringLiteral(
"svgBorderWidth" ), QStringLiteral(
"0.2" ) ).toDouble();
669 QString imagePath = itemElem.attribute( QStringLiteral(
"file" ) );
674 if ( imagePath.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
677 imagePath = pathResolver.
readPath( imagePath );
680 layoutItem->mPictureHeight = itemElem.attribute( QStringLiteral(
"pictureHeight" ), QStringLiteral(
"10" ) ).toDouble();
681 layoutItem->mPictureWidth = itemElem.attribute( QStringLiteral(
"pictureWidth" ), QStringLiteral(
"10" ) ).toDouble();
684 if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral(
"pictureRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
686 layoutItem->mPictureRotation = itemElem.attribute( QStringLiteral(
"pictureRotation" ), QStringLiteral(
"0" ) ).toDouble();
690 layoutItem->mNorthMode =
static_cast< QgsLayoutItemPicture::NorthMode >( itemElem.attribute( QStringLiteral(
"northMode" ), QStringLiteral(
"0" ) ).toInt() );
691 layoutItem->mNorthOffset = itemElem.attribute( QStringLiteral(
"northOffset" ), QStringLiteral(
"0" ) ).toDouble();
693 QString rotationMapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
694 if ( rotationMapId != QStringLiteral(
"-1" ) )
708 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemElem, project );
710 QDomNodeList startPointList = itemElem.elementsByTagName( QStringLiteral(
"StartPoint" ) );
711 if ( ! startPointList.isEmpty() )
713 QDomElement node = startPointList.at( 0 ).toElement();
714 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
716 QDomNodeList stopPointList = itemElem.elementsByTagName( QStringLiteral(
"StopPoint" ) );
717 if ( ! stopPointList.isEmpty() )
719 QDomElement node = stopPointList.at( 0 ).toElement();
720 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
725 if ( markerMode == QgsCompositionConverter::MarkerMode::DefaultMarker )
727 layoutItem->setEndMarker( QgsLayoutItemPolyline::MarkerMode::ArrowHead );
728 layoutItem->setStartMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
731 layoutItem->setArrowHeadStrokeWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"1.0" ) ).toDouble( ) );
732 layoutItem->setArrowHeadWidth( itemElem.attribute( QStringLiteral(
"arrowHeadWidth" ), QStringLiteral(
"1.0" ) ).toDouble( ) );
734 else if ( markerMode == QgsCompositionConverter::MarkerMode::SVGMarker )
736 QString endMarkerFile = itemElem.attribute( QStringLiteral(
"endMarkerFile" ) );
737 QString startMarkerFile = itemElem.attribute( QStringLiteral(
"endMarkerFile" ) );
744 if ( !endMarkerFile.isEmpty() )
746 if ( endMarkerFile.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
749 endMarkerFile = pathResolver.
readPath( endMarkerFile );
751 if ( !startMarkerFile.isEmpty() )
753 if ( startMarkerFile.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
756 startMarkerFile = pathResolver.
readPath( startMarkerFile );
759 if ( !endMarkerFile.isEmpty() )
761 layoutItem->setEndMarker( QgsLayoutItemPolyline::MarkerMode::SvgMarker );
762 layoutItem->setEndSvgMarkerPath( endMarkerFile );
764 if ( !startMarkerFile.isEmpty() )
766 layoutItem->setStartMarker( QgsLayoutItemPolyline::MarkerMode::SvgMarker );
767 layoutItem->setStartSvgMarkerPath( startMarkerFile );
772 layoutItem->setEndMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
773 layoutItem->setStartMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
776 double margin = polygon.boundingRect().left() - layoutItem->pos().x();
777 polygon.translate( - polygon.boundingRect().left() + margin, - polygon.boundingRect().top() + margin );
778 layoutItem->setNodes( polygon );
785 restoreGeneralComposeItemProperties( layoutItem, itemElem );
787 mapId2Uuid[ itemElem.attribute( QStringLiteral(
"id" ) ) ] = layoutItem->
uuid();
798 QDomNodeList extentNodeList = itemElem.elementsByTagName( QStringLiteral(
"Extent" ) );
799 if ( !extentNodeList.isEmpty() )
801 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
802 double xmin, xmax, ymin, ymax;
803 xmin = extentElem.attribute( QStringLiteral(
"xmin" ) ).toDouble();
804 xmax = extentElem.attribute( QStringLiteral(
"xmax" ) ).toDouble();
805 ymin = extentElem.attribute( QStringLiteral(
"ymin" ) ).toDouble();
806 ymax = extentElem.attribute( QStringLiteral(
"ymax" ) ).toDouble();
810 QDomNodeList crsNodeList = itemElem.elementsByTagName( QStringLiteral(
"crs" ) );
811 if ( !crsNodeList.isEmpty() )
813 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
822 if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
824 layoutItem->
setMapRotation( itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble() );
828 layoutItem->
setFollowVisibilityPreset( itemElem.attribute( QStringLiteral(
"followPreset" ) ).compare( QLatin1String(
"true" ) ) == 0 );
832 QString keepLayerSetFlag = itemElem.attribute( QStringLiteral(
"keepLayerSet" ) );
833 if ( keepLayerSetFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
842 QString drawCanvasItemsFlag = itemElem.attribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
843 if ( drawCanvasItemsFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
852 layoutItem->mLayerStyleOverrides.clear();
855 layoutItem->mLayers.clear();
857 QDomNodeList layerSetNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerSet" ) );
858 if ( !layerSetNodeList.isEmpty() )
860 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
861 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
862 layoutItem->mLayers.reserve( layerIdNodeList.size() );
863 for (
int i = 0; i < layerIdNodeList.size(); ++i )
865 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
866 QString layerId = layerElem.text();
867 QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
868 QString layerSource = layerElem.attribute( QStringLiteral(
"source" ) );
869 QString layerProvider = layerElem.attribute( QStringLiteral(
"provider" ) );
871 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
873 layoutItem->mLayers << ref;
878 QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerStyles" ) );
879 layoutItem->mKeepLayerStyles = !layerStylesNodeList.isEmpty();
880 if ( layoutItem->mKeepLayerStyles )
882 QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
883 QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( QStringLiteral(
"LayerStyle" ) );
884 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
886 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
887 QString layerId = layerStyleElement.attribute( QStringLiteral(
"layerid" ) );
888 QString layerName = layerStyleElement.attribute( QStringLiteral(
"name" ) );
889 QString layerSource = layerStyleElement.attribute( QStringLiteral(
"source" ) );
890 QString layerProvider = layerStyleElement.attribute( QStringLiteral(
"provider" ) );
891 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
895 style.
readXml( layerStyleElement );
896 layoutItem->mLayerStyleOverrides.insert( ref.
layerId, style.
xmlData() );
900 layoutItem->mDrawing =
false;
901 layoutItem->mNumCachedLayers = 0;
902 layoutItem->mCacheInvalidated =
true;
906 QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( QStringLiteral(
"ComposerMapOverview" ) );
907 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
909 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
910 std::unique_ptr<QgsLayoutItemMapOverview> mapOverview(
new QgsLayoutItemMapOverview( mapOverviewElem.attribute( QStringLiteral(
"name" ) ), layoutItem ) );
911 mapOverview->readXml( mapOverviewElem, doc, context );
912 QString frameMapId = mapOverviewElem.attribute( QStringLiteral(
"frameMap" ), QStringLiteral(
"-1" ) );
913 if ( frameMapId != QStringLiteral(
"-1" ) && mapId2Uuid.contains( frameMapId ) )
918 mapOverview->setLinkedMap( mapInstance );
920 layoutItem->mOverviewStack->addOverview( mapOverview.release() );
925 layoutItem->mGridStack->readXml( itemElem, doc, context );
930 QDomNodeList gridNodeList = itemElem.elementsByTagName( QStringLiteral(
"Grid" ) );
931 if ( layoutItem->mGridStack->size() == 0 && !gridNodeList.isEmpty() )
933 QDomElement gridElem = gridNodeList.at( 0 ).toElement();
935 mapGrid->
setEnabled( gridElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
937 mapGrid->
setIntervalX( gridElem.attribute( QStringLiteral(
"intervalX" ), QStringLiteral(
"0" ) ).toDouble() );
938 mapGrid->
setIntervalY( gridElem.attribute( QStringLiteral(
"intervalY" ), QStringLiteral(
"0" ) ).toDouble() );
939 mapGrid->
setOffsetX( gridElem.attribute( QStringLiteral(
"offsetX" ), QStringLiteral(
"0" ) ).toDouble() );
940 mapGrid->
setOffsetY( gridElem.attribute( QStringLiteral(
"offsetY" ), QStringLiteral(
"0" ) ).toDouble() );
941 mapGrid->
setCrossLength( gridElem.attribute( QStringLiteral(
"crossLength" ), QStringLiteral(
"3" ) ).toDouble() );
942 mapGrid->
setFrameStyle( static_cast< QgsLayoutItemMapGrid::FrameStyle >( gridElem.attribute( QStringLiteral(
"gridFrameStyle" ), QStringLiteral(
"0" ) ).toInt() ) );
943 mapGrid->
setFrameWidth( gridElem.attribute( QStringLiteral(
"gridFrameWidth" ), QStringLiteral(
"2.0" ) ).toDouble() );
944 mapGrid->
setFramePenSize( gridElem.attribute( QStringLiteral(
"gridFramePenThickness" ), QStringLiteral(
"0.5" ) ).toDouble() );
949 QDomElement gridSymbolElem = gridElem.firstChildElement( QStringLiteral(
"symbol" ) );
951 if ( gridSymbolElem.isNull() )
955 lineSymbol->
setWidth( gridElem.attribute( QStringLiteral(
"penWidth" ), QStringLiteral(
"0" ) ).toDouble() );
956 lineSymbol->
setColor( QColor( gridElem.attribute( QStringLiteral(
"penColorRed" ), QStringLiteral(
"0" ) ).toInt(),
957 gridElem.attribute( QStringLiteral(
"penColorGreen" ), QStringLiteral(
"0" ) ).toInt(),
958 gridElem.attribute( QStringLiteral(
"penColorBlue" ), QStringLiteral(
"0" ) ).toInt() ) );
962 lineSymbol = QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( gridSymbolElem, context );
967 QDomNodeList annotationNodeList = gridElem.elementsByTagName( QStringLiteral(
"Annotation" ) );
968 if ( !annotationNodeList.isEmpty() )
970 QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
971 mapGrid->
setAnnotationEnabled( annotationElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
981 mapGrid->
setAnnotationFrameDistance( annotationElem.attribute( QStringLiteral(
"frameDistance" ), QStringLiteral(
"0" ) ).toDouble() );
982 QFont annotationFont;
983 annotationFont.fromString( annotationElem.attribute( QStringLiteral(
"font" ), QString() ) );
987 mapGrid->
setAnnotationPrecision( annotationElem.attribute( QStringLiteral(
"precision" ), QStringLiteral(
"3" ) ).toInt() );
989 layoutItem->mGridStack->addGrid( mapGrid );
993 QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral(
"AtlasMap" ) );
994 if ( !atlasNodeList.isEmpty() )
996 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
997 layoutItem->mAtlasDriven = ( atlasElem.attribute( QStringLiteral(
"atlasDriven" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
998 if ( atlasElem.hasAttribute( QStringLiteral(
"fixedScale" ) ) )
1000 layoutItem->
setAtlasScalingMode( atlasElem.attribute( QStringLiteral(
"fixedScale" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) ? QgsLayoutItemMap::AtlasScalingMode::Fixed : QgsLayoutItemMap::AtlasScalingMode::Auto );
1002 else if ( atlasElem.hasAttribute( QStringLiteral(
"scalingMode" ) ) )
1004 layoutItem->
setAtlasScalingMode( static_cast<QgsLayoutItemMap::AtlasScalingMode>( atlasElem.attribute( QStringLiteral(
"scalingMode" ) ).toInt() ) );
1006 layoutItem->
setAtlasMargin( atlasElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"0.1" ) ).toDouble() );
1017 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1019 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1020 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1021 layoutItem->
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
1022 layoutItem->
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
1023 layoutItem->
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
1024 layoutItem->
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
1025 layoutItem->
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
1026 layoutItem->
setSegmentSizeMode( static_cast<QgsScaleBarSettings::SegmentSizeMode>( itemElem.attribute( QStringLiteral(
"segmentSizeMode" ), QStringLiteral(
"0" ) ).toInt() ) );
1027 layoutItem->
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1028 layoutItem->
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
1029 layoutItem->mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
1030 layoutItem->
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
1031 layoutItem->
setLineWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
1032 layoutItem->
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
1038 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QString() ) );
1046 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
1047 if ( !fillColorList.isEmpty() )
1049 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1050 bool redOk, greenOk, blueOk, alphaOk;
1051 int fillRed, fillGreen, fillBlue, fillAlpha;
1053 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1054 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1055 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1056 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1058 if ( redOk && greenOk && blueOk && alphaOk )
1060 layoutItem->
setFillColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1065 layoutItem->
setFillColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
1069 QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
1070 if ( !fillColor2List.isEmpty() )
1072 QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1073 bool redOk, greenOk, blueOk, alphaOk;
1074 int fillRed, fillGreen, fillBlue, fillAlpha;
1076 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1077 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1078 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1079 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1081 if ( redOk && greenOk && blueOk && alphaOk )
1083 layoutItem->
setFillColor2( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1088 layoutItem->
setFillColor2( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
1092 QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
1093 if ( !strokeColorList.isEmpty() )
1095 QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1096 bool redOk, greenOk, blueOk, alphaOk;
1097 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1099 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1100 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1101 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1102 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1104 if ( redOk && greenOk && blueOk && alphaOk )
1106 layoutItem->
setLineColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1107 QPen p = layoutItem->mSettings.
pen();
1108 p.setColor( layoutItem->mSettings.
lineColor() );
1109 layoutItem->setPen( p );
1114 layoutItem->
setLineColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
1115 QPen p = layoutItem->mSettings.
pen();
1116 p.setColor( layoutItem->mSettings.
lineColor() );
1117 layoutItem->setPen( p );
1121 QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
1122 if ( !textColorList.isEmpty() )
1124 QDomElement textColorElem = textColorList.at( 0 ).toElement();
1125 bool redOk, greenOk, blueOk, alphaOk;
1126 int textRed, textGreen, textBlue, textAlpha;
1128 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1129 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1130 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1131 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1133 if ( redOk && greenOk && blueOk && alphaOk )
1136 layoutItem->
setFontColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1143 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1150 QString styleString = itemElem.attribute( QStringLiteral(
"style" ), QString() );
1151 layoutItem->
setStyle( QObject::tr( styleString.toLocal8Bit().data() ) );
1153 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
1156 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
1177 layoutItem->
setAlignment( static_cast< QgsScaleBarSettings::Alignment >( itemElem.attribute( QStringLiteral(
"alignment" ), QStringLiteral(
"0" ) ).toInt() ) );
1180 QString mapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
1181 if ( mapId != QStringLiteral(
"-1" ) && mapId2Uuid.contains( mapId ) )
1195 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1205 QString mapId = itemElem.attribute( QStringLiteral(
"map" ), QStringLiteral(
"-1" ) );
1206 if ( mapId != QStringLiteral(
"-1" ) && mapId2Uuid.contains( mapId ) )
1216 layoutItem->
setTitle( itemElem.attribute( QStringLiteral(
"title" ) ) );
1217 if ( !itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).isEmpty() )
1219 layoutItem->
setTitleAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).toInt() ) );
1221 int colCount = itemElem.attribute( QStringLiteral(
"columnCount" ), QStringLiteral(
"1" ) ).toInt();
1222 if ( colCount < 1 ) colCount = 1;
1224 layoutItem->
setSplitLayer( itemElem.attribute( QStringLiteral(
"splitLayer" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1225 layoutItem->
setEqualColumnWidth( itemElem.attribute( QStringLiteral(
"equalColumnWidth" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1227 QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"styles" ) );
1228 if ( !stylesNodeList.isEmpty() )
1230 QDomNode stylesNode = stylesNodeList.at( 0 );
1231 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
1233 QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
1235 style.
readXml( styleElem, QDomDocument() );
1236 QString name = styleElem.attribute( QStringLiteral(
"name" ) );
1250 fontClr.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1254 layoutItem->
setBoxSpace( itemElem.attribute( QStringLiteral(
"boxSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1255 layoutItem->
setColumnSpace( itemElem.attribute( QStringLiteral(
"columnSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1257 layoutItem->
setSymbolWidth( itemElem.attribute( QStringLiteral(
"symbolWidth" ), QStringLiteral(
"7.0" ) ).toDouble() );
1258 layoutItem->
setSymbolHeight( itemElem.attribute( QStringLiteral(
"symbolHeight" ), QStringLiteral(
"14.0" ) ).toDouble() );
1259 layoutItem->
setWmsLegendWidth( itemElem.attribute( QStringLiteral(
"wmsLegendWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1260 layoutItem->
setWmsLegendHeight( itemElem.attribute( QStringLiteral(
"wmsLegendHeight" ), QStringLiteral(
"25" ) ).toDouble() );
1261 layoutItem->
setLineSpacing( itemElem.attribute( QStringLiteral(
"lineSpacing" ), QStringLiteral(
"1.0" ) ).toDouble() );
1263 layoutItem->
setDrawRasterStroke( itemElem.attribute( QStringLiteral(
"rasterBorder" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
1265 layoutItem->
setRasterStrokeWidth( itemElem.attribute( QStringLiteral(
"rasterBorderWidth" ), QStringLiteral(
"0" ) ).toDouble() );
1267 layoutItem->
setWrapString( itemElem.attribute( QStringLiteral(
"wrapChar" ) ) );
1269 layoutItem->mSizeToContents = itemElem.attribute( QStringLiteral(
"resizeToContents" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" );
1270 layoutItem->mLegendFilterByMap = itemElem.attribute( QStringLiteral(
"legendFilterByMap" ), QStringLiteral(
"0" ) ).toInt();
1271 layoutItem->mFilterOutAtlas = itemElem.attribute( QStringLiteral(
"legendFilterByAtlas" ), QStringLiteral(
"0" ) ).toInt();
1274 QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree" ) );
1275 if ( layerTreeElem.isNull() )
1276 layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
1278 if ( !layerTreeElem.isNull() )
1283 layoutItem->setCustomLayerTree( tree );
1287 layoutItem->setCustomLayerTree(
nullptr );
1293 bool QgsCompositionConverter::readAtlasXml(
QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project )
1295 atlasItem->
setEnabled( itemElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1298 QString layerId = itemElem.attribute( QStringLiteral(
"coverageLayer" ) );
1299 QString layerName = itemElem.attribute( QStringLiteral(
"coverageLayerName" ) );
1300 QString layerSource = itemElem.attribute( QStringLiteral(
"coverageLayerSource" ) );
1301 QString layerProvider = itemElem.attribute( QStringLiteral(
"coverageLayerProvider" ) );
1306 atlasItem->
setPageNameExpression( itemElem.attribute( QStringLiteral(
"pageNameExpression" ), QString() ) );
1307 QString errorString;
1308 atlasItem->
setFilenameExpression( itemElem.attribute( QStringLiteral(
"filenamePattern" ), QString() ), errorString );
1310 atlasItem->
setSortFeatures( itemElem.attribute( QStringLiteral(
"sortFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1313 atlasItem->
setSortExpression( itemElem.attribute( QStringLiteral(
"sortKey" ), QString() ) );
1314 atlasItem->
setSortAscending( itemElem.attribute( QStringLiteral(
"sortAscending" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1316 atlasItem->
setFilterFeatures( itemElem.attribute( QStringLiteral(
"filterFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1319 QString expErrorString;
1320 atlasItem->
setFilterExpression( itemElem.attribute( QStringLiteral(
"featureFilter" ), QString() ), expErrorString );
1324 atlasItem->
setHideCoverage( itemElem.attribute( QStringLiteral(
"hideCoverage" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1330 bool QgsCompositionConverter::readHtmlXml(
QgsLayoutItemHtml *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1333 readOldComposerObjectXml( layoutItem, itemElem );
1336 layoutItem->
setResizeMode( static_cast< QgsLayoutMultiFrame::ResizeMode >( itemElem.attribute( QStringLiteral(
"resizeMode" ), QStringLiteral(
"0" ) ).toInt() ) );
1337 QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1338 for (
int i = 0; i < frameList.size(); ++i )
1340 QDomElement frameElem = frameList.at( i ).toElement();
1342 restoreGeneralComposeItemProperties( newFrame, frameElem );
1344 double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1345 double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1346 double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1347 double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1349 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1350 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1351 layoutItem->
addFrame( newFrame,
false );
1355 layoutItem->
setContentMode( static_cast< QgsLayoutItemHtml::ContentMode >( itemElem.attribute( QStringLiteral(
"contentMode" ) ).toInt( &contentModeOK ) ) );
1356 if ( !contentModeOK )
1358 layoutItem->
setContentMode( QgsLayoutItemHtml::ContentMode::Url );
1360 layoutItem->
setEvaluateExpressions( itemElem.attribute( QStringLiteral(
"evaluateExpressions" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1361 layoutItem->
setUseSmartBreaks( itemElem.attribute( QStringLiteral(
"useSmartBreaks" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1362 layoutItem->
setMaxBreakDistance( itemElem.attribute( QStringLiteral(
"maxBreakDistance" ), QStringLiteral(
"10" ) ).toDouble() );
1363 layoutItem->
setHtml( itemElem.attribute( QStringLiteral(
"html" ) ) );
1364 layoutItem->
setUserStylesheet( itemElem.attribute( QStringLiteral(
"stylesheet" ) ) );
1365 layoutItem->
setUserStylesheetEnabled( itemElem.attribute( QStringLiteral(
"stylesheetEnabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1368 QString urlString = itemElem.attribute( QStringLiteral(
"url" ) );
1369 if ( !urlString.isEmpty() )
1371 layoutItem->
setUrl( urlString );
1382 readOldComposerObjectXml( layoutItem, itemElem );
1385 layoutItem->
setResizeMode( static_cast< QgsLayoutMultiFrame::ResizeMode >( itemElem.attribute( QStringLiteral(
"resizeMode" ), QStringLiteral(
"0" ) ).toInt() ) );
1386 QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1387 for (
int i = 0; i < frameList.size(); ++i )
1389 QDomElement frameElem = frameList.at( i ).toElement();
1391 restoreGeneralComposeItemProperties( newFrame, frameElem );
1393 double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1394 double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1395 double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1396 double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1398 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1399 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1400 layoutItem->
addFrame( newFrame,
false );
1403 layoutItem->
setEmptyTableBehavior( static_cast<QgsLayoutTable::EmptyTableMode>( itemElem.attribute( QStringLiteral(
"emptyTableMode" ), QStringLiteral(
"0" ) ).toInt() ) );
1404 layoutItem->
setEmptyTableMessage( itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), QObject::tr(
"No matching records" ) ) );
1405 layoutItem->
setShowEmptyRows( itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt() );
1408 layoutItem->
mHeaderFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
1411 layoutItem->
setHeaderHAlignment( static_cast<QgsLayoutTable::HeaderHAlignment>( itemElem.attribute( QStringLiteral(
"headerHAlignment" ), QStringLiteral(
"0" ) ).toInt() ) ) ;
1412 layoutItem->
setHeaderMode( static_cast<QgsLayoutTable::HeaderMode>( itemElem.attribute( QStringLiteral(
"headerMode" ), QStringLiteral(
"0" ) ).toInt() ) );
1415 layoutItem->
mContentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
1418 layoutItem->
setCellMargin( itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble() );
1419 layoutItem->
setGridStrokeWidth( itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble() );
1420 layoutItem->
setHorizontalGrid( itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1421 layoutItem->
setVerticalGrid( itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1422 layoutItem->
setShowGrid( itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt() );
1425 layoutItem->
setWrapBehavior( static_cast<QgsLayoutTable::WrapBehavior>( itemElem.attribute( QStringLiteral(
"wrapBehavior" ), QStringLiteral(
"0" ) ).toInt() ) );
1429 QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
1430 if ( !columnsList.isEmpty() )
1432 QDomElement columnsElem = columnsList.at( 0 ).toElement();
1433 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
1434 for (
int i = 0; i < columnEntryList.size(); ++i )
1436 QDomElement columnElem = columnEntryList.at( i ).toElement();
1438 column->mHAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
1439 column->mVAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
1440 column->mHeading = columnElem.attribute( QStringLiteral(
"heading" ), QString() );
1441 column->mAttribute = columnElem.attribute( QStringLiteral(
"attribute" ), QString() );
1442 column->mSortByRank = columnElem.attribute( QStringLiteral(
"sortByRank" ), QStringLiteral(
"0" ) ).toInt();
1443 column->mSortOrder =
static_cast< Qt::SortOrder
>( columnElem.attribute( QStringLiteral(
"sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
1444 column->mWidth = columnElem.attribute( QStringLiteral(
"width" ), QStringLiteral(
"0.0" ) ).toDouble();
1446 QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral(
"backgroundColor" ) );
1447 if ( !bgColorList.isEmpty() )
1449 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1450 bool redOk, greenOk, blueOk, alphaOk;
1451 int bgRed, bgGreen, bgBlue, bgAlpha;
1452 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1453 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1454 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1455 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1456 if ( redOk && greenOk && blueOk && alphaOk )
1458 column->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1461 layoutItem->
mColumns.append( column );
1466 QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
1467 if ( !stylesList.isEmpty() )
1469 QDomElement stylesElem = stylesList.at( 0 ).toElement();
1471 QMap< QgsLayoutTable::CellStyleGroup, QString >::const_iterator it = layoutItem->mCellStyleNames.constBegin();
1472 for ( ; it != layoutItem->mCellStyleNames.constEnd(); ++it )
1474 QString styleName = it.value();
1475 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
1476 if ( !styleList.isEmpty() )
1478 QDomElement styleElem = styleList.at( 0 ).toElement();
1487 QString layerId = itemElem.attribute( QStringLiteral(
"vectorLayer" ) );
1488 QString layerName = itemElem.attribute( QStringLiteral(
"vectorLayerName" ) );
1489 QString layerSource = itemElem.attribute( QStringLiteral(
"vectorLayerSource" ) );
1490 QString layerProvider = itemElem.attribute( QStringLiteral(
"vectorLayerProvider" ) );
1499 template <
class T,
class T2>
1500 bool QgsCompositionConverter::readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1502 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1503 QDomNodeList nodeList = itemElem.elementsByTagName( QStringLiteral(
"node" ) );
1504 if ( !nodeList.isEmpty() )
1507 for (
int i = 0; i < nodeList.length(); i++ )
1509 QDomElement node = nodeList.at( i ).toElement();
1510 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
1512 layoutItem->setNodes( polygon );
1514 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
1516 QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
1520 T2 *styleSymbol = QgsSymbolLayerUtils::loadSymbol<T2>( symbolElement, context );
1522 layoutItem->setSymbol( styleSymbol );
1525 layoutItem->setFrameEnabled(
false );
1526 layoutItem->setBackgroundEnabled(
false );
1531 bool QgsCompositionConverter::readXml(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
1533 if ( itemElem.isNull() )
1538 readOldComposerObjectXml( layoutItem, itemElem );
1541 layoutItem->mUuid = itemElem.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
1544 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1547 QString
id = itemElem.attribute( QStringLiteral(
"id" ), QString() );
1548 layoutItem->
setId(
id );
1551 QString frame = itemElem.attribute( QStringLiteral(
"frame" ) );
1552 layoutItem->
setFrameEnabled( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 ) ;
1555 QString background = itemElem.attribute( QStringLiteral(
"background" ) );
1556 layoutItem->
setBackgroundEnabled( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1559 QString positionLock = itemElem.attribute( QStringLiteral(
"positionLock" ) );
1560 layoutItem->
setLocked( positionLock.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1563 layoutItem->
setVisibility( itemElem.attribute( QStringLiteral(
"visibility" ), QStringLiteral(
"1" ) ) != QStringLiteral(
"0" ) );
1565 layoutItem->mParentGroupUuid = itemElem.attribute( QStringLiteral(
"groupUuid" ) );
1566 if ( !layoutItem->mParentGroupUuid.isEmpty() )
1570 group->addItem( layoutItem );
1573 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1576 QRectF position = itemPosition( layoutItem, itemElem );
1581 layoutItem->setZValue( itemElem.attribute( QStringLiteral(
"zValue" ) ).toDouble() );
1584 QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral(
"FrameColor" ) );
1585 if ( !frameColorList.isEmpty() )
1587 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
1588 bool redOk, greenOk, blueOk, alphaOk, widthOk;
1589 int penRed, penGreen, penBlue, penAlpha;
1592 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
1593 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1594 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1595 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1596 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1599 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
1606 layoutItem->setPen( framePen );
1613 QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
1614 if ( !bgColorList.isEmpty() )
1616 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1617 bool redOk, greenOk, blueOk, alphaOk;
1618 int bgRed, bgGreen, bgBlue, bgAlpha;
1619 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1620 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1621 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1622 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1623 if ( redOk && greenOk && blueOk && alphaOk )
1625 layoutItem->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1626 layoutItem->setBrush( QBrush( layoutItem->mBackgroundColor, Qt::SolidPattern ) );
1636 if ( itemElem.hasAttribute( QStringLiteral(
"opacity" ) ) )
1638 layoutItem->
setItemOpacity( itemElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
1642 layoutItem->
setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
1645 layoutItem->mExcludeFromExports = itemElem.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
1646 layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
1651 layoutItem->
setItemRotation( itemElem.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble(), false );
1653 layoutItem->mBlockUndoCommands =
false;
1660 bool QgsCompositionConverter::readOldComposerObjectXml(
QgsLayoutObject *layoutItem,
1661 const QDomElement &itemElem )
1663 if ( itemElem.isNull() )
1671 QDomNode propsNode = itemElem.namedItem( QStringLiteral(
"dataDefinedProperties" ) );
1672 if ( !propsNode.isNull() )
1680 exp = QStringLiteral(
"100.0 - (%1)" ).arg( exp );
1692 void QgsCompositionConverter::readOldDataDefinedPropertyMap(
const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties )
1695 QgsPropertiesDefinition::const_iterator i = defs.constBegin();
1696 for ( ; i != defs.constEnd(); ++i )
1698 QString elemName = i.value().name();
1699 QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
1700 if ( !ddNodeList.isEmpty() )
1702 QDomElement ddElem = ddNodeList.at( 0 ).toElement();
1703 QgsProperty prop = readOldDataDefinedProperty( static_cast< QgsCompositionConverter::DataDefinedProperty >( i.key() ), ddElem );
1705 dataDefinedProperties.
setProperty( i.key(), prop );
1718 QString active = ddElem.attribute( QStringLiteral(
"active" ) );
1719 bool isActive =
false;
1720 if ( active.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1724 QString field = ddElem.attribute( QStringLiteral(
"field" ) );
1725 QString expr = ddElem.attribute( QStringLiteral(
"expr" ) );
1727 QString useExpr = ddElem.attribute( QStringLiteral(
"useExpr" ) );
1728 bool isExpression =
false;
1729 if ( useExpr.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1731 isExpression =
true;
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
void setCoverageLayer(QgsVectorLayer *layer)
Sets the coverage layer to use for the atlas features.
void setColumnSpace(double spacing)
Sets the legend column spacing.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
void setFramePenSize(const double width)
Sets the width of the stroke drawn in the grid frame.
The class is used as a container of context for various read/write operations on other objects...
void setEqualColumnWidth(bool equalize)
Sets whether column widths should be equalized.
void setFontColor(const QColor &color)
Sets the legend font color.
void setIntervalY(double interval)
Sets the interval between grid lines in the y-direction.
void setFollowVisibilityPresetName(const QString &name)
Sets preset name for map rendering.
A rectangle specified with double values.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
void setLineWidth(double width)
Sets the line width in millimeters for lines in the scalebar.
void setWrapBehavior(WrapBehavior behavior)
Sets the wrap behavior for the table, which controls how text within cells is automatically wrapped...
void setTitle(const QString &title)
Sets the legend title.
void setOffsetX(double offset)
Sets the offset for grid lines in the x-direction.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Positive integer values (including 0)
QMap< CellStyleGroup, QgsLayoutTableStyle *> mCellStyles
void setSplitLayer(bool enabled)
Sets whether the legend items from a single layer can be split over multiple columns.
void setLineJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the lines in the scalebar.
void setAnnotationFontColor(const QColor &color)
Sets the font color used for drawing grid annotations.
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
Base class for graphical items within a QgsLayout.
void setSymbolWidth(double width)
Sets the legend symbol width.
An individual overview which is drawn above the map content in a QgsLayoutItemMap, and shows the extent of another QgsLayoutItemMap.
void setVAlign(Qt::AlignmentFlag alignment)
Sets for the vertical alignment of the label.
void setUserStylesheet(const QString &stylesheet)
Sets the user stylesheet CSS rules to use while rendering the HTML content.
void refreshBackgroundColor(bool updateItem=true)
Refresh item's background color, considering data defined colors.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from XML.
void setUserStylesheetEnabled(bool enabled)
Sets whether user stylesheets are enabled for the HTML content.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
QPen pen() const
Returns the pen used for drawing outlines in the scalebar.
void setCellMargin(double margin)
Sets the margin distance in mm between cell borders and their contents.
A layout item subclass for text labels.
Preset paper size for composition.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
QString xmlData() const
Returns XML content of the style.
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading)
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
static QgsFillSymbol * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
void setSortAscending(bool ascending)
Sets whether features should be sorted in an ascending order.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
void setHeaderFontColor(const QColor &color)
Sets the color used to draw header text in the table.
QgsLayoutItem * itemByUuid(const QString &uuid, bool includeTemplateUuids=false) const
Returns the layout item with matching uuid unique identifier, or nullptr if a matching item could not...
void setLineCapStyle(Qt::PenCapStyle style)
Sets the cap style used when drawing the lines in the scalebar.
bool frameEnabled() const
Returns true if the item includes a frame.
A container for grouping several QgsLayoutItems.
Styling option for a composer table cell.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
TYPE * resolveWeakly(const QgsProject *project)
Resolves the map layer by attempting to find a matching layer in a project using a weak match...
Non-zero positive integer values.
#define Q_NOWARN_DEPRECATED_PUSH
void setEmptyTableMessage(const QString &message)
Sets the message for empty tables with no content rows.
void setHtml(const QString &html)
Sets the html to display in the item when the item is using the QgsLayoutItemHtml::ManualHtml mode...
A layout item subclass that displays SVG files or raster format images (jpg, png, ...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static std::unique_ptr< QgsPrintLayout > createLayoutFromCompositionXml(const QDomElement &composerElement, QgsProject *project)
createLayoutFromCompositionXml is a factory that creates layout instances from a QGIS 2...
static QDomDocument convertCompositionTemplate(const QDomDocument &document, QgsProject *project)
Convert a composition template document to a layout template.
void setHeight(double height)
Sets the scalebar height (in millimeters).
void setAnnotationPosition(AnnotationPosition position, BorderSide side)
Sets the position for the grid annotations on a specified side of the map frame.
Contains detailed styling information relating to how a layout legend should be rendered.
void loadHtml(bool useCache=false, const QgsExpressionContext *context=nullptr)
Reloads the html source from the url and redraws the item.
void setFilterFeatures(bool filtered)
Sets whether features should be filtered in the coverage layer.
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
void setVerticalGrid(bool verticalGrid)
Sets whether the grid's vertical lines should be drawn in the table.
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
Color with alpha channel.
void setStyle(QgsLegendStyle::Style component, const QgsLegendStyle &style)
Sets the style of component to style for the legend.
void setAlignment(QgsScaleBarSettings::Alignment alignment)
Sets the scalebar alignment.
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
void attemptMoveBy(double deltaX, double deltaY)
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units...
QList< QgsLayoutItemPage *> pages()
Returns a list of pages in the collection.
void setKeepLayerSet(bool enabled)
Sets whether the stored layer set should be used or the current layer set of the associated project...
void setFrameStrokeColor(const QColor &color)
Sets the frame stroke color.
Layout item for node based polygon shapes.
QColor lineColor() const
Returns the color used for lines in the scalebar.
void setMarginX(double margin)
Sets the horizontal margin between the edge of the frame and the label contents, in layout units...
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
void setPictureAnchor(QgsLayoutItem::ReferencePoint anchor)
Sets the picture's anchor point, which controls how it is placed within the picture item's frame...
Positive double value (including 0)
void resolveReferences(const QgsProject *project, bool looseMatching=false) override
Calls resolveReferences() on child tree nodes.
void setLineColor(const QColor &color)
Sets the color used for lines in the scalebar.
void setSegmentSizeMode(QgsScaleBarSettings::SegmentSizeMode mode)
Sets the size mode for scale bar segments.
QMap< QString, QString > QgsStringMap
void setStyle(const QString &name)
Sets the scale bar style by name.
Rotation (value between 0-360 degrees)
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
void setSortExpression(const QString &expression)
Sets the expression (or field name) to use for sorting features.
A line symbol type, for rendering LineString and MultiLineString geometries.
Stores properties of a column for a QgsLayoutTable.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
void setFrameWidth(const double width)
Sets the grid frame width (in layout units).
void setContentSection(const QRectF §ion)
Sets the visible part of the multiframe's content which is visible within this frame (relative to the...
QgsLayoutMeasurement frameStrokeWidth() const
Returns the frame's stroke width.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
double spaceBetweenPages() const
Returns the space between pages, in layout units.
static QString encodeColor(const QColor &color)
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
void setAnnotationFont(const QFont &font)
Sets the font used for drawing grid annotations.
ReferencePoint
Fixed position reference point.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Exclude item from exports.
void setFillColor(const QColor &color)
Sets the color used for fills in the scalebar.
bool setFilenameExpression(const QString &expression, QString &errorString)
Sets the filename expression used for generating output filenames for each atlas page.
void setHeaderMode(HeaderMode mode)
Sets the display mode for headers in the table.
Stores style information (renderer, opacity, labeling, diagrams etc.) applicable to a map layer...
void setMaximumBarWidth(double maxWidth)
Sets the maximum width (in millimeters) for scale bar segments.
void setEvaluateExpressions(bool evaluateExpressions)
Sets whether the html item will evaluate QGIS expressions prior to rendering the HTML content...
Layout graphical items for displaying a map.
Layout item for node based polyline shapes.
virtual void setId(const QString &id)
Set the item's id name.
QString layerId
Original layer ID.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
void setHAlign(Qt::AlignmentFlag alignment)
Sets the horizontal alignment of the label.
void setLocked(bool locked)
Sets whether the item is locked, preventing mouse interactions with the item.
Namespace with helper functions for layer tree operations.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
static bool isCompositionTemplate(const QDomDocument &document)
Check if the given document is a composition template.
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
void setHorizontalGrid(bool horizontalGrid)
Sets whether the grid's horizontal lines should be drawn in the table.
void setFrameJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the item's frame.
bool hasBackground() const
Returns true if the item has a background.
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
void setUseSmartBreaks(bool useSmartBreaks)
Sets whether the html item should use smart breaks.
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
void setWidth(double width)
Sets the width for the whole line symbol.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout...
void setBlendMode(QPainter::CompositionMode mode)
Sets the item's composition blending mode.
void setHeaderHAlignment(HeaderHAlignment alignment)
Sets the horizontal alignment for table headers.
void attemptSetSceneRect(const QRectF &rect, bool includesFrame=false)
Attempts to update the item's position and size to match the passed rect in layout coordinates...
void setResizeMode(ResizeMode mode)
Sets the resize mode for the multiframe, and recalculates frame sizes to match.
Layout item for basic filled shapes (e.g.
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
void setMinimumBarWidth(double minWidth)
Sets the minimum width (in millimeters) for scale bar segments.
void setMode(Mode mode)
Sets the label's current mode, allowing the label to switch between font based and HTML based renderi...
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
virtual void setItemRotation(double rotation, bool adjustPosition=true)
Sets the layout item's rotation, in degrees clockwise.
Symbol icon (excluding label)
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
Scalebar secondary fill color.
void setMarginY(double margin)
Sets the vertical margin between the edge of the frame and the label contents, in layout units...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
A layout table subclass that displays attributes from a vector layer.
Item transparency (deprecated)
void setHideBackgroundIfEmpty(bool hideBackgroundIfEmpty)
Sets whether the background and frame stroke should be hidden if this frame is empty.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
void setContentFontColor(const QColor &color)
Sets the color used to draw text in table body cells.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the map's preset crs (coordinate reference system).
void setHideCoverage(bool hide)
Sets whether the coverage layer should be hidden in map items in the layouts.
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
void setLineSpacing(double spacing)
Sets the spacing in-between multiple lines.
QFont mHeaderFont
Header font.
void setPicturePath(const QString &path)
Sets the source path of the image (may be svg or a raster format).
void setUnitLabel(const QString &label)
Sets the label for units.
AnnotationFormat
Format for displaying grid annotations.
A store for object properties.
void setFillColor2(const QColor &color)
Sets the secondary color used for fills in the scalebar.
QColor frameStrokeColor() const
Returns the frame's stroke color.
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
void setStyle(GridStyle style)
Sets the grid style, which controls how the grid is drawn over the map's contents.
Double value (including negative values)
void setGridStrokeWidth(double width)
Sets the width in mm for grid lines in the table.
void setAnnotationDirection(AnnotationDirection direction, BorderSide side)
Sets the direction for drawing frame annotations for the specified map side.
void setWrapString(const QString &string)
Sets the legend text wrapping string.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
Style
Component of legends which can be styled.
void setContentMode(ContentMode mode)
Sets the source mode for item's HTML content.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
AnnotationDirection
Direction of grid annotations.
Definition for a property.
QFont mContentFont
Table contents font.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used for drawing grid lines.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
void setColumnCount(int count)
Sets the legend column count.
AnnotationPosition
Position for grid annotations.
void setUrl(const QUrl &url)
Sets the url for content to display in the item when the item is using the QgsLayoutItemHtml::Url mod...
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
DistanceUnit
Units of distance.
Number of pages in composition.
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
void setFontColor(const QColor &color)
Sets the label font color.
bool setFilterExpression(const QString &expression, QString &errorString)
Sets the expression used for filtering features in the coverage layer.
void readXml(const QDomElement &elem, const QDomDocument &doc)
Reads the component's style definition from an XML element.
void setFollowVisibilityPreset(bool follow)
Sets whether the map should follow a map theme.
#define Q_NOWARN_DEPRECATED_POP
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
MarkerMode
The MarkerMode enum is the old QGIS 2.x arrow marker mode.
QgsLayoutTableColumns mColumns
Columns to show in table.
static QList< QgsLayoutObject * > addItemsFromCompositionXml(QgsPrintLayout *layout, const QDomElement &parentElement, QPointF *position=nullptr, bool pasteInPlace=false)
addItemsFromCompositionXml parse a QGIS 2.x composition XML in the parentElement, converts the 2...
double length() const
Returns the length of the measurement.
void setMapRotation(double rotation)
Sets the rotation for the map - this does not affect the layout item shape, only the way the map is d...
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
bool readXml(const QDomElement &styleElem)
Reads the style's properties from XML.
void setSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to draw the shape.
NorthMode
Method for syncing rotation to a map's North direction.
Dummy property with no effect on item.
void setDrawAnnotations(bool draw)
Sets whether annotations are drawn within the map.
void setCrossLength(const double length)
Sets the length (in layout units) of the cross segments drawn for the grid.
Property requires a string value.
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
void setUnits(QgsUnitTypes::DistanceUnit units)
Sets the distance units used by the scalebar.
DataDefinedProperty
Composition data defined properties for different item types.
void setFont(const QFont &font)
Sets the label's current font.
static QgsLayerTree * readXml(QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
void updateBoundingRect()
Updates the bounding rect of this item. Call this function before doing any changes related to annota...
void setEnabled(bool enabled)
Sets whether the atlas is enabled.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
ResizeMode
Controls how pictures are scaled within the item's frame.
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
virtual QString uuid() const
Returns the item identification string.
This class represents a coordinate reference system (CRS).
void addLayoutItem(QgsLayoutItem *item)
Adds an item to the layout.
void refreshFrame(bool updateItem=true)
Refresh item's frame, considering data defined colors and frame size.
static QgsLayoutItemPage * create(QgsLayout *layout)
Returns a new page item for the specified layout.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
void setMaxBreakDistance(double distance)
Sets the maximum distance allowed when calculating where to place page breaks in the html...
QgsProject * project() const
The project associated with the layout.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
A layout item subclass for scale bars.
A base class for objects which belong to a layout.
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
void setBackgroundColor(const QColor &color)
Sets the color used for background of table.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
void setWmsLegendHeight(double height)
Sets the WMS legend height.
void setWmsLegendWidth(double width)
Sets the WMS legend width.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void setAnnotationFrameDistance(const double distance)
Sets the distance between the map frame and annotations.
void setOffsetY(double offset)
Sets the offset for grid lines in the y-direction.
void setIntervalX(double interval)
Sets the interval between grid lines in the x-direction.
void setPageSize(const QgsLayoutSize &size)
Sets the size of the page.
GridStyle
Grid drawing style.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
A layout item subclass for map legends.
virtual void addFrame(QgsLayoutFrame *frame, bool recalcFrameSizes=true)
Adds a frame to the multiframe.
void setSortFeatures(bool enabled)
Sets whether features should be sorted in the atlas.
Page number for item placement.
void setSymbolHeight(double height)
Sets the legend symbol height.
Symbol label (excluding icon)
Resolves relative paths into absolute paths and vice versa.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
void setEmptyTableBehavior(EmptyTableMode mode)
Sets the behavior mode for empty tables with no content rows.
void setBoxSpace(double space)
Sets the legend box space.
void setShowGrid(bool showGrid)
Sets whether grid lines should be drawn in the table.
void setPageNameExpression(const QString &expression)
Sets the expression (or field name) used for calculating the page name.
double height() const
Returns the height of the size.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
Base class for frame items, which form a layout multiframe item.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
void setEnabled(bool enabled) override
Controls whether the item will be drawn.
A layout multiframe subclass for HTML content.
void setHidePageIfEmpty(bool hidePageIfEmpty)
Sets whether the page should be hidden (ie, not included in layout exports) if this frame is empty...
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
Layer and style map theme.
void setGridColor(const QColor &color)
Sets the color used for grid lines in the table.
void setText(const QString &text)
Sets the label's preset text.
void setItemOpacity(double opacity)
Sets the item's opacity.
void setShowEmptyRows(bool showEmpty)
Sets whether empty rows should be drawn.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
void setCornerRadius(QgsLayoutMeasurement radius)
Sets the corner radius for rounded rectangle corners.
static QColor decodeColor(const QString &str)
Item representing the paper in a layout.
void setColor(const QColor &color)
Sets the color for the symbol.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.