65 void QgsCompositionConverter::initPropertyDefinitions()
67 if ( !sPropertyDefinitions.isEmpty() )
75 "|<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>"
76 "|<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>"
77 "|<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]"
121 QgsCompositionConverter::initPropertyDefinitions();
122 return sPropertyDefinitions;
128 initPropertyDefinitions();
130 const QDomElement parentElement = composerElement.parentNode().toElement();
132 std::unique_ptr< QgsPrintLayout > layout = std::make_unique< QgsPrintLayout >( project );
133 layout->undoStack()->blockCommands(
true );
135 layout->mCustomProperties.readXml( composerElement );
138 layout->guides().setVisible( composerElement.attribute( QStringLiteral(
"guidesVisible" ), QStringLiteral(
"1" ) ).toInt() != 0 );
140 const int printResolution = composerElement.attribute( QStringLiteral(
"printResolution" ), QStringLiteral(
"300" ) ).toInt();
141 layout->renderContext().setDpi( printResolution );
144 const int pages = composerElement.attribute( QStringLiteral(
"numPages" ) ).toInt( );
145 const float paperHeight = composerElement.attribute( QStringLiteral(
"paperHeight" ) ).toDouble( );
146 const float paperWidth = composerElement.attribute( QStringLiteral(
"paperWidth" ) ).toDouble( );
148 QString name = composerElement.attribute( QStringLiteral(
"name" ) );
150 if ( name.isEmpty() )
151 name = composerElement.attribute( QStringLiteral(
"title" ) );
153 if ( name.isEmpty() )
154 name = parentElement.attribute( QStringLiteral(
"title" ) );
155 layout->setName( name );
157 for (
int j = 0; j < pages; j++ )
161 layout->pageCollection()->addPage( page );
163 const QDomNodeList snapLineNodes = composerElement.elementsByTagName( QStringLiteral(
"SnapLine" ) );
164 for (
int i = 0; i < snapLineNodes.size(); ++i )
166 const QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
167 const double x1 = snapLineElem.attribute( QStringLiteral(
"x1" ) ).toDouble();
168 const double y1 = snapLineElem.attribute( QStringLiteral(
"y1" ) ).toDouble();
169 const double x2 = snapLineElem.attribute( QStringLiteral(
"x2" ) ).toDouble();
171 const Qt::Orientation orientation( x1 == x2 ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal );
173 std::unique_ptr< QgsLayoutGuide > guide = std::make_unique< QgsLayoutGuide >( orientation, position, page );
174 layout->guides().addGuide( guide.release() );
179 if ( composerElement.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
181 const QDomElement symbolElement = composerElement.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
185 const std::unique_ptr< QgsFillSymbol > symbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context ) );
187 layout->pageCollection()->setPageStyleSymbol( symbol.get() );
193 if ( parentElement.elementsByTagName( QStringLiteral(
"Atlas" ) ).size() )
195 const QDomElement atlasElement = parentElement.elementsByTagName( QStringLiteral(
"Atlas" ) ).at( 0 ).toElement();
196 readAtlasXml( layout->atlas(), atlasElement, layout->project() );
199 layout->undoStack()->blockCommands(
false );
204 void QgsCompositionConverter::adjustPos(
QgsPrintLayout *layout,
QgsLayoutItem *layoutItem, QPointF *position,
bool &pasteInPlace,
int zOrderOffset, QPointF &pasteShiftPos,
int &pageNumber )
214 layoutItem->
attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
218 if ( !layoutItem->scene() )
220 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
223 void QgsCompositionConverter::restoreGeneralComposeItemProperties(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
226 const QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral(
"ComposerItem" ) );
227 if ( !composerItemList.isEmpty() )
229 const QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
232 if ( !
qgsDoubleNear( composerItemElem.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
235 layoutItem->
setItemRotation( composerItemElem.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble(),
false );
237 QgsCompositionConverter::readXml( layoutItem, composerItemElem );
241 QRectF QgsCompositionConverter::itemPosition(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
244 double x, y, pagex, pagey, width, height;
245 bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOk;
247 x = itemElem.attribute( QStringLiteral(
"x" ) ).toDouble( &xOk );
248 y = itemElem.attribute( QStringLiteral(
"y" ) ).toDouble( &yOk );
249 page = itemElem.attribute( QStringLiteral(
"page" ) ).toInt( &pageOk );
250 pagex = itemElem.attribute( QStringLiteral(
"pagex" ) ).toDouble( &pagexOk );
251 pagey = itemElem.attribute( QStringLiteral(
"pagey" ) ).toDouble( &pageyOk );
252 width = itemElem.attribute( QStringLiteral(
"width" ) ).toDouble( &widthOk );
253 height = itemElem.attribute( QStringLiteral(
"height" ) ).toDouble( &heightOk );
256 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"positionMode" ) ).toInt( &positionModeOk ) );
257 if ( !positionModeOk )
262 if ( pageOk && pagexOk && pageyOk )
281 return QRectF( x, y, width, height );
284 QPointF QgsCompositionConverter::minPointFromXml(
const QDomElement &elem )
286 double minX = std::numeric_limits<double>::max();
287 double minY = std::numeric_limits<double>::max();
288 const QDomNodeList composerItemList = elem.elementsByTagName( QStringLiteral(
"ComposerItem" ) );
289 for (
int i = 0; i < composerItemList.size(); ++i )
291 const QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
294 x = currentComposerItemElem.attribute( QStringLiteral(
"x" ) ).toDouble( &xOk );
295 y = currentComposerItemElem.attribute( QStringLiteral(
"y" ) ).toDouble( &yOk );
300 minX = std::min( minX, x );
301 minY = std::min( minY, y );
303 if ( minX < std::numeric_limits<double>::max() )
305 return QPointF( minX, minY );
309 return QPointF( 0, 0 );
316 initPropertyDefinitions();
318 QList< QgsLayoutObject * > newItems;
323 const int zOrderOffset = layout->mItemsModel->zOrderListSize();
325 QPointF pasteShiftPos;
332 const QPointF minItemPos = minPointFromXml( parentElement );
335 pasteShiftPos = *position - minItemPos;
338 pageNumber = layout->mPageCollection->pageNumberForPoint( *position );
345 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerMap" ) ).size(); i++ )
347 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerMap" ) ).at( i ) );
349 readMapXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
350 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
351 newItems << layoutItem ;
355 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerLabel" ) ).size(); i++ )
357 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerLabel" ) ).at( i ) );
359 readLabelXml( layoutItem, itemNode.toElement(), layout->
project() );
360 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
361 newItems << layoutItem ;
365 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerShape" ) ).size(); i++ )
367 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerShape" ) ).at( i ) );
369 readShapeXml( layoutItem, itemNode.toElement(), layout->
project() );
370 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
371 newItems << layoutItem ;
375 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPicture" ) ).size(); i++ )
377 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPicture" ) ).at( i ) );
379 readPictureXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
380 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
381 newItems << layoutItem ;
385 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPolygon" ) ).size(); i++ )
387 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPolygon" ) ).at( i ) );
389 readPolyXml<QgsLayoutItemPolygon, QgsFillSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
390 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
391 newItems << layoutItem ;
395 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPolyline" ) ).size(); i++ )
397 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPolyline" ) ).at( i ) );
399 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
400 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
401 newItems << layoutItem ;
405 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerArrow" ) ).size(); i++ )
407 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerArrow" ) ).at( i ) );
409 readArrowXml( layoutItem, itemNode.toElement(), layout->
project() );
410 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
411 newItems << layoutItem ;
415 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerScaleBar" ) ).size(); i++ )
417 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerScaleBar" ) ).at( i ) );
419 readScaleBarXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
420 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
421 newItems << layoutItem ;
425 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerLegend" ) ).size(); i++ )
427 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerLegend" ) ).at( i ) );
429 readLegendXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
430 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
431 newItems << layoutItem ;
435 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerHtml" ) ).size(); i++ )
437 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerHtml" ) ).at( i ) );
439 readHtmlXml( layoutItem, itemNode.toElement(), layout->
project() );
441 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
442 for (
const auto &frame : framesList )
444 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
446 newItems << layoutItem ;
450 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerAttributeTableV2" ) ).size(); i++ )
452 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerAttributeTableV2" ) ).at( i ) );
454 readTableXml( layoutItem, itemNode.toElement(), layout->
project() );
456 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
457 for (
const auto &frame : framesList )
459 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
461 newItems << layoutItem ;
465 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerItemGroup" ) ).size(); i++ )
467 const QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerItemGroup" ) ).at( i ) );
469 readGroupXml( layoutItem, itemNode.toElement(), layout->
project(), newItems );
470 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
471 newItems << layoutItem ;
479 return document.elementsByTagName( QStringLiteral(
"Composition" ) ).count() > 0;
488 if ( document.elementsByTagName( QStringLiteral(
"Composition" ) ).count( ) > 0 )
490 const QDomElement composerElem = document.elementsByTagName( QStringLiteral(
"Composition" ) ).at( 0 ).toElement( );
494 const QDomElement elem = layout->writeXml( doc, context );
495 doc.appendChild( elem );
503 if ( itemElem.isNull() )
508 restoreGeneralComposeItemProperties( layoutItem, itemElem );
511 layoutItem->
setText( itemElem.attribute( QStringLiteral(
"labelText" ) ) );
514 layoutItem->
setMode( itemElem.attribute( QStringLiteral(
"htmlState" ) ).toInt() == Qt::Checked ? QgsLayoutItemLabel::Mode::ModeHtml : QgsLayoutItemLabel::Mode::ModeFont );
517 bool marginXOk =
false;
518 bool marginYOk =
false;
519 double marginX = itemElem.attribute( QStringLiteral(
"marginX" ) ).toDouble( &marginXOk );
520 double marginY = itemElem.attribute( QStringLiteral(
"marginY" ) ).toDouble( &marginYOk );
521 if ( !marginXOk || !marginYOk )
524 const double margin = itemElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"1.0" ) ).toDouble();
532 layoutItem->
setHAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"halign" ) ).toInt() ) );
535 layoutItem->
setVAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"valign" ) ).toInt() ) );
543 if ( font.pointSizeF() > 0 )
545 format.
setSize( font.pointSizeF() );
548 else if ( font.pixelSize() > 0 )
550 format.
setSize( font.pixelSize() );
555 const QDomNodeList fontColorList = itemElem.elementsByTagName( QStringLiteral(
"FontColor" ) );
556 if ( !fontColorList.isEmpty() )
558 const QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
559 const int red = fontColorElem.attribute( QStringLiteral(
"red" ), QStringLiteral(
"0" ) ).toInt();
560 const int green = fontColorElem.attribute( QStringLiteral(
"green" ), QStringLiteral(
"0" ) ).toInt();
561 const int blue = fontColorElem.attribute( QStringLiteral(
"blue" ), QStringLiteral(
"0" ) ).toInt();
562 format.
setColor( QColor( red, green, blue ) );
566 format.
setColor( QColor( 0, 0, 0 ) );
579 restoreGeneralComposeItemProperties( layoutItem, itemElem );
585 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
587 const QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
588 const std::unique_ptr< QgsFillSymbol > shapeStyleSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context ) );
589 if ( shapeStyleSymbol )
590 layoutItem->
setSymbol( shapeStyleSymbol.get() );
595 QVariantMap properties;
599 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
603 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"no" ) );
607 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
611 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"no" ) );
614 properties.insert( QStringLiteral(
"width_border" ), QString::number( layoutItem->pen().widthF() ) );
617 const QDomNodeList outlineColorList = itemElem.elementsByTagName( QStringLiteral(
"OutlineColor" ) );
618 if ( !outlineColorList.isEmpty() )
620 const QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
621 bool redOk, greenOk, blueOk, alphaOk, widthOk;
622 int penRed, penGreen, penBlue, penAlpha;
625 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
626 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toInt( &redOk );
627 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toInt( &greenOk );
628 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toInt( &blueOk );
629 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toInt( &alphaOk );
631 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
634 properties.insert( QStringLiteral(
"width_border" ), QString::number( penWidth ) );
637 const QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"FillColor" ) );
638 if ( !fillColorList.isEmpty() )
640 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
641 bool redOk, greenOk, blueOk, alphaOk;
642 int fillRed, fillGreen, fillBlue, fillAlpha;
644 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toInt( &redOk );
645 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toInt( &greenOk );
646 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toInt( &blueOk );
647 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toInt( &alphaOk );
649 if ( redOk && greenOk && blueOk && alphaOk )
652 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
655 if ( itemElem.hasAttribute( QStringLiteral(
"transparentFill" ) ) )
658 const bool hasOldTransparentFill = itemElem.attribute( QStringLiteral(
"transparentFill" ), QStringLiteral(
"0" ) ).toInt();
659 if ( hasOldTransparentFill )
661 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"no" ) );
666 layoutItem->
setSymbol( shapeStyleSymbol.get() );
677 restoreGeneralComposeItemProperties( layoutItem, itemElem );
681 bool positionModeOk =
false;
682 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"positionMode" ) ).toInt( &positionModeOk ) );
683 if ( !positionModeOk )
685 layoutItem->mReferencePoint = QgsLayoutItem::ReferencePoint::UpperLeft;
687 bool anchorPointOk =
false;
690 if ( !anchorPointOk )
692 layoutItem->mPictureAnchor = QgsLayoutItem::ReferencePoint::UpperLeft;
696 layoutItem->mSvgStrokeWidth = itemElem.attribute( QStringLiteral(
"svgBorderWidth" ), QStringLiteral(
"0.2" ) ).toDouble();
698 QString imagePath = itemElem.attribute( QStringLiteral(
"file" ) );
703 if ( imagePath.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
706 imagePath = pathResolver.
readPath( imagePath );
709 layoutItem->mPictureHeight = itemElem.attribute( QStringLiteral(
"pictureHeight" ), QStringLiteral(
"10" ) ).toDouble();
710 layoutItem->mPictureWidth = itemElem.attribute( QStringLiteral(
"pictureWidth" ), QStringLiteral(
"10" ) ).toDouble();
713 if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral(
"pictureRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
715 layoutItem->mPictureRotation = itemElem.attribute( QStringLiteral(
"pictureRotation" ), QStringLiteral(
"0" ) ).toDouble();
720 layoutItem->mNorthArrowHandler->
setNorthOffset( itemElem.attribute( QStringLiteral(
"northOffset" ), QStringLiteral(
"0" ) ).toDouble() );
722 const QString rotationMapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
723 if ( rotationMapId != QLatin1String(
"-1" ) )
737 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemElem, project );
739 const QDomNodeList startPointList = itemElem.elementsByTagName( QStringLiteral(
"StartPoint" ) );
740 if ( ! startPointList.isEmpty() )
742 const QDomElement node = startPointList.at( 0 ).toElement();
743 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
745 const QDomNodeList stopPointList = itemElem.elementsByTagName( QStringLiteral(
"StopPoint" ) );
746 if ( ! stopPointList.isEmpty() )
748 const QDomElement node = stopPointList.at( 0 ).toElement();
749 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
754 if ( markerMode == QgsCompositionConverter::MarkerMode::DefaultMarker )
756 layoutItem->
setEndMarker( QgsLayoutItemPolyline::MarkerMode::ArrowHead );
757 layoutItem->
setStartMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
760 layoutItem->
setArrowHeadStrokeWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"1.0" ) ).toDouble( ) );
761 layoutItem->
setArrowHeadWidth( itemElem.attribute( QStringLiteral(
"arrowHeadWidth" ), QStringLiteral(
"1.0" ) ).toDouble( ) );
763 else if ( markerMode == QgsCompositionConverter::MarkerMode::SVGMarker )
765 QString endMarkerFile = itemElem.attribute( QStringLiteral(
"endMarkerFile" ) );
766 QString startMarkerFile = itemElem.attribute( QStringLiteral(
"endMarkerFile" ) );
773 if ( !endMarkerFile.isEmpty() )
775 if ( endMarkerFile.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
778 endMarkerFile = pathResolver.
readPath( endMarkerFile );
780 if ( !startMarkerFile.isEmpty() )
782 if ( startMarkerFile.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
785 startMarkerFile = pathResolver.
readPath( startMarkerFile );
788 if ( !endMarkerFile.isEmpty() )
790 layoutItem->
setEndMarker( QgsLayoutItemPolyline::MarkerMode::SvgMarker );
793 if ( !startMarkerFile.isEmpty() )
795 layoutItem->
setStartMarker( QgsLayoutItemPolyline::MarkerMode::SvgMarker );
801 layoutItem->
setEndMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
802 layoutItem->
setStartMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
805 const double margin = polygon.boundingRect().left() - layoutItem->pos().x();
806 polygon.translate( - polygon.boundingRect().left() + margin, - polygon.boundingRect().top() + margin );
814 restoreGeneralComposeItemProperties( layoutItem, itemElem );
816 mapId2Uuid[ itemElem.attribute( QStringLiteral(
"id" ) ) ] = layoutItem->
uuid();
819 const QDomDocument doc;
827 const QDomNodeList extentNodeList = itemElem.elementsByTagName( QStringLiteral(
"Extent" ) );
828 if ( !extentNodeList.isEmpty() )
830 const QDomElement extentElem = extentNodeList.at( 0 ).toElement();
831 double xmin, xmax, ymin, ymax;
832 xmin = extentElem.attribute( QStringLiteral(
"xmin" ) ).toDouble();
833 xmax = extentElem.attribute( QStringLiteral(
"xmax" ) ).toDouble();
834 ymin = extentElem.attribute( QStringLiteral(
"ymin" ) ).toDouble();
835 ymax = extentElem.attribute( QStringLiteral(
"ymax" ) ).toDouble();
839 const QDomNodeList crsNodeList = itemElem.elementsByTagName( QStringLiteral(
"crs" ) );
840 if ( !crsNodeList.isEmpty() )
842 const QDomElement crsElem = crsNodeList.at( 0 ).toElement();
851 if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
853 layoutItem->
setMapRotation( itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble() );
857 layoutItem->
setFollowVisibilityPreset( itemElem.attribute( QStringLiteral(
"followPreset" ) ).compare( QLatin1String(
"true" ) ) == 0 );
861 const QString keepLayerSetFlag = itemElem.attribute( QStringLiteral(
"keepLayerSet" ) );
862 if ( keepLayerSetFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
871 const QString drawCanvasItemsFlag = itemElem.attribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
872 if ( drawCanvasItemsFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
881 layoutItem->mLayerStyleOverrides.clear();
884 layoutItem->mLayers.clear();
886 const QDomNodeList layerSetNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerSet" ) );
887 if ( !layerSetNodeList.isEmpty() )
889 const QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
890 const QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
891 layoutItem->mLayers.reserve( layerIdNodeList.size() );
892 for (
int i = 0; i < layerIdNodeList.size(); ++i )
894 const QDomElement layerElem = layerIdNodeList.at( i ).toElement();
895 const QString layerId = layerElem.text();
896 const QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
897 const QString layerSource = layerElem.attribute( QStringLiteral(
"source" ) );
898 const QString layerProvider = layerElem.attribute( QStringLiteral(
"provider" ) );
900 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
901 ref.resolveWeakly( project );
902 layoutItem->mLayers << ref;
907 const QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerStyles" ) );
908 layoutItem->mKeepLayerStyles = !layerStylesNodeList.isEmpty();
909 if ( layoutItem->mKeepLayerStyles )
911 const QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
912 const QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( QStringLiteral(
"LayerStyle" ) );
913 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
915 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
916 const QString layerId = layerStyleElement.attribute( QStringLiteral(
"layerid" ) );
917 const QString layerName = layerStyleElement.attribute( QStringLiteral(
"name" ) );
918 const QString layerSource = layerStyleElement.attribute( QStringLiteral(
"source" ) );
919 const QString layerProvider = layerStyleElement.attribute( QStringLiteral(
"provider" ) );
920 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
921 ref.resolveWeakly( project );
924 style.
readXml( layerStyleElement );
925 layoutItem->mLayerStyleOverrides.insert( ref.layerId, style.
xmlData() );
929 layoutItem->mDrawing =
false;
930 layoutItem->mNumCachedLayers = 0;
931 layoutItem->mCacheInvalidated =
true;
935 const QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( QStringLiteral(
"ComposerMapOverview" ) );
936 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
938 const QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
939 std::unique_ptr<QgsLayoutItemMapOverview> mapOverview(
new QgsLayoutItemMapOverview( mapOverviewElem.attribute( QStringLiteral(
"name" ) ), layoutItem ) );
940 mapOverview->readXml( mapOverviewElem, doc, context );
941 const QString frameMapId = mapOverviewElem.attribute( QStringLiteral(
"frameMap" ), QStringLiteral(
"-1" ) );
942 if ( frameMapId != QLatin1String(
"-1" ) && mapId2Uuid.contains( frameMapId ) )
947 mapOverview->setLinkedMap( mapInstance );
949 layoutItem->mOverviewStack->addOverview( mapOverview.release() );
954 layoutItem->mGridStack->readXml( itemElem, doc, context );
959 const QDomNodeList gridNodeList = itemElem.elementsByTagName( QStringLiteral(
"Grid" ) );
960 if ( layoutItem->mGridStack->size() == 0 && !gridNodeList.isEmpty() )
962 const QDomElement gridElem = gridNodeList.at( 0 ).toElement();
964 mapGrid->
setEnabled( gridElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
966 mapGrid->
setIntervalX( gridElem.attribute( QStringLiteral(
"intervalX" ), QStringLiteral(
"0" ) ).toDouble() );
967 mapGrid->
setIntervalY( gridElem.attribute( QStringLiteral(
"intervalY" ), QStringLiteral(
"0" ) ).toDouble() );
968 mapGrid->
setOffsetX( gridElem.attribute( QStringLiteral(
"offsetX" ), QStringLiteral(
"0" ) ).toDouble() );
969 mapGrid->
setOffsetY( gridElem.attribute( QStringLiteral(
"offsetY" ), QStringLiteral(
"0" ) ).toDouble() );
970 mapGrid->
setCrossLength( gridElem.attribute( QStringLiteral(
"crossLength" ), QStringLiteral(
"3" ) ).toDouble() );
972 mapGrid->
setFrameWidth( gridElem.attribute( QStringLiteral(
"gridFrameWidth" ), QStringLiteral(
"2.0" ) ).toDouble() );
973 mapGrid->
setFramePenSize( gridElem.attribute( QStringLiteral(
"gridFramePenThickness" ), QStringLiteral(
"0.5" ) ).toDouble() );
978 const QDomElement gridSymbolElem = gridElem.firstChildElement( QStringLiteral(
"symbol" ) );
980 if ( gridSymbolElem.isNull() )
984 lineSymbol->
setWidth( gridElem.attribute( QStringLiteral(
"penWidth" ), QStringLiteral(
"0" ) ).toDouble() );
985 lineSymbol->
setColor( QColor( gridElem.attribute( QStringLiteral(
"penColorRed" ), QStringLiteral(
"0" ) ).toInt(),
986 gridElem.attribute( QStringLiteral(
"penColorGreen" ), QStringLiteral(
"0" ) ).toInt(),
987 gridElem.attribute( QStringLiteral(
"penColorBlue" ), QStringLiteral(
"0" ) ).toInt() ) );
991 lineSymbol = QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( gridSymbolElem, context );
996 const QDomNodeList annotationNodeList = gridElem.elementsByTagName( QStringLiteral(
"Annotation" ) );
997 if ( !annotationNodeList.isEmpty() )
999 const QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1000 mapGrid->
setAnnotationEnabled( annotationElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
1010 mapGrid->
setAnnotationFrameDistance( annotationElem.attribute( QStringLiteral(
"frameDistance" ), QStringLiteral(
"0" ) ).toDouble() );
1011 QFont annotationFont;
1012 annotationFont.fromString( annotationElem.attribute( QStringLiteral(
"font" ), QString() ) );
1015 annotationFormat.
setFont( annotationFont );
1016 if ( annotationFont.pointSizeF() > 0 )
1018 annotationFormat.
setSize( annotationFont.pointSizeF() );
1021 else if ( annotationFont.pixelSize() > 0 )
1023 annotationFormat.
setSize( annotationFont.pixelSize() );
1029 mapGrid->
setAnnotationPrecision( annotationElem.attribute( QStringLiteral(
"precision" ), QStringLiteral(
"3" ) ).toInt() );
1031 layoutItem->mGridStack->addGrid( mapGrid );
1035 const QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral(
"AtlasMap" ) );
1036 if ( !atlasNodeList.isEmpty() )
1038 const QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1039 layoutItem->mAtlasDriven = ( atlasElem.attribute( QStringLiteral(
"atlasDriven" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
1040 if ( atlasElem.hasAttribute( QStringLiteral(
"fixedScale" ) ) )
1042 layoutItem->
setAtlasScalingMode( atlasElem.attribute( QStringLiteral(
"fixedScale" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) ? QgsLayoutItemMap::AtlasScalingMode::Fixed : QgsLayoutItemMap::AtlasScalingMode::Auto );
1044 else if ( atlasElem.hasAttribute( QStringLiteral(
"scalingMode" ) ) )
1048 layoutItem->
setAtlasMargin( atlasElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"0.1" ) ).toDouble() );
1059 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1061 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1062 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1063 layoutItem->
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
1064 layoutItem->
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
1065 layoutItem->
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
1066 layoutItem->
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
1067 layoutItem->
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
1069 layoutItem->
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1070 layoutItem->
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
1071 layoutItem->mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
1072 layoutItem->
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
1073 layoutItem->
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
1078 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QString() ) );
1086 const QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
1087 if ( !fillColorList.isEmpty() )
1089 const QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1090 bool redOk, greenOk, blueOk, alphaOk;
1091 int fillRed, fillGreen, fillBlue, fillAlpha;
1093 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1094 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1095 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1096 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1098 if ( redOk && greenOk && blueOk && alphaOk )
1100 layoutItem->
fillSymbol()->
setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1105 layoutItem->
fillSymbol()->
setColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
1109 const QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
1110 if ( !fillColor2List.isEmpty() )
1112 const QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1113 bool redOk, greenOk, blueOk, alphaOk;
1114 int fillRed, fillGreen, fillBlue, fillAlpha;
1116 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1117 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1118 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1119 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1121 if ( redOk && greenOk && blueOk && alphaOk )
1128 layoutItem->
alternateFillSymbol()->
setColor( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
1131 std::unique_ptr< QgsLineSymbol > lineSymbol = std::make_unique< QgsLineSymbol >();
1132 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = std::make_unique< QgsSimpleLineSymbolLayer >();
1133 lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
1138 const QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
1139 if ( !strokeColorList.isEmpty() )
1141 const QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1142 bool redOk, greenOk, blueOk, alphaOk;
1143 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1145 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1146 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1147 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1148 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1150 if ( redOk && greenOk && blueOk && alphaOk )
1152 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1157 lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
1159 lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1165 const QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
1166 if ( !textColorList.isEmpty() )
1168 const QDomElement textColorElem = textColorList.at( 0 ).toElement();
1169 bool redOk, greenOk, blueOk, alphaOk;
1170 int textRed, textGreen, textBlue, textAlpha;
1172 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1173 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1174 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1175 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1177 if ( redOk && greenOk && blueOk && alphaOk )
1180 layoutItem->
setFontColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1187 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1194 const QString styleString = itemElem.attribute( QStringLiteral(
"style" ), QString() );
1195 layoutItem->
setStyle( QObject::tr( styleString.toLocal8Bit().data() ) );
1197 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
1200 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
1224 const QString mapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
1225 if ( mapId != QLatin1String(
"-1" ) && mapId2Uuid.contains( mapId ) )
1239 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1249 const QString mapId = itemElem.attribute( QStringLiteral(
"map" ), QStringLiteral(
"-1" ) );
1250 if ( mapId != QLatin1String(
"-1" ) && mapId2Uuid.contains( mapId ) )
1260 layoutItem->
setTitle( itemElem.attribute( QStringLiteral(
"title" ) ) );
1261 if ( !itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).isEmpty() )
1263 layoutItem->
setTitleAlignment(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).toInt() ) );
1265 int colCount = itemElem.attribute( QStringLiteral(
"columnCount" ), QStringLiteral(
"1" ) ).toInt();
1266 if ( colCount < 1 ) colCount = 1;
1268 layoutItem->
setSplitLayer( itemElem.attribute( QStringLiteral(
"splitLayer" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1269 layoutItem->
setEqualColumnWidth( itemElem.attribute( QStringLiteral(
"equalColumnWidth" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1271 const QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"styles" ) );
1272 if ( !stylesNodeList.isEmpty() )
1274 const QDomNode stylesNode = stylesNodeList.at( 0 );
1275 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
1277 const QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
1279 style.
readXml( styleElem, QDomDocument() );
1280 const QString name = styleElem.attribute( QStringLiteral(
"name" ) );
1294 fontClr.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1298 layoutItem->
setBoxSpace( itemElem.attribute( QStringLiteral(
"boxSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1299 layoutItem->
setColumnSpace( itemElem.attribute( QStringLiteral(
"columnSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1301 layoutItem->
setSymbolWidth( itemElem.attribute( QStringLiteral(
"symbolWidth" ), QStringLiteral(
"7.0" ) ).toDouble() );
1302 layoutItem->
setSymbolHeight( itemElem.attribute( QStringLiteral(
"symbolHeight" ), QStringLiteral(
"14.0" ) ).toDouble() );
1303 layoutItem->
setWmsLegendWidth( itemElem.attribute( QStringLiteral(
"wmsLegendWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1304 layoutItem->
setWmsLegendHeight( itemElem.attribute( QStringLiteral(
"wmsLegendHeight" ), QStringLiteral(
"25" ) ).toDouble() );
1305 layoutItem->
setLineSpacing( itemElem.attribute( QStringLiteral(
"lineSpacing" ), QStringLiteral(
"1.0" ) ).toDouble() );
1307 layoutItem->
setDrawRasterStroke( itemElem.attribute( QStringLiteral(
"rasterBorder" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
1309 layoutItem->
setRasterStrokeWidth( itemElem.attribute( QStringLiteral(
"rasterBorderWidth" ), QStringLiteral(
"0" ) ).toDouble() );
1311 layoutItem->
setWrapString( itemElem.attribute( QStringLiteral(
"wrapChar" ) ) );
1313 layoutItem->mSizeToContents = itemElem.attribute( QStringLiteral(
"resizeToContents" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" );
1314 layoutItem->mLegendFilterByMap = itemElem.attribute( QStringLiteral(
"legendFilterByMap" ), QStringLiteral(
"0" ) ).toInt();
1315 layoutItem->mFilterOutAtlas = itemElem.attribute( QStringLiteral(
"legendFilterByAtlas" ), QStringLiteral(
"0" ) ).toInt();
1318 QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree" ) );
1319 if ( layerTreeElem.isNull() )
1320 layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
1322 if ( !layerTreeElem.isNull() )
1326 tree->resolveReferences( project,
true );
1327 layoutItem->setCustomLayerTree( tree );
1331 layoutItem->setCustomLayerTree(
nullptr );
1337 bool QgsCompositionConverter::readAtlasXml(
QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project )
1339 atlasItem->
setEnabled( itemElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1342 const QString layerId = itemElem.attribute( QStringLiteral(
"coverageLayer" ) );
1343 const QString layerName = itemElem.attribute( QStringLiteral(
"coverageLayerName" ) );
1344 const QString layerSource = itemElem.attribute( QStringLiteral(
"coverageLayerSource" ) );
1345 const QString layerProvider = itemElem.attribute( QStringLiteral(
"coverageLayerProvider" ) );
1350 atlasItem->
setPageNameExpression( itemElem.attribute( QStringLiteral(
"pageNameExpression" ), QString() ) );
1351 QString errorString;
1352 atlasItem->
setFilenameExpression( itemElem.attribute( QStringLiteral(
"filenamePattern" ), QString() ), errorString );
1354 atlasItem->
setSortFeatures( itemElem.attribute( QStringLiteral(
"sortFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1357 atlasItem->
setSortExpression( itemElem.attribute( QStringLiteral(
"sortKey" ), QString() ) );
1358 atlasItem->
setSortAscending( itemElem.attribute( QStringLiteral(
"sortAscending" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1360 atlasItem->
setFilterFeatures( itemElem.attribute( QStringLiteral(
"filterFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1363 QString expErrorString;
1364 atlasItem->
setFilterExpression( itemElem.attribute( QStringLiteral(
"featureFilter" ), QString() ), expErrorString );
1368 atlasItem->
setHideCoverage( itemElem.attribute( QStringLiteral(
"hideCoverage" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1374 bool QgsCompositionConverter::readHtmlXml(
QgsLayoutItemHtml *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1377 readOldComposerObjectXml( layoutItem, itemElem );
1381 const QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1382 for (
int i = 0; i < frameList.size(); ++i )
1384 const QDomElement frameElem = frameList.at( i ).toElement();
1386 restoreGeneralComposeItemProperties( newFrame, frameElem );
1388 const double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1389 const double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1390 const double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1391 const double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1393 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1394 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1395 layoutItem->
addFrame( newFrame,
false );
1400 if ( !contentModeOK )
1402 layoutItem->
setContentMode( QgsLayoutItemHtml::ContentMode::Url );
1404 layoutItem->
setEvaluateExpressions( itemElem.attribute( QStringLiteral(
"evaluateExpressions" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1405 layoutItem->
setUseSmartBreaks( itemElem.attribute( QStringLiteral(
"useSmartBreaks" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1406 layoutItem->
setMaxBreakDistance( itemElem.attribute( QStringLiteral(
"maxBreakDistance" ), QStringLiteral(
"10" ) ).toDouble() );
1407 layoutItem->
setHtml( itemElem.attribute( QStringLiteral(
"html" ) ) );
1408 layoutItem->
setUserStylesheet( itemElem.attribute( QStringLiteral(
"stylesheet" ) ) );
1409 layoutItem->
setUserStylesheetEnabled( itemElem.attribute( QStringLiteral(
"stylesheetEnabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1412 const QString urlString = itemElem.attribute( QStringLiteral(
"url" ) );
1413 if ( !urlString.isEmpty() )
1415 layoutItem->
setUrl( urlString );
1426 readOldComposerObjectXml( layoutItem, itemElem );
1430 const QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1431 for (
int i = 0; i < frameList.size(); ++i )
1433 const QDomElement frameElem = frameList.at( i ).toElement();
1435 restoreGeneralComposeItemProperties( newFrame, frameElem );
1437 const double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1438 const double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1439 const double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1440 const double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1442 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1443 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1444 layoutItem->
addFrame( newFrame,
false );
1448 layoutItem->
setEmptyTableMessage( itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), QObject::tr(
"No matching records" ) ) );
1449 layoutItem->
setShowEmptyRows( itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt() );
1453 headerFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
1456 headerFormat.
setFont( headerFont );
1457 if ( headerFont.pointSizeF() > 0 )
1459 headerFormat.
setSize( headerFont.pointSizeF() );
1462 else if ( headerFont.pixelSize() > 0 )
1464 headerFormat.
setSize( headerFont.pixelSize() );
1475 contentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
1478 contentFormat.
setFont( contentFont );
1479 if ( contentFont.pointSizeF() > 0 )
1481 contentFormat.
setSize( contentFont.pointSizeF() );
1484 else if ( contentFont.pixelSize() > 0 )
1486 contentFormat.
setSize( contentFont.pixelSize() );
1492 layoutItem->
setCellMargin( itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble() );
1493 layoutItem->
setGridStrokeWidth( itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble() );
1494 layoutItem->
setHorizontalGrid( itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1495 layoutItem->
setVerticalGrid( itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1496 layoutItem->
setShowGrid( itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt() );
1505 const QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
1506 if ( !columnsList.isEmpty() )
1508 const QDomElement columnsElem = columnsList.at( 0 ).toElement();
1509 const QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
1510 for (
int i = 0; i < columnEntryList.size(); ++i )
1512 const QDomElement columnElem = columnEntryList.at( i ).toElement();
1514 column.mHAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
1515 column.mVAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
1516 column.mHeading = columnElem.attribute( QStringLiteral(
"heading" ), QString() );
1517 column.mAttribute = columnElem.attribute( QStringLiteral(
"attribute" ), QString() );
1518 column.mSortByRank = columnElem.attribute( QStringLiteral(
"sortByRank" ), QStringLiteral(
"0" ) ).toInt();
1519 column.mSortOrder =
static_cast< Qt::SortOrder
>( columnElem.attribute( QStringLiteral(
"sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
1520 column.mWidth = columnElem.attribute( QStringLiteral(
"width" ), QStringLiteral(
"0.0" ) ).toDouble();
1522 const QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral(
"backgroundColor" ) );
1523 if ( !bgColorList.isEmpty() )
1525 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1526 bool redOk, greenOk, blueOk, alphaOk;
1527 int bgRed, bgGreen, bgBlue, bgAlpha;
1528 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1529 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1530 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1531 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1532 if ( redOk && greenOk && blueOk && alphaOk )
1534 column.mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1537 layoutItem->
mColumns.append( column );
1549 const QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
1550 if ( !stylesList.isEmpty() )
1552 const QDomElement stylesElem = stylesList.at( 0 ).toElement();
1554 QMap< QgsLayoutTable::CellStyleGroup, QString >::const_iterator it = layoutItem->mCellStyleNames.constBegin();
1555 for ( ; it != layoutItem->mCellStyleNames.constEnd(); ++it )
1557 const QString styleName = it.value();
1558 const QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
1559 if ( !styleList.isEmpty() )
1561 const QDomElement styleElem = styleList.at( 0 ).toElement();
1570 const QString layerId = itemElem.attribute( QStringLiteral(
"vectorLayer" ) );
1571 const QString layerName = itemElem.attribute( QStringLiteral(
"vectorLayerName" ) );
1572 const QString layerSource = itemElem.attribute( QStringLiteral(
"vectorLayerSource" ) );
1573 const QString layerProvider = itemElem.attribute( QStringLiteral(
"vectorLayerProvider" ) );
1581 bool QgsCompositionConverter::readGroupXml(
QgsLayoutItemGroup *layoutItem,
const QDomElement &itemElem,
const QgsProject *project,
const QList< QgsLayoutObject * > &items )
1585 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1587 const QDomNodeList nodes = itemElem.elementsByTagName(
"ComposerItemGroupElement" );
1588 for (
int i = 0, n = nodes.size(); i < n; ++i )
1590 const QDomElement groupElement = nodes.at( i ).toElement();
1591 const QString elementUuid = groupElement.attribute(
"uuid" );
1606 template <
class T,
class T2>
1607 bool QgsCompositionConverter::readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1609 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1610 const QDomNodeList nodeList = itemElem.elementsByTagName( QStringLiteral(
"node" ) );
1611 if ( !nodeList.isEmpty() )
1614 for (
int i = 0; i < nodeList.length(); i++ )
1616 const QDomElement node = nodeList.at( i ).toElement();
1617 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
1619 layoutItem->setNodes( polygon );
1621 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
1623 const QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
1627 T2 *styleSymbol = QgsSymbolLayerUtils::loadSymbol<T2>( symbolElement, context );
1629 layoutItem->setSymbol( styleSymbol );
1632 layoutItem->setFrameEnabled(
false );
1633 layoutItem->setBackgroundEnabled(
false );
1638 bool QgsCompositionConverter::readXml(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
1640 if ( itemElem.isNull() )
1645 readOldComposerObjectXml( layoutItem, itemElem );
1648 layoutItem->mUuid = itemElem.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
1651 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1654 const QString
id = itemElem.attribute( QStringLiteral(
"id" ), QString() );
1655 layoutItem->
setId(
id );
1658 const QString frame = itemElem.attribute( QStringLiteral(
"frame" ) );
1659 layoutItem->
setFrameEnabled( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 ) ;
1662 const QString background = itemElem.attribute( QStringLiteral(
"background" ) );
1663 layoutItem->
setBackgroundEnabled( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1666 const QString positionLock = itemElem.attribute( QStringLiteral(
"positionLock" ) );
1667 layoutItem->
setLocked( positionLock.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1670 layoutItem->
setVisibility( itemElem.attribute( QStringLiteral(
"visibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
1672 layoutItem->mParentGroupUuid = itemElem.attribute( QStringLiteral(
"groupUuid" ) );
1673 if ( !layoutItem->mParentGroupUuid.isEmpty() )
1677 group->addItem( layoutItem );
1680 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1683 const QRectF position = itemPosition( layoutItem, itemElem );
1688 layoutItem->setZValue( itemElem.attribute( QStringLiteral(
"zValue" ) ).toDouble() );
1691 const QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral(
"FrameColor" ) );
1692 if ( !frameColorList.isEmpty() )
1694 const QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
1695 bool redOk, greenOk, blueOk, alphaOk, widthOk;
1696 int penRed, penGreen, penBlue, penAlpha;
1699 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
1700 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1701 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1702 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1703 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1706 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
1713 layoutItem->setPen( framePen );
1720 const QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
1721 if ( !bgColorList.isEmpty() )
1723 const QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1724 bool redOk, greenOk, blueOk, alphaOk;
1725 int bgRed, bgGreen, bgBlue, bgAlpha;
1726 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1727 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1728 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1729 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1730 if ( redOk && greenOk && blueOk && alphaOk )
1732 layoutItem->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1733 layoutItem->setBrush( QBrush( layoutItem->mBackgroundColor, Qt::SolidPattern ) );
1743 if ( itemElem.hasAttribute( QStringLiteral(
"opacity" ) ) )
1745 layoutItem->
setItemOpacity( itemElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
1749 layoutItem->
setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
1752 layoutItem->mExcludeFromExports = itemElem.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
1753 layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
1758 layoutItem->
setItemRotation( itemElem.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble(),
false );
1760 layoutItem->mBlockUndoCommands =
false;
1767 bool QgsCompositionConverter::readOldComposerObjectXml(
QgsLayoutObject *layoutItem,
1768 const QDomElement &itemElem )
1770 if ( itemElem.isNull() )
1778 const QDomNode propsNode = itemElem.namedItem( QStringLiteral(
"dataDefinedProperties" ) );
1779 if ( !propsNode.isNull() )
1787 exp = QStringLiteral(
"100.0 - (%1)" ).arg( exp );
1799 void QgsCompositionConverter::readOldDataDefinedPropertyMap(
const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties )
1802 QgsPropertiesDefinition::const_iterator i = defs.constBegin();
1803 for ( ; i != defs.constEnd(); ++i )
1805 const QString elemName = i.value().name();
1806 const QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
1807 if ( !ddNodeList.isEmpty() )
1809 const QDomElement ddElem = ddNodeList.at( 0 ).toElement();
1812 dataDefinedProperties.
setProperty( i.key(), prop );
1825 const QString active = ddElem.attribute( QStringLiteral(
"active" ) );
1826 bool isActive =
false;
1827 if ( active.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1831 const QString
field = ddElem.attribute( QStringLiteral(
"field" ) );
1832 const QString expr = ddElem.attribute( QStringLiteral(
"expr" ) );
1834 const QString useExpr = ddElem.attribute( QStringLiteral(
"useExpr" ) );
1835 bool isExpression =
false;
1836 if ( useExpr.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1838 isExpression =
true;