63using namespace Qt::StringLiterals;
67void QgsCompositionConverter::initPropertyDefinitions()
69 if ( !sPropertyDefinitions.isEmpty() )
76 QgsPropertyDefinition(
77 "dataDefinedPaperSize",
79 QObject::tr(
"Paper size" ),
80 QObject::tr(
"string " )
82 "[<b>A5</b>|<b>A4</b>|<b>A3</b>|<b>A2</b>|<b>A1</b>|<b>A0</b>"
83 "|<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>"
84 "|<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>"
85 "|<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]"
95 QgsPropertyDefinition(
"dataDefinedPaperOrientation",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Symbol size" ), QObject::tr(
"string " ) + u
"[<b>portrait</b>|<b>landscape</b>]"_s ) },
122 QgsPropertyDefinition(
"dataDefinedMapLayers",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Symbol size" ), QObject::tr(
"list of map layer names separated by | characters" ) ) },
124 QgsPropertyDefinition(
"dataDefinedMapStylePreset",
QgsPropertyDefinition::DataTypeString, QObject::tr(
"Symbol size" ), QObject::tr(
"list of map layer names separated by | characters" ) ) },
150 QgsCompositionConverter::initPropertyDefinitions();
151 return sPropertyDefinitions;
157 initPropertyDefinitions();
159 const QDomElement parentElement = composerElement.parentNode().toElement();
161 auto layout = std::make_unique< QgsPrintLayout >( project );
162 layout->undoStack()->blockCommands(
true );
164 layout->mCustomProperties.readXml( composerElement );
167 layout->guides().setVisible( composerElement.attribute( u
"guidesVisible"_s, u
"1"_s ).toInt() != 0 );
169 const int printResolution = composerElement.attribute( u
"printResolution"_s, u
"300"_s ).toInt();
170 layout->renderContext().setDpi( printResolution );
173 const int pages = composerElement.attribute( u
"numPages"_s ).toInt();
174 const float paperHeight = composerElement.attribute( u
"paperHeight"_s ).toDouble();
175 const float paperWidth = composerElement.attribute( u
"paperWidth"_s ).toDouble();
177 QString name = composerElement.attribute( u
"name"_s );
179 if ( name.isEmpty() )
180 name = composerElement.attribute( u
"title"_s );
182 if ( name.isEmpty() )
183 name = parentElement.attribute( u
"title"_s );
184 layout->setName( name );
186 for (
int j = 0; j < pages; j++ )
190 layout->pageCollection()->addPage( page );
192 const QDomNodeList snapLineNodes = composerElement.elementsByTagName( u
"SnapLine"_s );
193 for (
int i = 0; i < snapLineNodes.size(); ++i )
195 const QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
196 const double x1 = snapLineElem.attribute( u
"x1"_s ).toDouble();
197 const double y1 = snapLineElem.attribute( u
"y1"_s ).toDouble();
198 const double x2 = snapLineElem.attribute( u
"x2"_s ).toDouble();
200 const Qt::Orientation orientation( x1 == x2 ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal );
202 auto guide = std::make_unique< QgsLayoutGuide >( orientation, position, page );
203 layout->guides().addGuide( guide.release() );
208 if ( composerElement.elementsByTagName( u
"symbol"_s ).size() )
210 const QDomElement symbolElement = composerElement.elementsByTagName( u
"symbol"_s ).at( 0 ).toElement();
216 layout->pageCollection()->setPageStyleSymbol( symbol.get() );
222 if ( parentElement.elementsByTagName( u
"Atlas"_s ).size() )
224 const QDomElement atlasElement = parentElement.elementsByTagName( u
"Atlas"_s ).at( 0 ).toElement();
225 readAtlasXml( layout->atlas(), atlasElement, layout->project() );
228 layout->undoStack()->blockCommands(
false );
233void QgsCompositionConverter::adjustPos(
QgsPrintLayout *layout,
QgsLayoutItem *layoutItem, QPointF *position,
bool &pasteInPlace,
int zOrderOffset, QPointF &pasteShiftPos,
int &pageNumber )
243 layoutItem->
attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
247 if ( !layoutItem->scene() )
249 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
252void QgsCompositionConverter::restoreGeneralComposeItemProperties(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
255 const QDomNodeList composerItemList = itemElem.elementsByTagName( u
"ComposerItem"_s );
256 if ( !composerItemList.isEmpty() )
258 const QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
261 if ( !
qgsDoubleNear( composerItemElem.attribute( u
"rotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
264 layoutItem->
setItemRotation( composerItemElem.attribute( u
"rotation"_s, u
"0"_s ).toDouble(),
false );
266 QgsCompositionConverter::readXml( layoutItem, composerItemElem );
270QRectF QgsCompositionConverter::itemPosition(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
273 double x, y, pagex, pagey, width, height;
274 bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOk;
276 x = itemElem.attribute( u
"x"_s ).toDouble( &xOk );
277 y = itemElem.attribute( u
"y"_s ).toDouble( &yOk );
278 page = itemElem.attribute( u
"page"_s ).toInt( &pageOk );
279 pagex = itemElem.attribute( u
"pagex"_s ).toDouble( &pagexOk );
280 pagey = itemElem.attribute( u
"pagey"_s ).toDouble( &pageyOk );
281 width = itemElem.attribute( u
"width"_s ).toDouble( &widthOk );
282 height = itemElem.attribute( u
"height"_s ).toDouble( &heightOk );
285 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( u
"positionMode"_s ).toInt( &positionModeOk ) );
286 if ( !positionModeOk )
291 if ( pageOk && pagexOk && pageyOk )
297 if ( page <= layoutItem->layout()->pageCollection()->pageCount() )
307 return QRectF( x, y, width, height );
310QPointF QgsCompositionConverter::minPointFromXml(
const QDomElement &elem )
312 double minX = std::numeric_limits<double>::max();
313 double minY = std::numeric_limits<double>::max();
314 const QDomNodeList composerItemList = elem.elementsByTagName( u
"ComposerItem"_s );
315 for (
int i = 0; i < composerItemList.size(); ++i )
317 const QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
320 x = currentComposerItemElem.attribute( u
"x"_s ).toDouble( &xOk );
321 y = currentComposerItemElem.attribute( u
"y"_s ).toDouble( &yOk );
326 minX = std::min( minX, x );
327 minY = std::min( minY, y );
329 if ( minX < std::numeric_limits<double>::max() )
331 return QPointF( minX, minY );
335 return QPointF( 0, 0 );
341 initPropertyDefinitions();
343 QList< QgsLayoutObject * > newItems;
348 const int zOrderOffset = layout->mItemsModel->zOrderListSize();
350 QPointF pasteShiftPos;
357 const QPointF minItemPos = minPointFromXml( parentElement );
360 pasteShiftPos = *position - minItemPos;
363 pageNumber = layout->mPageCollection->pageNumberForPoint( *position );
370 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerMap"_s ).size(); i++ )
372 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerMap"_s ).at( i ) );
374 readMapXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
375 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
376 newItems << layoutItem;
380 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerLabel"_s ).size(); i++ )
382 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerLabel"_s ).at( i ) );
384 readLabelXml( layoutItem, itemNode.toElement(), layout->
project() );
385 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
386 newItems << layoutItem;
390 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerShape"_s ).size(); i++ )
392 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerShape"_s ).at( i ) );
394 readShapeXml( layoutItem, itemNode.toElement(), layout->
project() );
395 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
396 newItems << layoutItem;
400 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerPicture"_s ).size(); i++ )
402 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerPicture"_s ).at( i ) );
404 readPictureXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
405 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
406 newItems << layoutItem;
410 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerPolygon"_s ).size(); i++ )
412 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerPolygon"_s ).at( i ) );
414 readPolyXml<QgsLayoutItemPolygon, QgsFillSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
415 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
416 newItems << layoutItem;
420 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerPolyline"_s ).size(); i++ )
422 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerPolyline"_s ).at( i ) );
424 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
425 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
426 newItems << layoutItem;
430 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerArrow"_s ).size(); i++ )
432 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerArrow"_s ).at( i ) );
434 readArrowXml( layoutItem, itemNode.toElement(), layout->
project() );
435 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
436 newItems << layoutItem;
440 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerScaleBar"_s ).size(); i++ )
442 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerScaleBar"_s ).at( i ) );
444 readScaleBarXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
445 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
446 newItems << layoutItem;
450 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerLegend"_s ).size(); i++ )
452 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerLegend"_s ).at( i ) );
454 readLegendXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
455 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
456 newItems << layoutItem;
460 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerHtml"_s ).size(); i++ )
462 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerHtml"_s ).at( i ) );
464 readHtmlXml( layoutItem, itemNode.toElement(), layout->
project() );
466 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
467 for (
const auto &frame : framesList )
469 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
471 newItems << layoutItem;
475 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerAttributeTableV2"_s ).size(); i++ )
477 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerAttributeTableV2"_s ).at( i ) );
479 readTableXml( layoutItem, itemNode.toElement(), layout->
project() );
481 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
482 for (
const auto &frame : framesList )
484 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
486 newItems << layoutItem;
490 for (
int i = 0; i < parentElement.elementsByTagName( u
"ComposerItemGroup"_s ).size(); i++ )
492 const QDomNode itemNode( parentElement.elementsByTagName( u
"ComposerItemGroup"_s ).at( i ) );
494 readGroupXml( layoutItem, itemNode.toElement(), layout->
project(), newItems );
495 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
496 newItems << layoutItem;
504 return document.elementsByTagName( u
"Composition"_s ).count() > 0;
513 if ( document.elementsByTagName( u
"Composition"_s ).count() > 0 )
515 const QDomElement composerElem = document.elementsByTagName( u
"Composition"_s ).at( 0 ).toElement();
518 const QDomElement elem = layout->writeXml( doc, context );
519 doc.appendChild( elem );
527 if ( itemElem.isNull() )
532 restoreGeneralComposeItemProperties( layoutItem, itemElem );
535 layoutItem->
setText( itemElem.attribute( u
"labelText"_s ) );
541 bool marginXOk =
false;
542 bool marginYOk =
false;
543 double marginX = itemElem.attribute( u
"marginX"_s ).toDouble( &marginXOk );
544 double marginY = itemElem.attribute( u
"marginY"_s ).toDouble( &marginYOk );
545 if ( !marginXOk || !marginYOk )
548 const double margin = itemElem.attribute( u
"margin"_s, u
"1.0"_s ).toDouble();
556 layoutItem->
setHAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( u
"halign"_s ).toInt() ) );
559 layoutItem->
setVAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( u
"valign"_s ).toInt() ) );
565 QgsTextFormat format;
567 if ( font.pointSizeF() > 0 )
569 format.
setSize( font.pointSizeF() );
572 else if ( font.pixelSize() > 0 )
574 format.
setSize( font.pixelSize() );
579 const QDomNodeList fontColorList = itemElem.elementsByTagName( u
"FontColor"_s );
580 if ( !fontColorList.isEmpty() )
582 const QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
583 const int red = fontColorElem.attribute( u
"red"_s, u
"0"_s ).toInt();
584 const int green = fontColorElem.attribute( u
"green"_s, u
"0"_s ).toInt();
585 const int blue = fontColorElem.attribute( u
"blue"_s, u
"0"_s ).toInt();
586 format.
setColor( QColor( red, green, blue ) );
590 format.
setColor( QColor( 0, 0, 0 ) );
601 layoutItem->
setCornerRadius( QgsLayoutMeasurement( itemElem.attribute( u
"cornerRadius"_s, u
"0"_s ).toDouble() ) );
603 restoreGeneralComposeItemProperties( layoutItem, itemElem );
605 QgsReadWriteContext context;
609 if ( itemElem.elementsByTagName( u
"symbol"_s ).size() )
611 const QDomElement symbolElement = itemElem.elementsByTagName( u
"symbol"_s ).at( 0 ).toElement();
613 if ( shapeStyleSymbol )
614 layoutItem->
setSymbol( shapeStyleSymbol.get() );
619 QVariantMap properties;
623 properties.insert( u
"style"_s, u
"solid"_s );
627 properties.insert( u
"style"_s, u
"no"_s );
631 properties.insert( u
"style_border"_s, u
"solid"_s );
635 properties.insert( u
"style_border"_s, u
"no"_s );
638 properties.insert( u
"width_border"_s, QString::number( layoutItem->pen().widthF() ) );
641 const QDomNodeList outlineColorList = itemElem.elementsByTagName( u
"OutlineColor"_s );
642 if ( !outlineColorList.isEmpty() )
644 const QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
645 bool redOk, greenOk, blueOk, alphaOk, widthOk;
646 int penRed, penGreen, penBlue, penAlpha;
649 penWidth = itemElem.attribute( u
"outlineWidth"_s ).toDouble( &widthOk );
650 penRed = frameColorElem.attribute( u
"red"_s ).toInt( &redOk );
651 penGreen = frameColorElem.attribute( u
"green"_s ).toInt( &greenOk );
652 penBlue = frameColorElem.attribute( u
"blue"_s ).toInt( &blueOk );
653 penAlpha = frameColorElem.attribute( u
"alpha"_s ).toInt( &alphaOk );
655 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
658 properties.insert( u
"width_border"_s, QString::number( penWidth ) );
661 const QDomNodeList fillColorList = itemElem.elementsByTagName( u
"FillColor"_s );
662 if ( !fillColorList.isEmpty() )
664 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
665 bool redOk, greenOk, blueOk, alphaOk;
666 int fillRed, fillGreen, fillBlue, fillAlpha;
668 fillRed = fillColorElem.attribute( u
"red"_s ).toInt( &redOk );
669 fillGreen = fillColorElem.attribute( u
"green"_s ).toInt( &greenOk );
670 fillBlue = fillColorElem.attribute( u
"blue"_s ).toInt( &blueOk );
671 fillAlpha = fillColorElem.attribute( u
"alpha"_s ).toInt( &alphaOk );
673 if ( redOk && greenOk && blueOk && alphaOk )
676 properties.insert( u
"style"_s, u
"solid"_s );
679 if ( itemElem.hasAttribute( u
"transparentFill"_s ) )
682 const bool hasOldTransparentFill = itemElem.attribute( u
"transparentFill"_s, u
"0"_s ).toInt();
683 if ( hasOldTransparentFill )
685 properties.insert( u
"style"_s, u
"no"_s );
690 layoutItem->
setSymbol( shapeStyleSymbol.get() );
701 restoreGeneralComposeItemProperties( layoutItem, itemElem );
705 bool positionModeOk =
false;
706 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( u
"positionMode"_s ).toInt( &positionModeOk ) );
707 if ( !positionModeOk )
711 bool anchorPointOk =
false;
714 if ( !anchorPointOk )
720 layoutItem->mSvgStrokeWidth = itemElem.attribute( u
"svgBorderWidth"_s, u
"0.2"_s ).toDouble();
722 QString imagePath = itemElem.attribute( u
"file"_s );
726 const QgsPathResolver pathResolver = project->
pathResolver();
727 if ( imagePath.endsWith(
".svg"_L1, Qt::CaseInsensitive ) )
730 imagePath = pathResolver.
readPath( imagePath );
733 layoutItem->mPictureHeight = itemElem.attribute( u
"pictureHeight"_s, u
"10"_s ).toDouble();
734 layoutItem->mPictureWidth = itemElem.attribute( u
"pictureWidth"_s, u
"10"_s ).toDouble();
737 if ( !
qgsDoubleNear( itemElem.attribute( u
"pictureRotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
739 layoutItem->mPictureRotation = itemElem.attribute( u
"pictureRotation"_s, u
"0"_s ).toDouble();
744 layoutItem->mNorthArrowHandler->
setNorthOffset( itemElem.attribute( u
"northOffset"_s, u
"0"_s ).toDouble() );
746 const QString rotationMapId = itemElem.attribute( u
"mapId"_s, u
"-1"_s );
747 if ( rotationMapId !=
"-1"_L1 )
750 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[rotationMapId] ) );
761 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemElem, project );
763 const QDomNodeList startPointList = itemElem.elementsByTagName( u
"StartPoint"_s );
764 if ( !startPointList.isEmpty() )
766 const QDomElement node = startPointList.at( 0 ).toElement();
767 polygon.append( QPointF( node.attribute( u
"x"_s ).toDouble(), node.attribute( u
"y"_s ).toDouble() ) );
769 const QDomNodeList stopPointList = itemElem.elementsByTagName( u
"StopPoint"_s );
770 if ( !stopPointList.isEmpty() )
772 const QDomElement node = stopPointList.at( 0 ).toElement();
773 polygon.append( QPointF( node.attribute( u
"x"_s ).toDouble(), node.attribute( u
"y"_s ).toDouble() ) );
785 layoutItem->
setArrowHeadWidth( itemElem.attribute( u
"arrowHeadWidth"_s, u
"1.0"_s ).toDouble() );
789 QString endMarkerFile = itemElem.attribute( u
"endMarkerFile"_s );
790 QString startMarkerFile = itemElem.attribute( u
"endMarkerFile"_s );
796 const QgsPathResolver pathResolver = project->
pathResolver();
797 if ( !endMarkerFile.isEmpty() )
799 if ( endMarkerFile.endsWith(
".svg"_L1, Qt::CaseInsensitive ) )
802 endMarkerFile = pathResolver.
readPath( endMarkerFile );
804 if ( !startMarkerFile.isEmpty() )
806 if ( startMarkerFile.endsWith(
".svg"_L1, Qt::CaseInsensitive ) )
809 startMarkerFile = pathResolver.
readPath( startMarkerFile );
812 if ( !endMarkerFile.isEmpty() )
817 if ( !startMarkerFile.isEmpty() )
829 const double margin = polygon.boundingRect().left() - layoutItem->pos().x();
830 polygon.translate( -polygon.boundingRect().left() + margin, -polygon.boundingRect().top() + margin );
838 restoreGeneralComposeItemProperties( layoutItem, itemElem );
840 mapId2Uuid[itemElem.attribute( u
"id"_s )] = layoutItem->
uuid();
843 const QDomDocument doc;
845 QgsReadWriteContext context;
851 const QDomNodeList extentNodeList = itemElem.elementsByTagName( u
"Extent"_s );
852 if ( !extentNodeList.isEmpty() )
854 const QDomElement extentElem = extentNodeList.at( 0 ).toElement();
855 double xmin, xmax, ymin, ymax;
856 xmin = extentElem.attribute( u
"xmin"_s ).toDouble();
857 xmax = extentElem.attribute( u
"xmax"_s ).toDouble();
858 ymin = extentElem.attribute( u
"ymin"_s ).toDouble();
859 ymax = extentElem.attribute( u
"ymax"_s ).toDouble();
860 layoutItem->
setExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
863 const QDomNodeList crsNodeList = itemElem.elementsByTagName( u
"crs"_s );
864 if ( !crsNodeList.isEmpty() )
866 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
871 layoutItem->
setCrs( QgsCoordinateReferenceSystem() );
875 if ( !
qgsDoubleNear( itemElem.attribute( u
"mapRotation"_s, u
"0"_s ).toDouble(), 0.0 ) )
877 layoutItem->
setMapRotation( itemElem.attribute( u
"mapRotation"_s, u
"0"_s ).toDouble() );
885 const QString keepLayerSetFlag = itemElem.attribute( u
"keepLayerSet"_s );
886 if ( keepLayerSetFlag.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
895 const QString drawCanvasItemsFlag = itemElem.attribute( u
"drawCanvasItems"_s, u
"true"_s );
896 if ( drawCanvasItemsFlag.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
905 layoutItem->mLayerStyleOverrides.clear();
908 layoutItem->mLayers.clear();
910 const QDomNodeList layerSetNodeList = itemElem.elementsByTagName( u
"LayerSet"_s );
911 if ( !layerSetNodeList.isEmpty() )
913 const QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
914 const QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( u
"Layer"_s );
915 layoutItem->mLayers.reserve( layerIdNodeList.size() );
916 for (
int i = 0; i < layerIdNodeList.size(); ++i )
918 const QDomElement layerElem = layerIdNodeList.at( i ).toElement();
919 const QString layerId = layerElem.text();
920 const QString layerName = layerElem.attribute( u
"name"_s );
921 const QString layerSource = layerElem.attribute( u
"source"_s );
922 const QString layerProvider = layerElem.attribute( u
"provider"_s );
924 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
925 ref.resolveWeakly( project );
926 layoutItem->mLayers << ref;
931 const QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( u
"LayerStyles"_s );
932 layoutItem->mKeepLayerStyles = !layerStylesNodeList.isEmpty();
933 if ( layoutItem->mKeepLayerStyles )
935 const QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
936 const QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( u
"LayerStyle"_s );
937 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
939 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
940 const QString layerId = layerStyleElement.attribute( u
"layerid"_s );
941 const QString layerName = layerStyleElement.attribute( u
"name"_s );
942 const QString layerSource = layerStyleElement.attribute( u
"source"_s );
943 const QString layerProvider = layerStyleElement.attribute( u
"provider"_s );
944 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
945 ref.resolveWeakly( project );
947 QgsMapLayerStyle style;
948 style.
readXml( layerStyleElement );
949 layoutItem->mLayerStyleOverrides.insert( ref.layerId, style.
xmlData() );
953 layoutItem->mDrawing =
false;
954 layoutItem->mNumCachedLayers = 0;
955 layoutItem->mCacheInvalidated =
true;
959 const QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( u
"ComposerMapOverview"_s );
960 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
962 const QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
963 auto mapOverview = std::make_unique<QgsLayoutItemMapOverview>( mapOverviewElem.attribute( u
"name"_s ), layoutItem );
964 mapOverview->readXml( mapOverviewElem, doc, context );
965 const QString frameMapId = mapOverviewElem.attribute( u
"frameMap"_s, u
"-1"_s );
966 if ( frameMapId !=
"-1"_L1 && mapId2Uuid.contains( frameMapId ) )
968 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[frameMapId] ) );
971 mapOverview->setLinkedMap( mapInstance );
973 layoutItem->mOverviewStack->addOverview( mapOverview.release() );
978 layoutItem->mGridStack->readXml( itemElem, doc, context );
983 const QDomNodeList gridNodeList = itemElem.elementsByTagName( u
"Grid"_s );
984 if ( layoutItem->mGridStack->size() == 0 && !gridNodeList.isEmpty() )
986 const QDomElement gridElem = gridNodeList.at( 0 ).toElement();
987 QgsLayoutItemMapGrid *mapGrid =
new QgsLayoutItemMapGrid( QObject::tr(
"Grid %1" ).arg( 1 ), layoutItem );
988 mapGrid->
setEnabled( gridElem.attribute( u
"show"_s, u
"0"_s ) !=
"0"_L1 );
990 mapGrid->
setIntervalX( gridElem.attribute( u
"intervalX"_s, u
"0"_s ).toDouble() );
991 mapGrid->
setIntervalY( gridElem.attribute( u
"intervalY"_s, u
"0"_s ).toDouble() );
992 mapGrid->
setOffsetX( gridElem.attribute( u
"offsetX"_s, u
"0"_s ).toDouble() );
993 mapGrid->
setOffsetY( gridElem.attribute( u
"offsetY"_s, u
"0"_s ).toDouble() );
994 mapGrid->
setCrossLength( gridElem.attribute( u
"crossLength"_s, u
"3"_s ).toDouble() );
996 mapGrid->
setFrameWidth( gridElem.attribute( u
"gridFrameWidth"_s, u
"2.0"_s ).toDouble() );
997 mapGrid->
setFramePenSize( gridElem.attribute( u
"gridFramePenThickness"_s, u
"0.5"_s ).toDouble() );
1002 const QDomElement gridSymbolElem = gridElem.firstChildElement( u
"symbol"_s );
1003 std::unique_ptr< QgsLineSymbol > lineSymbol;
1004 if ( gridSymbolElem.isNull() )
1008 lineSymbol->setWidth( gridElem.attribute( u
"penWidth"_s, u
"0"_s ).toDouble() );
1009 lineSymbol->setColor(
1010 QColor( gridElem.attribute( u
"penColorRed"_s, u
"0"_s ).toInt(), gridElem.attribute( u
"penColorGreen"_s, u
"0"_s ).toInt(), gridElem.attribute( u
"penColorBlue"_s, u
"0"_s ).toInt() )
1020 const QDomNodeList annotationNodeList = gridElem.elementsByTagName( u
"Annotation"_s );
1021 if ( !annotationNodeList.isEmpty() )
1023 const QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1035 QFont annotationFont;
1036 annotationFont.fromString( annotationElem.attribute( u
"font"_s, QString() ) );
1039 annotationFormat.
setFont( annotationFont );
1040 if ( annotationFont.pointSizeF() > 0 )
1042 annotationFormat.
setSize( annotationFont.pointSizeF() );
1045 else if ( annotationFont.pixelSize() > 0 )
1047 annotationFormat.
setSize( annotationFont.pixelSize() );
1055 layoutItem->mGridStack->addGrid( mapGrid );
1059 const QDomNodeList atlasNodeList = itemElem.elementsByTagName( u
"AtlasMap"_s );
1060 if ( !atlasNodeList.isEmpty() )
1062 const QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1063 layoutItem->mAtlasDriven = ( atlasElem.attribute( u
"atlasDriven"_s, u
"0"_s ) !=
"0"_L1 );
1064 if ( atlasElem.hasAttribute( u
"fixedScale"_s ) )
1068 else if ( atlasElem.hasAttribute( u
"scalingMode"_s ) )
1072 layoutItem->
setAtlasMargin( atlasElem.attribute( u
"margin"_s, u
"0.1"_s ).toDouble() );
1083 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1085 layoutItem->
setHeight( itemElem.attribute( u
"height"_s, u
"5.0"_s ).toDouble() );
1086 layoutItem->
setHeight( itemElem.attribute( u
"height"_s, u
"5.0"_s ).toDouble() );
1087 layoutItem->
setLabelBarSpace( itemElem.attribute( u
"labelBarSpace"_s, u
"3.0"_s ).toDouble() );
1088 layoutItem->
setBoxContentSpace( itemElem.attribute( u
"boxContentSpace"_s, u
"1.0"_s ).toDouble() );
1089 layoutItem->
setNumberOfSegments( itemElem.attribute( u
"numSegments"_s, u
"2"_s ).toInt() );
1091 layoutItem->
setUnitsPerSegment( itemElem.attribute( u
"numUnitsPerSegment"_s, u
"1.0"_s ).toDouble() );
1093 layoutItem->
setMinimumBarWidth( itemElem.attribute( u
"minBarWidth"_s, u
"50"_s ).toDouble() );
1094 layoutItem->
setMaximumBarWidth( itemElem.attribute( u
"maxBarWidth"_s, u
"150"_s ).toDouble() );
1095 layoutItem->mSegmentMillimeters = itemElem.attribute( u
"segmentMillimeters"_s, u
"0.0"_s ).toDouble();
1097 layoutItem->
setUnitLabel( itemElem.attribute( u
"unitLabel"_s ) );
1102 f.fromString( itemElem.attribute( u
"font"_s, QString() ) );
1110 const QDomNodeList fillColorList = itemElem.elementsByTagName( u
"fillColor"_s );
1111 if ( !fillColorList.isEmpty() )
1113 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1114 bool redOk, greenOk, blueOk, alphaOk;
1115 int fillRed, fillGreen, fillBlue, fillAlpha;
1117 fillRed = fillColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1118 fillGreen = fillColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1119 fillBlue = fillColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1120 fillAlpha = fillColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1122 if ( redOk && greenOk && blueOk && alphaOk )
1124 layoutItem->
fillSymbol()->
setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1129 layoutItem->
fillSymbol()->
setColor( QColor( itemElem.attribute( u
"brushColor"_s, u
"#000000"_s ) ) );
1133 const QDomNodeList fillColor2List = itemElem.elementsByTagName( u
"fillColor2"_s );
1134 if ( !fillColor2List.isEmpty() )
1136 const QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1137 bool redOk, greenOk, blueOk, alphaOk;
1138 int fillRed, fillGreen, fillBlue, fillAlpha;
1140 fillRed = fillColor2Elem.attribute( u
"red"_s ).toDouble( &redOk );
1141 fillGreen = fillColor2Elem.attribute( u
"green"_s ).toDouble( &greenOk );
1142 fillBlue = fillColor2Elem.attribute( u
"blue"_s ).toDouble( &blueOk );
1143 fillAlpha = fillColor2Elem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1145 if ( redOk && greenOk && blueOk && alphaOk )
1155 auto lineSymbol = std::make_unique< QgsLineSymbol >();
1156 auto lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >();
1157 lineSymbolLayer->setWidth( itemElem.attribute( u
"outlineWidth"_s, u
"0.3"_s ).toDouble() );
1162 const QDomNodeList strokeColorList = itemElem.elementsByTagName( u
"strokeColor"_s );
1163 if ( !strokeColorList.isEmpty() )
1165 const QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1166 bool redOk, greenOk, blueOk, alphaOk;
1167 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1169 strokeRed = strokeColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1170 strokeGreen = strokeColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1171 strokeBlue = strokeColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1172 strokeAlpha = strokeColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1174 if ( redOk && greenOk && blueOk && alphaOk )
1176 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1181 lineSymbolLayer->setColor( QColor( itemElem.attribute( u
"penColor"_s, u
"#000000"_s ) ) );
1183 lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1189 const QDomNodeList textColorList = itemElem.elementsByTagName( u
"textColor"_s );
1190 if ( !textColorList.isEmpty() )
1192 const QDomElement textColorElem = textColorList.at( 0 ).toElement();
1193 bool redOk, greenOk, blueOk, alphaOk;
1194 int textRed, textGreen, textBlue, textAlpha;
1196 textRed = textColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1197 textGreen = textColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1198 textBlue = textColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1199 textAlpha = textColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1201 if ( redOk && greenOk && blueOk && alphaOk )
1204 layoutItem->
setFontColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1211 c.setNamedColor( itemElem.attribute( u
"fontColor"_s, u
"#000000"_s ) );
1218 const QString styleString = itemElem.attribute( u
"style"_s, QString() );
1219 layoutItem->
setStyle( QObject::tr( styleString.toLocal8Bit().data() ) );
1221 if ( itemElem.attribute( u
"unitType"_s ).isEmpty() )
1224 switch ( itemElem.attribute( u
"units"_s ).toInt() )
1248 const QString mapId = itemElem.attribute( u
"mapId"_s, u
"-1"_s );
1249 if ( mapId !=
"-1"_L1 && mapId2Uuid.contains( mapId ) )
1251 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[mapId] ) );
1263 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1265 QgsPathResolver pathResolver;
1268 QgsReadWriteContext context;
1273 const QString mapId = itemElem.attribute( u
"map"_s, u
"-1"_s );
1274 if ( mapId !=
"-1"_L1 && mapId2Uuid.contains( mapId ) )
1276 QgsLayoutItemMap *mapInstance = qobject_cast<QgsLayoutItemMap *>( layoutItem->
layout()->
itemByUuid( mapId2Uuid[mapId] ) );
1284 layoutItem->
setTitle( itemElem.attribute( u
"title"_s ) );
1285 if ( !itemElem.attribute( u
"titleAlignment"_s ).isEmpty() )
1287 layoutItem->
setTitleAlignment(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( u
"titleAlignment"_s ).toInt() ) );
1289 int colCount = itemElem.attribute( u
"columnCount"_s, u
"1"_s ).toInt();
1293 layoutItem->
setSplitLayer( itemElem.attribute( u
"splitLayer"_s, u
"0"_s ).toInt() == 1 );
1294 layoutItem->
setEqualColumnWidth( itemElem.attribute( u
"equalColumnWidth"_s, u
"0"_s ).toInt() == 1 );
1296 const QDomNodeList stylesNodeList = itemElem.elementsByTagName( u
"styles"_s );
1297 if ( !stylesNodeList.isEmpty() )
1299 const QDomNode stylesNode = stylesNodeList.at( 0 );
1300 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
1302 const QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
1303 QgsLegendStyle style;
1304 style.
readXml( styleElem, QDomDocument() );
1305 const QString name = styleElem.attribute( u
"name"_s );
1307 if ( name ==
"title"_L1 )
1309 else if ( name ==
"group"_L1 )
1311 else if ( name ==
"subgroup"_L1 )
1313 else if ( name ==
"symbol"_L1 )
1315 else if ( name ==
"symbolLabel"_L1 )
1325 fontClr.setNamedColor( itemElem.attribute( u
"fontColor"_s, u
"#000000"_s ) );
1332 layoutItem->
setBoxSpace( itemElem.attribute( u
"boxSpace"_s, u
"2.0"_s ).toDouble() );
1333 layoutItem->
setColumnSpace( itemElem.attribute( u
"columnSpace"_s, u
"2.0"_s ).toDouble() );
1335 layoutItem->
setSymbolWidth( itemElem.attribute( u
"symbolWidth"_s, u
"7.0"_s ).toDouble() );
1336 layoutItem->
setSymbolHeight( itemElem.attribute( u
"symbolHeight"_s, u
"14.0"_s ).toDouble() );
1337 layoutItem->
setWmsLegendWidth( itemElem.attribute( u
"wmsLegendWidth"_s, u
"50"_s ).toDouble() );
1338 layoutItem->
setWmsLegendHeight( itemElem.attribute( u
"wmsLegendHeight"_s, u
"25"_s ).toDouble() );
1340 layoutItem->
setLineSpacing( itemElem.attribute( u
"lineSpacing"_s, u
"1.0"_s ).toDouble() );
1343 layoutItem->
setDrawRasterStroke( itemElem.attribute( u
"rasterBorder"_s, u
"1"_s ) !=
"0"_L1 );
1345 layoutItem->
setRasterStrokeWidth( itemElem.attribute( u
"rasterBorderWidth"_s, u
"0"_s ).toDouble() );
1347 layoutItem->
setWrapString( itemElem.attribute( u
"wrapChar"_s ) );
1349 layoutItem->mSizeToContents = itemElem.attribute( u
"resizeToContents"_s, u
"1"_s ) !=
"0"_L1;
1350 layoutItem->mLegendFilterByMap = itemElem.attribute( u
"legendFilterByMap"_s, u
"0"_s ).toInt();
1351 layoutItem->mFilterOutAtlas = itemElem.attribute( u
"legendFilterByAtlas"_s, u
"0"_s ).toInt();
1354 QDomElement layerTreeElem = itemElem.firstChildElement( u
"layer-tree"_s );
1355 if ( layerTreeElem.isNull() )
1356 layerTreeElem = itemElem.firstChildElement( u
"layer-tree-group"_s );
1358 if ( !layerTreeElem.isNull() )
1362 tree->resolveReferences( project,
true );
1364 layoutItem->setCustomLayerTree( tree.release() );
1368 layoutItem->setCustomLayerTree(
nullptr );
1375bool QgsCompositionConverter::readAtlasXml(
QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project )
1377 atlasItem->
setEnabled( itemElem.attribute( u
"enabled"_s, u
"false"_s ) ==
"true"_L1 );
1380 const QString layerId = itemElem.attribute( u
"coverageLayer"_s );
1381 const QString layerName = itemElem.attribute( u
"coverageLayerName"_s );
1382 const QString layerSource = itemElem.attribute( u
"coverageLayerSource"_s );
1383 const QString layerProvider = itemElem.attribute( u
"coverageLayerProvider"_s );
1389 QString errorString;
1390 atlasItem->
setFilenameExpression( itemElem.attribute( u
"filenamePattern"_s, QString() ), errorString );
1392 atlasItem->
setSortFeatures( itemElem.attribute( u
"sortFeatures"_s, u
"false"_s ) ==
"true"_L1 );
1396 atlasItem->
setSortAscending( itemElem.attribute( u
"sortAscending"_s, u
"true"_s ) ==
"true"_L1 );
1398 atlasItem->
setFilterFeatures( itemElem.attribute( u
"filterFeatures"_s, u
"false"_s ) ==
"true"_L1 );
1401 QString expErrorString;
1402 atlasItem->
setFilterExpression( itemElem.attribute( u
"featureFilter"_s, QString() ), expErrorString );
1406 atlasItem->
setHideCoverage( itemElem.attribute( u
"hideCoverage"_s, u
"false"_s ) ==
"true"_L1 );
1414 readOldComposerObjectXml( layoutItem, itemElem );
1418 const QDomNodeList frameList = itemElem.elementsByTagName( u
"ComposerFrame"_s );
1419 for (
int i = 0; i < frameList.size(); ++i )
1421 const QDomElement frameElem = frameList.at( i ).toElement();
1422 QgsLayoutFrame *newFrame =
new QgsLayoutFrame( layoutItem->
layout(), layoutItem );
1423 restoreGeneralComposeItemProperties( newFrame, frameElem );
1425 const double x = itemElem.attribute( u
"sectionX"_s ).toDouble();
1426 const double y = itemElem.attribute( u
"sectionY"_s ).toDouble();
1427 const double width = itemElem.attribute( u
"sectionWidth"_s ).toDouble();
1428 const double height = itemElem.attribute( u
"sectionHeight"_s ).toDouble();
1430 newFrame->
setHidePageIfEmpty( itemElem.attribute( u
"hidePageIfEmpty"_s, u
"0"_s ).toInt() );
1432 layoutItem->
addFrame( newFrame,
false );
1437 if ( !contentModeOK )
1441 layoutItem->
setEvaluateExpressions( itemElem.attribute( u
"evaluateExpressions"_s, u
"true"_s ) ==
"true"_L1 );
1442 layoutItem->
setUseSmartBreaks( itemElem.attribute( u
"useSmartBreaks"_s, u
"true"_s ) ==
"true"_L1 );
1443 layoutItem->
setMaxBreakDistance( itemElem.attribute( u
"maxBreakDistance"_s, u
"10"_s ).toDouble() );
1444 layoutItem->
setHtml( itemElem.attribute( u
"html"_s ) );
1449 const QString urlString = itemElem.attribute( u
"url"_s );
1450 if ( !urlString.isEmpty() )
1452 layoutItem->
setUrl( urlString );
1462 readOldComposerObjectXml( layoutItem, itemElem );
1466 const QDomNodeList frameList = itemElem.elementsByTagName( u
"ComposerFrame"_s );
1467 for (
int i = 0; i < frameList.size(); ++i )
1469 const QDomElement frameElem = frameList.at( i ).toElement();
1470 QgsLayoutFrame *newFrame =
new QgsLayoutFrame( layoutItem->
layout(), layoutItem );
1471 restoreGeneralComposeItemProperties( newFrame, frameElem );
1473 const double x = itemElem.attribute( u
"sectionX"_s ).toDouble();
1474 const double y = itemElem.attribute( u
"sectionY"_s ).toDouble();
1475 const double width = itemElem.attribute( u
"sectionWidth"_s ).toDouble();
1476 const double height = itemElem.attribute( u
"sectionHeight"_s ).toDouble();
1478 newFrame->
setHidePageIfEmpty( itemElem.attribute( u
"hidePageIfEmpty"_s, u
"0"_s ).toInt() );
1480 layoutItem->
addFrame( newFrame,
false );
1484 layoutItem->
setEmptyTableMessage( itemElem.attribute( u
"emptyTableMessage"_s, QObject::tr(
"No matching records" ) ) );
1485 layoutItem->
setShowEmptyRows( itemElem.attribute( u
"showEmptyRows"_s, u
"0"_s ).toInt() );
1489 headerFont.fromString( itemElem.attribute( u
"headerFont"_s, QString() ) );
1492 headerFormat.
setFont( headerFont );
1493 if ( headerFont.pointSizeF() > 0 )
1495 headerFormat.
setSize( headerFont.pointSizeF() );
1498 else if ( headerFont.pixelSize() > 0 )
1500 headerFormat.
setSize( headerFont.pixelSize() );
1511 contentFont.fromString( itemElem.attribute( u
"contentFont"_s, QString() ) );
1514 contentFormat.
setFont( contentFont );
1515 if ( contentFont.pointSizeF() > 0 )
1517 contentFormat.
setSize( contentFont.pointSizeF() );
1520 else if ( contentFont.pixelSize() > 0 )
1522 contentFormat.
setSize( contentFont.pixelSize() );
1528 layoutItem->
setCellMargin( itemElem.attribute( u
"cellMargin"_s, u
"1.0"_s ).toDouble() );
1529 layoutItem->
setGridStrokeWidth( itemElem.attribute( u
"gridStrokeWidth"_s, u
"0.5"_s ).toDouble() );
1530 layoutItem->
setHorizontalGrid( itemElem.attribute( u
"horizontalGrid"_s, u
"1"_s ).toInt() );
1531 layoutItem->
setVerticalGrid( itemElem.attribute( u
"verticalGrid"_s, u
"1"_s ).toInt() );
1532 layoutItem->
setShowGrid( itemElem.attribute( u
"showGrid"_s, u
"1"_s ).toInt() );
1541 const QDomNodeList columnsList = itemElem.elementsByTagName( u
"displayColumns"_s );
1542 if ( !columnsList.isEmpty() )
1544 const QDomElement columnsElem = columnsList.at( 0 ).toElement();
1545 const QDomNodeList columnEntryList = columnsElem.elementsByTagName( u
"column"_s );
1546 for (
int i = 0; i < columnEntryList.size(); ++i )
1548 const QDomElement columnElem = columnEntryList.at( i ).toElement();
1549 QgsLayoutTableColumn column;
1550 column.mHAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( u
"hAlignment"_s, QString::number( Qt::AlignLeft ) ).toInt() );
1551 column.mVAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( u
"vAlignment"_s, QString::number( Qt::AlignVCenter ) ).toInt() );
1552 column.mHeading = columnElem.attribute( u
"heading"_s, QString() );
1553 column.mAttribute = columnElem.attribute( u
"attribute"_s, QString() );
1554 column.mSortByRank = columnElem.attribute( u
"sortByRank"_s, u
"0"_s ).toInt();
1555 column.mSortOrder =
static_cast< Qt::SortOrder
>( columnElem.attribute( u
"sortOrder"_s, QString::number( Qt::AscendingOrder ) ).toInt() );
1556 column.mWidth = columnElem.attribute( u
"width"_s, u
"0.0"_s ).toDouble();
1558 const QDomNodeList bgColorList = columnElem.elementsByTagName( u
"backgroundColor"_s );
1559 if ( !bgColorList.isEmpty() )
1561 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1562 bool redOk, greenOk, blueOk, alphaOk;
1563 int bgRed, bgGreen, bgBlue, bgAlpha;
1564 bgRed = bgColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1565 bgGreen = bgColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1566 bgBlue = bgColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1567 bgAlpha = bgColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1568 if ( redOk && greenOk && blueOk && alphaOk )
1570 column.mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1573 layoutItem->
mColumns.append( column );
1578 std::copy_if( layoutItem->
mColumns.begin(), layoutItem->
mColumns.end(), std::back_inserter( layoutItem->
mSortColumns ), [](
const QgsLayoutTableColumn &col ) { return col.sortByRank() > 0; } );
1579 std::sort( layoutItem->
mSortColumns.begin(), layoutItem->
mSortColumns.end(), [](
const QgsLayoutTableColumn &a,
const QgsLayoutTableColumn &b ) { return a.sortByRank() < b.sortByRank(); } );
1585 const QDomNodeList stylesList = itemElem.elementsByTagName( u
"cellStyles"_s );
1586 if ( !stylesList.isEmpty() )
1588 const QDomElement stylesElem = stylesList.at( 0 ).toElement();
1590 QMap< QgsLayoutTable::CellStyleGroup, QString >::const_iterator it = layoutItem->mCellStyleNames.constBegin();
1591 for ( ; it != layoutItem->mCellStyleNames.constEnd(); ++it )
1593 const QString styleName = it.value();
1594 const QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
1595 if ( !styleList.isEmpty() )
1597 const QDomElement styleElem = styleList.at( 0 ).toElement();
1598 QgsLayoutTableStyle *style = layoutItem->
mCellStyles.value( it.key() );
1606 const QString layerId = itemElem.attribute( u
"vectorLayer"_s );
1607 const QString layerName = itemElem.attribute( u
"vectorLayerName"_s );
1608 const QString layerSource = itemElem.attribute( u
"vectorLayerSource"_s );
1609 const QString layerProvider = itemElem.attribute( u
"vectorLayerProvider"_s );
1617bool QgsCompositionConverter::readGroupXml(
QgsLayoutItemGroup *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
const QList< QgsLayoutObject * > &items )
1621 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1623 const QDomNodeList nodes = itemElem.elementsByTagName(
"ComposerItemGroupElement" );
1624 for (
int i = 0, n = nodes.size(); i < n; ++i )
1626 const QDomElement groupElement = nodes.at( i ).toElement();
1627 const QString elementUuid = groupElement.attribute(
"uuid" );
1629 for ( QgsLayoutObject *item : items )
1631 if (
dynamic_cast<QgsLayoutItem *
>( item ) &&
static_cast<QgsLayoutItem *
>( item )->uuid() == elementUuid )
1633 layoutItem->
addItem(
static_cast<QgsLayoutItem *
>( item ) );
1642template<
class T,
class T2>
bool QgsCompositionConverter::readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1644 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1645 const QDomNodeList nodeList = itemElem.elementsByTagName( u
"node"_s );
1646 if ( !nodeList.isEmpty() )
1649 for (
int i = 0; i < nodeList.length(); i++ )
1651 const QDomElement node = nodeList.at( i ).toElement();
1652 polygon.append( QPointF( node.attribute( u
"x"_s ).toDouble(), node.attribute( u
"y"_s ).toDouble() ) );
1654 layoutItem->setNodes( polygon );
1656 if ( itemElem.elementsByTagName( u
"symbol"_s ).size() )
1658 const QDomElement symbolElement = itemElem.elementsByTagName( u
"symbol"_s ).at( 0 ).toElement();
1659 QgsReadWriteContext context;
1664 layoutItem->setSymbol( styleSymbol.release() );
1667 layoutItem->setFrameEnabled(
false );
1668 layoutItem->setBackgroundEnabled(
false );
1673bool QgsCompositionConverter::readXml(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
1675 if ( itemElem.isNull() )
1680 readOldComposerObjectXml( layoutItem, itemElem );
1683 layoutItem->mUuid = itemElem.attribute( u
"uuid"_s, QUuid::createUuid().toString() );
1686 layoutItem->mTemplateUuid = itemElem.attribute( u
"templateUuid"_s );
1689 const QString
id = itemElem.attribute( u
"id"_s, QString() );
1690 layoutItem->
setId(
id );
1693 const QString frame = itemElem.attribute( u
"frame"_s );
1694 layoutItem->
setFrameEnabled( frame.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 );
1697 const QString background = itemElem.attribute( u
"background"_s );
1701 const QString positionLock = itemElem.attribute( u
"positionLock"_s );
1702 layoutItem->
setLocked( positionLock.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 );
1705 layoutItem->
setVisibility( itemElem.attribute( u
"visibility"_s, u
"1"_s ) !=
"0"_L1 );
1707 layoutItem->mParentGroupUuid = itemElem.attribute( u
"groupUuid"_s );
1708 if ( !layoutItem->mParentGroupUuid.isEmpty() )
1710 if ( QgsLayoutItemGroup *group = layoutItem->
parentGroup() )
1712 group->addItem( layoutItem );
1715 layoutItem->mTemplateUuid = itemElem.attribute( u
"templateUuid"_s );
1718 const QRectF position = itemPosition( layoutItem, itemElem );
1723 layoutItem->setZValue( itemElem.attribute( u
"zValue"_s ).toDouble() );
1726 const QDomNodeList frameColorList = itemElem.elementsByTagName( u
"FrameColor"_s );
1727 if ( !frameColorList.isEmpty() )
1729 const QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
1730 bool redOk, greenOk, blueOk, alphaOk, widthOk;
1731 int penRed, penGreen, penBlue, penAlpha;
1734 penWidth = itemElem.attribute( u
"outlineWidth"_s ).toDouble( &widthOk );
1735 penRed = frameColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1736 penGreen = frameColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1737 penBlue = frameColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1738 penAlpha = frameColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1741 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
1748 layoutItem->setPen( framePen );
1755 const QDomNodeList bgColorList = itemElem.elementsByTagName( u
"BackgroundColor"_s );
1756 if ( !bgColorList.isEmpty() )
1758 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1759 bool redOk, greenOk, blueOk, alphaOk;
1760 int bgRed, bgGreen, bgBlue, bgAlpha;
1761 bgRed = bgColorElem.attribute( u
"red"_s ).toDouble( &redOk );
1762 bgGreen = bgColorElem.attribute( u
"green"_s ).toDouble( &greenOk );
1763 bgBlue = bgColorElem.attribute( u
"blue"_s ).toDouble( &blueOk );
1764 bgAlpha = bgColorElem.attribute( u
"alpha"_s ).toDouble( &alphaOk );
1765 if ( redOk && greenOk && blueOk && alphaOk )
1767 layoutItem->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1768 layoutItem->setBrush( QBrush( layoutItem->mBackgroundColor, Qt::SolidPattern ) );
1778 if ( itemElem.hasAttribute( u
"opacity"_s ) )
1780 layoutItem->
setItemOpacity( itemElem.attribute( u
"opacity"_s, u
"1"_s ).toDouble() );
1784 layoutItem->
setItemOpacity( 1.0 - itemElem.attribute( u
"transparency"_s, u
"0"_s ).toInt() / 100.0 );
1787 layoutItem->mExcludeFromExports = itemElem.attribute( u
"excludeFromExports"_s, u
"0"_s ).toInt();
1788 layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
1793 layoutItem->
setItemRotation( itemElem.attribute( u
"itemRotation"_s, u
"0"_s ).toDouble(),
false );
1795 layoutItem->mBlockUndoCommands =
false;
1801bool QgsCompositionConverter::readOldComposerObjectXml(
QgsLayoutObject *layoutItem,
const QDomElement &itemElem )
1803 if ( itemElem.isNull() )
1811 const QDomNode propsNode = itemElem.namedItem( u
"dataDefinedProperties"_s );
1812 if ( !propsNode.isNull() )
1820 exp = u
"100.0 - (%1)"_s.arg( exp );
1832void QgsCompositionConverter::readOldDataDefinedPropertyMap(
const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties )
1835 QgsPropertiesDefinition::const_iterator i = defs.constBegin();
1836 for ( ; i != defs.constEnd(); ++i )
1838 const QString elemName = i.value().name();
1839 const QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
1840 if ( !ddNodeList.isEmpty() )
1842 const QDomElement ddElem = ddNodeList.at( 0 ).toElement();
1845 dataDefinedProperties.
setProperty( i.key(), prop );
1855 return QgsProperty();
1858 const QString active = ddElem.attribute( u
"active"_s );
1859 bool isActive =
false;
1860 if ( active.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
1864 const QString field = ddElem.attribute( u
"field"_s );
1865 const QString expr = ddElem.attribute( u
"expr"_s );
1867 const QString useExpr = ddElem.attribute( u
"useExpr"_s );
1868 bool isExpression =
false;
1869 if ( useExpr.compare(
"true"_L1, Qt::CaseInsensitive ) == 0 )
1871 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