63using namespace Qt::StringLiterals;
67void QgsCompositionConverter::initPropertyDefinitions()
69 if ( !sPropertyDefinitions.isEmpty() )
77 "|<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>"
78 "|<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>"
79 "|<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]"
123 QgsCompositionConverter::initPropertyDefinitions();
124 return sPropertyDefinitions;
130 initPropertyDefinitions();
132 const QDomElement parentElement = composerElement.parentNode().toElement();
134 auto layout = std::make_unique< QgsPrintLayout >( project );
135 layout->undoStack()->blockCommands(
true );
137 layout->mCustomProperties.readXml( composerElement );
140 layout->guides().setVisible( composerElement.attribute( u
"guidesVisible"_s, u
"1"_s ).toInt() != 0 );
142 const int printResolution = composerElement.attribute( u
"printResolution"_s, u
"300"_s ).toInt();
143 layout->renderContext().setDpi( printResolution );
146 const int pages = composerElement.attribute( u
"numPages"_s ).toInt( );
147 const float paperHeight = composerElement.attribute( u
"paperHeight"_s ).toDouble( );
148 const float paperWidth = composerElement.attribute( u
"paperWidth"_s ).toDouble( );
150 QString name = composerElement.attribute( u
"name"_s );
152 if ( name.isEmpty() )
153 name = composerElement.attribute( u
"title"_s );
155 if ( name.isEmpty() )
156 name = parentElement.attribute( u
"title"_s );
157 layout->setName( name );
159 for (
int j = 0; j < pages; j++ )
163 layout->pageCollection()->addPage( page );
165 const QDomNodeList snapLineNodes = composerElement.elementsByTagName( u
"SnapLine"_s );
166 for (
int i = 0; i < snapLineNodes.size(); ++i )
168 const QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
169 const double x1 = snapLineElem.attribute( u
"x1"_s ).toDouble();
170 const double y1 = snapLineElem.attribute( u
"y1"_s ).toDouble();
171 const double x2 = snapLineElem.attribute( u
"x2"_s ).toDouble();
173 const Qt::Orientation orientation( x1 == x2 ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal );
175 auto guide = std::make_unique< QgsLayoutGuide >( orientation, position, page );
176 layout->guides().addGuide( guide.release() );
181 if ( composerElement.elementsByTagName( u
"symbol"_s ).size() )
183 const QDomElement symbolElement = composerElement.elementsByTagName( u
"symbol"_s ).at( 0 ).toElement();
189 layout->pageCollection()->setPageStyleSymbol( symbol.get() );
195 if ( parentElement.elementsByTagName( u
"Atlas"_s ).size() )
197 const QDomElement atlasElement = parentElement.elementsByTagName( u
"Atlas"_s ).at( 0 ).toElement();
198 readAtlasXml( layout->atlas(), atlasElement, layout->project() );
201 layout->undoStack()->blockCommands(
false );
206void QgsCompositionConverter::adjustPos(
QgsPrintLayout *layout,
QgsLayoutItem *layoutItem, QPointF *position,
bool &pasteInPlace,
int zOrderOffset, QPointF &pasteShiftPos,
int &pageNumber )
216 layoutItem->
attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
220 if ( !layoutItem->scene() )
222 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
225void QgsCompositionConverter::restoreGeneralComposeItemProperties(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
228 const QDomNodeList composerItemList = itemElem.elementsByTagName( u
"ComposerItem"_s );
229 if ( !composerItemList.isEmpty() )
231 const QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
234 if ( !
qgsDoubleNear( composerItemElem.attribute( u
"rotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
237 layoutItem->
setItemRotation( composerItemElem.attribute( u
"rotation"_s, u
"0"_s ).toDouble(),
false );
239 QgsCompositionConverter::readXml( layoutItem, composerItemElem );
243QRectF QgsCompositionConverter::itemPosition(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
246 double x, y, pagex, pagey, width, height;
247 bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOk;
249 x = itemElem.attribute( u
"x"_s ).toDouble( &xOk );
250 y = itemElem.attribute( u
"y"_s ).toDouble( &yOk );
251 page = itemElem.attribute( u
"page"_s ).toInt( &pageOk );
252 pagex = itemElem.attribute( u
"pagex"_s ).toDouble( &pagexOk );
253 pagey = itemElem.attribute( u
"pagey"_s ).toDouble( &pageyOk );
254 width = itemElem.attribute( u
"width"_s ).toDouble( &widthOk );
255 height = itemElem.attribute( u
"height"_s ).toDouble( &heightOk );
258 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( u
"positionMode"_s ).toInt( &positionModeOk ) );
259 if ( !positionModeOk )
264 if ( pageOk && pagexOk && pageyOk )
270 if ( page <= layoutItem->layout()->pageCollection()->pageCount() )
283 return QRectF( x, y, width, height );
286QPointF QgsCompositionConverter::minPointFromXml(
const QDomElement &elem )
288 double minX = std::numeric_limits<double>::max();
289 double minY = std::numeric_limits<double>::max();
290 const QDomNodeList composerItemList = elem.elementsByTagName( u
"ComposerItem"_s );
291 for (
int i = 0; i < composerItemList.size(); ++i )
293 const QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
296 x = currentComposerItemElem.attribute( u
"x"_s ).toDouble( &xOk );
297 y = currentComposerItemElem.attribute( u
"y"_s ).toDouble( &yOk );
302 minX = std::min( minX, x );
303 minY = std::min( minY, y );
305 if ( minX < std::numeric_limits<double>::max() )
307 return QPointF( minX, minY );
311 return QPointF( 0, 0 );
318 initPropertyDefinitions();
320 QList< QgsLayoutObject * > newItems;
325 const int zOrderOffset = layout->mItemsModel->zOrderListSize();
327 QPointF pasteShiftPos;
334 const QPointF minItemPos = minPointFromXml( parentElement );
337 pasteShiftPos = *position - minItemPos;
340 pageNumber = layout->mPageCollection->pageNumberForPoint( *position );
347 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerMap"_s ).size(); i++ )
349 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerMap"_s ).at( i ) );
351 readMapXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
352 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
353 newItems << layoutItem ;
357 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerLabel"_s ).size(); i++ )
359 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerLabel"_s ).at( i ) );
361 readLabelXml( layoutItem, itemNode.toElement(), layout->
project() );
362 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
363 newItems << layoutItem ;
367 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerShape"_s ).size(); i++ )
369 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerShape"_s ).at( i ) );
371 readShapeXml( layoutItem, itemNode.toElement(), layout->
project() );
372 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
373 newItems << layoutItem ;
377 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerPicture"_s ).size(); i++ )
379 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerPicture"_s ).at( i ) );
381 readPictureXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
382 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
383 newItems << layoutItem ;
387 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerPolygon"_s ).size(); i++ )
389 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerPolygon"_s ).at( i ) );
391 readPolyXml<QgsLayoutItemPolygon, QgsFillSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
392 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
393 newItems << layoutItem ;
397 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerPolyline"_s ).size(); i++ )
399 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerPolyline"_s ).at( i ) );
401 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
402 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
403 newItems << layoutItem ;
407 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerArrow"_s ).size(); i++ )
409 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerArrow"_s ).at( i ) );
411 readArrowXml( layoutItem, itemNode.toElement(), layout->
project() );
412 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
413 newItems << layoutItem ;
417 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerScaleBar"_s ).size(); i++ )
419 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerScaleBar"_s ).at( i ) );
421 readScaleBarXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
422 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
423 newItems << layoutItem ;
427 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerLegend"_s ).size(); i++ )
429 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerLegend"_s ).at( i ) );
431 readLegendXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
432 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
433 newItems << layoutItem ;
437 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerHtml"_s ).size(); i++ )
439 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerHtml"_s ).at( i ) );
441 readHtmlXml( layoutItem, itemNode.toElement(), layout->
project() );
443 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
444 for (
const auto &frame : framesList )
446 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
448 newItems << layoutItem ;
452 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerAttributeTableV2"_s ).size(); i++ )
454 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerAttributeTableV2"_s ).at( i ) );
456 readTableXml( layoutItem, itemNode.toElement(), layout->
project() );
458 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
459 for (
const auto &frame : framesList )
461 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
463 newItems << layoutItem ;
467 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerItemGroup"_s ).size(); i++ )
469 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerItemGroup"_s ).at( i ) );
471 readGroupXml( layoutItem, itemNode.toElement(), layout->
project(), newItems );
472 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
473 newItems << layoutItem ;
481 return document.elementsByTagName( u
"Composition"_s ).count() > 0;
490 if ( document.elementsByTagName( u
"Composition"_s ).count( ) > 0 )
492 const QDomElement composerElem = document.elementsByTagName( u
"Composition"_s ).at( 0 ).toElement( );
496 const QDomElement elem = layout->writeXml( doc, context );
497 doc.appendChild( elem );
505 if ( itemElem.isNull() )
510 restoreGeneralComposeItemProperties( layoutItem, itemElem );
513 layoutItem->
setText( itemElem.attribute( u
"labelText"_s ) );
519 bool marginXOk =
false;
520 bool marginYOk =
false;
521 double marginX = itemElem.attribute( u
"marginX"_s ).toDouble( &marginXOk );
522 double marginY = itemElem.attribute( u
"marginY"_s ).toDouble( &marginYOk );
523 if ( !marginXOk || !marginYOk )
526 const double margin = itemElem.attribute( u
"margin"_s, u
"1.0"_s ).toDouble();
534 layoutItem->
setHAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( u
"halign"_s ).toInt() ) );
537 layoutItem->
setVAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( u
"valign"_s ).toInt() ) );
543 QgsTextFormat format;
545 if ( font.pointSizeF() > 0 )
547 format.
setSize( font.pointSizeF() );
550 else if ( font.pixelSize() > 0 )
552 format.
setSize( font.pixelSize() );
557 const QDomNodeList fontColorList = itemElem.elementsByTagName( u
"FontColor"_s );
558 if ( !fontColorList.isEmpty() )
560 const QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
561 const int red = fontColorElem.attribute( u
"red"_s, u
"0"_s ).toInt();
562 const int green = fontColorElem.attribute( u
"green"_s, u
"0"_s ).toInt();
563 const int blue = fontColorElem.attribute( u
"blue"_s, u
"0"_s ).toInt();
564 format.
setColor( QColor( red, green, blue ) );
568 format.
setColor( QColor( 0, 0, 0 ) );
579 layoutItem->
setCornerRadius( QgsLayoutMeasurement( itemElem.attribute( u
"cornerRadius"_s, u
"0"_s ).toDouble() ) );
581 restoreGeneralComposeItemProperties( layoutItem, itemElem );
583 QgsReadWriteContext context;
587 if ( itemElem.elementsByTagName( u
"symbol"_s ).size() )
589 const QDomElement symbolElement = itemElem.elementsByTagName( u
"symbol"_s ).at( 0 ).toElement();
591 if ( shapeStyleSymbol )
592 layoutItem->
setSymbol( shapeStyleSymbol.get() );
597 QVariantMap properties;
601 properties.insert( u
"style"_s, u
"solid"_s );
605 properties.insert( u
"style"_s, u
"no"_s );
609 properties.insert( u
"style_border"_s, u
"solid"_s );
613 properties.insert( u
"style_border"_s, u
"no"_s );
616 properties.insert( u
"width_border"_s, QString::number( layoutItem->pen().widthF() ) );
619 const QDomNodeList outlineColorList = itemElem.elementsByTagName( u
"OutlineColor"_s );
620 if ( !outlineColorList.isEmpty() )
622 const QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
623 bool redOk, greenOk, blueOk, alphaOk, widthOk;
624 int penRed, penGreen, penBlue, penAlpha;
627 penWidth = itemElem.attribute( u
"outlineWidth"_s ).toDouble( &widthOk );
628 penRed = frameColorElem.attribute( u
"red"_s ).toInt( &redOk );
629 penGreen = frameColorElem.attribute( u
"green"_s ).toInt( &greenOk );
630 penBlue = frameColorElem.attribute( u
"blue"_s ).toInt( &blueOk );
631 penAlpha = frameColorElem.attribute( u
"alpha"_s ).toInt( &alphaOk );
633 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
636 properties.insert( u
"width_border"_s, QString::number( penWidth ) );
639 const QDomNodeList fillColorList = itemElem.elementsByTagName( u
"FillColor"_s );
640 if ( !fillColorList.isEmpty() )
642 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
643 bool redOk, greenOk, blueOk, alphaOk;
644 int fillRed, fillGreen, fillBlue, fillAlpha;
646 fillRed = fillColorElem.attribute( u
"red"_s ).toInt( &redOk );
647 fillGreen = fillColorElem.attribute( u
"green"_s ).toInt( &greenOk );
648 fillBlue = fillColorElem.attribute( u
"blue"_s ).toInt( &blueOk );
649 fillAlpha = fillColorElem.attribute( u
"alpha"_s ).toInt( &alphaOk );
651 if ( redOk && greenOk && blueOk && alphaOk )
654 properties.insert( u
"style"_s, u
"solid"_s );
657 if ( itemElem.hasAttribute( u
"transparentFill"_s ) )
660 const bool hasOldTransparentFill = itemElem.attribute( u
"transparentFill"_s, u
"0"_s ).toInt();
661 if ( hasOldTransparentFill )
663 properties.insert( u
"style"_s, u
"no"_s );
668 layoutItem->
setSymbol( shapeStyleSymbol.get() );
679 restoreGeneralComposeItemProperties( layoutItem, itemElem );
683 bool positionModeOk =
false;
684 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( u
"positionMode"_s ).toInt( &positionModeOk ) );
685 if ( !positionModeOk )
689 bool anchorPointOk =
false;
692 if ( !anchorPointOk )
698 layoutItem->mSvgStrokeWidth = itemElem.attribute( u
"svgBorderWidth"_s, u
"0.2"_s ).toDouble();
700 QString imagePath = itemElem.attribute( u
"file"_s );
704 const QgsPathResolver pathResolver = project->
pathResolver();
705 if ( imagePath.endsWith(
".svg"_L1, Qt::CaseInsensitive ) )
708 imagePath = pathResolver.
readPath( imagePath );
711 layoutItem->mPictureHeight = itemElem.attribute( u
"pictureHeight"_s, u
"10"_s ).toDouble();
712 layoutItem->mPictureWidth = itemElem.attribute( u
"pictureWidth"_s, u
"10"_s ).toDouble();
715 if ( !
qgsDoubleNear( itemElem.attribute( u
"pictureRotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
717 layoutItem->mPictureRotation = itemElem.attribute( u
"pictureRotation"_s, u
"0"_s ).toDouble();
722 layoutItem->mNorthArrowHandler->
setNorthOffset( itemElem.attribute( u
"northOffset"_s, u
"0"_s ).toDouble() );
724 const QString rotationMapId = itemElem.attribute( u
"mapId"_s, u
"-1"_s );
725 if ( rotationMapId !=
"-1"_L1 )
728 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[ rotationMapId ] ) );
739 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemElem, project );
741 const QDomNodeList startPointList = itemElem.elementsByTagName( u
"StartPoint"_s );
742 if ( ! startPointList.isEmpty() )
744 const QDomElement node = startPointList.at( 0 ).toElement();
745 polygon.append( QPointF( node.attribute( u
"x"_s ).toDouble( ), node.attribute( u
"y"_s ).toDouble() ) );
747 const QDomNodeList stopPointList = itemElem.elementsByTagName( u
"StopPoint"_s );
748 if ( ! stopPointList.isEmpty() )
750 const QDomElement node = stopPointList.at( 0 ).toElement();
751 polygon.append( QPointF( node.attribute( u
"x"_s ).toDouble( ), node.attribute( u
"y"_s ).toDouble() ) );
763 layoutItem->
setArrowHeadWidth( itemElem.attribute( u
"arrowHeadWidth"_s, u
"1.0"_s ).toDouble( ) );
767 QString endMarkerFile = itemElem.attribute( u
"endMarkerFile"_s );
768 QString startMarkerFile = itemElem.attribute( u
"endMarkerFile"_s );
774 const QgsPathResolver pathResolver = project->
pathResolver();
775 if ( !endMarkerFile.isEmpty() )
777 if ( endMarkerFile.endsWith(
".svg"_L1, Qt::CaseInsensitive ) )
780 endMarkerFile = pathResolver.
readPath( endMarkerFile );
782 if ( !startMarkerFile.isEmpty() )
784 if ( startMarkerFile.endsWith(
".svg"_L1, Qt::CaseInsensitive ) )
787 startMarkerFile = pathResolver.
readPath( startMarkerFile );
790 if ( !endMarkerFile.isEmpty() )
795 if ( !startMarkerFile.isEmpty() )
807 const double margin = polygon.boundingRect().left() - layoutItem->pos().x();
808 polygon.translate( - polygon.boundingRect().left() + margin, - polygon.boundingRect().top() + margin );
816 restoreGeneralComposeItemProperties( layoutItem, itemElem );
818 mapId2Uuid[ itemElem.attribute( u
"id"_s ) ] = layoutItem->
uuid();
821 const QDomDocument doc;
823 QgsReadWriteContext context;
829 const QDomNodeList extentNodeList = itemElem.elementsByTagName( u
"Extent"_s );
830 if ( !extentNodeList.isEmpty() )
832 const QDomElement extentElem = extentNodeList.at( 0 ).toElement();
833 double xmin, xmax, ymin, ymax;
834 xmin = extentElem.attribute( u
"xmin"_s ).toDouble();
835 xmax = extentElem.attribute( u
"xmax"_s ).toDouble();
836 ymin = extentElem.attribute( u
"ymin"_s ).toDouble();
837 ymax = extentElem.attribute( u
"ymax"_s ).toDouble();
838 layoutItem->
setExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
841 const QDomNodeList crsNodeList = itemElem.elementsByTagName( u
"crs"_s );
842 if ( !crsNodeList.isEmpty() )
844 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
849 layoutItem->
setCrs( QgsCoordinateReferenceSystem() );
853 if ( !
qgsDoubleNear( itemElem.attribute( u
"mapRotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
855 layoutItem->
setMapRotation( itemElem.attribute( u
"mapRotation"_s, u
"0"_s ).toDouble() );
863 const QString keepLayerSetFlag = itemElem.attribute( u
"keepLayerSet"_s );
864 if ( keepLayerSetFlag.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
873 const QString drawCanvasItemsFlag = itemElem.attribute( u
"drawCanvasItems"_s, u
"true"_s );
874 if ( drawCanvasItemsFlag.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
883 layoutItem->mLayerStyleOverrides.clear();
886 layoutItem->mLayers.clear();
888 const QDomNodeList layerSetNodeList = itemElem.elementsByTagName( u
"LayerSet"_s );
889 if ( !layerSetNodeList.isEmpty() )
891 const QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
892 const QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( u
"Layer"_s );
893 layoutItem->mLayers.reserve( layerIdNodeList.size() );
894 for (
int i = 0; i < layerIdNodeList.size(); ++i )
896 const QDomElement layerElem = layerIdNodeList.at( i ).toElement();
897 const QString layerId = layerElem.text();
898 const QString layerName = layerElem.attribute( u
"name"_s );
899 const QString layerSource = layerElem.attribute( u
"source"_s );
900 const QString layerProvider = layerElem.attribute( u
"provider"_s );
902 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
903 ref.resolveWeakly( project );
904 layoutItem->mLayers << ref;
909 const QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( u
"LayerStyles"_s );
910 layoutItem->mKeepLayerStyles = !layerStylesNodeList.isEmpty();
911 if ( layoutItem->mKeepLayerStyles )
913 const QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
914 const QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( u
"LayerStyle"_s );
915 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
917 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
918 const QString layerId = layerStyleElement.attribute( u
"layerid"_s );
919 const QString layerName = layerStyleElement.attribute( u
"name"_s );
920 const QString layerSource = layerStyleElement.attribute( u
"source"_s );
921 const QString layerProvider = layerStyleElement.attribute( u
"provider"_s );
922 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
923 ref.resolveWeakly( project );
925 QgsMapLayerStyle style;
926 style.
readXml( layerStyleElement );
927 layoutItem->mLayerStyleOverrides.insert( ref.layerId, style.
xmlData() );
931 layoutItem->mDrawing =
false;
932 layoutItem->mNumCachedLayers = 0;
933 layoutItem->mCacheInvalidated =
true;
937 const QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( u
"ComposerMapOverview"_s );
938 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
940 const QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
941 auto mapOverview = std::make_unique<QgsLayoutItemMapOverview>( mapOverviewElem.attribute( u
"name"_s ), layoutItem );
942 mapOverview->readXml( mapOverviewElem, doc, context );
943 const QString frameMapId = mapOverviewElem.attribute( u
"frameMap"_s, u
"-1"_s );
944 if ( frameMapId !=
"-1"_L1 && mapId2Uuid.contains( frameMapId ) )
946 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[ frameMapId ] ) );
949 mapOverview->setLinkedMap( mapInstance );
951 layoutItem->mOverviewStack->addOverview( mapOverview.release() );
956 layoutItem->mGridStack->readXml( itemElem, doc, context );
961 const QDomNodeList gridNodeList = itemElem.elementsByTagName( u
"Grid"_s );
962 if ( layoutItem->mGridStack->size() == 0 && !gridNodeList.isEmpty() )
964 const QDomElement gridElem = gridNodeList.at( 0 ).toElement();
965 QgsLayoutItemMapGrid *mapGrid =
new QgsLayoutItemMapGrid( QObject::tr(
"Grid %1" ).arg( 1 ), layoutItem );
966 mapGrid->
setEnabled( gridElem.attribute( u
"show"_s, u
"0"_s ) !=
"0"_L1 );
968 mapGrid->
setIntervalX( gridElem.attribute( u
"intervalX"_s, u
"0"_s ).toDouble() );
969 mapGrid->
setIntervalY( gridElem.attribute( u
"intervalY"_s, u
"0"_s ).toDouble() );
970 mapGrid->
setOffsetX( gridElem.attribute( u
"offsetX"_s, u
"0"_s ).toDouble() );
971 mapGrid->
setOffsetY( gridElem.attribute( u
"offsetY"_s, u
"0"_s ).toDouble() );
972 mapGrid->
setCrossLength( gridElem.attribute( u
"crossLength"_s, u
"3"_s ).toDouble() );
974 mapGrid->
setFrameWidth( gridElem.attribute( u
"gridFrameWidth"_s, u
"2.0"_s ).toDouble() );
975 mapGrid->
setFramePenSize( gridElem.attribute( u
"gridFramePenThickness"_s, u
"0.5"_s ).toDouble() );
980 const QDomElement gridSymbolElem = gridElem.firstChildElement( u
"symbol"_s );
981 std::unique_ptr< QgsLineSymbol > lineSymbol;
982 if ( gridSymbolElem.isNull() )
986 lineSymbol->setWidth( gridElem.attribute( u
"penWidth"_s, u
"0"_s ).toDouble() );
987 lineSymbol->setColor( QColor( gridElem.attribute( u
"penColorRed"_s, u
"0"_s ).toInt(),
988 gridElem.attribute( u
"penColorGreen"_s, u
"0"_s ).toInt(),
989 gridElem.attribute( u
"penColorBlue"_s, u
"0"_s ).toInt() ) );
998 const QDomNodeList annotationNodeList = gridElem.elementsByTagName( u
"Annotation"_s );
999 if ( !annotationNodeList.isEmpty() )
1001 const QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1013 QFont annotationFont;
1014 annotationFont.fromString( annotationElem.attribute( u
"font"_s, QString() ) );
1017 annotationFormat.
setFont( annotationFont );
1018 if ( annotationFont.pointSizeF() > 0 )
1020 annotationFormat.
setSize( annotationFont.pointSizeF() );
1023 else if ( annotationFont.pixelSize() > 0 )
1025 annotationFormat.
setSize( annotationFont.pixelSize() );
1033 layoutItem->mGridStack->addGrid( mapGrid );
1037 const QDomNodeList atlasNodeList = itemElem.elementsByTagName( u
"AtlasMap"_s );
1038 if ( !atlasNodeList.isEmpty() )
1040 const QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1041 layoutItem->mAtlasDriven = ( atlasElem.attribute( u
"atlasDriven"_s, u
"0"_s ) !=
"0"_L1 );
1042 if ( atlasElem.hasAttribute( u
"fixedScale"_s ) )
1046 else if ( atlasElem.hasAttribute( u
"scalingMode"_s ) )
1050 layoutItem->
setAtlasMargin( atlasElem.attribute( u
"margin"_s, u
"0.1"_s ).toDouble() );
1061 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1063 layoutItem->
setHeight( itemElem.attribute( u
"height"_s, u
"5.0"_s ).toDouble() );
1064 layoutItem->
setHeight( itemElem.attribute( u
"height"_s, u
"5.0"_s ).toDouble() );
1065 layoutItem->
setLabelBarSpace( itemElem.attribute( u
"labelBarSpace"_s, u
"3.0"_s ).toDouble() );
1066 layoutItem->
setBoxContentSpace( itemElem.attribute( u
"boxContentSpace"_s, u
"1.0"_s ).toDouble() );
1067 layoutItem->
setNumberOfSegments( itemElem.attribute( u
"numSegments"_s, u
"2"_s ).toInt() );
1069 layoutItem->
setUnitsPerSegment( itemElem.attribute( u
"numUnitsPerSegment"_s, u
"1.0"_s ).toDouble() );
1071 layoutItem->
setMinimumBarWidth( itemElem.attribute( u
"minBarWidth"_s, u
"50"_s ).toDouble() );
1072 layoutItem->
setMaximumBarWidth( itemElem.attribute( u
"maxBarWidth"_s, u
"150"_s ).toDouble() );
1073 layoutItem->mSegmentMillimeters = itemElem.attribute( u
"segmentMillimeters"_s, u
"0.0"_s ).toDouble();
1075 layoutItem->
setUnitLabel( itemElem.attribute( u
"unitLabel"_s ) );
1080 f.fromString( itemElem.attribute( u
"font"_s, QString() ) );
1088 const QDomNodeList fillColorList = itemElem.elementsByTagName( u
"fillColor"_s );
1089 if ( !fillColorList.isEmpty() )
1091 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1092 bool redOk, greenOk, blueOk, alphaOk;
1093 int fillRed, fillGreen, fillBlue, fillAlpha;
1095 fillRed = fillColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1096 fillGreen = fillColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1097 fillBlue = fillColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1098 fillAlpha = fillColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1100 if ( redOk && greenOk && blueOk && alphaOk )
1102 layoutItem->
fillSymbol()->
setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1107 layoutItem->
fillSymbol()->
setColor( QColor( itemElem.attribute( u
"brushColor"_s, u
"#000000"_s ) ) );
1111 const QDomNodeList fillColor2List = itemElem.elementsByTagName( u
"fillColor2"_s );
1112 if ( !fillColor2List.isEmpty() )
1114 const QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1115 bool redOk, greenOk, blueOk, alphaOk;
1116 int fillRed, fillGreen, fillBlue, fillAlpha;
1118 fillRed = fillColor2Elem.attribute( u
"red"_s ).toDouble( &redOk );
1119 fillGreen = fillColor2Elem.attribute( u
"green"_s ).toDouble( &greenOk );
1120 fillBlue = fillColor2Elem.attribute( u
"blue"_s ).toDouble( &blueOk );
1121 fillAlpha = fillColor2Elem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1123 if ( redOk && greenOk && blueOk && alphaOk )
1133 auto lineSymbol = std::make_unique< QgsLineSymbol >();
1134 auto lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >();
1135 lineSymbolLayer->setWidth( itemElem.attribute( u
"outlineWidth"_s, u
"0.3"_s ).toDouble() );
1140 const QDomNodeList strokeColorList = itemElem.elementsByTagName( u
"strokeColor"_s );
1141 if ( !strokeColorList.isEmpty() )
1143 const QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1144 bool redOk, greenOk, blueOk, alphaOk;
1145 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1147 strokeRed = strokeColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1148 strokeGreen = strokeColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1149 strokeBlue = strokeColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1150 strokeAlpha = strokeColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1152 if ( redOk && greenOk && blueOk && alphaOk )
1154 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1159 lineSymbolLayer->setColor( QColor( itemElem.attribute( u
"penColor"_s, u
"#000000"_s ) ) );
1161 lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1167 const QDomNodeList textColorList = itemElem.elementsByTagName( u
"textColor"_s );
1168 if ( !textColorList.isEmpty() )
1170 const QDomElement textColorElem = textColorList.at( 0 ).toElement();
1171 bool redOk, greenOk, blueOk, alphaOk;
1172 int textRed, textGreen, textBlue, textAlpha;
1174 textRed = textColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1175 textGreen = textColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1176 textBlue = textColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1177 textAlpha = textColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1179 if ( redOk && greenOk && blueOk && alphaOk )
1182 layoutItem->
setFontColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1189 c.setNamedColor( itemElem.attribute( u
"fontColor"_s, u
"#000000"_s ) );
1196 const QString styleString = itemElem.attribute( u
"style"_s, QString() );
1197 layoutItem->
setStyle( QObject::tr( styleString.toLocal8Bit().data() ) );
1199 if ( itemElem.attribute( u
"unitType"_s ).isEmpty() )
1202 switch ( itemElem.attribute( u
"units"_s ).toInt() )
1226 const QString mapId = itemElem.attribute( u
"mapId"_s, u
"-1"_s );
1227 if ( mapId !=
"-1"_L1 && mapId2Uuid.contains( mapId ) )
1229 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[ mapId ] ) );
1241 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1243 QgsPathResolver pathResolver;
1246 QgsReadWriteContext context;
1251 const QString mapId = itemElem.attribute( u
"map"_s, u
"-1"_s );
1252 if ( mapId !=
"-1"_L1 && mapId2Uuid.contains( mapId ) )
1254 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[ mapId ] ) );
1262 layoutItem->
setTitle( itemElem.attribute( u
"title"_s ) );
1263 if ( !itemElem.attribute( u
"titleAlignment"_s ).isEmpty() )
1265 layoutItem->
setTitleAlignment(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( u
"titleAlignment"_s ).toInt() ) );
1267 int colCount = itemElem.attribute( u
"columnCount"_s, u
"1"_s ).toInt();
1268 if ( colCount < 1 ) colCount = 1;
1270 layoutItem->
setSplitLayer( itemElem.attribute( u
"splitLayer"_s, u
"0"_s ).toInt() == 1 );
1271 layoutItem->
setEqualColumnWidth( itemElem.attribute( u
"equalColumnWidth"_s, u
"0"_s ).toInt() == 1 );
1273 const QDomNodeList stylesNodeList = itemElem.elementsByTagName( u
"styles"_s );
1274 if ( !stylesNodeList.isEmpty() )
1276 const QDomNode stylesNode = stylesNodeList.at( 0 );
1277 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
1279 const QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
1280 QgsLegendStyle style;
1281 style.
readXml( styleElem, QDomDocument() );
1282 const QString name = styleElem.attribute( u
"name"_s );
1296 fontClr.setNamedColor( itemElem.attribute( u
"fontColor"_s, u
"#000000"_s ) );
1303 layoutItem->
setBoxSpace( itemElem.attribute( u
"boxSpace"_s, u
"2.0"_s ).toDouble() );
1304 layoutItem->
setColumnSpace( itemElem.attribute( u
"columnSpace"_s, u
"2.0"_s ).toDouble() );
1306 layoutItem->
setSymbolWidth( itemElem.attribute( u
"symbolWidth"_s, u
"7.0"_s ).toDouble() );
1307 layoutItem->
setSymbolHeight( itemElem.attribute( u
"symbolHeight"_s, u
"14.0"_s ).toDouble() );
1308 layoutItem->
setWmsLegendWidth( itemElem.attribute( u
"wmsLegendWidth"_s, u
"50"_s ).toDouble() );
1309 layoutItem->
setWmsLegendHeight( itemElem.attribute( u
"wmsLegendHeight"_s, u
"25"_s ).toDouble() );
1311 layoutItem->
setLineSpacing( itemElem.attribute( u
"lineSpacing"_s, u
"1.0"_s ).toDouble() );
1314 layoutItem->
setDrawRasterStroke( itemElem.attribute( u
"rasterBorder"_s, u
"1"_s ) !=
"0"_L1 );
1316 layoutItem->
setRasterStrokeWidth( itemElem.attribute( u
"rasterBorderWidth"_s, u
"0"_s ).toDouble() );
1318 layoutItem->
setWrapString( itemElem.attribute( u
"wrapChar"_s ) );
1320 layoutItem->mSizeToContents = itemElem.attribute( u
"resizeToContents"_s, u
"1"_s ) !=
"0"_L1;
1321 layoutItem->mLegendFilterByMap = itemElem.attribute( u
"legendFilterByMap"_s, u
"0"_s ).toInt();
1322 layoutItem->mFilterOutAtlas = itemElem.attribute( u
"legendFilterByAtlas"_s, u
"0"_s ).toInt();
1325 QDomElement layerTreeElem = itemElem.firstChildElement( u
"layer-tree"_s );
1326 if ( layerTreeElem.isNull() )
1327 layerTreeElem = itemElem.firstChildElement( u
"layer-tree-group"_s );
1329 if ( !layerTreeElem.isNull() )
1333 tree->resolveReferences( project,
true );
1335 layoutItem->setCustomLayerTree( tree.release() );
1339 layoutItem->setCustomLayerTree(
nullptr );
1346bool QgsCompositionConverter::readAtlasXml(
QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project )
1348 atlasItem->
setEnabled( itemElem.attribute( u
"enabled"_s, u
"false"_s ) ==
"true"_L1 );
1351 const QString layerId = itemElem.attribute( u
"coverageLayer"_s );
1352 const QString layerName = itemElem.attribute( u
"coverageLayerName"_s );
1353 const QString layerSource = itemElem.attribute( u
"coverageLayerSource"_s );
1354 const QString layerProvider = itemElem.attribute( u
"coverageLayerProvider"_s );
1360 QString errorString;
1361 atlasItem->
setFilenameExpression( itemElem.attribute( u
"filenamePattern"_s, QString() ), errorString );
1363 atlasItem->
setSortFeatures( itemElem.attribute( u
"sortFeatures"_s, u
"false"_s ) ==
"true"_L1 );
1367 atlasItem->
setSortAscending( itemElem.attribute( u
"sortAscending"_s, u
"true"_s ) ==
"true"_L1 );
1369 atlasItem->
setFilterFeatures( itemElem.attribute( u
"filterFeatures"_s, u
"false"_s ) ==
"true"_L1 );
1372 QString expErrorString;
1373 atlasItem->
setFilterExpression( itemElem.attribute( u
"featureFilter"_s, QString() ), expErrorString );
1377 atlasItem->
setHideCoverage( itemElem.attribute( u
"hideCoverage"_s, u
"false"_s ) ==
"true"_L1 );
1386 readOldComposerObjectXml( layoutItem, itemElem );
1390 const QDomNodeList frameList = itemElem.elementsByTagName( u
"ComposerFrame"_s );
1391 for (
int i = 0; i < frameList.size(); ++i )
1393 const QDomElement frameElem = frameList.at( i ).toElement();
1394 QgsLayoutFrame *newFrame =
new QgsLayoutFrame( layoutItem->
layout(), layoutItem );
1395 restoreGeneralComposeItemProperties( newFrame, frameElem );
1397 const double x = itemElem.attribute( u
"sectionX"_s ).toDouble();
1398 const double y = itemElem.attribute( u
"sectionY"_s ).toDouble();
1399 const double width = itemElem.attribute( u
"sectionWidth"_s ).toDouble();
1400 const double height = itemElem.attribute( u
"sectionHeight"_s ).toDouble();
1402 newFrame->
setHidePageIfEmpty( itemElem.attribute( u
"hidePageIfEmpty"_s, u
"0"_s ).toInt() );
1404 layoutItem->
addFrame( newFrame,
false );
1409 if ( !contentModeOK )
1413 layoutItem->
setEvaluateExpressions( itemElem.attribute( u
"evaluateExpressions"_s, u
"true"_s ) ==
"true"_L1 );
1414 layoutItem->
setUseSmartBreaks( itemElem.attribute( u
"useSmartBreaks"_s, u
"true"_s ) ==
"true"_L1 );
1415 layoutItem->
setMaxBreakDistance( itemElem.attribute( u
"maxBreakDistance"_s, u
"10"_s ).toDouble() );
1416 layoutItem->
setHtml( itemElem.attribute( u
"html"_s ) );
1421 const QString urlString = itemElem.attribute( u
"url"_s );
1422 if ( !urlString.isEmpty() )
1424 layoutItem->
setUrl( urlString );
1435 readOldComposerObjectXml( layoutItem, itemElem );
1439 const QDomNodeList frameList = itemElem.elementsByTagName( u
"ComposerFrame"_s );
1440 for (
int i = 0; i < frameList.size(); ++i )
1442 const QDomElement frameElem = frameList.at( i ).toElement();
1443 QgsLayoutFrame *newFrame =
new QgsLayoutFrame( layoutItem->
layout(), layoutItem );
1444 restoreGeneralComposeItemProperties( newFrame, frameElem );
1446 const double x = itemElem.attribute( u
"sectionX"_s ).toDouble();
1447 const double y = itemElem.attribute( u
"sectionY"_s ).toDouble();
1448 const double width = itemElem.attribute( u
"sectionWidth"_s ).toDouble();
1449 const double height = itemElem.attribute( u
"sectionHeight"_s ).toDouble();
1451 newFrame->
setHidePageIfEmpty( itemElem.attribute( u
"hidePageIfEmpty"_s, u
"0"_s ).toInt() );
1453 layoutItem->
addFrame( newFrame,
false );
1457 layoutItem->
setEmptyTableMessage( itemElem.attribute( u
"emptyTableMessage"_s, QObject::tr(
"No matching records" ) ) );
1458 layoutItem->
setShowEmptyRows( itemElem.attribute( u
"showEmptyRows"_s, u
"0"_s ).toInt() );
1462 headerFont.fromString( itemElem.attribute( u
"headerFont"_s, QString() ) );
1465 headerFormat.
setFont( headerFont );
1466 if ( headerFont.pointSizeF() > 0 )
1468 headerFormat.
setSize( headerFont.pointSizeF() );
1471 else if ( headerFont.pixelSize() > 0 )
1473 headerFormat.
setSize( headerFont.pixelSize() );
1484 contentFont.fromString( itemElem.attribute( u
"contentFont"_s, QString() ) );
1487 contentFormat.
setFont( contentFont );
1488 if ( contentFont.pointSizeF() > 0 )
1490 contentFormat.
setSize( contentFont.pointSizeF() );
1493 else if ( contentFont.pixelSize() > 0 )
1495 contentFormat.
setSize( contentFont.pixelSize() );
1501 layoutItem->
setCellMargin( itemElem.attribute( u
"cellMargin"_s, u
"1.0"_s ).toDouble() );
1502 layoutItem->
setGridStrokeWidth( itemElem.attribute( u
"gridStrokeWidth"_s, u
"0.5"_s ).toDouble() );
1503 layoutItem->
setHorizontalGrid( itemElem.attribute( u
"horizontalGrid"_s, u
"1"_s ).toInt() );
1504 layoutItem->
setVerticalGrid( itemElem.attribute( u
"verticalGrid"_s, u
"1"_s ).toInt() );
1505 layoutItem->
setShowGrid( itemElem.attribute( u
"showGrid"_s, u
"1"_s ).toInt() );
1514 const QDomNodeList columnsList = itemElem.elementsByTagName( u
"displayColumns"_s );
1515 if ( !columnsList.isEmpty() )
1517 const QDomElement columnsElem = columnsList.at( 0 ).toElement();
1518 const QDomNodeList columnEntryList = columnsElem.elementsByTagName( u
"column"_s );
1519 for (
int i = 0; i < columnEntryList.size(); ++i )
1521 const QDomElement columnElem = columnEntryList.at( i ).toElement();
1522 QgsLayoutTableColumn column;
1523 column.mHAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( u
"hAlignment"_s, QString::number( Qt::AlignLeft ) ).toInt() );
1524 column.mVAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( u
"vAlignment"_s, QString::number( Qt::AlignVCenter ) ).toInt() );
1525 column.mHeading = columnElem.attribute( u
"heading"_s, QString() );
1526 column.mAttribute = columnElem.attribute( u
"attribute"_s, QString() );
1527 column.mSortByRank = columnElem.attribute( u
"sortByRank"_s, u
"0"_s ).toInt();
1528 column.mSortOrder =
static_cast< Qt::SortOrder
>( columnElem.attribute( u
"sortOrder"_s, QString::number( Qt::AscendingOrder ) ).toInt() );
1529 column.mWidth = columnElem.attribute( u
"width"_s, u
"0.0"_s ).toDouble();
1531 const QDomNodeList bgColorList = columnElem.elementsByTagName( u
"backgroundColor"_s );
1532 if ( !bgColorList.isEmpty() )
1534 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1535 bool redOk, greenOk, blueOk, alphaOk;
1536 int bgRed, bgGreen, bgBlue, bgAlpha;
1537 bgRed = bgColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1538 bgGreen = bgColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1539 bgBlue = bgColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1540 bgAlpha = bgColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1541 if ( redOk && greenOk && blueOk && alphaOk )
1543 column.mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1546 layoutItem->
mColumns.append( column );
1551 std::copy_if( layoutItem->
mColumns.begin(), layoutItem->
mColumns.end(), std::back_inserter( layoutItem->
mSortColumns ), [](
const QgsLayoutTableColumn & col ) {return col.sortByRank() > 0;} );
1552 std::sort( layoutItem->
mSortColumns.begin(), layoutItem->
mSortColumns.end(), [](
const QgsLayoutTableColumn & a,
const QgsLayoutTableColumn & b ) {return a.sortByRank() < b.sortByRank();} );
1558 const QDomNodeList stylesList = itemElem.elementsByTagName( u
"cellStyles"_s );
1559 if ( !stylesList.isEmpty() )
1561 const QDomElement stylesElem = stylesList.at( 0 ).toElement();
1563 QMap< QgsLayoutTable::CellStyleGroup, QString >::const_iterator it = layoutItem->mCellStyleNames.constBegin();
1564 for ( ; it != layoutItem->mCellStyleNames.constEnd(); ++it )
1566 const QString styleName = it.value();
1567 const QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
1568 if ( !styleList.isEmpty() )
1570 const QDomElement styleElem = styleList.at( 0 ).toElement();
1571 QgsLayoutTableStyle *style = layoutItem->
mCellStyles.value( it.key() );
1579 const QString layerId = itemElem.attribute( u
"vectorLayer"_s );
1580 const QString layerName = itemElem.attribute( u
"vectorLayerName"_s );
1581 const QString layerSource = itemElem.attribute( u
"vectorLayerSource"_s );
1582 const QString layerProvider = itemElem.attribute( u
"vectorLayerProvider"_s );
1590bool QgsCompositionConverter::readGroupXml(
QgsLayoutItemGroup *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
const QList< QgsLayoutObject * > &items )
1594 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1596 const QDomNodeList nodes = itemElem.elementsByTagName(
"ComposerItemGroupElement" );
1597 for (
int i = 0, n = nodes.size(); i < n; ++i )
1599 const QDomElement groupElement = nodes.at( i ).toElement();
1600 const QString elementUuid = groupElement.attribute(
"uuid" );
1602 for ( QgsLayoutObject *item : items )
1604 if (
dynamic_cast<QgsLayoutItem *
>( item ) &&
static_cast<QgsLayoutItem *
>( item )->uuid() == elementUuid )
1606 layoutItem->
addItem(
static_cast<QgsLayoutItem *
>( item ) );
1615template <
class T,
class T2>
1616bool QgsCompositionConverter::readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1618 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1619 const QDomNodeList nodeList = itemElem.elementsByTagName( u
"node"_s );
1620 if ( !nodeList.isEmpty() )
1623 for (
int i = 0; i < nodeList.length(); i++ )
1625 const QDomElement node = nodeList.at( i ).toElement();
1626 polygon.append( QPointF( node.attribute( u
"x"_s ).toDouble( ), node.attribute( u
"y"_s ).toDouble() ) );
1628 layoutItem->setNodes( polygon );
1630 if ( itemElem.elementsByTagName( u
"symbol"_s ).size() )
1632 const QDomElement symbolElement = itemElem.elementsByTagName( u
"symbol"_s ).at( 0 ).toElement();
1633 QgsReadWriteContext context;
1638 layoutItem->setSymbol( styleSymbol.release() );
1641 layoutItem->setFrameEnabled(
false );
1642 layoutItem->setBackgroundEnabled(
false );
1647bool QgsCompositionConverter::readXml(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
1649 if ( itemElem.isNull() )
1654 readOldComposerObjectXml( layoutItem, itemElem );
1657 layoutItem->mUuid = itemElem.attribute( u
"uuid"_s, QUuid::createUuid().toString() );
1660 layoutItem->mTemplateUuid = itemElem.attribute( u
"templateUuid"_s );
1663 const QString
id = itemElem.attribute( u
"id"_s, QString() );
1664 layoutItem->
setId(
id );
1667 const QString frame = itemElem.attribute( u
"frame"_s );
1668 layoutItem->
setFrameEnabled( frame.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 ) ;
1671 const QString background = itemElem.attribute( u
"background"_s );
1675 const QString positionLock = itemElem.attribute( u
"positionLock"_s );
1676 layoutItem->
setLocked( positionLock.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 );
1679 layoutItem->
setVisibility( itemElem.attribute( u
"visibility"_s, u
"1"_s ) !=
"0"_L1 );
1681 layoutItem->mParentGroupUuid = itemElem.attribute( u
"groupUuid"_s );
1682 if ( !layoutItem->mParentGroupUuid.isEmpty() )
1684 if ( QgsLayoutItemGroup *group = layoutItem->
parentGroup() )
1686 group->addItem( layoutItem );
1689 layoutItem->mTemplateUuid = itemElem.attribute( u
"templateUuid"_s );
1692 const QRectF position = itemPosition( layoutItem, itemElem );
1697 layoutItem->setZValue( itemElem.attribute( u
"zValue"_s ).toDouble() );
1700 const QDomNodeList frameColorList = itemElem.elementsByTagName( u
"FrameColor"_s );
1701 if ( !frameColorList.isEmpty() )
1703 const QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
1704 bool redOk, greenOk, blueOk, alphaOk, widthOk;
1705 int penRed, penGreen, penBlue, penAlpha;
1708 penWidth = itemElem.attribute( u
"outlineWidth"_s ).toDouble( &widthOk );
1709 penRed = frameColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1710 penGreen = frameColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1711 penBlue = frameColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1712 penAlpha = frameColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1715 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
1722 layoutItem->setPen( framePen );
1729 const QDomNodeList bgColorList = itemElem.elementsByTagName( u
"BackgroundColor"_s );
1730 if ( !bgColorList.isEmpty() )
1732 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1733 bool redOk, greenOk, blueOk, alphaOk;
1734 int bgRed, bgGreen, bgBlue, bgAlpha;
1735 bgRed = bgColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1736 bgGreen = bgColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1737 bgBlue = bgColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1738 bgAlpha = bgColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1739 if ( redOk && greenOk && blueOk && alphaOk )
1741 layoutItem->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1742 layoutItem->setBrush( QBrush( layoutItem->mBackgroundColor, Qt::SolidPattern ) );
1752 if ( itemElem.hasAttribute( u
"opacity"_s ) )
1754 layoutItem->
setItemOpacity( itemElem.attribute( u
"opacity"_s, u
"1"_s ).toDouble() );
1758 layoutItem->
setItemOpacity( 1.0 - itemElem.attribute( u
"transparency"_s, u
"0"_s ).toInt() / 100.0 );
1761 layoutItem->mExcludeFromExports = itemElem.attribute( u
"excludeFromExports"_s, u
"0"_s ).toInt();
1762 layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
1767 layoutItem->
setItemRotation( itemElem.attribute( u
"itemRotation"_s, u
"0"_s ).toDouble(),
false );
1769 layoutItem->mBlockUndoCommands =
false;
1776bool QgsCompositionConverter::readOldComposerObjectXml(
QgsLayoutObject *layoutItem,
1777 const QDomElement &itemElem )
1779 if ( itemElem.isNull() )
1787 const QDomNode propsNode = itemElem.namedItem( u
"dataDefinedProperties"_s );
1788 if ( !propsNode.isNull() )
1796 exp = u
"100.0 - (%1)"_s.arg( exp );
1808void QgsCompositionConverter::readOldDataDefinedPropertyMap(
const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties )
1811 QgsPropertiesDefinition::const_iterator i = defs.constBegin();
1812 for ( ; i != defs.constEnd(); ++i )
1814 const QString elemName = i.value().name();
1815 const QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
1816 if ( !ddNodeList.isEmpty() )
1818 const QDomElement ddElem = ddNodeList.at( 0 ).toElement();
1821 dataDefinedProperties.
setProperty( i.key(), prop );
1831 return QgsProperty();
1834 const QString active = ddElem.attribute( u
"active"_s );
1835 bool isActive =
false;
1836 if ( active.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
1840 const QString field = ddElem.attribute( u
"field"_s );
1841 const QString expr = ddElem.attribute( u
"expr"_s );
1843 const QString useExpr = ddElem.attribute( u
"useExpr"_s );
1844 bool isExpression =
false;
1845 if ( useExpr.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
1847 isExpression =
true;
LegendComponent
Component of legends which can be styled.
@ Symbol
Symbol icon (excluding label).
@ Group
Legend group title.
@ Subgroup
Legend subgroup title.
@ SymbolLabel
Symbol label (excluding icon).
MapGridAnnotationPosition
Position for map grid annotations.
ScaleBarAlignment
Scalebar alignment.
DistanceUnit
Units of distance.
@ Unknown
Unknown distance unit.
@ NauticalMiles
Nautical miles.
@ AllProjectLayers
Synchronize to all project layers.
@ Manual
No automatic synchronization of legend layers. The legend will be manually populated.
BlendMode
Blending modes defining the available composition modes that can be used when painting.
MapGridStyle
Map grid drawing styles.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
ScaleBarSegmentSizeMode
Modes for setting size for scale bar segments.
MapGridFrameStyle
Style for map grid frames.
MapGridAnnotationDirection
Direction of grid annotations.
MapGridAnnotationFormat
Format for displaying map grid annotations.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
DataDefinedProperty
Composition data defined properties for different item types.
@ PositionX
X position on page.
@ ItemWidth
Width of item.
@ MapYMin
Map extent y minimum.
@ ExcludeFromExports
Exclude item from exports.
@ MapLayers
Map layer set.
@ PictureSvgStrokeColor
SVG stroke color.
@ MapRotation
Map rotation.
@ ItemRotation
Rotation of item.
@ TestProperty
Dummy property with no effect on item.
@ PositionY
Y position on page.
@ PaperOrientation
Paper orientation.
@ MapXMax
Map extent x maximum.
@ MapStylePreset
Layer and style map theme.
@ PageNumber
Page number for item placement.
@ MapYMax
Map extent y maximum.
@ MapAtlasMargin
Map atlas margin.
@ NumPages
Number of pages in composition.
@ PaperHeight
Paper height.
@ ItemHeight
Height of item.
@ ScalebarLineColor
Scalebar line color.
@ Transparency
Item transparency (deprecated).
@ SourceUrl
Html source url.
@ ScalebarFillColor2
Scalebar secondary fill color.
@ BackgroundColor
Item background color.
@ BlendMode
Item blend mode.
@ PresetPaperSize
Preset paper size for composition.
@ ScalebarFillColor
Scalebar fill color.
@ ScalebarLineWidth
Scalebar line width.
@ PictureSvgBackgroundColor
SVG background color.
@ PictureSource
Picture source url.
@ FrameColor
Item frame color.
@ LegendTitle
Legend title.
@ LegendColumnCount
Legend column count.
@ MapXMin
Map extent x minimum.
@ PictureSvgStrokeWidth
SVG stroke width.
@ AllProperties
All properties for item.
MarkerMode
The MarkerMode enum is the old QGIS 2.x arrow marker mode.
static bool isCompositionTemplate(const QDomDocument &document)
Check if the given document is a composition template.
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.
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....
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
static std::unique_ptr< QgsFillSymbol > createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
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.
static std::unique_ptr< QgsLayerTree > readXml(const QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
Used to render QgsLayout as an atlas, by iterating over the features from an associated vector layer.
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
void setCoverageLayer(QgsVectorLayer *layer)
Sets the coverage layer to use for the atlas features.
bool setFilterExpression(const QString &expression, QString &errorString)
Sets the expression used for filtering features in the coverage layer.
void setSortAscending(bool ascending)
Sets whether features should be sorted in an ascending order.
void setEnabled(bool enabled)
Sets whether the atlas is enabled.
void setPageNameExpression(const QString &expression)
Sets the expression (or field name) used for calculating the page name.
bool setFilenameExpression(const QString &expression, QString &errorString)
Sets the filename expression used for generating output filenames for each atlas page.
void setSortFeatures(bool enabled)
Sets whether features should be sorted in the atlas.
void setSortExpression(const QString &expression)
Sets the expression (or field name) to use for sorting features.
void setFilterFeatures(bool filtered)
Sets whether features should be filtered in the coverage layer.
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
void setHideCoverage(bool hide)
Sets whether the coverage layer should be hidden in map items in the layouts.
void setContentSection(const QRectF §ion)
Sets the visible part of the multiframe's content which is visible within this frame (relative to the...
void setHideBackgroundIfEmpty(bool hideBackgroundIfEmpty)
Sets whether the background and frame stroke should be hidden if this frame is empty.
void setHidePageIfEmpty(bool hidePageIfEmpty)
Sets whether the page should be hidden (ie, not included in layout exports) if this frame is empty.
A layout table subclass that displays attributes from a vector layer.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
A container for grouping several QgsLayoutItems.
void addItem(QgsLayoutItem *item)
Adds an item to the group.
A layout multiframe subclass for HTML content.
void setUrl(const QUrl &url)
Sets the url for content to display in the item when the item is using the QgsLayoutItemHtml::Url mod...
ContentMode
Source modes for the HTML content to render in the item.
@ Url
Using this mode item fetches its content via a url.
void setEvaluateExpressions(bool evaluateExpressions)
Sets whether the html item will evaluate QGIS expressions prior to rendering the HTML content.
void setMaxBreakDistance(double distance)
Sets the maximum distance allowed when calculating where to place page breaks in the html.
void setUserStylesheetEnabled(bool enabled)
Sets whether user stylesheets are enabled for the HTML content.
void setHtml(const QString &html)
Sets the html to display in the item when the item is using the QgsLayoutItemHtml::ManualHtml mode.
void setUseSmartBreaks(bool useSmartBreaks)
Sets whether the html item should use smart breaks.
void setUserStylesheet(const QString &stylesheet)
Sets the user stylesheet CSS rules to use while rendering the HTML content.
void setContentMode(ContentMode mode)
Sets the source mode for item's HTML content.
void loadHtml(bool useCache=false, const QgsExpressionContext *context=nullptr)
Reloads the html source from the url and redraws the item.
A layout item subclass for text labels.
void setHAlign(Qt::AlignmentFlag alignment)
Sets the horizontal alignment of the label.
void setMarginX(double margin)
Sets the horizontal margin between the edge of the frame and the label contents, in layout units.
void setText(const QString &text)
Sets the label's preset text.
void setMarginY(double margin)
Sets the vertical margin between the edge of the frame and the label contents, in layout units.
void setMode(Mode mode)
Sets the label's current mode, allowing the label to switch between font based and HTML based renderi...
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for drawing text in the label.
void setVAlign(Qt::AlignmentFlag alignment)
Sets for the vertical alignment of the label.
@ ModeHtml
Label displays rendered HTML content.
@ ModeFont
Label displays text rendered using a single font.
A layout item subclass for map legends.
void setSplitLayer(bool enabled)
Sets whether the legend items from a single layer can be split over multiple columns.
QgsLegendStyle & rstyle(Qgis::LegendComponent s)
Returns reference to modifiable legend style.
void setColumnSpace(double spacing)
Sets the legend column spacing.
void setBoxSpace(double space)
Sets the legend box space.
void setEqualColumnWidth(bool equalize)
Sets whether column widths should be equalized.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
void setSymbolWidth(double width)
Sets the legend symbol width.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
void setWmsLegendWidth(double width)
Sets the WMS legend width.
void setTitle(const QString &title)
Sets the legend title.
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
Q_DECL_DEPRECATED void setLineSpacing(double spacing)
Sets the spacing in-between multiple lines.
void setSymbolHeight(double height)
Sets the legend symbol height.
void setSyncMode(Qgis::LegendSyncMode mode)
Sets the legend's synchronization mode.
void setWmsLegendHeight(double height)
Sets the WMS legend height.
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
void setStyle(Qgis::LegendComponent component, const QgsLegendStyle &style)
Sets the style of component to style for the legend.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void setWrapString(const QString &string)
Sets the legend text wrapping string.
void setColumnCount(int count)
Sets the legend column count.
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
void setFrameStyle(const Qgis::MapGridFrameStyle style)
Sets the grid frame style.
void setIntervalY(double interval)
Sets the interval between grid lines in the y-direction.
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
QgsTextFormat annotationTextFormat() const
Returns the text format used when rendering grid annotations.
void setStyle(Qgis::MapGridStyle style)
Sets the grid style, which controls how the grid is drawn over the map's contents.
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
void setFramePenSize(const double width)
Sets the width of the stroke drawn in the grid frame.
void setIntervalX(double interval)
Sets the interval between grid lines in the x-direction.
void setCrossLength(const double length)
Sets the length (in layout units) of the cross segments drawn for the grid.
void setAnnotationDirection(Qgis::MapGridAnnotationDirection direction, Qgis::MapGridBorderSide side)
Sets the direction for drawing frame annotations for the specified map side.
void setEnabled(bool enabled) override
Controls whether the item will be drawn.
void setAnnotationFrameDistance(const double distance)
Sets the distance between the map frame and annotations.
void setAnnotationTextFormat(const QgsTextFormat &format)
Sets the text format to use when rendering grid annotations.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
void setAnnotationPosition(Qgis::MapGridAnnotationPosition position, Qgis::MapGridBorderSide side)
Sets the position for the grid annotations on a specified side of the map frame.
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used for drawing grid lines.
void setOffsetY(double offset)
Sets the offset for grid lines in the y-direction.
void setAnnotationFormat(const Qgis::MapGridAnnotationFormat format)
Sets the format for drawing grid annotations.
void setFrameWidth(const double width)
Sets the grid frame width (in layout units).
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
void setOffsetX(double offset)
Sets the offset for grid lines in the x-direction.
Layout graphical items for displaying a map.
void setFollowVisibilityPreset(bool follow)
Sets whether the map should follow a map theme.
void setFollowVisibilityPresetName(const QString &name)
Sets preset name for map rendering.
void setKeepLayerSet(bool enabled)
Sets whether the stored layer set should be used or the current layer set of the associated project.
AtlasScalingMode
Scaling modes used for the serial rendering (atlas).
@ Auto
The extent is adjusted so that each feature is fully visible.
@ Fixed
The current scale of the map is used for each feature of the atlas.
void updateBoundingRect()
Updates the bounding rect of this item. Call this function before doing any changes related to annota...
void setDrawAnnotations(bool draw)
Sets whether annotations are drawn within the map.
void setExtent(const QgsRectangle &extent)
Sets a new extent for the map.
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the map's preset crs (coordinate reference system).
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
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...
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Item representing the paper in a layout.
void setPageSize(const QgsLayoutSize &size)
Sets the size of the page.
static QgsLayoutItemPage * create(QgsLayout *layout)
Returns a new page item for the specified layout.
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
void setPictureAnchor(QgsLayoutItem::ReferencePoint anchor)
Sets the picture's anchor point, which controls how it is placed within the picture item's frame.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
void setPicturePath(const QString &path, Qgis::PictureFormat format=Qgis::PictureFormat::Unknown)
Sets the source path of the image (may be svg or a raster format).
ResizeMode
Controls how pictures are scaled within the item's frame.
Layout item for node based polygon shapes.
Layout item for node based polyline shapes.
void setArrowHeadWidth(double width)
Sets the width of line arrow heads in mm.
void setEndMarker(MarkerMode mode)
Sets the end marker mode, which controls what marker is drawn at the end of the line.
void setEndSvgMarkerPath(const QString &path)
Sets the path to a SVG marker to draw at the end of the line.
void setArrowHeadStrokeWidth(double width)
Sets the pen width in millimeters for the stroke of the arrow head.
void setArrowHeadFillColor(const QColor &color)
Sets the color used to fill the arrow head.
void setArrowHeadStrokeColor(const QColor &color)
Sets the color used to draw the stroke around the arrow head.
void setStartMarker(MarkerMode mode)
Sets the start marker mode, which controls what marker is drawn at the start of the line.
@ ArrowHead
Show arrow marker.
@ SvgMarker
Show SVG marker.
@ NoMarker
Don't show marker.
void setStartSvgMarkerPath(const QString &path)
Sets the path to a SVG marker to draw at the start of the line.
A layout item subclass for scale bars.
void setNumberOfSegments(int segments)
Sets the number of segments included in the scalebar.
QgsFillSymbol * alternateFillSymbol() const
Returns the secondary fill symbol used to render the scalebar (only used for some scalebar types).
void setMinimumBarWidth(double minWidth)
Sets the minimum width (in millimeters) for scale bar segments.
QgsFillSymbol * fillSymbol() const
Returns the primary fill symbol used to render the scalebar (only used for some scalebar types).
void setMaximumBarWidth(double maxWidth)
Sets the maximum width (in millimeters) for scale bar segments.
void setDivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar divisions (only used for some scalebar types).
void setAlignment(Qgis::ScaleBarAlignment alignment)
Sets the scalebar alignment.
void setLabelBarSpace(double space)
Sets the spacing (in millimeters) between labels and the scalebar.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar (only used for some scalebar types).
void setStyle(const QString &name)
Sets the scale bar style by name.
void setMapUnitsPerScaleBarUnit(double units)
Sets the number of map units per scale bar unit used by the scalebar.
void setHeight(double height)
Sets the scalebar height (in millimeters).
void setNumberOfSegmentsLeft(int segments)
Sets the number of segments included in the left part of the scalebar.
void setUnits(Qgis::DistanceUnit units)
Sets the distance units used by the scalebar.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
void setSegmentSizeMode(Qgis::ScaleBarSegmentSizeMode mode)
Sets the size mode for scale bar segments.
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the color used for drawing text in the scalebar.
void setBoxContentSpace(double space)
Sets the space (margin) between the scalebar box and content in millimeters.
void setUnitLabel(const QString &label)
Sets the label for units.
void setUnitsPerSegment(double units)
Sets the number of scalebar units per segment.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for drawing text in the scalebar.
void setSubdivisionLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render the scalebar subdivisions (only used for some scalebar types).
Layout item for basic filled shapes (e.g.
void setShapeType(QgsLayoutItemShape::Shape type)
Sets the type of shape (e.g.
void setSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to draw the shape.
void setCornerRadius(QgsLayoutMeasurement radius)
Sets the corner radius for rounded rectangle corners.
Base class for graphical items within a QgsLayout.
virtual void setFrameStrokeWidth(QgsLayoutMeasurement width)
Sets the frame stroke width.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QgsLayoutItemGroup * parentGroup() const
Returns the item's parent group, if the item is part of a QgsLayoutItemGroup group.
virtual void setItemRotation(double rotation, bool adjustPosition=true)
Sets the layout item's rotation, in degrees clockwise.
QgsLayoutMeasurement frameStrokeWidth() const
Returns the frame's stroke width.
void setItemOpacity(double opacity)
Sets the item's opacity.
virtual void setVisibility(bool visible)
Sets whether the item is visible.
ReferencePoint
Fixed position reference point.
@ UpperLeft
Upper left corner of item.
virtual void setId(const QString &id)
Set the item's id name.
void setFrameStrokeColor(const QColor &color)
Sets the frame stroke color.
void setFrameJoinStyle(Qt::PenJoinStyle style)
Sets the join style used when drawing the item's frame.
void refreshBackgroundColor(bool updateItem=true)
Refresh item's background color, considering data defined colors.
virtual void setFrameEnabled(bool drawFrame)
Sets whether this item has a frame drawn around it or not.
void setLocked(bool locked)
Sets whether the item is locked, preventing mouse interactions with the item.
void refreshFrame(bool updateItem=true)
Refresh item's frame, considering data defined colors and frame size.
virtual QString uuid() const
Returns the item identification string.
virtual void attemptMove(const QgsLayoutPoint &point, bool useReferencePoint=true, bool includesFrame=false, int page=-1)
Attempts to move the item to a specified point.
void setBlendMode(QPainter::CompositionMode mode)
Sets the item's composition blending mode.
bool frameEnabled() const
Returns true if the item includes a frame.
void attemptMoveBy(double deltaX, double deltaY)
Attempts to shift the item's position by a specified deltaX and deltaY, in layout units.
void setReferencePoint(ReferencePoint point)
Sets the reference point for positioning of the layout item.
bool hasBackground() const
Returns true if the item has a background.
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.
QColor frameStrokeColor() const
Returns the frame's stroke color.
void setBackgroundEnabled(bool drawBackground)
Sets whether this item has a background drawn under it or not.
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
double length() const
Returns the length of the measurement.
void setResizeMode(ResizeMode mode)
Sets the resize mode for the multiframe, and recalculates frame sizes to match.
virtual void addFrame(QgsLayoutFrame *frame, bool recalcFrameSizes=true)
Adds a frame to the multiframe.
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe's content.
QList< QgsLayoutFrame * > frames() const
Returns a list of all child frames for this multiframe.
void setNodes(const QPolygonF &nodes)
Sets the nodes the shape consists of.
void setNorthOffset(double offset)
Sets the offset added to the arrows's rotation from a map's North.
NorthMode
Method for syncing rotation to a map's North direction.
void setNorthMode(NorthMode mode)
Sets the mode used to calculate the arrow rotation.
A base class for objects which belong to a layout.
QgsObjectCustomProperties mCustomProperties
Custom properties for object.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
double spaceBetweenPages() const
Returns the space between pages, in layout units.
QList< QgsLayoutItemPage * > pages()
Returns a list of pages in the collection.
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
Provides a method of storing sizes, consisting of a width and height, for use in QGIS layouts.
double height() const
Returns the height of the size.
bool readXml(const QDomElement &styleElem)
Reads the style's properties from XML.
void setHeaderHAlignment(HeaderHAlignment alignment)
Sets the horizontal alignment for table headers.
void setShowEmptyRows(bool showEmpty)
Sets whether empty rows should be drawn.
void setVerticalGrid(bool verticalGrid)
Sets whether the grid's vertical lines should be drawn in the table.
void setGridColor(const QColor &color)
Sets the color used for grid lines in the table.
void setCellMargin(double margin)
Sets the margin distance in mm between cell borders and their contents.
void setBackgroundColor(const QColor &color)
Sets the color used for background of table.
void setContentTextFormat(const QgsTextFormat &format)
Sets the format used to draw content text in the table.
QgsTextFormat contentTextFormat() const
Returns the format used to draw content text in the table.
void setWrapBehavior(WrapBehavior behavior)
Sets the wrap behavior for the table, which controls how text within cells is automatically wrapped.
void setEmptyTableBehavior(EmptyTableMode mode)
Sets the behavior mode for empty tables with no content rows.
void setHeaderMode(HeaderMode mode)
Sets the display mode for headers in the table.
void setHorizontalGrid(bool horizontalGrid)
Sets whether the grid's horizontal lines should be drawn in the table.
HeaderMode
Controls where headers are shown in the table.
QgsLayoutTableColumns mColumns
Columns to show in table.
void setShowGrid(bool showGrid)
Sets whether grid lines should be drawn in the table.
QgsTextFormat headerTextFormat() const
Returns the format used to draw header text in the table.
void setEmptyTableMessage(const QString &message)
Sets the message for empty tables with no content rows.
void setHeaderTextFormat(const QgsTextFormat &format)
Sets the format used to draw header text in the table.
QgsLayoutTableSortColumns mSortColumns
Columns to sort the table.
void setGridStrokeWidth(double width)
Sets the width in mm for grid lines in the table.
WrapBehavior
Controls how long strings in the table are handled.
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
EmptyTableMode
Controls how empty tables are displayed.
QMap< CellStyleGroup, QgsLayoutTableStyle * > mCellStyles
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
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 addLayoutItem(QgsLayoutItem *item)
Adds an item to the layout.
QgsProject * project() const
The project associated with the layout.
QgsTextFormat & textFormat()
Returns the text format used for rendering this legend component.
void readXml(const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads the component's style definition from an XML element.
static std::unique_ptr< QgsLineSymbol > createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading).
QString xmlData() const
Returns XML content of the style.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
@ Double
Double value (including negative values).
@ StrokeWidth
Line stroke width.
@ String
Any string value.
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ IntegerPositive
Positive integer values (including 0).
@ Opacity
Opacity (0-100).
@ Rotation
Rotation (value between 0-360 degrees).
@ ColorWithAlpha
Color with alpha channel.
@ DoublePositive
Positive double value (including 0).
@ DataTypeString
Property requires a string value.
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
A container for the context for various read/write operations on objects.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QColor decodeColor(const QString &str)
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
static QString encodeColor(const QColor &color)
void setColor(const QColor &color) const
Sets the color for the symbol.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
static Q_INVOKABLE Qgis::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
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
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QMap< QString, QString > QgsStringMap
_LayerRef< QgsMapLayer > QgsMapLayerRef
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
_LayerRef< QgsVectorLayer > QgsVectorLayerRef