41void QgsDiagramLayerSettings::initPropertyDefinitions()
43 if ( !sPropertyDefinitions.isEmpty() )
46 const QString origin = QStringLiteral(
"diagram" );
67 initPropertyDefinitions();
68 return sPropertyDefinitions;
73 initPropertyDefinitions();
78 , mPlacement( rh.mPlacement )
79 , mPlacementFlags( rh.mPlacementFlags )
80 , mPriority( rh.mPriority )
81 , mZIndex( rh.mZIndex )
82 , mObstacle( rh.mObstacle )
83 , mDistance( rh.mDistance )
84 , mRenderer( rh.mRenderer ? rh.mRenderer->clone() : nullptr )
85 , mShowAll( rh.mShowAll )
86 , mDataDefinedProperties( rh.mDataDefinedProperties )
88 initPropertyDefinitions();
93 mPlacement = rh.mPlacement;
94 mPlacementFlags = rh.mPlacementFlags;
95 mPriority = rh.mPriority;
97 mObstacle = rh.mObstacle;
98 mDistance = rh.mDistance;
99 mRenderer = rh.mRenderer ? rh.mRenderer->
clone() :
nullptr;
101 mShowAll = rh.mShowAll;
102 mDataDefinedProperties = rh.mDataDefinedProperties;
113 if ( diagramRenderer == mRenderer )
117 mRenderer = diagramRenderer;
127 const QDomNodeList propertyElems = elem.elementsByTagName( QStringLiteral(
"properties" ) );
128 if ( !propertyElems.isEmpty() )
130 ( void )mDataDefinedProperties.
readXml( propertyElems.at( 0 ).toElement(), sPropertyDefinitions );
134 mDataDefinedProperties.
clear();
137 mPlacement =
static_cast< Placement >( elem.attribute( QStringLiteral(
"placement" ) ).toInt() );
138 mPlacementFlags =
static_cast< LinePlacementFlag >( elem.attribute( QStringLiteral(
"linePlacementFlags" ) ).toInt() );
139 mPriority = elem.attribute( QStringLiteral(
"priority" ) ).toInt();
140 mZIndex = elem.attribute( QStringLiteral(
"zIndex" ) ).toDouble();
141 mObstacle = elem.attribute( QStringLiteral(
"obstacle" ) ).toInt();
142 mDistance = elem.attribute( QStringLiteral(
"dist" ) ).toDouble();
143 mShowAll = ( elem.attribute( QStringLiteral(
"showAll" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
148 QDomElement diagramLayerElem = doc.createElement( QStringLiteral(
"DiagramLayerSettings" ) );
149 QDomElement propertiesElem = doc.createElement( QStringLiteral(
"properties" ) );
150 ( void )mDataDefinedProperties.
writeXml( propertiesElem, sPropertyDefinitions );
151 diagramLayerElem.appendChild( propertiesElem );
152 diagramLayerElem.setAttribute( QStringLiteral(
"placement" ), mPlacement );
153 diagramLayerElem.setAttribute( QStringLiteral(
"linePlacementFlags" ), mPlacementFlags );
154 diagramLayerElem.setAttribute( QStringLiteral(
"priority" ), mPriority );
155 diagramLayerElem.setAttribute( QStringLiteral(
"zIndex" ), mZIndex );
156 diagramLayerElem.setAttribute( QStringLiteral(
"obstacle" ), mObstacle );
157 diagramLayerElem.setAttribute( QStringLiteral(
"dist" ), QString::number( mDistance ) );
158 diagramLayerElem.setAttribute( QStringLiteral(
"showAll" ), mShowAll );
159 layerElem.appendChild( diagramLayerElem );
164 return mDataDefinedProperties.
prepare( context );
169 QSet< QString > referenced;
181 enabled = ( elem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
184 font.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
186 backgroundColor.setNamedColor( elem.attribute( QStringLiteral(
"backgroundColor" ) ) );
187 backgroundColor.setAlpha( elem.attribute( QStringLiteral(
"backgroundAlpha" ) ).toInt() );
188 size.setWidth( elem.attribute( QStringLiteral(
"width" ) ).toDouble() );
189 size.setHeight( elem.attribute( QStringLiteral(
"height" ) ).toDouble() );
190 if ( elem.hasAttribute( QStringLiteral(
"transparency" ) ) )
192 opacity = 1 - elem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 255.0;
196 opacity = elem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1.00" ) ).toDouble();
199 penColor.setNamedColor( elem.attribute( QStringLiteral(
"penColor" ) ) );
200 const int penAlpha = elem.attribute( QStringLiteral(
"penAlpha" ), QStringLiteral(
"255" ) ).toInt();
202 penWidth = elem.attribute( QStringLiteral(
"penWidth" ) ).toDouble();
204 mDirection =
static_cast< Direction >( elem.attribute( QStringLiteral(
"direction" ), QStringLiteral(
"1" ) ).toInt() );
206 maximumScale = elem.attribute( QStringLiteral(
"minScaleDenominator" ), QStringLiteral(
"-1" ) ).toDouble();
207 minimumScale = elem.attribute( QStringLiteral(
"maxScaleDenominator" ), QStringLiteral(
"-1" ) ).toDouble();
208 if ( elem.hasAttribute( QStringLiteral(
"scaleBasedVisibility" ) ) )
210 scaleBasedVisibility = ( elem.attribute( QStringLiteral(
"scaleBasedVisibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
218 if ( elem.attribute( QStringLiteral(
"sizeType" ) ) == QLatin1String(
"MapUnits" ) )
233 mSpacing = elem.attribute( QStringLiteral(
"spacing" ) ).toDouble();
237 mStackedDiagramSpacing = elem.attribute( QStringLiteral(
"stackedDiagramSpacing" ) ).toDouble();
242 if ( elem.attribute( QStringLiteral(
"labelPlacementMethod" ) ) == QLatin1String(
"Height" ) )
252 if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Left" ) )
256 else if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Right" ) )
260 else if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Down" ) )
270 if ( elem.attribute( QStringLiteral(
"stackedDiagramMode" ) ) == QLatin1String(
"Horizontal" ) )
274 else if ( elem.attribute( QStringLiteral(
"stackedDiagramMode" ) ) == QLatin1String(
"Vertical" ) )
280 if ( elem.attribute( QStringLiteral(
"scaleDependency" ) ) == QLatin1String(
"Diameter" ) )
289 barWidth = elem.attribute( QStringLiteral(
"barWidth" ) ).toDouble();
291 if ( elem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
292 rotationOffset = std::fmod( 360.0 - elem.attribute( QStringLiteral(
"angleOffset" ) ).toInt() / 16.0, 360.0 );
294 rotationOffset = elem.attribute( QStringLiteral(
"rotationOffset" ) ).toDouble();
296 minimumSize = elem.attribute( QStringLiteral(
"minimumSize" ) ).toDouble();
298 const QDomNodeList axisSymbolNodes = elem.elementsByTagName( QStringLiteral(
"axisSymbol" ) );
299 if ( axisSymbolNodes.count() > 0 )
301 const QDomElement axisSymbolElem = axisSymbolNodes.at( 0 ).toElement().firstChildElement();
302 mAxisLineSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( axisSymbolElem, context ) );
306 mAxisLineSymbol = std::make_unique< QgsLineSymbol >();
309 mShowAxis = elem.attribute( QStringLiteral(
"showAxis" ), QStringLiteral(
"0" ) ).toInt();
313 const QDomNodeList attributes = elem.elementsByTagName( QStringLiteral(
"attribute" ) );
316 if ( attributes.length() > 0 )
318 for (
int i = 0; i < attributes.size(); i++ )
320 const QDomElement attrElem = attributes.at( i ).toElement();
321 QColor newColor( attrElem.attribute( QStringLiteral(
"color" ) ) );
322 newColor.setAlphaF( attrElem.attribute( QStringLiteral(
"colorOpacity" ), QStringLiteral(
"1.0" ) ).toDouble() );
325 categoryLabels.append( attrElem.attribute( QStringLiteral(
"label" ) ) );
336 const QStringList colorList = elem.attribute( QStringLiteral(
"colors" ) ).split(
'/' );
337 QStringList::const_iterator colorIt = colorList.constBegin();
338 for ( ; colorIt != colorList.constEnd(); ++colorIt )
340 QColor newColor( *colorIt );
346 const QStringList catList = elem.attribute( QStringLiteral(
"categories" ) ).split(
'/' );
347 QStringList::const_iterator catIt = catList.constBegin();
348 for ( ; catIt != catList.constEnd(); ++catIt )
355 const QDomElement effectElem = elem.firstChildElement( QStringLiteral(
"effect" ) );
356 if ( !effectElem.isNull() )
364 QDomElement categoryElem = doc.createElement( QStringLiteral(
"DiagramCategory" ) );
365 categoryElem.setAttribute( QStringLiteral(
"enabled" ),
enabled );
367 categoryElem.setAttribute( QStringLiteral(
"backgroundColor" ),
backgroundColor.name() );
368 categoryElem.setAttribute( QStringLiteral(
"backgroundAlpha" ),
backgroundColor.alpha() );
369 categoryElem.setAttribute( QStringLiteral(
"width" ), QString::number(
size.width() ) );
370 categoryElem.setAttribute( QStringLiteral(
"height" ), QString::number(
size.height() ) );
371 categoryElem.setAttribute( QStringLiteral(
"penColor" ),
penColor.name() );
372 categoryElem.setAttribute( QStringLiteral(
"penAlpha" ),
penColor.alpha() );
373 categoryElem.setAttribute( QStringLiteral(
"penWidth" ), QString::number(
penWidth ) );
375 categoryElem.setAttribute( QStringLiteral(
"minScaleDenominator" ), QString::number(
maximumScale ) );
376 categoryElem.setAttribute( QStringLiteral(
"maxScaleDenominator" ), QString::number(
minimumScale ) );
377 categoryElem.setAttribute( QStringLiteral(
"opacity" ), QString::number(
opacity ) );
378 categoryElem.setAttribute( QStringLiteral(
"spacing" ), QString::number( mSpacing ) );
381 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramSpacing" ), QString::number( mStackedDiagramSpacing ) );
382 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramSpacingUnit" ),
QgsUnitTypes::encodeUnit( mStackedDiagramSpacingUnit ) );
384 categoryElem.setAttribute( QStringLiteral(
"direction" ), QString::number( mDirection ) );
397 categoryElem.setAttribute( QStringLiteral(
"labelPlacementMethod" ), QStringLiteral(
"Height" ) );
401 categoryElem.setAttribute( QStringLiteral(
"labelPlacementMethod" ), QStringLiteral(
"XHeight" ) );
406 categoryElem.setAttribute( QStringLiteral(
"scaleDependency" ), QStringLiteral(
"Area" ) );
410 categoryElem.setAttribute( QStringLiteral(
"scaleDependency" ), QStringLiteral(
"Diameter" ) );
417 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Left" ) );
421 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Right" ) );
425 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Down" ) );
429 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Up" ) );
437 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramMode" ), QStringLiteral(
"Horizontal" ) );
441 categoryElem.setAttribute( QStringLiteral(
"stackedDiagramMode" ), QStringLiteral(
"Vertical" ) );
445 categoryElem.setAttribute( QStringLiteral(
"barWidth" ), QString::number(
barWidth ) );
446 categoryElem.setAttribute( QStringLiteral(
"minimumSize" ), QString::number(
minimumSize ) );
447 categoryElem.setAttribute( QStringLiteral(
"rotationOffset" ), QString::number(
rotationOffset ) );
450 for (
int i = 0; i < nCats; ++i )
452 QDomElement attributeElem = doc.createElement( QStringLiteral(
"attribute" ) );
455 attributeElem.setAttribute( QStringLiteral(
"color" ),
categoryColors.at( i ).name() );
456 attributeElem.setAttribute( QStringLiteral(
"colorOpacity" ), QString::number(
categoryColors.at( i ).alphaF() ) );
457 attributeElem.setAttribute( QStringLiteral(
"label" ),
categoryLabels.at( i ) );
458 categoryElem.appendChild( attributeElem );
461 categoryElem.setAttribute( QStringLiteral(
"showAxis" ), mShowAxis ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
462 QDomElement axisSymbolElem = doc.createElement( QStringLiteral(
"axisSymbol" ) );
464 axisSymbolElem.appendChild( symbolElem );
465 categoryElem.appendChild( axisSymbolElem );
468 mPaintEffect->saveProperties( doc, categoryElem );
470 rendererElem.appendChild( categoryElem );
482 : mDiagram( other.mDiagram ? other.mDiagram->clone() : nullptr )
483 , mShowAttributeLegend( other.mShowAttributeLegend )
513 c.expressionContext().setOriginalValueVariable( s.
penWidth );
520 std::unique_ptr< QgsEffectPainter > effectPainter;
521 if ( effect && effect->
enabled() )
523 effectPainter = std::make_unique< QgsEffectPainter >(
c, effect );
526 mDiagram->renderDiagram( feature,
c, s, pos );
540 const double rendererScale =
c.rendererScale();
558 if ( size.isValid() )
561 size.rheight() *= width / size.width();
562 size.setWidth( width );
569 QSet< QString > referenced;
575 for (
const QString &att : constDiagramAttributes )
579 for (
const QString &field : constReferencedColumns )
589 if ( !size.isValid() )
595 size.rwidth() *= pixelToMap;
596 size.rheight() *= pixelToMap;
603 QPaintDevice *device = painter->device();
606 return device->logicalDpiX();
616 const QString diagramType = elem.attribute( QStringLiteral(
"diagramType" ) );
642 mShowAttributeLegend = ( elem.attribute( QStringLiteral(
"attributeLegend" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
652 rendererElem.setAttribute( QStringLiteral(
"diagramType" ),
mDiagram->diagramName() );
678 QList<QgsDiagramSettings> settingsList;
679 settingsList.push_back( mSettings );
685 const QDomElement categoryElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
686 if ( categoryElem.isNull() )
691 mSettings.
readXml( categoryElem, context );
697 QDomElement rendererElem = doc.createElement( QStringLiteral(
"SingleCategoryDiagramRenderer" ) );
698 mSettings.
writeXml( rendererElem, doc, context );
700 layerElem.appendChild( rendererElem );
712 , mSettings( other.mSettings )
713 , mInterpolationSettings( other.mInterpolationSettings )
714 , mDataDefinedSizeLegend( other.mDataDefinedSizeLegend ? new
QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegend ) : nullptr )
720 delete mDataDefinedSizeLegend;
725 if ( &other ==
this )
729 mSettings = other.mSettings;
730 mInterpolationSettings = other.mInterpolationSettings;
731 delete mDataDefinedSizeLegend;
743 QList<QgsDiagramSettings> settingsList;
744 settingsList.push_back( mSettings );
767 for (
const QString &field : constReferencedColumns )
781 return mDiagram->diagramSize( feature,
c, mSettings, mInterpolationSettings );
786 mInterpolationSettings.
lowerValue = elem.attribute( QStringLiteral(
"lowerValue" ) ).toDouble();
787 mInterpolationSettings.
upperValue = elem.attribute( QStringLiteral(
"upperValue" ) ).toDouble();
788 mInterpolationSettings.
lowerSize.setWidth( elem.attribute( QStringLiteral(
"lowerWidth" ) ).toDouble() );
789 mInterpolationSettings.
lowerSize.setHeight( elem.attribute( QStringLiteral(
"lowerHeight" ) ).toDouble() );
790 mInterpolationSettings.
upperSize.setWidth( elem.attribute( QStringLiteral(
"upperWidth" ) ).toDouble() );
791 mInterpolationSettings.
upperSize.setHeight( elem.attribute( QStringLiteral(
"upperHeight" ) ).toDouble() );
799 mInterpolationSettings.
classificationField = elem.attribute( QStringLiteral(
"classificationField" ) );
801 const QDomElement settingsElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
802 if ( !settingsElem.isNull() )
804 mSettings.
readXml( settingsElem );
807 delete mDataDefinedSizeLegend;
809 const QDomElement ddsLegendSizeElem = elem.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
810 if ( !ddsLegendSizeElem.isNull() )
817 if ( elem.attribute( QStringLiteral(
"sizeLegend" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) )
820 const QDomElement sizeLegendSymbolElem = elem.firstChildElement( QStringLiteral(
"symbol" ) );
821 if ( !sizeLegendSymbolElem.isNull() && sizeLegendSymbolElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"sizeSymbol" ) )
823 mDataDefinedSizeLegend->
setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( sizeLegendSymbolElem, context ) );
828 mDataDefinedSizeLegend =
nullptr;
837 QDomElement rendererElem = doc.createElement( QStringLiteral(
"LinearlyInterpolatedDiagramRenderer" ) );
838 rendererElem.setAttribute( QStringLiteral(
"lowerValue" ), QString::number( mInterpolationSettings.
lowerValue ) );
839 rendererElem.setAttribute( QStringLiteral(
"upperValue" ), QString::number( mInterpolationSettings.
upperValue ) );
840 rendererElem.setAttribute( QStringLiteral(
"lowerWidth" ), QString::number( mInterpolationSettings.
lowerSize.width() ) );
841 rendererElem.setAttribute( QStringLiteral(
"lowerHeight" ), QString::number( mInterpolationSettings.
lowerSize.height() ) );
842 rendererElem.setAttribute( QStringLiteral(
"upperWidth" ), QString::number( mInterpolationSettings.
upperSize.width() ) );
843 rendererElem.setAttribute( QStringLiteral(
"upperHeight" ), QString::number( mInterpolationSettings.
upperSize.height() ) );
850 rendererElem.setAttribute( QStringLiteral(
"classificationField" ), mInterpolationSettings.
classificationField );
852 mSettings.
writeXml( rendererElem, doc );
854 if ( mDataDefinedSizeLegend )
856 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
857 mDataDefinedSizeLegend->
writeXml( ddsLegendElem, context );
858 rendererElem.appendChild( ddsLegendElem );
862 layerElem.appendChild( rendererElem );
869 , mSettings( other.mSettings )
870 , mDiagramRenderers()
881 mSettings = other.mSettings;
882 qDeleteAll( mDiagramRenderers );
883 mDiagramRenderers.clear();
895 qDeleteAll( mDiagramRenderers );
905 QSizeF stackedSize( 0, 0 );
906 int enabledDiagramCount = 0;
913 QSizeF size = subRenderer->sizeMapUnits( feature,
c );
915 if ( size.isValid() )
917 enabledDiagramCount++;
921 stackedSize.setWidth( stackedSize.width() + size.width() );
922 stackedSize.setHeight( std::max( stackedSize.height(), size.height() ) );
926 stackedSize.setWidth( std::max( stackedSize.width(), size.width() ) );
927 stackedSize.setHeight( stackedSize.height() + size.height() );
933 if ( stackedSize.isValid() )
940 stackedSize.scale( stackedSize.width() + spacing * ( enabledDiagramCount - 1 ), stackedSize.height(), Qt::IgnoreAspectRatio );
944 stackedSize.scale( stackedSize.width(), stackedSize.height() + spacing * ( enabledDiagramCount - 1 ), Qt::IgnoreAspectRatio );
958 QPointF newPos = pos;
961 const QList< QgsDiagramRenderer * > stackedRenderers =
renderers(
true );
968 stackedRenderer->renderDiagram( feature,
c, newPos, properties );
973 if ( !stackedRenderer->diagramSettings( feature,
c, s ) )
986 const double rendererScale =
c.rendererScale();
1009 c.expressionContext().setOriginalValueVariable( s.
penWidth );
1016 std::unique_ptr< QgsEffectPainter > effectPainter;
1017 if ( effect && effect->
enabled() )
1019 effectPainter = std::make_unique< QgsEffectPainter >(
c, effect );
1022 stackedRenderer->diagram()->renderDiagram( feature,
c, s, newPos );
1040 return QSizeF( 0, 0 );
1045 QList<QgsDiagramSettings> settingsList;
1046 settingsList.push_back( mSettings );
1047 return settingsList;
1057 QList< QgsLayerTreeModelLegendNode * > nodes;
1068 QList< QgsDiagramRenderer * >
renderers = mDiagramRenderers;
1083 mDiagramRenderers.append(
renderer );
1089 return mDiagramRenderers.value( index );
1094 return mDiagramRenderers.size();
1099 const QDomElement categoryElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
1100 if ( categoryElem.isNull() )
1105 mSettings.
readXml( categoryElem, context );
1112 qDeleteAll( mDiagramRenderers );
1113 mDiagramRenderers.clear();
1115 const QDomElement subRenderersElem = elem.firstChildElement( QStringLiteral(
"DiagramRenderers" ) );
1117 if ( !subRenderersElem.isNull() )
1119 const QDomNodeList childRendererList = subRenderersElem.childNodes();
1121 for (
int i = 0; i < childRendererList.size(); i++ )
1123 const QDomElement subRendererElem = childRendererList.at( i ).toElement();
1125 if ( subRendererElem.nodeName() == QStringLiteral(
"SingleCategoryDiagramRenderer" ) )
1127 std::unique_ptr< QgsSingleCategoryDiagramRenderer > singleCatDiagramRenderer = std::make_unique< QgsSingleCategoryDiagramRenderer >();
1128 singleCatDiagramRenderer->readXml( subRendererElem, context );
1129 addRenderer( singleCatDiagramRenderer.release() );
1131 else if ( subRendererElem.nodeName() == QStringLiteral(
"LinearlyInterpolatedDiagramRenderer" ) )
1133 std::unique_ptr< QgsLinearlyInterpolatedDiagramRenderer > linearDiagramRenderer = std::make_unique< QgsLinearlyInterpolatedDiagramRenderer >();
1134 linearDiagramRenderer->readXml( subRendererElem, context );
1137 else if ( subRendererElem.nodeName() == QStringLiteral(
"StackedDiagramRenderer" ) )
1139 std::unique_ptr< QgsStackedDiagramRenderer > stackedDiagramRenderer = std::make_unique< QgsStackedDiagramRenderer >();
1140 stackedDiagramRenderer->readXml( subRendererElem, context );
1149 QDomElement rendererElem = doc.createElement( QStringLiteral(
"StackedDiagramRenderer" ) );
1150 mSettings.
writeXml( rendererElem, doc, context );
1151 _writeXml( rendererElem, doc, context );
1153 layerElem.appendChild( rendererElem );
1158 QDomElement renderersElem = doc.createElement( QStringLiteral(
"DiagramRenderers" ) );
1161 for (
int i = 0; i < mDiagramRenderers.count(); i++ )
1163 mDiagramRenderers.at( i )->writeXml( renderersElem, doc, context );
1165 rendererElem.appendChild( renderersElem );
1170 QList< QgsLayerTreeModelLegendNode * > list;
1174 QPixmap pix( 16, 16 );
1183 return mAxisLineSymbol.get();
1204 return mPaintEffect.get();
1209 if ( effect != mPaintEffect.get() )
1210 mPaintEffect.reset( effect );
1221 : enabled( other.enabled )
1222 , font( other.font )
1223 , categoryColors( other.categoryColors )
1224 , categoryAttributes( other.categoryAttributes )
1225 , categoryLabels( other.categoryLabels )
1226 , size( other.size )
1227 , sizeType( other.sizeType )
1228 , sizeScale( other.sizeScale )
1229 , lineSizeUnit( other.lineSizeUnit )
1230 , lineSizeScale( other.lineSizeScale )
1231 , backgroundColor( other.backgroundColor )
1232 , penColor( other.penColor )
1233 , penWidth( other.penWidth )
1234 , labelPlacementMethod( other.labelPlacementMethod )
1235 , diagramOrientation( other.diagramOrientation )
1236 , stackedDiagramMode( other.stackedDiagramMode )
1237 , barWidth( other.barWidth )
1238 , opacity( other.opacity )
1239 , scaleByArea( other.scaleByArea )
1240 , rotationOffset( other.rotationOffset )
1241 , scaleBasedVisibility( other.scaleBasedVisibility )
1242 , maximumScale( other.maximumScale )
1243 , minimumScale( other.minimumScale )
1244 , minimumSize( other.minimumSize )
1245 , mSpacing( other.mSpacing )
1246 , mSpacingUnit( other.mSpacingUnit )
1247 , mSpacingMapUnitScale( other.mSpacingMapUnitScale )
1248 , mStackedDiagramSpacing( other.mStackedDiagramSpacing )
1249 , mStackedDiagramSpacingUnit( other.mStackedDiagramSpacingUnit )
1250 , mStackedDiagramSpacingMapUnitScale( other.mStackedDiagramSpacingMapUnitScale )
1251 , mDirection( other.mDirection )
1252 , mShowAxis( other.mShowAxis )
1253 , mAxisLineSymbol( other.mAxisLineSymbol ? other.mAxisLineSymbol->clone() : nullptr )
1254 , mPaintEffect( other.mPaintEffect ? other.mPaintEffect->clone() : nullptr )
1285 mSpacing = other.mSpacing;
1286 mSpacingUnit = other.mSpacingUnit;
1287 mSpacingMapUnitScale = other.mSpacingMapUnitScale;
1288 mStackedDiagramSpacing = other.mStackedDiagramSpacing;
1289 mStackedDiagramSpacingUnit = other.mStackedDiagramSpacingUnit;
1290 mStackedDiagramSpacingMapUnitScale = other.mStackedDiagramSpacingMapUnitScale;
1291 mDirection = other.mDirection;
1292 mAxisLineSymbol.reset( other.mAxisLineSymbol ? other.mAxisLineSymbol->clone() : nullptr );
1293 mShowAxis = other.mShowAxis;
1294 mPaintEffect.reset( other.mPaintEffect ? other.mPaintEffect->clone() : nullptr );
1310 return QList< QgsLayerTreeModelLegendNode * >();
1315 QList< QgsLayerTreeModelLegendNode * > nodes;
1324 QList< QgsLayerTreeModelLegendNode * > nodes;
1333 if ( mDataDefinedSizeLegend &&
mDiagram )
1343 QList<QgsDataDefinedSizeLegend::SizeClass> sizeClasses;
1344 if ( ddSizeLegend.
classes().isEmpty() )
1348 for (
const double v : prettyBreaks )
1350 const double size =
mDiagram->legendSize( v, mSettings, mInterpolationSettings );
1357 const auto constClasses = ddSizeLegend.
classes();
1360 const double size =
mDiagram->legendSize( sc.size, mSettings, mInterpolationSettings );
1369 if (
auto *lDataDefinedSizeLegendSettings = si.dataDefinedSizeLegendSettings() )
1381 delete mDataDefinedSizeLegend;
1382 mDataDefinedSizeLegend = settings;
1387 return mDataDefinedSizeLegend;
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.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
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.
Produces 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.
QgsMarkerSymbol * symbol() const
Returns 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...
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes configuration to the given XML element.
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
bool classificationAttributeIsExpression
QString classificationField
Name of the field for classification.
QString classificationAttributeExpression
Stores the settings for rendering of all diagrams for a layer.
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
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
Qgis::RenderUnit stackedDiagramSpacingUnit() const
Returns the units for the spacing between subdiagrams in a stacked diagram.
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.
const QgsMapUnitScale & stackedDiagramSpacingMapUnitScale() const
Returns the map unit scale for the spacing between subdiagrams in a stacked diagram.
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.
double stackedDiagramSpacing() const
Returns the spacing between subdiagrams in a stacked diagram.
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...
Class for 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.
A histogram style diagram.
static const QString DIAGRAM_NAME_HISTOGRAM
Layer tree node points to a map layer.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
A line symbol type, for rendering LineString and MultiLineString geometries.
Alters the size of rendered diagrams using a linear scaling.
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 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 a integer key value.
void clear() final
Removes all properties from the collection.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const final
Prepares the collection against a specified expression context.
bool hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const final
Returns the set of any fields referenced by the active properties from the collection.
Definition for a property.
@ 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)
The class is used as a container of context for various read/write operations on other 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 label with icon.
Renders the diagrams for all features with the same settings.
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
A stacked bar chart diagram.
static const QString DIAGRAM_NAME_STACKED_BAR
Renders diagrams using mixed diagram render types.
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.
virtual 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
virtual 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 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.