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 != QStringLiteral(
"-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 != QStringLiteral(
"-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() ) );
990 mapGrid->
setAnnotationPrecision( annotationElem.attribute( QStringLiteral(
"precision" ), QStringLiteral(
"3" ) ).toInt() );
992 layoutItem->mGridStack->addGrid( mapGrid );
996 QDomNodeList atlasNodeList = itemElem.elementsByTagName( QStringLiteral(
"AtlasMap" ) );
997 if ( !atlasNodeList.isEmpty() )
999 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1000 layoutItem->mAtlasDriven = ( atlasElem.attribute( QStringLiteral(
"atlasDriven" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
1001 if ( atlasElem.hasAttribute( QStringLiteral(
"fixedScale" ) ) )
1003 layoutItem->
setAtlasScalingMode( atlasElem.attribute( QStringLiteral(
"fixedScale" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) ? QgsLayoutItemMap::AtlasScalingMode::Fixed : QgsLayoutItemMap::AtlasScalingMode::Auto );
1005 else if ( atlasElem.hasAttribute( QStringLiteral(
"scalingMode" ) ) )
1009 layoutItem->
setAtlasMargin( atlasElem.attribute( QStringLiteral(
"margin" ), QStringLiteral(
"0.1" ) ).toDouble() );
1020 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1022 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1023 layoutItem->
setHeight( itemElem.attribute( QStringLiteral(
"height" ), QStringLiteral(
"5.0" ) ).toDouble() );
1024 layoutItem->
setLabelBarSpace( itemElem.attribute( QStringLiteral(
"labelBarSpace" ), QStringLiteral(
"3.0" ) ).toDouble() );
1025 layoutItem->
setBoxContentSpace( itemElem.attribute( QStringLiteral(
"boxContentSpace" ), QStringLiteral(
"1.0" ) ).toDouble() );
1026 layoutItem->
setNumberOfSegments( itemElem.attribute( QStringLiteral(
"numSegments" ), QStringLiteral(
"2" ) ).toInt() );
1027 layoutItem->
setNumberOfSegmentsLeft( itemElem.attribute( QStringLiteral(
"numSegmentsLeft" ), QStringLiteral(
"0" ) ).toInt() );
1028 layoutItem->
setUnitsPerSegment( itemElem.attribute( QStringLiteral(
"numUnitsPerSegment" ), QStringLiteral(
"1.0" ) ).toDouble() );
1030 layoutItem->
setMinimumBarWidth( itemElem.attribute( QStringLiteral(
"minBarWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1031 layoutItem->
setMaximumBarWidth( itemElem.attribute( QStringLiteral(
"maxBarWidth" ), QStringLiteral(
"150" ) ).toDouble() );
1032 layoutItem->mSegmentMillimeters = itemElem.attribute( QStringLiteral(
"segmentMillimeters" ), QStringLiteral(
"0.0" ) ).toDouble();
1033 layoutItem->
setMapUnitsPerScaleBarUnit( itemElem.attribute( QStringLiteral(
"numMapUnitsPerScaleBarUnit" ), QStringLiteral(
"1.0" ) ).toDouble() );
1034 layoutItem->
setUnitLabel( itemElem.attribute( QStringLiteral(
"unitLabel" ) ) );
1039 f.fromString( itemElem.attribute( QStringLiteral(
"font" ), QString() ) );
1047 QDomNodeList fillColorList = itemElem.elementsByTagName( QStringLiteral(
"fillColor" ) );
1048 if ( !fillColorList.isEmpty() )
1050 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
1051 bool redOk, greenOk, blueOk, alphaOk;
1052 int fillRed, fillGreen, fillBlue, fillAlpha;
1054 fillRed = fillColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1055 fillGreen = fillColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1056 fillBlue = fillColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1057 fillAlpha = fillColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1059 if ( redOk && greenOk && blueOk && alphaOk )
1061 layoutItem->
fillSymbol()->
setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
1066 layoutItem->
fillSymbol()->
setColor( QColor( itemElem.attribute( QStringLiteral(
"brushColor" ), QStringLiteral(
"#000000" ) ) ) );
1070 QDomNodeList fillColor2List = itemElem.elementsByTagName( QStringLiteral(
"fillColor2" ) );
1071 if ( !fillColor2List.isEmpty() )
1073 QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
1074 bool redOk, greenOk, blueOk, alphaOk;
1075 int fillRed, fillGreen, fillBlue, fillAlpha;
1077 fillRed = fillColor2Elem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1078 fillGreen = fillColor2Elem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1079 fillBlue = fillColor2Elem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1080 fillAlpha = fillColor2Elem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1082 if ( redOk && greenOk && blueOk && alphaOk )
1089 layoutItem->
alternateFillSymbol()->
setColor( QColor( itemElem.attribute( QStringLiteral(
"brush2Color" ), QStringLiteral(
"#ffffff" ) ) ) );
1092 std::unique_ptr< QgsLineSymbol > lineSymbol = qgis::make_unique< QgsLineSymbol >();
1093 std::unique_ptr< QgsSimpleLineSymbolLayer > lineSymbolLayer = qgis::make_unique< QgsSimpleLineSymbolLayer >();
1094 lineSymbolLayer->setWidth( itemElem.attribute( QStringLiteral(
"outlineWidth" ), QStringLiteral(
"0.3" ) ).toDouble() );
1099 QDomNodeList strokeColorList = itemElem.elementsByTagName( QStringLiteral(
"strokeColor" ) );
1100 if ( !strokeColorList.isEmpty() )
1102 QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
1103 bool redOk, greenOk, blueOk, alphaOk;
1104 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
1106 strokeRed = strokeColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1107 strokeGreen = strokeColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1108 strokeBlue = strokeColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1109 strokeAlpha = strokeColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1111 if ( redOk && greenOk && blueOk && alphaOk )
1113 lineSymbolLayer->setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
1118 lineSymbolLayer->setColor( QColor( itemElem.attribute( QStringLiteral(
"penColor" ), QStringLiteral(
"#000000" ) ) ) );
1120 lineSymbol->changeSymbolLayer( 0, lineSymbolLayer.release() );
1126 QDomNodeList textColorList = itemElem.elementsByTagName( QStringLiteral(
"textColor" ) );
1127 if ( !textColorList.isEmpty() )
1129 QDomElement textColorElem = textColorList.at( 0 ).toElement();
1130 bool redOk, greenOk, blueOk, alphaOk;
1131 int textRed, textGreen, textBlue, textAlpha;
1133 textRed = textColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1134 textGreen = textColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1135 textBlue = textColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1136 textAlpha = textColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1138 if ( redOk && greenOk && blueOk && alphaOk )
1141 layoutItem->
setFontColor( QColor( textRed, textGreen, textBlue, textAlpha ) );
1148 c.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1155 QString styleString = itemElem.attribute( QStringLiteral(
"style" ), QString() );
1156 layoutItem->
setStyle( QObject::tr( styleString.toLocal8Bit().data() ) );
1158 if ( itemElem.attribute( QStringLiteral(
"unitType" ) ).isEmpty() )
1161 switch ( itemElem.attribute( QStringLiteral(
"units" ) ).toInt() )
1185 QString mapId = itemElem.attribute( QStringLiteral(
"mapId" ), QStringLiteral(
"-1" ) );
1186 if ( mapId != QStringLiteral(
"-1" ) && mapId2Uuid.contains( mapId ) )
1200 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1210 QString mapId = itemElem.attribute( QStringLiteral(
"map" ), QStringLiteral(
"-1" ) );
1211 if ( mapId != QStringLiteral(
"-1" ) && mapId2Uuid.contains( mapId ) )
1221 layoutItem->
setTitle( itemElem.attribute( QStringLiteral(
"title" ) ) );
1222 if ( !itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).isEmpty() )
1224 layoutItem->
setTitleAlignment(
static_cast< Qt::AlignmentFlag
>( itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).toInt() ) );
1226 int colCount = itemElem.attribute( QStringLiteral(
"columnCount" ), QStringLiteral(
"1" ) ).toInt();
1227 if ( colCount < 1 ) colCount = 1;
1229 layoutItem->
setSplitLayer( itemElem.attribute( QStringLiteral(
"splitLayer" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1230 layoutItem->
setEqualColumnWidth( itemElem.attribute( QStringLiteral(
"equalColumnWidth" ), QStringLiteral(
"0" ) ).toInt() == 1 );
1232 QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"styles" ) );
1233 if ( !stylesNodeList.isEmpty() )
1235 QDomNode stylesNode = stylesNodeList.at( 0 );
1236 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
1238 QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
1240 style.
readXml( styleElem, QDomDocument() );
1241 QString name = styleElem.attribute( QStringLiteral(
"name" ) );
1255 fontClr.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
1259 layoutItem->
setBoxSpace( itemElem.attribute( QStringLiteral(
"boxSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1260 layoutItem->
setColumnSpace( itemElem.attribute( QStringLiteral(
"columnSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
1262 layoutItem->
setSymbolWidth( itemElem.attribute( QStringLiteral(
"symbolWidth" ), QStringLiteral(
"7.0" ) ).toDouble() );
1263 layoutItem->
setSymbolHeight( itemElem.attribute( QStringLiteral(
"symbolHeight" ), QStringLiteral(
"14.0" ) ).toDouble() );
1264 layoutItem->
setWmsLegendWidth( itemElem.attribute( QStringLiteral(
"wmsLegendWidth" ), QStringLiteral(
"50" ) ).toDouble() );
1265 layoutItem->
setWmsLegendHeight( itemElem.attribute( QStringLiteral(
"wmsLegendHeight" ), QStringLiteral(
"25" ) ).toDouble() );
1266 layoutItem->
setLineSpacing( itemElem.attribute( QStringLiteral(
"lineSpacing" ), QStringLiteral(
"1.0" ) ).toDouble() );
1268 layoutItem->
setDrawRasterStroke( itemElem.attribute( QStringLiteral(
"rasterBorder" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
1270 layoutItem->
setRasterStrokeWidth( itemElem.attribute( QStringLiteral(
"rasterBorderWidth" ), QStringLiteral(
"0" ) ).toDouble() );
1272 layoutItem->
setWrapString( itemElem.attribute( QStringLiteral(
"wrapChar" ) ) );
1274 layoutItem->mSizeToContents = itemElem.attribute( QStringLiteral(
"resizeToContents" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" );
1275 layoutItem->mLegendFilterByMap = itemElem.attribute( QStringLiteral(
"legendFilterByMap" ), QStringLiteral(
"0" ) ).toInt();
1276 layoutItem->mFilterOutAtlas = itemElem.attribute( QStringLiteral(
"legendFilterByAtlas" ), QStringLiteral(
"0" ) ).toInt();
1279 QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree" ) );
1280 if ( layerTreeElem.isNull() )
1281 layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
1283 if ( !layerTreeElem.isNull() )
1287 tree->resolveReferences( project,
true );
1288 layoutItem->setCustomLayerTree( tree );
1292 layoutItem->setCustomLayerTree(
nullptr );
1298 bool QgsCompositionConverter::readAtlasXml(
QgsLayoutAtlas *atlasItem,
const QDomElement &itemElem,
const QgsProject *project )
1300 atlasItem->
setEnabled( itemElem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1303 QString layerId = itemElem.attribute( QStringLiteral(
"coverageLayer" ) );
1304 QString layerName = itemElem.attribute( QStringLiteral(
"coverageLayerName" ) );
1305 QString layerSource = itemElem.attribute( QStringLiteral(
"coverageLayerSource" ) );
1306 QString layerProvider = itemElem.attribute( QStringLiteral(
"coverageLayerProvider" ) );
1311 atlasItem->
setPageNameExpression( itemElem.attribute( QStringLiteral(
"pageNameExpression" ), QString() ) );
1312 QString errorString;
1313 atlasItem->
setFilenameExpression( itemElem.attribute( QStringLiteral(
"filenamePattern" ), QString() ), errorString );
1315 atlasItem->
setSortFeatures( itemElem.attribute( QStringLiteral(
"sortFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1318 atlasItem->
setSortExpression( itemElem.attribute( QStringLiteral(
"sortKey" ), QString() ) );
1319 atlasItem->
setSortAscending( itemElem.attribute( QStringLiteral(
"sortAscending" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1321 atlasItem->
setFilterFeatures( itemElem.attribute( QStringLiteral(
"filterFeatures" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1324 QString expErrorString;
1325 atlasItem->
setFilterExpression( itemElem.attribute( QStringLiteral(
"featureFilter" ), QString() ), expErrorString );
1329 atlasItem->
setHideCoverage( itemElem.attribute( QStringLiteral(
"hideCoverage" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1335 bool QgsCompositionConverter::readHtmlXml(
QgsLayoutItemHtml *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1338 readOldComposerObjectXml( layoutItem, itemElem );
1342 QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1343 for (
int i = 0; i < frameList.size(); ++i )
1345 QDomElement frameElem = frameList.at( i ).toElement();
1347 restoreGeneralComposeItemProperties( newFrame, frameElem );
1349 double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1350 double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1351 double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1352 double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1354 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1355 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1356 layoutItem->
addFrame( newFrame,
false );
1361 if ( !contentModeOK )
1363 layoutItem->
setContentMode( QgsLayoutItemHtml::ContentMode::Url );
1365 layoutItem->
setEvaluateExpressions( itemElem.attribute( QStringLiteral(
"evaluateExpressions" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1366 layoutItem->
setUseSmartBreaks( itemElem.attribute( QStringLiteral(
"useSmartBreaks" ), QStringLiteral(
"true" ) ) == QLatin1String(
"true" ) );
1367 layoutItem->
setMaxBreakDistance( itemElem.attribute( QStringLiteral(
"maxBreakDistance" ), QStringLiteral(
"10" ) ).toDouble() );
1368 layoutItem->
setHtml( itemElem.attribute( QStringLiteral(
"html" ) ) );
1369 layoutItem->
setUserStylesheet( itemElem.attribute( QStringLiteral(
"stylesheet" ) ) );
1370 layoutItem->
setUserStylesheetEnabled( itemElem.attribute( QStringLiteral(
"stylesheetEnabled" ), QStringLiteral(
"false" ) ) == QLatin1String(
"true" ) );
1373 QString urlString = itemElem.attribute( QStringLiteral(
"url" ) );
1374 if ( !urlString.isEmpty() )
1376 layoutItem->
setUrl( urlString );
1387 readOldComposerObjectXml( layoutItem, itemElem );
1391 QDomNodeList frameList = itemElem.elementsByTagName( QStringLiteral(
"ComposerFrame" ) );
1392 for (
int i = 0; i < frameList.size(); ++i )
1394 QDomElement frameElem = frameList.at( i ).toElement();
1396 restoreGeneralComposeItemProperties( newFrame, frameElem );
1398 double x = itemElem.attribute( QStringLiteral(
"sectionX" ) ).toDouble();
1399 double y = itemElem.attribute( QStringLiteral(
"sectionY" ) ).toDouble();
1400 double width = itemElem.attribute( QStringLiteral(
"sectionWidth" ) ).toDouble();
1401 double height = itemElem.attribute( QStringLiteral(
"sectionHeight" ) ).toDouble();
1403 newFrame->
setHidePageIfEmpty( itemElem.attribute( QStringLiteral(
"hidePageIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1404 newFrame->
setHideBackgroundIfEmpty( itemElem.attribute( QStringLiteral(
"hideBackgroundIfEmpty" ), QStringLiteral(
"0" ) ).toInt() );
1405 layoutItem->
addFrame( newFrame,
false );
1409 layoutItem->
setEmptyTableMessage( itemElem.attribute( QStringLiteral(
"emptyTableMessage" ), QObject::tr(
"No matching records" ) ) );
1410 layoutItem->
setShowEmptyRows( itemElem.attribute( QStringLiteral(
"showEmptyRows" ), QStringLiteral(
"0" ) ).toInt() );
1413 layoutItem->
mHeaderFont.fromString( itemElem.attribute( QStringLiteral(
"headerFont" ), QString() ) );
1420 layoutItem->
mContentFont.fromString( itemElem.attribute( QStringLiteral(
"contentFont" ), QString() ) );
1423 layoutItem->
setCellMargin( itemElem.attribute( QStringLiteral(
"cellMargin" ), QStringLiteral(
"1.0" ) ).toDouble() );
1424 layoutItem->
setGridStrokeWidth( itemElem.attribute( QStringLiteral(
"gridStrokeWidth" ), QStringLiteral(
"0.5" ) ).toDouble() );
1425 layoutItem->
setHorizontalGrid( itemElem.attribute( QStringLiteral(
"horizontalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1426 layoutItem->
setVerticalGrid( itemElem.attribute( QStringLiteral(
"verticalGrid" ), QStringLiteral(
"1" ) ).toInt() );
1427 layoutItem->
setShowGrid( itemElem.attribute( QStringLiteral(
"showGrid" ), QStringLiteral(
"1" ) ).toInt() );
1436 QDomNodeList columnsList = itemElem.elementsByTagName( QStringLiteral(
"displayColumns" ) );
1437 if ( !columnsList.isEmpty() )
1439 QDomElement columnsElem = columnsList.at( 0 ).toElement();
1440 QDomNodeList columnEntryList = columnsElem.elementsByTagName( QStringLiteral(
"column" ) );
1441 for (
int i = 0; i < columnEntryList.size(); ++i )
1443 QDomElement columnElem = columnEntryList.at( i ).toElement();
1445 column.mHAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"hAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
1446 column.mVAlignment =
static_cast< Qt::AlignmentFlag
>( columnElem.attribute( QStringLiteral(
"vAlignment" ), QString::number( Qt::AlignVCenter ) ).toInt() );
1447 column.mHeading = columnElem.attribute( QStringLiteral(
"heading" ), QString() );
1448 column.mAttribute = columnElem.attribute( QStringLiteral(
"attribute" ), QString() );
1449 column.mSortByRank = columnElem.attribute( QStringLiteral(
"sortByRank" ), QStringLiteral(
"0" ) ).toInt();
1450 column.mSortOrder =
static_cast< Qt::SortOrder
>( columnElem.attribute( QStringLiteral(
"sortOrder" ), QString::number( Qt::AscendingOrder ) ).toInt() );
1451 column.mWidth = columnElem.attribute( QStringLiteral(
"width" ), QStringLiteral(
"0.0" ) ).toDouble();
1453 QDomNodeList bgColorList = columnElem.elementsByTagName( QStringLiteral(
"backgroundColor" ) );
1454 if ( !bgColorList.isEmpty() )
1456 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1457 bool redOk, greenOk, blueOk, alphaOk;
1458 int bgRed, bgGreen, bgBlue, bgAlpha;
1459 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1460 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1461 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1462 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1463 if ( redOk && greenOk && blueOk && alphaOk )
1465 column.mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1468 layoutItem->
mColumns.append( column );
1480 QDomNodeList stylesList = itemElem.elementsByTagName( QStringLiteral(
"cellStyles" ) );
1481 if ( !stylesList.isEmpty() )
1483 QDomElement stylesElem = stylesList.at( 0 ).toElement();
1485 QMap< QgsLayoutTable::CellStyleGroup, QString >::const_iterator it = layoutItem->mCellStyleNames.constBegin();
1486 for ( ; it != layoutItem->mCellStyleNames.constEnd(); ++it )
1488 QString styleName = it.value();
1489 QDomNodeList styleList = stylesElem.elementsByTagName( styleName );
1490 if ( !styleList.isEmpty() )
1492 QDomElement styleElem = styleList.at( 0 ).toElement();
1501 QString layerId = itemElem.attribute( QStringLiteral(
"vectorLayer" ) );
1502 QString layerName = itemElem.attribute( QStringLiteral(
"vectorLayerName" ) );
1503 QString layerSource = itemElem.attribute( QStringLiteral(
"vectorLayerSource" ) );
1504 QString layerProvider = itemElem.attribute( QStringLiteral(
"vectorLayerProvider" ) );
1513 template <
class T,
class T2>
1514 bool QgsCompositionConverter::readPolyXml( T *layoutItem,
const QDomElement &itemElem,
const QgsProject *project )
1516 restoreGeneralComposeItemProperties( layoutItem, itemElem );
1517 QDomNodeList nodeList = itemElem.elementsByTagName( QStringLiteral(
"node" ) );
1518 if ( !nodeList.isEmpty() )
1521 for (
int i = 0; i < nodeList.length(); i++ )
1523 QDomElement node = nodeList.at( i ).toElement();
1524 polygon.append( QPointF( node.attribute( QStringLiteral(
"x" ) ).toDouble( ), node.attribute( QStringLiteral(
"y" ) ).toDouble() ) );
1526 layoutItem->setNodes( polygon );
1528 if ( itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).size() )
1530 QDomElement symbolElement = itemElem.elementsByTagName( QStringLiteral(
"symbol" ) ).at( 0 ).toElement();
1534 T2 *styleSymbol = QgsSymbolLayerUtils::loadSymbol<T2>( symbolElement, context );
1536 layoutItem->setSymbol( styleSymbol );
1539 layoutItem->setFrameEnabled(
false );
1540 layoutItem->setBackgroundEnabled(
false );
1545 bool QgsCompositionConverter::readXml(
QgsLayoutItem *layoutItem,
const QDomElement &itemElem )
1547 if ( itemElem.isNull() )
1552 readOldComposerObjectXml( layoutItem, itemElem );
1555 layoutItem->mUuid = itemElem.attribute( QStringLiteral(
"uuid" ), QUuid::createUuid().toString() );
1558 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1561 QString
id = itemElem.attribute( QStringLiteral(
"id" ), QString() );
1562 layoutItem->
setId(
id );
1565 QString frame = itemElem.attribute( QStringLiteral(
"frame" ) );
1566 layoutItem->
setFrameEnabled( frame.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 ) ;
1569 QString background = itemElem.attribute( QStringLiteral(
"background" ) );
1570 layoutItem->
setBackgroundEnabled( background.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1573 QString positionLock = itemElem.attribute( QStringLiteral(
"positionLock" ) );
1574 layoutItem->
setLocked( positionLock.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 );
1577 layoutItem->
setVisibility( itemElem.attribute( QStringLiteral(
"visibility" ), QStringLiteral(
"1" ) ) != QStringLiteral(
"0" ) );
1579 layoutItem->mParentGroupUuid = itemElem.attribute( QStringLiteral(
"groupUuid" ) );
1580 if ( !layoutItem->mParentGroupUuid.isEmpty() )
1584 group->addItem( layoutItem );
1587 layoutItem->mTemplateUuid = itemElem.attribute( QStringLiteral(
"templateUuid" ) );
1590 QRectF position = itemPosition( layoutItem, itemElem );
1595 layoutItem->setZValue( itemElem.attribute( QStringLiteral(
"zValue" ) ).toDouble() );
1598 QDomNodeList frameColorList = itemElem.elementsByTagName( QStringLiteral(
"FrameColor" ) );
1599 if ( !frameColorList.isEmpty() )
1601 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
1602 bool redOk, greenOk, blueOk, alphaOk, widthOk;
1603 int penRed, penGreen, penBlue, penAlpha;
1606 penWidth = itemElem.attribute( QStringLiteral(
"outlineWidth" ) ).toDouble( &widthOk );
1607 penRed = frameColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1608 penGreen = frameColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1609 penBlue = frameColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1610 penAlpha = frameColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1613 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
1620 layoutItem->setPen( framePen );
1627 QDomNodeList bgColorList = itemElem.elementsByTagName( QStringLiteral(
"BackgroundColor" ) );
1628 if ( !bgColorList.isEmpty() )
1630 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
1631 bool redOk, greenOk, blueOk, alphaOk;
1632 int bgRed, bgGreen, bgBlue, bgAlpha;
1633 bgRed = bgColorElem.attribute( QStringLiteral(
"red" ) ).toDouble( &redOk );
1634 bgGreen = bgColorElem.attribute( QStringLiteral(
"green" ) ).toDouble( &greenOk );
1635 bgBlue = bgColorElem.attribute( QStringLiteral(
"blue" ) ).toDouble( &blueOk );
1636 bgAlpha = bgColorElem.attribute( QStringLiteral(
"alpha" ) ).toDouble( &alphaOk );
1637 if ( redOk && greenOk && blueOk && alphaOk )
1639 layoutItem->mBackgroundColor = QColor( bgRed, bgGreen, bgBlue, bgAlpha );
1640 layoutItem->setBrush( QBrush( layoutItem->mBackgroundColor, Qt::SolidPattern ) );
1650 if ( itemElem.hasAttribute( QStringLiteral(
"opacity" ) ) )
1652 layoutItem->
setItemOpacity( itemElem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1" ) ).toDouble() );
1656 layoutItem->
setItemOpacity( 1.0 - itemElem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 100.0 );
1659 layoutItem->mExcludeFromExports = itemElem.attribute( QStringLiteral(
"excludeFromExports" ), QStringLiteral(
"0" ) ).toInt();
1660 layoutItem->mEvaluatedExcludeFromExports = layoutItem->mExcludeFromExports;
1665 layoutItem->
setItemRotation( itemElem.attribute( QStringLiteral(
"itemRotation" ), QStringLiteral(
"0" ) ).toDouble(),
false );
1667 layoutItem->mBlockUndoCommands =
false;
1674 bool QgsCompositionConverter::readOldComposerObjectXml(
QgsLayoutObject *layoutItem,
1675 const QDomElement &itemElem )
1677 if ( itemElem.isNull() )
1685 QDomNode propsNode = itemElem.namedItem( QStringLiteral(
"dataDefinedProperties" ) );
1686 if ( !propsNode.isNull() )
1694 exp = QStringLiteral(
"100.0 - (%1)" ).arg( exp );
1706 void QgsCompositionConverter::readOldDataDefinedPropertyMap(
const QDomElement &itemElem,
QgsPropertyCollection &dataDefinedProperties )
1709 QgsPropertiesDefinition::const_iterator i = defs.constBegin();
1710 for ( ; i != defs.constEnd(); ++i )
1712 QString elemName = i.value().name();
1713 QDomNodeList ddNodeList = itemElem.elementsByTagName( elemName );
1714 if ( !ddNodeList.isEmpty() )
1716 QDomElement ddElem = ddNodeList.at( 0 ).toElement();
1719 dataDefinedProperties.
setProperty( i.key(), prop );
1732 QString active = ddElem.attribute( QStringLiteral(
"active" ) );
1733 bool isActive =
false;
1734 if ( active.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1738 QString field = ddElem.attribute( QStringLiteral(
"field" ) );
1739 QString expr = ddElem.attribute( QStringLiteral(
"expr" ) );
1741 QString useExpr = ddElem.attribute( QStringLiteral(
"useExpr" ) );
1742 bool isExpression =
false;
1743 if ( useExpr.compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0 )
1745 isExpression =
true;