43void QgsDiagramLayerSettings::initPropertyDefinitions()
45 if ( !sPropertyDefinitions.isEmpty() )
48 const QString origin = QStringLiteral(
"diagram" );
69 initPropertyDefinitions();
70 return sPropertyDefinitions;
75 initPropertyDefinitions();
81 , mPlacement( rh.mPlacement )
82 , mPlacementFlags( rh.mPlacementFlags )
83 , mPriority( rh.mPriority )
84 , mZIndex( rh.mZIndex )
85 , mObstacle( rh.mObstacle )
86 , mDistance( rh.mDistance )
87 , mRenderer( rh.mRenderer ? rh.mRenderer->clone() : nullptr )
88 , mShowAll( rh.mShowAll )
89 , mDataDefinedProperties( rh.mDataDefinedProperties )
92 initPropertyDefinitions();
96 : mCt( std::move( rh.mCt ) )
97 , mPlacement( rh.mPlacement )
98 , mPlacementFlags( rh.mPlacementFlags )
99 , mPriority( rh.mPriority )
100 , mZIndex( rh.mZIndex )
101 , mObstacle( rh.mObstacle )
102 , mDistance( rh.mDistance )
103 , mRenderer( std::move( rh.mRenderer ) )
104 , mShowAll( rh.mShowAll )
105 , mDataDefinedProperties( std::move( rh.mDataDefinedProperties ) )
115 mPlacement = rh.mPlacement;
116 mPlacementFlags = rh.mPlacementFlags;
117 mPriority = rh.mPriority;
118 mZIndex = rh.mZIndex;
119 mObstacle = rh.mObstacle;
120 mDistance = rh.mDistance;
121 mRenderer.reset( rh.mRenderer ? rh.mRenderer->clone() :
nullptr );
123 mShowAll = rh.mShowAll;
124 mDataDefinedProperties = rh.mDataDefinedProperties;
134 mPlacement = rh.mPlacement;
135 mPlacementFlags = rh.mPlacementFlags;
136 mPriority = rh.mPriority;
137 mZIndex = rh.mZIndex;
138 mObstacle = rh.mObstacle;
139 mDistance = rh.mDistance;
140 mRenderer = std::move( rh.mRenderer );
141 mCt = std::move( rh.mCt );
142 mShowAll = rh.mShowAll;
143 mDataDefinedProperties = std::move( rh.mDataDefinedProperties );
154 if ( diagramRenderer == mRenderer.get() )
157 mRenderer.reset( diagramRenderer );
168 const QDomNodeList propertyElems = elem.elementsByTagName( QStringLiteral(
"properties" ) );
169 if ( !propertyElems.isEmpty() )
171 ( void )mDataDefinedProperties.readXml( propertyElems.at( 0 ).toElement(), sPropertyDefinitions );
175 mDataDefinedProperties.clear();
178 mPlacement =
static_cast< Placement >( elem.attribute( QStringLiteral(
"placement" ) ).toInt() );
179 mPlacementFlags =
static_cast< LinePlacementFlag >( elem.attribute( QStringLiteral(
"linePlacementFlags" ) ).toInt() );
180 mPriority = elem.attribute( QStringLiteral(
"priority" ) ).toInt();
181 mZIndex = elem.attribute( QStringLiteral(
"zIndex" ) ).toDouble();
182 mObstacle = elem.attribute( QStringLiteral(
"obstacle" ) ).toInt();
183 mDistance = elem.attribute( QStringLiteral(
"dist" ) ).toDouble();
184 mShowAll = ( elem.attribute( QStringLiteral(
"showAll" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
189 QDomElement diagramLayerElem = doc.createElement( QStringLiteral(
"DiagramLayerSettings" ) );
190 QDomElement propertiesElem = doc.createElement( QStringLiteral(
"properties" ) );
191 ( void )mDataDefinedProperties.writeXml( propertiesElem, sPropertyDefinitions );
192 diagramLayerElem.appendChild( propertiesElem );
193 diagramLayerElem.setAttribute( QStringLiteral(
"placement" ), mPlacement );
194 diagramLayerElem.setAttribute( QStringLiteral(
"linePlacementFlags" ), mPlacementFlags );
195 diagramLayerElem.setAttribute( QStringLiteral(
"priority" ), mPriority );
196 diagramLayerElem.setAttribute( QStringLiteral(
"zIndex" ), mZIndex );
197 diagramLayerElem.setAttribute( QStringLiteral(
"obstacle" ), mObstacle );
198 diagramLayerElem.setAttribute( QStringLiteral(
"dist" ), QString::number( mDistance ) );
199 diagramLayerElem.setAttribute( QStringLiteral(
"showAll" ), mShowAll );
200 layerElem.appendChild( diagramLayerElem );
205 return mDataDefinedProperties.prepare( context );
210 QSet< QString > referenced;
212 referenced = mRenderer->referencedFields( context );
215 referenced.unite( mDataDefinedProperties.referencedFields( context ) );
222 enabled = ( elem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
225 font.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
227 backgroundColor.setNamedColor( elem.attribute( QStringLiteral(
"backgroundColor" ) ) );
228 backgroundColor.setAlpha( elem.attribute( QStringLiteral(
"backgroundAlpha" ) ).toInt() );
229 size.setWidth( elem.attribute( QStringLiteral(
"width" ) ).toDouble() );
230 size.setHeight( elem.attribute( QStringLiteral(
"height" ) ).toDouble() );
231 if ( elem.hasAttribute( QStringLiteral(
"transparency" ) ) )
233 opacity = 1 - elem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 255.0;
237 opacity = elem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1.00" ) ).toDouble();
240 penColor.setNamedColor( elem.attribute( QStringLiteral(
"penColor" ) ) );
241 const int penAlpha = elem.attribute( QStringLiteral(
"penAlpha" ), QStringLiteral(
"255" ) ).toInt();
243 penWidth = elem.attribute( QStringLiteral(
"penWidth" ) ).toDouble();
245 mDirection =
static_cast< Direction >( elem.attribute( QStringLiteral(
"direction" ), QStringLiteral(
"1" ) ).toInt() );
247 maximumScale = elem.attribute( QStringLiteral(
"minScaleDenominator" ), QStringLiteral(
"-1" ) ).toDouble();
248 minimumScale = elem.attribute( QStringLiteral(
"maxScaleDenominator" ), QStringLiteral(
"-1" ) ).toDouble();
249 if ( elem.hasAttribute( QStringLiteral(
"scaleBasedVisibility" ) ) )
251 scaleBasedVisibility = ( elem.attribute( QStringLiteral(
"scaleBasedVisibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
259 if ( elem.attribute( QStringLiteral(
"sizeType" ) ) == QLatin1String(
"MapUnits" ) )
274 mSpacing = elem.attribute( QStringLiteral(
"spacing" ) ).toDouble();
278 mStackedDiagramSpacing = elem.attribute( QStringLiteral(
"stackedDiagramSpacing" ) ).toDouble();
283 if ( elem.attribute( QStringLiteral(
"labelPlacementMethod" ) ) == QLatin1String(
"Height" ) )
293 if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Left" ) )
297 else if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Right" ) )
301 else if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Down" ) )
311 if ( elem.attribute( QStringLiteral(
"stackedDiagramMode" ) ) == QLatin1String(
"Horizontal" ) )
315 else if ( elem.attribute( QStringLiteral(
"stackedDiagramMode" ) ) == QLatin1String(
"Vertical" ) )
321 if ( elem.attribute( QStringLiteral(
"scaleDependency" ) ) == QLatin1String(
"Diameter" ) )
330 barWidth = elem.attribute( QStringLiteral(
"barWidth" ) ).toDouble();
332 if ( elem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
333 rotationOffset = std::fmod( 360.0 - elem.attribute( QStringLiteral(
"angleOffset" ) ).toInt() / 16.0, 360.0 );
335 rotationOffset = elem.attribute( QStringLiteral(
"rotationOffset" ) ).toDouble();
337 minimumSize = elem.attribute( QStringLiteral(
"minimumSize" ) ).toDouble();
339 const QDomNodeList axisSymbolNodes = elem.elementsByTagName( QStringLiteral(
"axisSymbol" ) );
340 if ( axisSymbolNodes.count() > 0 )
342 const QDomElement axisSymbolElem = axisSymbolNodes.at( 0 ).toElement().firstChildElement();
347 mAxisLineSymbol = std::make_unique< QgsLineSymbol >();
350 mShowAxis = elem.attribute( QStringLiteral(
"showAxis" ), QStringLiteral(
"0" ) ).toInt();
354 const QDomNodeList attributes = elem.elementsByTagName( QStringLiteral(
"attribute" ) );
357 if ( attributes.length() > 0 )
359 for (
int i = 0; i < attributes.size(); i++ )
361 const QDomElement attrElem = attributes.at( i ).toElement();
362 QColor newColor( attrElem.attribute( QStringLiteral(
"color" ) ) );
363 newColor.setAlphaF( attrElem.attribute( QStringLiteral(
"colorOpacity" ), QStringLiteral(
"1.0" ) ).toDouble() );
366 categoryLabels.append( attrElem.attribute( QStringLiteral(
"label" ) ) );
377 const QStringList colorList = elem.attribute( QStringLiteral(
"colors" ) ).split(
'/' );
378 QStringList::const_iterator colorIt = colorList.constBegin();
379 for ( ; colorIt != colorList.constEnd(); ++colorIt )
381 QColor newColor( *colorIt );
387 const QStringList catList = elem.attribute( QStringLiteral(
"categories" ) ).split(
'/' );
388 QStringList::const_iterator catIt = catList.constBegin();
389 for ( ; catIt != catList.constEnd(); ++catIt )
396 const QDomElement effectElem = elem.firstChildElement( QStringLiteral(
"effect" ) );
397 if ( !effectElem.isNull() )
405 QDomElement categoryElem = doc.createElement( QStringLiteral(
"DiagramCategory" ) );
406 categoryElem.setAttribute( QStringLiteral(
"enabled" ),
enabled );
408 categoryElem.setAttribute( QStringLiteral(
"backgroundColor" ),
backgroundColor.name() );
409 categoryElem.setAttribute( QStringLiteral(
"backgroundAlpha" ),
backgroundColor.alpha() );
410 categoryElem.setAttribute( QStringLiteral(
"width" ), QString::number(
size.width() ) );
411 categoryElem.setAttribute( QStringLiteral(
"height" ), QString::number(
size.height() ) );
412 categoryElem.setAttribute( QStringLiteral(
"penColor" ),
penColor.name() );
413 categoryElem.setAttribute( QStringLiteral(
"penAlpha" ),
penColor.alpha() );
414 categoryElem.setAttribute( QStringLiteral(
"penWidth" ), QString::number(
penWidth ) );
416 categoryElem.setAttribute( QStringLiteral(
"minScaleDenominator" ), QString::number(
maximumScale ) );
417 categoryElem.setAttribute( QStringLiteral(
"maxScaleDenominator" ), QString::number(
minimumScale ) );
418 categoryElem.setAttribute( QStringLiteral(
"opacity" ), QString::number(
opacity ) );
419 categoryElem.setAttribute( QStringLiteral(
"spacing" ), QString::number( mSpacing ) );
422 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramSpacing" ), QString::number( mStackedDiagramSpacing ) );
423 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramSpacingUnit" ),
QgsUnitTypes::encodeUnit( mStackedDiagramSpacingUnit ) );
425 categoryElem.setAttribute( QStringLiteral(
"direction" ), QString::number( mDirection ) );
438 categoryElem.setAttribute( QStringLiteral(
"labelPlacementMethod" ), QStringLiteral(
"Height" ) );
442 categoryElem.setAttribute( QStringLiteral(
"labelPlacementMethod" ), QStringLiteral(
"XHeight" ) );
447 categoryElem.setAttribute( QStringLiteral(
"scaleDependency" ), QStringLiteral(
"Area" ) );
451 categoryElem.setAttribute( QStringLiteral(
"scaleDependency" ), QStringLiteral(
"Diameter" ) );
458 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Left" ) );
462 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Right" ) );
466 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Down" ) );
470 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Up" ) );
478 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramMode" ), QStringLiteral(
"Horizontal" ) );
482 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramMode" ), QStringLiteral(
"Vertical" ) );
486 categoryElem.setAttribute( QStringLiteral(
"barWidth" ), QString::number(
barWidth ) );
487 categoryElem.setAttribute( QStringLiteral(
"minimumSize" ), QString::number(
minimumSize ) );
488 categoryElem.setAttribute( QStringLiteral(
"rotationOffset" ), QString::number(
rotationOffset ) );
491 for (
int i = 0; i < nCats; ++i )
493 QDomElement attributeElem = doc.createElement( QStringLiteral(
"attribute" ) );
496 attributeElem.setAttribute( QStringLiteral(
"color" ),
categoryColors.at( i ).name() );
497 attributeElem.setAttribute( QStringLiteral(
"colorOpacity" ), QString::number(
categoryColors.at( i ).alphaF() ) );
498 attributeElem.setAttribute( QStringLiteral(
"label" ),
categoryLabels.at( i ) );
499 categoryElem.appendChild( attributeElem );
502 categoryElem.setAttribute( QStringLiteral(
"showAxis" ), mShowAxis ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
503 QDomElement axisSymbolElem = doc.createElement( QStringLiteral(
"axisSymbol" ) );
505 axisSymbolElem.appendChild( symbolElem );
506 categoryElem.appendChild( axisSymbolElem );
509 mPaintEffect->saveProperties( doc, categoryElem );
511 rendererElem.appendChild( categoryElem );
530 if ( &other ==
this )
557 c.expressionContext().setOriginalValueVariable( s.
penWidth );
564 std::unique_ptr< QgsEffectPainter > effectPainter;
565 if ( effect && effect->
enabled() )
567 effectPainter = std::make_unique< QgsEffectPainter >(
c, effect );
570 mDiagram->renderDiagram( feature,
c, s, pos );
584 const double rendererScale =
c.rendererScale();
602 if ( size.isValid() )
605 size.rheight() *= width / size.width();
606 size.setWidth( width );
613 QSet< QString > referenced;
619 for (
const QString &att : constDiagramAttributes )
623 for (
const QString &field : constReferencedColumns )
633 if ( !size.isValid() )
639 size.rwidth() *= pixelToMap;
640 size.rheight() *= pixelToMap;
647 QPaintDevice *device = painter->device();
650 return device->logicalDpiX();
660 const QString diagramType = elem.attribute( QStringLiteral(
"diagramType" ) );
663 mDiagram = std::make_unique<QgsPieDiagram>( );
667 mDiagram = std::make_unique<QgsTextDiagram>( );
671 mDiagram = std::make_unique<QgsHistogramDiagram>( );
675 mDiagram = std::make_unique<QgsStackedBarDiagram>( );
679 mDiagram = std::make_unique<QgsStackedDiagram>( );
684 mDiagram = std::make_unique<QgsHistogramDiagram>( );
686 mShowAttributeLegend = ( elem.attribute( QStringLiteral(
"attributeLegend" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
696 rendererElem.setAttribute( QStringLiteral(
"diagramType" ),
mDiagram->diagramName() );
722 QList<QgsDiagramSettings> settingsList;
723 settingsList.push_back( mSettings );
729 const QDomElement categoryElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
730 if ( categoryElem.isNull() )
735 mSettings.readXml( categoryElem, context );
741 QDomElement rendererElem = doc.createElement( QStringLiteral(
"SingleCategoryDiagramRenderer" ) );
742 mSettings.writeXml( rendererElem, doc, context );
744 layerElem.appendChild( rendererElem );
751 mInterpolationSettings.classificationAttributeIsExpression =
false;
756 , mSettings( other.mSettings )
757 , mInterpolationSettings( other.mInterpolationSettings )
758 , mDataDefinedSizeLegend( other.mDataDefinedSizeLegend ? new
QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegend ) : nullptr )
769 if ( &other ==
this )
773 mSettings = other.mSettings;
774 mInterpolationSettings = other.mInterpolationSettings;
775 mDataDefinedSizeLegend = std::make_unique<QgsDataDefinedSizeLegend>( *other.mDataDefinedSizeLegend );
787 QList<QgsDiagramSettings> settingsList;
788 settingsList.push_back( mSettings );
801 return mSettings.categoryAttributes;
807 if ( mInterpolationSettings.classificationAttributeIsExpression )
809 QgsExpression *expression =
mDiagram->getExpression( mInterpolationSettings.classificationAttributeExpression, context );
811 for (
const QString &field : constReferencedColumns )
818 referenced << mInterpolationSettings.classificationField;
825 return mDiagram->diagramSize( feature,
c, mSettings, mInterpolationSettings );
830 mInterpolationSettings.lowerValue = elem.attribute( QStringLiteral(
"lowerValue" ) ).toDouble();
831 mInterpolationSettings.upperValue = elem.attribute( QStringLiteral(
"upperValue" ) ).toDouble();
832 mInterpolationSettings.lowerSize.setWidth( elem.attribute( QStringLiteral(
"lowerWidth" ) ).toDouble() );
833 mInterpolationSettings.lowerSize.setHeight( elem.attribute( QStringLiteral(
"lowerHeight" ) ).toDouble() );
834 mInterpolationSettings.upperSize.setWidth( elem.attribute( QStringLiteral(
"upperWidth" ) ).toDouble() );
835 mInterpolationSettings.upperSize.setHeight( elem.attribute( QStringLiteral(
"upperHeight" ) ).toDouble() );
836 mInterpolationSettings.classificationAttributeIsExpression = elem.hasAttribute( QStringLiteral(
"classificationAttributeExpression" ) );
837 if ( mInterpolationSettings.classificationAttributeIsExpression )
839 mInterpolationSettings.classificationAttributeExpression = elem.attribute( QStringLiteral(
"classificationAttributeExpression" ) );
843 mInterpolationSettings.classificationField = elem.attribute( QStringLiteral(
"classificationField" ) );
845 const QDomElement settingsElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
846 if ( !settingsElem.isNull() )
848 mSettings.readXml( settingsElem );
851 mDataDefinedSizeLegend.reset( );
853 const QDomElement ddsLegendSizeElem = elem.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
854 if ( !ddsLegendSizeElem.isNull() )
861 if ( elem.attribute( QStringLiteral(
"sizeLegend" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) )
863 mDataDefinedSizeLegend = std::make_unique<QgsDataDefinedSizeLegend>();
864 const QDomElement sizeLegendSymbolElem = elem.firstChildElement( QStringLiteral(
"symbol" ) );
865 if ( !sizeLegendSymbolElem.isNull() && sizeLegendSymbolElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"sizeSymbol" ) )
872 mDataDefinedSizeLegend =
nullptr;
881 QDomElement rendererElem = doc.createElement( QStringLiteral(
"LinearlyInterpolatedDiagramRenderer" ) );
882 rendererElem.setAttribute( QStringLiteral(
"lowerValue" ), QString::number( mInterpolationSettings.lowerValue ) );
883 rendererElem.setAttribute( QStringLiteral(
"upperValue" ), QString::number( mInterpolationSettings.upperValue ) );
884 rendererElem.setAttribute( QStringLiteral(
"lowerWidth" ), QString::number( mInterpolationSettings.lowerSize.width() ) );
885 rendererElem.setAttribute( QStringLiteral(
"lowerHeight" ), QString::number( mInterpolationSettings.lowerSize.height() ) );
886 rendererElem.setAttribute( QStringLiteral(
"upperWidth" ), QString::number( mInterpolationSettings.upperSize.width() ) );
887 rendererElem.setAttribute( QStringLiteral(
"upperHeight" ), QString::number( mInterpolationSettings.upperSize.height() ) );
888 if ( mInterpolationSettings.classificationAttributeIsExpression )
890 rendererElem.setAttribute( QStringLiteral(
"classificationAttributeExpression" ), mInterpolationSettings.classificationAttributeExpression );
894 rendererElem.setAttribute( QStringLiteral(
"classificationField" ), mInterpolationSettings.classificationField );
896 mSettings.writeXml( rendererElem, doc );
898 if ( mDataDefinedSizeLegend )
900 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
901 mDataDefinedSizeLegend->writeXml( ddsLegendElem, context );
902 rendererElem.appendChild( ddsLegendElem );
906 layerElem.appendChild( rendererElem );
913 , mSettings( other.mSettings )
914 , mDiagramRenderers()
919 mDiagramRenderers << renderer->clone();
925 if ( &other ==
this )
928 mSettings = other.mSettings;
929 qDeleteAll( mDiagramRenderers );
930 mDiagramRenderers.clear();
934 mDiagramRenderers <<
renderer->clone();
942 qDeleteAll( mDiagramRenderers );
952 QSizeF stackedSize( 0, 0 );
953 int enabledDiagramCount = 0;
960 QSizeF size = subRenderer->sizeMapUnits( feature,
c );
962 if ( size.isValid() )
964 enabledDiagramCount++;
965 switch ( mSettings.stackedDiagramMode )
968 stackedSize.setWidth( stackedSize.width() + size.width() );
969 stackedSize.setHeight( std::max( stackedSize.height(), size.height() ) );
973 stackedSize.setWidth( std::max( stackedSize.width(), size.width() ) );
974 stackedSize.setHeight( stackedSize.height() + size.height() );
980 if ( stackedSize.isValid() )
982 const double spacing =
c.convertToMapUnits( mSettings.stackedDiagramSpacing(), mSettings.stackedDiagramSpacingUnit(), mSettings.stackedDiagramSpacingMapUnitScale() );
984 switch ( mSettings.stackedDiagramMode )
987 stackedSize.scale( stackedSize.width() + spacing * ( enabledDiagramCount - 1 ), stackedSize.height(), Qt::IgnoreAspectRatio );
991 stackedSize.scale( stackedSize.width(), stackedSize.height() + spacing * ( enabledDiagramCount - 1 ), Qt::IgnoreAspectRatio );
1005 QPointF newPos = pos;
1008 const QList< QgsDiagramRenderer * > stackedRenderers =
renderers(
true );
1015 stackedRenderer->renderDiagram( feature,
c, newPos, properties );
1020 if ( !stackedRenderer->diagramSettings( feature,
c, s ) )
1033 const double rendererScale =
c.rendererScale();
1056 c.expressionContext().setOriginalValueVariable( s.
penWidth );
1063 std::unique_ptr< QgsEffectPainter > effectPainter;
1064 if ( effect && effect->
enabled() )
1066 effectPainter = std::make_unique< QgsEffectPainter >(
c, effect );
1069 stackedRenderer->diagram()->renderDiagram( feature,
c, s, newPos );
1087 return QSizeF( 0, 0 );
1092 QList<QgsDiagramSettings> settingsList;
1093 settingsList.push_back( mSettings );
1094 return settingsList;
1099 return mSettings.categoryAttributes;
1104 QList< QgsLayerTreeModelLegendNode * > nodes;
1107 nodes <<
renderer->legendItems( nodeLayer );
1115 QList< QgsDiagramRenderer * >
renderers = mDiagramRenderers;
1130 mDiagramRenderers.append(
renderer );
1136 return mDiagramRenderers.value( index );
1141 return mDiagramRenderers.size();
1146 const QDomElement categoryElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
1147 if ( categoryElem.isNull() )
1152 mSettings.
readXml( categoryElem, context );
1159 qDeleteAll( mDiagramRenderers );
1160 mDiagramRenderers.clear();
1162 const QDomElement subRenderersElem = elem.firstChildElement( QStringLiteral(
"DiagramRenderers" ) );
1164 if ( !subRenderersElem.isNull() )
1166 const QDomNodeList childRendererList = subRenderersElem.childNodes();
1168 for (
int i = 0; i < childRendererList.size(); i++ )
1170 const QDomElement subRendererElem = childRendererList.at( i ).toElement();
1172 if ( subRendererElem.nodeName() == QLatin1String(
"SingleCategoryDiagramRenderer" ) )
1174 auto singleCatDiagramRenderer = std::make_unique< QgsSingleCategoryDiagramRenderer >();
1175 singleCatDiagramRenderer->readXml( subRendererElem, context );
1176 addRenderer( singleCatDiagramRenderer.release() );
1178 else if ( subRendererElem.nodeName() == QLatin1String(
"LinearlyInterpolatedDiagramRenderer" ) )
1180 auto linearDiagramRenderer = std::make_unique< QgsLinearlyInterpolatedDiagramRenderer >();
1181 linearDiagramRenderer->readXml( subRendererElem, context );
1184 else if ( subRendererElem.nodeName() == QLatin1String(
"StackedDiagramRenderer" ) )
1186 auto stackedDiagramRenderer = std::make_unique< QgsStackedDiagramRenderer >();
1187 stackedDiagramRenderer->readXml( subRendererElem, context );
1196 QDomElement rendererElem = doc.createElement( QStringLiteral(
"StackedDiagramRenderer" ) );
1197 mSettings.writeXml( rendererElem, doc, context );
1198 _writeXml( rendererElem, doc, context );
1200 layerElem.appendChild( rendererElem );
1205 QDomElement renderersElem = doc.createElement( QStringLiteral(
"DiagramRenderers" ) );
1208 for (
int i = 0; i < mDiagramRenderers.count(); i++ )
1210 mDiagramRenderers.at( i )->writeXml( renderersElem, doc, context );
1212 rendererElem.appendChild( renderersElem );
1217 QList< QgsLayerTreeModelLegendNode * > list;
1221 QPixmap pix( 16, 16 );
1230 return mAxisLineSymbol.get();
1251 return mPaintEffect.get();
1256 if ( effect != mPaintEffect.get() )
1257 mPaintEffect.reset( effect );
1292 , mSpacing( other.mSpacing )
1293 , mSpacingUnit( other.mSpacingUnit )
1294 , mSpacingMapUnitScale( other.mSpacingMapUnitScale )
1295 , mStackedDiagramSpacing( other.mStackedDiagramSpacing )
1296 , mStackedDiagramSpacingUnit( other.mStackedDiagramSpacingUnit )
1297 , mStackedDiagramSpacingMapUnitScale( other.mStackedDiagramSpacingMapUnitScale )
1298 , mDirection( other.mDirection )
1299 , mShowAxis( other.mShowAxis )
1300 , mAxisLineSymbol( other.mAxisLineSymbol ? other.mAxisLineSymbol->clone() : nullptr )
1301 , mPaintEffect( other.mPaintEffect ? other.mPaintEffect->clone() : nullptr )
1308 if ( &other ==
this )
1335 mSpacing = other.mSpacing;
1336 mSpacingUnit = other.mSpacingUnit;
1337 mSpacingMapUnitScale = other.mSpacingMapUnitScale;
1338 mStackedDiagramSpacing = other.mStackedDiagramSpacing;
1339 mStackedDiagramSpacingUnit = other.mStackedDiagramSpacingUnit;
1340 mStackedDiagramSpacingMapUnitScale = other.mStackedDiagramSpacingMapUnitScale;
1341 mDirection = other.mDirection;
1342 mAxisLineSymbol.reset( other.mAxisLineSymbol ? other.mAxisLineSymbol->clone() :
nullptr );
1343 mShowAxis = other.mShowAxis;
1344 mPaintEffect.reset( other.mPaintEffect ? other.mPaintEffect->clone() :
nullptr );
1360 return QList< QgsLayerTreeModelLegendNode * >();
1365 QList< QgsLayerTreeModelLegendNode * > nodes;
1367 nodes = mSettings.legendItems( nodeLayer );
1374 QList< QgsLayerTreeModelLegendNode * > nodes;
1375 if ( !mSettings.enabled )
1381 nodes = mSettings.legendItems( nodeLayer );
1383 if ( mDataDefinedSizeLegend &&
mDiagram )
1393 QList<QgsDataDefinedSizeLegend::SizeClass> sizeClasses;
1394 if ( ddSizeLegend.
classes().isEmpty() )
1398 for (
const double v : prettyBreaks )
1400 const double size =
mDiagram->legendSize( v, mSettings, mInterpolationSettings );
1407 const auto constClasses = ddSizeLegend.
classes();
1410 const double size =
mDiagram->legendSize( sc.size, mSettings, mInterpolationSettings );
1419 if (
auto *lDataDefinedSizeLegendSettings = si.dataDefinedSizeLegendSettings() )
1431 mDataDefinedSizeLegend.reset( settings );
1437 return mDataDefinedSizeLegend.get();
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
A legend node with a marker symbol.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
QList< QgsDataDefinedSizeLegend::SizeClass > classes() const
Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label.
void setSymbol(QgsMarkerSymbol *symbol SIP_TRANSFER)
Sets marker symbol that will be used to draw markers in legend.
void setClasses(const QList< QgsDataDefinedSizeLegend::SizeClass > &classes)
Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label.
static QgsDataDefinedSizeLegend * readXml(const QDomElement &elem, const QgsReadWriteContext &context) SIP_FACTORY
Creates instance from given element and returns it (caller takes ownership). Returns nullptr on error...
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
LinePlacementFlag
Line placement flags for controlling line based placements.
QgsDiagramLayerSettings & operator=(const QgsDiagramLayerSettings &rh)
void setRenderer(QgsDiagramRenderer *diagramRenderer)
Sets the diagram renderer associated with the layer.
~QgsDiagramLayerSettings()
@ PositionX
X-coordinate data defined diagram position.
@ Distance
Distance to diagram from feature.
@ PositionY
Y-coordinate data defined diagram position.
@ Show
Whether to show the diagram.
@ Priority
Diagram priority (between 0 and 10).
@ ZIndex
Z-index for diagram ordering.
@ StrokeColor
Stroke color.
@ BackgroundColor
Diagram background color.
@ StartAngle
Angle offset for pie diagram.
@ IsObstacle
Whether diagram features act as obstacles for other diagrams/labels.
@ StrokeWidth
Stroke width.
@ AlwaysShow
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
void readXml(const QDomElement &elem)
Reads the diagram settings from a DOM element.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the diagram property definitions.
QgsDiagramLayerSettings()
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields referenced by the layer's diagrams.
void writeXml(QDomElement &layerElem, QDomDocument &doc) const
Writes the diagram settings to a DOM element.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the diagrams for a specified expression context.
void setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform associated with the layer.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
virtual QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
virtual QSizeF diagramSize(const QgsFeature &feature, const QgsRenderContext &c) const =0
Returns size of the diagram (in painter units) or an invalid size in case of error.
void _writeXml(QDomElement &rendererElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes internal QgsDiagramRenderer diagram state to a DOM element.
virtual QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields required for diagram rendering.
virtual void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos, const QgsPropertyCollection &properties=QgsPropertyCollection()) const
Renders the diagram for a specified feature at a specific position in the passed render context.
void _readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads internal QgsDiagramRenderer state from a DOM element.
QgsDiagramRenderer & operator=(const QgsDiagramRenderer &other)
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c) const
Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error.
virtual QList< QString > diagramAttributes() const =0
Returns attribute indices needed for diagram rendering.
std::unique_ptr< QgsDiagram > mDiagram
Reference to the object that does the real diagram rendering.
void convertSizeToMapUnits(QSizeF &size, const QgsRenderContext &context) const
Converts size from mm to map units.
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
bool mShowAttributeLegend
Whether to show an attribute legend for the diagrams.
QgsDiagramRenderer()=default
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads diagram state from a DOM element.
void setDiagram(QgsDiagram *d)
virtual QgsDiagramRenderer * clone() const =0
Returns new instance that is equivalent to this one.
static int dpiPaintDevice(const QPainter *)
Returns the paint device dpi (or -1 in case of error.
Stores the settings for rendering a single diagram.
Direction direction() const
Returns the chart's angular direction.
StackedDiagramMode stackedDiagramMode
void setDirection(Direction direction)
Sets the chart's angular direction.
bool showAxis() const
Returns true if the diagram axis should be shown.
LabelPlacementMethod labelPlacementMethod
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads diagram settings from XML.
double opacity
Opacity, from 0 (transparent) to 1.0 (opaque).
QgsDiagramSettings & operator=(const QgsDiagramSettings &other)
QgsLineSymbol * axisLineSymbol() const
Returns the line symbol to use for rendering axis in diagrams.
Qgis::RenderUnit sizeType
Diagram size unit.
QList< QString > categoryAttributes
QList< QString > categoryLabels
DiagramOrientation diagramOrientation
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
QgsMapUnitScale lineSizeScale
Line unit scale.
void writeXml(QDomElement &rendererElem, QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes diagram settings to XML.
QList< QColor > categoryColors
double rotationOffset
Rotation offset, in degrees clockwise from horizontal.
QgsMapUnitScale sizeScale
Diagram size unit scale.
double minimumScale
The minimum map scale (i.e.
bool scaleBasedVisibility
double maximumScale
The maximum map scale (i.e.
void setAxisLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol to use for rendering axis in diagrams.
Qgis::RenderUnit lineSizeUnit
Line unit index.
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
Direction
Angular directions.
void setShowAxis(bool showAxis)
Sets whether the diagram axis should be shown.
void setPaintEffect(QgsPaintEffect *effect)
Sets the paint effect to use while rendering diagrams.
QgsPaintEffect * paintEffect() const
Returns the paint effect to use while rendering diagrams.
Base class for all diagram types.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles parsing and evaluation of expressions (formerly called "search strings").
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
static const QString DIAGRAM_NAME_HISTOGRAM
Layer tree node points to a map layer.
Stores information about one class/rule of a vector layer renderer in a unified way that can be used ...
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLinearlyInterpolatedDiagramRenderer()
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend.
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c) const override
Returns size of the diagram (in painter units) or an invalid size in case of error.
QList< QString > diagramAttributes() const override
Returns attribute indices needed for diagram rendering.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields required for diagram rendering.
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes diagram state to a DOM element.
QgsLinearlyInterpolatedDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads diagram state from a DOM element.
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend.
~QgsLinearlyInterpolatedDiagramRenderer() override
QgsLinearlyInterpolatedDiagramRenderer & operator=(const QgsLinearlyInterpolatedDiagramRenderer &other)
static const QString DIAGRAM_RENDERER_NAME_LINEARLY_INTERPOLATED
double mapUnitsPerPixel() const
Returns the current map units per pixel.
A marker symbol type, for rendering Point and MultiPoint geometries.
static std::unique_ptr< QgsMarkerSymbol > createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
void setSizeMapUnitScale(const QgsMapUnitScale &scale) const
Sets the size map unit scale for the whole symbol (including all symbol layers).
void setSizeUnit(Qgis::RenderUnit unit) const
Sets the size units for the whole symbol (including all symbol layers).
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
Base class for visual effects which can be applied to QPicture drawings.
bool enabled() const
Returns whether the effect is enabled.
static const QString DIAGRAM_NAME_PIE
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
bool hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...
@ Double
Double value (including negative values).
@ StrokeWidth
Line stroke width.
@ Rotation
Rotation (value between 0-360 degrees).
@ ColorWithAlpha
Color with alpha channel.
@ DoublePositive
Positive double value (including 0).
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
static bool equalToOrGreaterThanMinimumScale(const double scale, const double minScale)
Returns whether the scale is equal to or greater than the minScale, taking non-round numbers into acc...
static bool lessThanMaximumScale(const double scale, const double maxScale)
Returns whether the scale is less than the maxScale, taking non-round numbers into account.
Implementation of legend node interface for displaying arbitrary labels with icons.
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c) const override
Returns size of the diagram (in painter units) or an invalid size in case of error.
void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes diagram state to a DOM element.
QgsSingleCategoryDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
QgsSingleCategoryDiagramRenderer()=default
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads diagram state from a DOM element.
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
static const QString DIAGRAM_RENDERER_NAME_SINGLE_CATEGORY
static const QString DIAGRAM_NAME_STACKED_BAR
QgsStackedDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c) const override
Returns size of the diagram (in painter units) or an invalid size in case of error.
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos, const QgsPropertyCollection &properties=QgsPropertyCollection()) const override
Renders the diagram for a specified feature at a specific position in the passed render context,...
QList< QString > diagramAttributes() const override
Returns attribute indices needed for diagram rendering.
void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes diagram state to a DOM element.
static const QString DIAGRAM_RENDERER_NAME_STACKED
QgsStackedDiagramRenderer & operator=(const QgsStackedDiagramRenderer &other)
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads diagram state from a DOM element.
void addRenderer(QgsDiagramRenderer *renderer)
Adds a renderer to the stacked renderer object.
void _writeXmlSubRenderers(QDomElement &rendererElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes stacked renderers state to a DOM element.
QList< QgsDiagramRenderer * > renderers(bool sortByDiagramMode=false) const
Returns an ordered list with the renderers of the stacked renderer object.
const QgsDiagramRenderer * renderer(const int index) const
Returns the renderer at the given index.
void _readXmlSubRenderers(const QDomElement &elem, const QgsReadWriteContext &context)
Reads stacked renderers state from a DOM element.
int rendererCount() const
Returns the number of sub renderers in the stacked diagram renderer.
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
QgsStackedDiagramRenderer()=default
~QgsStackedDiagramRenderer() override
QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c) const override
Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error.
A diagram composed of several subdiagrams, located side by side.
static const QString DIAGRAM_NAME_STACKED
void subDiagramPosition(QPointF &newPos, const QgsRenderContext &c, const QgsDiagramSettings &s, const QgsDiagramSettings &subSettings)
Calculates the position for the next subdiagram, updating the newPos object.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
static const QString DIAGRAM_NAME_TEXT
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition of one class for the legend.