61 void QgsCompositionConverter::initPropertyDefinitions()
63 if ( !sPropertyDefinitions.isEmpty() )
71 "|<b>B5</b>|<b>B4</b>|<b>B3</b>|<b>B2</b>|<b>B1</b>|<b>B0</b>"
72 "|<b>Legal</b>|<b>Ansi A</b>|<b>Ansi B</b>|<b>Ansi C</b>|<b>Ansi D</b>|<b>Ansi E</b>"
73 "|<b>Arch A</b>|<b>Arch B</b>|<b>Arch C</b>|<b>Arch D</b>|<b>Arch E</b>|<b>Arch E1</b>]"
117 QgsCompositionConverter::initPropertyDefinitions();
118 return sPropertyDefinitions;
124 initPropertyDefinitions();
126 QDomElement parentElement = composerElement.parentNode().toElement();
128 std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( project );
129 layout->undoStack()->blockCommands(
true );
131 layout->mCustomProperties.readXml( composerElement );
134 layout->guides().setVisible( composerElement.attribute( QStringLiteral(
"guidesVisible" ), QStringLiteral(
"1" ) ).toInt() != 0 );
136 int printResolution = composerElement.attribute( QStringLiteral(
"printResolution" ), QStringLiteral(
"300" ) ).toInt();
137 layout->renderContext().setDpi( printResolution );
140 int pages = composerElement.attribute( QStringLiteral(
"numPages" ) ).toInt( );
141 float paperHeight = composerElement.attribute( QStringLiteral(
"paperHeight" ) ).toDouble( );
142 float paperWidth = composerElement.attribute( QStringLiteral(
"paperWidth" ) ).toDouble( );
144 QString name = composerElement.attribute( QStringLiteral(
"name" ) );
146 if ( name.isEmpty() )
147 name = composerElement.attribute( QStringLiteral(
"title" ) );
149 if ( name.isEmpty() )
150 name = parentElement.attribute( QStringLiteral(
"title" ) );
151 layout->setName( name );
153 for (
int j = 0; j < pages; j++ )
157 layout->pageCollection()->addPage( page );
159 QDomNodeList snapLineNodes = composerElement.elementsByTagName( QStringLiteral(
"SnapLine" ) );
160 for (
int i = 0; i < snapLineNodes.size(); ++i )
162 QDomElement snapLineElem = snapLineNodes.at( i ).toElement();
163 double x1 = snapLineElem.attribute( QStringLiteral(
"x1" ) ).toDouble();
164 double y1 = snapLineElem.attribute( QStringLiteral(
"y1" ) ).toDouble();
165 double x2 = snapLineElem.attribute( QStringLiteral(
"x2" ) ).toDouble();
167 Qt::Orientation orientation( x1 == x2 ? Qt::Orientation::Vertical : Qt::Orientation::Horizontal );
169 std::unique_ptr< QgsLayoutGuide > guide = qgis::make_unique< QgsLayoutGuide >( orientation, position, page );
170 layout->guides().addGuide( guide.release() );
175 if ( composerElement.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
177 QDomElement symbolElement = composerElement.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
181 std::unique_ptr< QgsFillSymbol > symbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context ) );
183 layout->pageCollection()->setPageStyleSymbol( symbol.get() );
189 if ( parentElement.elementsByTagName( QStringLiteral(
"Atlas" ) ).size() )
191 QDomElement atlasElement = parentElement.elementsByTagName( QStringLiteral(
"Atlas" ) ).at( 0 ).toElement();
192 readAtlasXml( layout->atlas(), atlasElement, layout->project() );
195 layout->undoStack()->blockCommands(
false );
200 void QgsCompositionConverter::adjustPos(
QgsPrintLayout *layout,
QgsLayoutItem *layoutItem, QPointF *position,
bool &pasteInPlace,
int zOrderOffset, QPointF &pasteShiftPos,
int &pageNumber )
210 layoutItem->
attemptMoveBy( pasteShiftPos.x(), pasteShiftPos.y() );
214 if ( !layoutItem->scene() )
216 layoutItem->setZValue( layoutItem->zValue() + zOrderOffset );
219 void QgsCompositionConverter::restoreGeneralComposeItemProperties(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
222 QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral(
"ComposerItem" ) );
223 if ( !composerItemList.isEmpty() )
225 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
228 if ( !
qgsDoubleNear( composerItemElem.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
231 layoutItem->
setItemRotation( composerItemElem.attribute( QStringLiteral(
"rotation" ), QStringLiteral(
"0" ) ).toDouble(),
false );
233 QgsCompositionConverter::readXml( layoutItem, composerItemElem );
237 QRectF QgsCompositionConverter::itemPosition(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
240 double x, y, pagex, pagey, width, height;
241 bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOk;
243 x = itemElem.attribute( QStringLiteral(
"x" ) ).toDouble( &xOk );
244 y = itemElem.attribute( QStringLiteral(
"y" ) ).toDouble( &yOk );
245 page = itemElem.attribute( QStringLiteral(
"page" ) ).toInt( &pageOk );
246 pagex = itemElem.attribute( QStringLiteral(
"pagex" ) ).toDouble( &pagexOk );
247 pagey = itemElem.attribute( QStringLiteral(
"pagey" ) ).toDouble( &pageyOk );
248 width = itemElem.attribute( QStringLiteral(
"width" ) ).toDouble( &widthOk );
249 height = itemElem.attribute( QStringLiteral(
"height" ) ).toDouble( &heightOk );
252 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"positionMode" ) ).toInt( &positionModeOk ) );
253 if ( !positionModeOk )
258 if ( pageOk && pagexOk && pageyOk )
277 return QRectF( x, y, width, height );
280 QPointF QgsCompositionConverter::minPointFromXml(
const QDomElement &elem )
282 double minX = std::numeric_limits<double>::max();
283 double minY = std::numeric_limits<double>::max();
284 QDomNodeList composerItemList = elem.elementsByTagName( QStringLiteral(
"ComposerItem" ) );
285 for (
int i = 0; i < composerItemList.size(); ++i )
287 QDomElement currentComposerItemElem = composerItemList.at( i ).toElement();
290 x = currentComposerItemElem.attribute( QStringLiteral(
"x" ) ).toDouble( &xOk );
291 y = currentComposerItemElem.attribute( QStringLiteral(
"y" ) ).toDouble( &yOk );
296 minX = std::min( minX, x );
297 minY = std::min( minY, y );
299 if ( minX < std::numeric_limits<double>::max() )
301 return QPointF( minX, minY );
305 return QPointF( 0, 0 );
312 initPropertyDefinitions();
314 QList< QgsLayoutObject * > newItems;
319 int zOrderOffset = layout->mItemsModel->zOrderListSize();
321 QPointF pasteShiftPos;
328 QPointF minItemPos = minPointFromXml( parentElement );
331 pasteShiftPos = *position - minItemPos;
334 pageNumber = layout->mPageCollection->pageNumberForPoint( *position );
341 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerMap" ) ).size(); i++ )
343 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerMap" ) ).at( i ) );
345 readMapXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
346 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
347 newItems << layoutItem ;
351 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerLabel" ) ).size(); i++ )
353 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerLabel" ) ).at( i ) );
355 readLabelXml( layoutItem, itemNode.toElement(), layout->
project() );
356 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
357 newItems << layoutItem ;
361 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerShape" ) ).size(); i++ )
363 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerShape" ) ).at( i ) );
365 readShapeXml( layoutItem, itemNode.toElement(), layout->
project() );
366 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
367 newItems << layoutItem ;
371 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPicture" ) ).size(); i++ )
373 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPicture" ) ).at( i ) );
375 readPictureXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
376 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
377 newItems << layoutItem ;
381 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPolygon" ) ).size(); i++ )
383 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPolygon" ) ).at( i ) );
385 readPolyXml<QgsLayoutItemPolygon, QgsFillSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
386 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
387 newItems << layoutItem ;
391 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerPolyline" ) ).size(); i++ )
393 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerPolyline" ) ).at( i ) );
395 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemNode.toElement(), layout->
project() );
396 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
397 newItems << layoutItem ;
401 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerArrow" ) ).size(); i++ )
403 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerArrow" ) ).at( i ) );
405 readArrowXml( layoutItem, itemNode.toElement(), layout->
project() );
406 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
407 newItems << layoutItem ;
411 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerScaleBar" ) ).size(); i++ )
413 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerScaleBar" ) ).at( i ) );
415 readScaleBarXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
416 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
417 newItems << layoutItem ;
421 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerLegend" ) ).size(); i++ )
423 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerLegend" ) ).at( i ) );
425 readLegendXml( layoutItem, itemNode.toElement(), layout->
project(), mapIdUiidMap );
426 adjustPos( layout, layoutItem, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
427 newItems << layoutItem ;
431 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerHtml" ) ).size(); i++ )
433 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerHtml" ) ).at( i ) );
435 readHtmlXml( layoutItem, itemNode.toElement(), layout->
project() );
437 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
438 for (
const auto &frame : framesList )
440 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
442 newItems << layoutItem ;
446 for (
int i = 0; i < parentElement.elementsByTagName( QStringLiteral(
"ComposerAttributeTableV2" ) ).size(); i++ )
448 QDomNode itemNode( parentElement.elementsByTagName( QStringLiteral(
"ComposerAttributeTableV2" ) ).at( i ) );
450 readTableXml( layoutItem, itemNode.toElement(), layout->
project() );
452 const QList<QgsLayoutFrame *> framesList( layoutItem->
frames() );
453 for (
const auto &frame : framesList )
455 adjustPos( layout, frame, position, pasteInPlace, zOrderOffset, pasteShiftPos, pageNumber );
457 newItems << layoutItem ;
465 return document.elementsByTagName( QStringLiteral(
"Composition" ) ).count() > 0;
474 if ( document.elementsByTagName( QStringLiteral(
"Composition" ) ).count( ) > 0 )
476 QDomElement composerElem = document.elementsByTagName( QStringLiteral(
"Composition" ) ).at( 0 ).toElement( );
480 QDomElement elem = layout->writeXml( doc, context );
481 doc.appendChild( elem );
489 if ( itemElem.isNull() )
494 restoreGeneralComposeItemProperties( layoutItem, itemElem );
497 layoutItem->
setText( itemElem.attribute( QStringLiteral(
"labelText" ) ) );
500 layoutItem->
setMode( itemElem.attribute( QStringLiteral(
"htmlState" ) ).toInt() == Qt::Checked ? QgsLayoutItemLabel::Mode::ModeHtml : QgsLayoutItemLabel::Mode::ModeFont );
503 bool marginXOk =
false;
504 bool marginYOk =
false;
505 double marginX = itemElem.attribute( QStringLiteral(
"marginX" ) ).toDouble( &marginXOk );
506 double marginY = itemElem.attribute( QStringLiteral(
"marginY" ) ).toDouble( &marginYOk );
507 if ( !marginXOk || !marginYOk )
510 double margin = itemElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"1.0" ) ).toDouble();
518 layoutItem->
setHAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"halign" ) ).toInt() ) );
521 layoutItem->
setVAlign(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"valign" ) ).toInt() ) );
530 QDomNodeList fontColorList = itemElem.elementsByTagName( QStringLiteral(
"FontColor" ) );
531 if ( !fontColorList.isEmpty() )
533 QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
534 int red = fontColorElem.attribute( QStringLiteral(
"red" ), QStringLiteral(
"0" ) ).toInt();
535 int green = fontColorElem.attribute( QStringLiteral(
"green" ), QStringLiteral(
"0" ) ).toInt();
536 int blue = fontColorElem.attribute( QStringLiteral(
"blue" ), QStringLiteral(
"0" ) ).toInt();
553 restoreGeneralComposeItemProperties( layoutItem, itemElem );
559 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
561 QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
562 std::unique_ptr< QgsFillSymbol > shapeStyleSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElement, context ) );
563 if ( shapeStyleSymbol )
564 layoutItem->
setSymbol( shapeStyleSymbol.get() );
573 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
577 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"no" ) );
581 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
585 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"no" ) );
588 properties.insert( QStringLiteral(
"width_border" ), QString::number( layoutItem->pen().widthF() ) );
591 QDomNodeList outlineColorList = itemElem.elementsByTagName( QStringLiteral(
"OutlineColor" ) );
592 if ( !outlineColorList.isEmpty() )
594 QDomElement frameColorElem = outlineColorList.at( 0 ).toElement();
595 bool redOk, greenOk, blueOk, alphaOk, widthOk;
596 int penRed, penGreen, penBlue, penAlpha;
599 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
600 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toInt( &redOk );
601 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toInt( &greenOk );
602 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toInt( &blueOk );
603 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toInt( &alphaOk );
605 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
608 properties.insert( QStringLiteral(
"width_border" ), QString::number( penWidth ) );
611 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"FillColor" ) );
612 if ( !fillColorList.isEmpty() )
614 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
615 bool redOk, greenOk, blueOk, alphaOk;
616 int fillRed, fillGreen, fillBlue, fillAlpha;
618 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toInt( &redOk );
619 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toInt( &greenOk );
620 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toInt( &blueOk );
621 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toInt( &alphaOk );
623 if ( redOk && greenOk && blueOk && alphaOk )
626 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
629 if ( itemElem.hasAttribute( QStringLiteral(
"transparentFill" ) ) )
632 bool hasOldTransparentFill = itemElem.attribute( QStringLiteral(
"transparentFill" ), QStringLiteral(
"0" ) ).toInt();
633 if ( hasOldTransparentFill )
635 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"no" ) );
640 layoutItem->
setSymbol( shapeStyleSymbol.get() );
651 restoreGeneralComposeItemProperties( layoutItem, itemElem );
655 bool positionModeOk =
false;
656 layoutItem->mReferencePoint =
static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral(
"positionMode" ) ).toInt( &positionModeOk ) );
657 if ( !positionModeOk )
659 layoutItem->mReferencePoint = QgsLayoutItem::ReferencePoint::UpperLeft;
661 bool anchorPointOk =
false;
664 if ( !anchorPointOk )
666 layoutItem->mPictureAnchor = QgsLayoutItem::ReferencePoint::UpperLeft;
670 layoutItem->mSvgStrokeWidth = itemElem.attribute( QStringLiteral(
"svgBorderWidth" ), QStringLiteral(
"0.2" ) ).toDouble();
672 QString imagePath = itemElem.attribute( QStringLiteral(
"file" ) );
677 if ( imagePath.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
680 imagePath = pathResolver.
readPath( imagePath );
683 layoutItem->mPictureHeight = itemElem.attribute( QStringLiteral(
"pictureHeight" ), QStringLiteral(
"10" ) ).toDouble();
684 layoutItem->mPictureWidth = itemElem.attribute( QStringLiteral(
"pictureWidth" ), QStringLiteral(
"10" ) ).toDouble();
687 if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral(
"pictureRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
689 layoutItem->mPictureRotation = itemElem.attribute( QStringLiteral(
"pictureRotation" ), QStringLiteral(
"0" ) ).toDouble();
694 layoutItem->mNorthArrowHandler->
setNorthOffset( itemElem.attribute( QStringLiteral(
"northOffset" ), QStringLiteral(
"0" ) ).toDouble() );
696 QString rotationMapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
697 if ( rotationMapId != QLatin1String(
"-1" ) )
711 readPolyXml<QgsLayoutItemPolyline, QgsLineSymbol>( layoutItem, itemElem, project );
713 QDomNodeList startPointList = itemElem.elementsByTagName( QStringLiteral(
"StartPoint" ) );
714 if ( ! startPointList.isEmpty() )
716 QDomElement node = startPointList.at( 0 ).toElement();
717 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
719 QDomNodeList stopPointList = itemElem.elementsByTagName( QStringLiteral(
"StopPoint" ) );
720 if ( ! stopPointList.isEmpty() )
722 QDomElement node = stopPointList.at( 0 ).toElement();
723 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
728 if ( markerMode == QgsCompositionConverter::MarkerMode::DefaultMarker )
730 layoutItem->
setEndMarker( QgsLayoutItemPolyline::MarkerMode::ArrowHead );
731 layoutItem->
setStartMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
734 layoutItem->
setArrowHeadStrokeWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"1.0" ) ).toDouble( ) );
735 layoutItem->
setArrowHeadWidth( itemElem.attribute( QStringLiteral(
"arrowHeadWidth" ), QStringLiteral(
"1.0" ) ).toDouble( ) );
737 else if ( markerMode == QgsCompositionConverter::MarkerMode::SVGMarker )
739 QString endMarkerFile = itemElem.attribute( QStringLiteral(
"endMarkerFile" ) );
740 QString startMarkerFile = itemElem.attribute( QStringLiteral(
"endMarkerFile" ) );
747 if ( !endMarkerFile.isEmpty() )
749 if ( endMarkerFile.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
752 endMarkerFile = pathResolver.
readPath( endMarkerFile );
754 if ( !startMarkerFile.isEmpty() )
756 if ( startMarkerFile.endsWith( QLatin1String(
".svg" ), Qt::CaseInsensitive ) )
759 startMarkerFile = pathResolver.
readPath( startMarkerFile );
762 if ( !endMarkerFile.isEmpty() )
764 layoutItem->
setEndMarker( QgsLayoutItemPolyline::MarkerMode::SvgMarker );
767 if ( !startMarkerFile.isEmpty() )
769 layoutItem->
setStartMarker( QgsLayoutItemPolyline::MarkerMode::SvgMarker );
775 layoutItem->
setEndMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
776 layoutItem->
setStartMarker( QgsLayoutItemPolyline::MarkerMode::NoMarker );
779 double margin = polygon.boundingRect().left() - layoutItem->pos().x();
780 polygon.translate( - polygon.boundingRect().left() + margin, - polygon.boundingRect().top() + margin );
788 restoreGeneralComposeItemProperties( layoutItem, itemElem );
790 mapId2Uuid[ itemElem.attribute( QStringLiteral(
"id" ) ) ] = layoutItem->
uuid();
801 QDomNodeList extentNodeList = itemElem.elementsByTagName( QStringLiteral(
"Extent" ) );
802 if ( !extentNodeList.isEmpty() )
804 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
805 double xmin, xmax, ymin, ymax;
806 xmin = extentElem.attribute( QStringLiteral(
"xmin" ) ).toDouble();
807 xmax = extentElem.attribute( QStringLiteral(
"xmax" ) ).toDouble();
808 ymin = extentElem.attribute( QStringLiteral(
"ymin" ) ).toDouble();
809 ymax = extentElem.attribute( QStringLiteral(
"ymax" ) ).toDouble();
813 QDomNodeList crsNodeList = itemElem.elementsByTagName( QStringLiteral(
"crs" ) );
814 if ( !crsNodeList.isEmpty() )
816 QDomElement crsElem = crsNodeList.at( 0 ).toElement();
825 if ( !
qgsDoubleNear( itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble(), 0.0 ) )
827 layoutItem->
setMapRotation( itemElem.attribute( QStringLiteral(
"mapRotation" ), QStringLiteral(
"0" ) ).toDouble() );
831 layoutItem->
setFollowVisibilityPreset( itemElem.attribute( QStringLiteral(
"followPreset" ) ).compare( QLatin1String(
"true" ) ) == 0 );
835 QString keepLayerSetFlag = itemElem.attribute( QStringLiteral(
"keepLayerSet" ) );
836 if ( keepLayerSetFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
845 QString drawCanvasItemsFlag = itemElem.attribute( QStringLiteral(
"drawCanvasItems" ), QStringLiteral(
"true" ) );
846 if ( drawCanvasItemsFlag.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
855 layoutItem->mLayerStyleOverrides.clear();
858 layoutItem->mLayers.clear();
860 QDomNodeList layerSetNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerSet" ) );
861 if ( !layerSetNodeList.isEmpty() )
863 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
864 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( QStringLiteral(
"Layer" ) );
865 layoutItem->mLayers.reserve( layerIdNodeList.size() );
866 for (
int i = 0; i < layerIdNodeList.size(); ++i )
868 QDomElement layerElem = layerIdNodeList.at( i ).toElement();
869 QString layerId = layerElem.text();
870 QString layerName = layerElem.attribute( QStringLiteral(
"name" ) );
871 QString layerSource = layerElem.attribute( QStringLiteral(
"source" ) );
872 QString layerProvider = layerElem.attribute( QStringLiteral(
"provider" ) );
874 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
875 ref.resolveWeakly( project );
876 layoutItem->mLayers << ref;
881 QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"LayerStyles" ) );
882 layoutItem->mKeepLayerStyles = !layerStylesNodeList.isEmpty();
883 if ( layoutItem->mKeepLayerStyles )
885 QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
886 QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( QStringLiteral(
"LayerStyle" ) );
887 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
889 const QDomElement &layerStyleElement = layerStyleNodeList.at( i ).toElement();
890 QString layerId = layerStyleElement.attribute( QStringLiteral(
"layerid" ) );
891 QString layerName = layerStyleElement.attribute( QStringLiteral(
"name" ) );
892 QString layerSource = layerStyleElement.attribute( QStringLiteral(
"source" ) );
893 QString layerProvider = layerStyleElement.attribute( QStringLiteral(
"provider" ) );
894 QgsMapLayerRef ref( layerId, layerName, layerSource, layerProvider );
895 ref.resolveWeakly( project );
898 style.
readXml( layerStyleElement );
899 layoutItem->mLayerStyleOverrides.insert( ref.layerId, style.
xmlData() );
903 layoutItem->mDrawing =
false;
904 layoutItem->mNumCachedLayers = 0;
905 layoutItem->mCacheInvalidated =
true;
909 QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( QStringLiteral(
"ComposerMapOverview" ) );
910 for (
int i = 0; i < mapOverviewNodeList.size(); ++i )
912 QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
913 std::unique_ptr<QgsLayoutItemMapOverview> mapOverview(
new QgsLayoutItemMapOverview( mapOverviewElem.attribute( QStringLiteral(
"name" ) ), layoutItem ) );
914 mapOverview->readXml( mapOverviewElem, doc, context );
915 QString frameMapId = mapOverviewElem.attribute( QStringLiteral(
"frameMap" ), QStringLiteral(
"-1" ) );
916 if ( frameMapId != QLatin1String(
"-1" ) && mapId2Uuid.contains( frameMapId ) )
921 mapOverview->setLinkedMap( mapInstance );
923 layoutItem->mOverviewStack->addOverview( mapOverview.release() );
928 layoutItem->mGridStack->readXml( itemElem, doc, context );
933 QDomNodeList gridNodeList = itemElem.elementsByTagName( QStringLiteral(
"Grid" ) );
934 if ( layoutItem->mGridStack->size() == 0 && !gridNodeList.isEmpty() )
936 QDomElement gridElem = gridNodeList.at( 0 ).toElement();
938 mapGrid->
setEnabled( gridElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
940 mapGrid->
setIntervalX( gridElem.attribute( QStringLiteral(
"intervalX" ), QStringLiteral(
"0" ) ).toDouble() );
941 mapGrid->
setIntervalY( gridElem.attribute( QStringLiteral(
"intervalY" ), QStringLiteral(
"0" ) ).toDouble() );
942 mapGrid->
setOffsetX( gridElem.attribute( QStringLiteral(
"offsetX" ), QStringLiteral(
"0" ) ).toDouble() );
943 mapGrid->
setOffsetY( gridElem.attribute( QStringLiteral(
"offsetY" ), QStringLiteral(
"0" ) ).toDouble() );
944 mapGrid->
setCrossLength( gridElem.attribute( QStringLiteral(
"crossLength" ), QStringLiteral(
"3" ) ).toDouble() );
946 mapGrid->
setFrameWidth( gridElem.attribute( QStringLiteral(
"gridFrameWidth" ), QStringLiteral(
"2.0" ) ).toDouble() );
947 mapGrid->
setFramePenSize( gridElem.attribute( QStringLiteral(
"gridFramePenThickness" ), QStringLiteral(
"0.5" ) ).toDouble() );
952 QDomElement gridSymbolElem = gridElem.firstChildElement( QStringLiteral(
"symbol" ) );
954 if ( gridSymbolElem.isNull() )
958 lineSymbol->
setWidth( gridElem.attribute( QStringLiteral(
"penWidth" ), QStringLiteral(
"0" ) ).toDouble() );
959 lineSymbol->
setColor( QColor( gridElem.attribute( QStringLiteral(
"penColorRed" ), QStringLiteral(
"0" ) ).toInt(),
960 gridElem.attribute( QStringLiteral(
"penColorGreen" ), QStringLiteral(
"0" ) ).toInt(),
961 gridElem.attribute( QStringLiteral(
"penColorBlue" ), QStringLiteral(
"0" ) ).toInt() ) );
965 lineSymbol = QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( gridSymbolElem, context );
970 QDomNodeList annotationNodeList = gridElem.elementsByTagName( QStringLiteral(
"Annotation" ) );
971 if ( !annotationNodeList.isEmpty() )
973 QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
974 mapGrid->
setAnnotationEnabled( annotationElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
984 mapGrid->
setAnnotationFrameDistance( annotationElem.attribute( QStringLiteral(
"frameDistance" ), QStringLiteral(
"0" ) ).toDouble() );
985 QFont annotationFont;
986 annotationFont.fromString( annotationElem.attribute( QStringLiteral(
"font" ), QString() ) );
989 annotationFormat.
setFont( annotationFont );
990 if ( annotationFont.pointSizeF() > 0 )
992 annotationFormat.
setSize( annotationFont.pointSizeF() );
995 else if ( annotationFont.pixelSize() > 0 )
997 annotationFormat.
setSize( annotationFont.pixelSize() );
1003 mapGrid->
setAnnotationPrecision( annotationElem.attribute( QStringLiteral(
"precision" ), QStringLiteral(
"3" ) ).toInt() );
1005 layoutItem->mGridStack->addGrid( mapGrid );
1009 QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral(
"AtlasMap" ) );
1010 if ( !atlasNodeList.isEmpty() )
1012 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1013 layoutItem->mAtlasDriven = ( atlasElem.attribute( QStringLiteral(
"atlasDriven" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
1014 if ( atlasElem.hasAttribute( QStringLiteral(
"fixedScale" ) ) )
1016 layoutItem->
setAtlasScalingMode( atlasElem.attribute( QStringLiteral(
"fixedScale" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) ? QgsLayoutItemMap::AtlasScalingMode::Fixed : QgsLayoutItemMap::AtlasScalingMode::Auto );
1018 else if ( atlasElem.hasAttribute( QStringLiteral(
"scalingMode" ) ) )
1022 layoutItem->
setAtlasMargin( atlasElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"0.1" ) ).toDouble() );
1033 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1035 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1036 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1037 layoutItem->
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
1038 layoutItem->
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
1039 layoutItem->
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
1040 layoutItem->
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
1041 layoutItem->
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
1043 layoutItem->
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1044 layoutItem->
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
1045 layoutItem->mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
1046 layoutItem->
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
1047 layoutItem->
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
1052 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QString() ) );
1060 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
1061 if ( !fillColorList.isEmpty() )
1063 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1064 bool redOk, greenOk, blueOk, alphaOk;
1065 int fillRed, fillGreen, fillBlue, fillAlpha;
1067 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1068 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1069 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1070 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1072 if ( redOk && greenOk && blueOk && alphaOk )
1074 layoutItem->
fillSymbol()->
setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1079 layoutItem->
fillSymbol()->
setColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
1083 QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
1084 if ( !fillColor2List.isEmpty() )
1086 QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1087 bool redOk, greenOk, blueOk, alphaOk;
1088 int fillRed, fillGreen, fillBlue, fillAlpha;
1090 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1091 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1092 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1093 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1095 if ( redOk && greenOk && blueOk && alphaOk )
1102 layoutItem->
alternateFillSymbol()->
setColor( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
1105 std::unique_ptr< QgsLineSymbol > lineSymbol = qgis::make_unique< QgsLineSymbol >();
1106 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = qgis::make_unique< QgsSimpleLineSymbolLayer >();
1107 lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
1112 QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
1113 if ( !strokeColorList.isEmpty() )
1115 QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1116 bool redOk, greenOk, blueOk, alphaOk;
1117 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1119 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1120 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1121 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1122 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1124 if ( redOk && greenOk && blueOk && alphaOk )
1126 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1131 lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
1133 lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1139 QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
1140 if ( !textColorList.isEmpty() )
1142 QDomElement textColorElem = textColorList.at( 0 ).toElement();
1143 bool redOk, greenOk, blueOk, alphaOk;
1144 int textRed, textGreen, textBlue, textAlpha;
1146 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1147 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1148 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1149 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1151 if ( redOk && greenOk && blueOk && alphaOk )
1154 layoutItem->
setFontColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1161 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1168 QString styleString = itemElem.attribute( QStringLiteral(
"style" ), QString() );
1169 layoutItem->
setStyle( QObject::tr( styleString.toLocal8Bit().data() ) );
1171 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
1174 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
1198 QString mapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
1199 if ( mapId != QLatin1String(
"-1" ) && mapId2Uuid.contains( mapId ) )
1213 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1223 QString mapId = itemElem.attribute( QStringLiteral(
"map" ), QStringLiteral(
"-1" ) );
1224 if ( mapId != QLatin1String(
"-1" ) && mapId2Uuid.contains( mapId ) )
1234 layoutItem->
setTitle( itemElem.attribute( QStringLiteral(
"title" ) ) );
1235 if ( !itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).isEmpty() )
1237 layoutItem->
setTitleAlignment(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).toInt() ) );
1239 int colCount = itemElem.attribute( QStringLiteral(
"columnCount" ), QStringLiteral(
"1" ) ).toInt();
1240 if ( colCount < 1 ) colCount = 1;
1242 layoutItem->
setSplitLayer( itemElem.attribute( QStringLiteral(
"splitLayer" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1243 layoutItem->
setEqualColumnWidth( itemElem.attribute( QStringLiteral(
"equalColumnWidth" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1245 QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"styles" ) );
1246 if ( !stylesNodeList.isEmpty() )
1248 QDomNode stylesNode = stylesNodeList.at( 0 );
1249 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
1251 QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
1253 style.
readXml( styleElem, QDomDocument() );
1254 QString name = styleElem.attribute( QStringLiteral(
"name" ) );
1268 fontClr.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1272 layoutItem->
setBoxSpace( itemElem.attribute( QStringLiteral(
"boxSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1273 layoutItem->
setColumnSpace( itemElem.attribute( QStringLiteral(
"columnSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1275 layoutItem->
setSymbolWidth( itemElem.attribute( QStringLiteral(
"symbolWidth" ), QStringLiteral(
"7.0" ) ).toDouble() );
1276 layoutItem->
setSymbolHeight( itemElem.attribute( QStringLiteral(
"symbolHeight" ), QStringLiteral(
"14.0" ) ).toDouble() );
1277 layoutItem->
setWmsLegendWidth( itemElem.attribute( QStringLiteral(
"wmsLegendWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1278 layoutItem->
setWmsLegendHeight( itemElem.attribute( QStringLiteral(
"wmsLegendHeight" ), QStringLiteral(
"25" ) ).toDouble() );
1279 layoutItem->
setLineSpacing( itemElem.attribute( QStringLiteral(
"lineSpacing" ), QStringLiteral(
"1.0" ) ).toDouble() );
1281 layoutItem->
setDrawRasterStroke( itemElem.attribute( QStringLiteral(
"rasterBorder" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
1283 layoutItem->
setRasterStrokeWidth( itemElem.attribute( QStringLiteral(
"rasterBorderWidth" ), QStringLiteral(
"0" ) ).toDouble() );
1285 layoutItem->
setWrapString( itemElem.attribute( QStringLiteral(
"wrapChar" ) ) );
1287 layoutItem->mSizeToContents = itemElem.attribute( QStringLiteral(
"resizeToContents" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" );
1288 layoutItem->mLegendFilterByMap = itemElem.attribute( QStringLiteral(
"legendFilterByMap" ), QStringLiteral(
"0" ) ).toInt();
1289 layoutItem->mFilterOutAtlas = itemElem.attribute( QStringLiteral(
"legendFilterByAtlas" ), QStringLiteral(
"0" ) ).toInt();
1292 QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree" ) );
1293 if ( layerTreeElem.isNull() )
1294 layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
1296 if ( !layerTreeElem.isNull() )
1300 tree->resolveReferences( project,
true );
1301 layoutItem->setCustomLayerTree( tree );
1305 layoutItem->setCustomLayerTree(
nullptr );
1311 bool QgsCompositionConverter::readAtlasXml(
QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project )
1313 atlasItem->
setEnabled( itemElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1316 QString layerId = itemElem.attribute( QStringLiteral(
"coverageLayer" ) );
1317 QString layerName = itemElem.attribute( QStringLiteral(
"coverageLayerName" ) );
1318 QString layerSource = itemElem.attribute( QStringLiteral(
"coverageLayerSource" ) );
1319 QString layerProvider = itemElem.attribute( QStringLiteral(
"coverageLayerProvider" ) );
1324 atlasItem->
setPageNameExpression( itemElem.attribute( QStringLiteral(
"pageNameExpression" ), QString() ) );
1325 QString errorString;
1326 atlasItem->
setFilenameExpression( itemElem.attribute( QStringLiteral(
"filenamePattern" ), QString() ), errorString );
1328 atlasItem->
setSortFeatures( itemElem.attribute( QStringLiteral(
"sortFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1331 atlasItem->
setSortExpression( itemElem.attribute( QStringLiteral(
"sortKey" ), QString() ) );
1332 atlasItem->
setSortAscending( itemElem.attribute( QStringLiteral(
"sortAscending" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1334 atlasItem->
setFilterFeatures( itemElem.attribute( QStringLiteral(
"filterFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1337 QString expErrorString;
1338 atlasItem->
setFilterExpression( itemElem.attribute( QStringLiteral(
"featureFilter" ), QString() ), expErrorString );
1342 atlasItem->
setHideCoverage( itemElem.attribute( QStringLiteral(
"hideCoverage" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1348 bool QgsCompositionConverter::readHtmlXml(
QgsLayoutItemHtml *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1351 readOldComposerObjectXml( layoutItem, itemElem );
1355 QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1356 for (
int i = 0; i < frameList.size(); ++i )
1358 QDomElement frameElem = frameList.at( i ).toElement();
1360 restoreGeneralComposeItemProperties( newFrame, frameElem );
1362 double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1363 double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1364 double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1365 double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1367 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1368 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1369 layoutItem->
addFrame( newFrame,
false );
1374 if ( !contentModeOK )
1376 layoutItem->
setContentMode( QgsLayoutItemHtml::ContentMode::Url );
1378 layoutItem->
setEvaluateExpressions( itemElem.attribute( QStringLiteral(
"evaluateExpressions" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1379 layoutItem->
setUseSmartBreaks( itemElem.attribute( QStringLiteral(
"useSmartBreaks" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1380 layoutItem->
setMaxBreakDistance( itemElem.attribute( QStringLiteral(
"maxBreakDistance" ), QStringLiteral(
"10" ) ).toDouble() );
1381 layoutItem->
setHtml( itemElem.attribute( QStringLiteral(
"html" ) ) );
1382 layoutItem->
setUserStylesheet( itemElem.attribute( QStringLiteral(
"stylesheet" ) ) );
1383 layoutItem->
setUserStylesheetEnabled( itemElem.attribute( QStringLiteral(
"stylesheetEnabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1386 QString urlString = itemElem.attribute( QStringLiteral(
"url" ) );
1387 if ( !urlString.isEmpty() )
1389 layoutItem->
setUrl( urlString );
1400 readOldComposerObjectXml( layoutItem, itemElem );
1404 QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1405 for (
int i = 0; i < frameList.size(); ++i )
1407 QDomElement frameElem = frameList.at( i ).toElement();
1409 restoreGeneralComposeItemProperties( newFrame, frameElem );
1411 double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1412 double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1413 double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1414 double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1416 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1417 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1418 layoutItem->
addFrame( newFrame,
false );
1422 layoutItem->
setEmptyTableMessage( itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), QObject::tr(
"No matching records" ) ) );
1423 layoutItem->
setShowEmptyRows( itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt() );
1427 headerFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
1430 headerFormat.
setFont( headerFont );
1431 if ( headerFont.pointSizeF() > 0 )
1433 headerFormat.
setSize( headerFont.pointSizeF() );
1436 else if ( headerFont.pixelSize() > 0 )
1438 headerFormat.
setSize( headerFont.pixelSize() );
1449 contentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
1452 contentFormat.
setFont( contentFont );
1453 if ( contentFont.pointSizeF() > 0 )
1455 contentFormat.
setSize( contentFont.pointSizeF() );
1458 else if ( contentFont.pixelSize() > 0 )
1460 contentFormat.
setSize( contentFont.pixelSize() );
1466 layoutItem->
setCellMargin( itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble() );
1467 layoutItem->
setGridStrokeWidth( itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble() );
1468 layoutItem->
setHorizontalGrid( itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1469 layoutItem->
setVerticalGrid( itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1470 layoutItem->
setShowGrid( itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt() );
1479 QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
1480 if ( !columnsList.isEmpty() )
1482 QDomElement columnsElem = columnsList.at( 0 ).toElement();
1483 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
1484 for (
int i = 0; i < columnEntryList.size(); ++i )
1486 QDomElement columnElem = columnEntryList.at( i ).toElement();
1488 column.mHAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
1489 column.mVAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
1490 column.mHeading = columnElem.attribute( QStringLiteral(
"heading" ), QString() );
1491 column.mAttribute = columnElem.attribute( QStringLiteral(
"attribute" ), QString() );
1492 column.mSortByRank = columnElem.attribute( QStringLiteral(
"sortByRank" ), QStringLiteral(
"0" ) ).toInt();
1493 column.mSortOrder =
static_cast< Qt::SortOrder
>( columnElem.attribute( QStringLiteral(
"sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
1494 column.mWidth = columnElem.attribute( QStringLiteral(
"width" ), QStringLiteral(
"0.0" ) ).toDouble();
1496 QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral(
"backgroundColor" ) );
1497 if ( !bgColorList.isEmpty() )
1499 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1500 bool redOk, greenOk, blueOk, alphaOk;
1501 int bgRed, bgGreen, bgBlue, bgAlpha;
1502 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1503 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1504 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1505 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1506 if ( redOk && greenOk && blueOk && alphaOk )
1508 column.mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1511 layoutItem->
mColumns.append( column );
1523 QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
1524 if ( !stylesList.isEmpty() )
1526 QDomElement stylesElem = stylesList.at( 0 ).toElement();
1528 QMap< QgsLayoutTable::CellStyleGroup, QString >::const_iterator it = layoutItem->mCellStyleNames.constBegin();
1529 for ( ; it != layoutItem->mCellStyleNames.constEnd(); ++it )
1531 QString styleName = it.value();
1532 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
1533 if ( !styleList.isEmpty() )
1535 QDomElement styleElem = styleList.at( 0 ).toElement();
1544 QString layerId = itemElem.attribute( QStringLiteral(
"vectorLayer" ) );
1545 QString layerName = itemElem.attribute( QStringLiteral(
"vectorLayerName" ) );
1546 QString layerSource = itemElem.attribute( QStringLiteral(
"vectorLayerSource" ) );
1547 QString layerProvider = itemElem.attribute( QStringLiteral(
"vectorLayerProvider" ) );
1556 template <
class T,
class T2>
1557 bool QgsCompositionConverter::readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1559 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1560 QDomNodeList nodeList = itemElem.elementsByTagName( QStringLiteral(
"node" ) );
1561 if ( !nodeList.isEmpty() )
1564 for (
int i = 0; i < nodeList.length(); i++ )
1566 QDomElement node = nodeList.at( i ).toElement();
1567 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
1569 layoutItem->setNodes( polygon );
1571 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
1573 QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
1577 T2 *styleSymbol = QgsSymbolLayerUtils::loadSymbol<T2>( symbolElement, context );
1579 layoutItem->setSymbol( styleSymbol );
1582 layoutItem->setFrameEnabled(
false );
1583 layoutItem->setBackgroundEnabled(
false );
1588 bool QgsCompositionConverter::readXml(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
1590 if ( itemElem.isNull() )
1595 readOldComposerObjectXml( layoutItem, itemElem );
1598 layoutItem->mUuid = itemElem.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
1601 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1604 QString
id = itemElem.attribute( QStringLiteral(
"id" ), QString() );
1605 layoutItem->
setId(
id );
1608 QString frame = itemElem.attribute( QStringLiteral(
"frame" ) );
1609 layoutItem->
setFrameEnabled( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 ) ;
1612 QString background = itemElem.attribute( QStringLiteral(
"background" ) );
1613 layoutItem->
setBackgroundEnabled( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1616 QString positionLock = itemElem.attribute( QStringLiteral(
"positionLock" ) );
1617 layoutItem->
setLocked( positionLock.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1620 layoutItem->
setVisibility( itemElem.attribute( QStringLiteral(
"visibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
1622 layoutItem->mParentGroupUuid = itemElem.attribute( QStringLiteral(
"groupUuid" ) );
1623 if ( !layoutItem->mParentGroupUuid.isEmpty() )
1627 group->addItem( layoutItem );
1630 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1633 QRectF position = itemPosition( layoutItem, itemElem );
1638 layoutItem->setZValue( itemElem.attribute( QStringLiteral(
"zValue" ) ).toDouble() );
1641 QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral(
"FrameColor" ) );
1642 if ( !frameColorList.isEmpty() )
1644 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
1645 bool redOk, greenOk, blueOk, alphaOk, widthOk;
1646 int penRed, penGreen, penBlue, penAlpha;
1649 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
1650 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1651 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1652 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1653 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1656 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
1663 layoutItem->setPen( framePen );
1670 QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
1671 if ( !bgColorList.isEmpty() )
1673 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1674 bool redOk, greenOk, blueOk, alphaOk;
1675 int bgRed, bgGreen, bgBlue, bgAlpha;
1676 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1677 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1678 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1679 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1680 if ( redOk && greenOk && blueOk && alphaOk )
1682 layoutItem->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1683 layoutItem->setBrush( QBrush( layoutItem->mBackgroundColor, Qt::SolidPattern ) );
1693 if ( itemElem.hasAttribute( QStringLiteral(
"opacity" ) ) )
1695 layoutItem->
setItemOpacity( itemElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
1699 layoutItem->
setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
1702 layoutItem->mExcludeFromExports = itemElem.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
1703 layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
1708 layoutItem->
setItemRotation( itemElem.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble(),
false );
1710 layoutItem->mBlockUndoCommands =
false;
1717 bool QgsCompositionConverter::readOldComposerObjectXml(
QgsLayoutObject *layoutItem,
1718 const QDomElement &itemElem )
1720 if ( itemElem.isNull() )
1728 QDomNode propsNode = itemElem.namedItem( QStringLiteral(
"dataDefinedProperties" ) );
1729 if ( !propsNode.isNull() )
1737 exp = QStringLiteral(
"100.0 - (%1)" ).arg( exp );
1749 void QgsCompositionConverter::readOldDataDefinedPropertyMap(
const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties )
1752 QgsPropertiesDefinition::const_iterator i = defs.constBegin();
1753 for ( ; i != defs.constEnd(); ++i )
1755 QString elemName = i.value().name();
1756 QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
1757 if ( !ddNodeList.isEmpty() )
1759 QDomElement ddElem = ddNodeList.at( 0 ).toElement();
1762 dataDefinedProperties.
setProperty( i.key(), prop );
1775 QString active = ddElem.attribute( QStringLiteral(
"active" ) );
1776 bool isActive =
false;
1777 if ( active.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1781 QString
field = ddElem.attribute( QStringLiteral(
"field" ) );
1782 QString expr = ddElem.attribute( QStringLiteral(
"expr" ) );
1784 QString useExpr = ddElem.attribute( QStringLiteral(
"useExpr" ) );
1785 bool isExpression =
false;
1786 if ( useExpr.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1788 isExpression =
true;