31 #include <QDomElement> 36 void QgsDiagramLayerSettings::initPropertyDefinitions()
38 if ( !sPropertyDefinitions.isEmpty() )
41 const QString origin = QStringLiteral(
"diagram" );
62 initPropertyDefinitions();
63 return sPropertyDefinitions;
68 initPropertyDefinitions();
73 , mPlacement( rh.mPlacement )
74 , mPlacementFlags( rh.mPlacementFlags )
75 , mPriority( rh.mPriority )
76 , mZIndex( rh.mZIndex )
77 , mObstacle( rh.mObstacle )
78 , mDistance( rh.mDistance )
79 , mRenderer( rh.mRenderer ? rh.mRenderer->clone() : nullptr )
80 , mShowAll( rh.mShowAll )
81 , mDataDefinedProperties( rh.mDataDefinedProperties )
83 initPropertyDefinitions();
88 mPlacement = rh.mPlacement;
89 mPlacementFlags = rh.mPlacementFlags;
90 mPriority = rh.mPriority;
92 mObstacle = rh.mObstacle;
93 mDistance = rh.mDistance;
94 mRenderer = rh.mRenderer ? rh.mRenderer->
clone() :
nullptr;
96 mShowAll = rh.mShowAll;
97 mDataDefinedProperties = rh.mDataDefinedProperties;
108 if ( diagramRenderer == mRenderer )
112 mRenderer = diagramRenderer;
122 QDomNodeList propertyElems = elem.elementsByTagName( QStringLiteral(
"properties" ) );
123 if ( !propertyElems.isEmpty() )
125 ( void )mDataDefinedProperties.
readXml( propertyElems.at( 0 ).toElement(), sPropertyDefinitions );
129 mDataDefinedProperties.
clear();
132 mPlacement =
static_cast< Placement >( elem.attribute( QStringLiteral(
"placement" ) ).toInt() );
133 mPlacementFlags =
static_cast< LinePlacementFlag >( elem.attribute( QStringLiteral(
"linePlacementFlags" ) ).toInt() );
134 mPriority = elem.attribute( QStringLiteral(
"priority" ) ).toInt();
135 mZIndex = elem.attribute( QStringLiteral(
"zIndex" ) ).toDouble();
136 mObstacle = elem.attribute( QStringLiteral(
"obstacle" ) ).toInt();
137 mDistance = elem.attribute( QStringLiteral(
"dist" ) ).toDouble();
138 mShowAll = ( elem.attribute( QStringLiteral(
"showAll" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
143 QDomElement diagramLayerElem = doc.createElement( QStringLiteral(
"DiagramLayerSettings" ) );
144 QDomElement propertiesElem = doc.createElement( QStringLiteral(
"properties" ) );
145 ( void )mDataDefinedProperties.
writeXml( propertiesElem, sPropertyDefinitions );
146 diagramLayerElem.appendChild( propertiesElem );
147 diagramLayerElem.setAttribute( QStringLiteral(
"placement" ), mPlacement );
148 diagramLayerElem.setAttribute( QStringLiteral(
"linePlacementFlags" ), mPlacementFlags );
149 diagramLayerElem.setAttribute( QStringLiteral(
"priority" ), mPriority );
150 diagramLayerElem.setAttribute( QStringLiteral(
"zIndex" ), mZIndex );
151 diagramLayerElem.setAttribute( QStringLiteral(
"obstacle" ), mObstacle );
152 diagramLayerElem.setAttribute( QStringLiteral(
"dist" ), QString::number( mDistance ) );
153 diagramLayerElem.setAttribute( QStringLiteral(
"showAll" ), mShowAll );
154 layerElem.appendChild( diagramLayerElem );
159 return mDataDefinedProperties.
prepare( context );
164 QSet< QString > referenced;
176 enabled = ( elem.attribute( QStringLiteral(
"enabled" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
179 font.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
181 backgroundColor.setNamedColor( elem.attribute( QStringLiteral(
"backgroundColor" ) ) );
182 backgroundColor.setAlpha( elem.attribute( QStringLiteral(
"backgroundAlpha" ) ).toInt() );
183 size.setWidth( elem.attribute( QStringLiteral(
"width" ) ).toDouble() );
184 size.setHeight( elem.attribute( QStringLiteral(
"height" ) ).toDouble() );
185 if ( elem.hasAttribute( QStringLiteral(
"transparency" ) ) )
187 opacity = 1 - elem.attribute( QStringLiteral(
"transparency" ), QStringLiteral(
"0" ) ).toInt() / 255.0;
191 opacity = elem.attribute( QStringLiteral(
"opacity" ), QStringLiteral(
"1.00" ) ).toDouble();
194 penColor.setNamedColor( elem.attribute( QStringLiteral(
"penColor" ) ) );
195 int penAlpha = elem.attribute( QStringLiteral(
"penAlpha" ), QStringLiteral(
"255" ) ).toInt();
196 penColor.setAlpha( penAlpha );
197 penWidth = elem.attribute( QStringLiteral(
"penWidth" ) ).toDouble();
199 mDirection =
static_cast< Direction >( elem.attribute( QStringLiteral(
"direction" ), QStringLiteral(
"1" ) ).toInt() );
201 maximumScale = elem.attribute( QStringLiteral(
"minScaleDenominator" ), QStringLiteral(
"-1" ) ).toDouble();
202 minimumScale = elem.attribute( QStringLiteral(
"maxScaleDenominator" ), QStringLiteral(
"-1" ) ).toDouble();
203 if ( elem.hasAttribute( QStringLiteral(
"scaleBasedVisibility" ) ) )
205 scaleBasedVisibility = ( elem.attribute( QStringLiteral(
"scaleBasedVisibility" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
209 scaleBasedVisibility = maximumScale >= 0 && minimumScale >= 0;
213 if ( elem.attribute( QStringLiteral(
"sizeType" ) ) == QLatin1String(
"MapUnits" ) )
228 mSpacing = elem.attribute( QStringLiteral(
"spacing" ) ).toDouble();
233 if ( elem.attribute( QStringLiteral(
"labelPlacementMethod" ) ) == QLatin1String(
"Height" ) )
235 labelPlacementMethod = Height;
239 labelPlacementMethod = XHeight;
243 if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Left" ) )
245 diagramOrientation = Left;
247 else if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Right" ) )
249 diagramOrientation = Right;
251 else if ( elem.attribute( QStringLiteral(
"diagramOrientation" ) ) == QLatin1String(
"Down" ) )
253 diagramOrientation = Down;
257 diagramOrientation = Up;
261 if ( elem.attribute( QStringLiteral(
"scaleDependency" ) ) == QLatin1String(
"Diameter" ) )
270 barWidth = elem.attribute( QStringLiteral(
"barWidth" ) ).toDouble();
272 if ( elem.hasAttribute( QStringLiteral(
"angleOffset" ) ) )
273 rotationOffset = std::fmod( 360.0 - elem.attribute( QStringLiteral(
"angleOffset" ) ).toInt() / 16.0, 360.0 );
275 rotationOffset = elem.attribute( QStringLiteral(
"rotationOffset" ) ).toDouble();
277 minimumSize = elem.attribute( QStringLiteral(
"minimumSize" ) ).toDouble();
279 QDomNodeList axisSymbolNodes = elem.elementsByTagName( QStringLiteral(
"axisSymbol" ) );
280 if ( axisSymbolNodes.count() > 0 )
282 QDomElement axisSymbolElem = axisSymbolNodes.at( 0 ).toElement().firstChildElement();
283 mAxisLineSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( axisSymbolElem, context ) );
287 mAxisLineSymbol = qgis::make_unique< QgsLineSymbol >();
290 mShowAxis = elem.attribute( QStringLiteral(
"showAxis" ), QStringLiteral(
"0" ) ).toInt();
293 categoryColors.clear();
294 QDomNodeList attributes = elem.elementsByTagName( QStringLiteral(
"attribute" ) );
297 if ( attributes.length() > 0 )
299 for (
int i = 0; i < attributes.size(); i++ )
301 QDomElement attrElem = attributes.at( i ).toElement();
302 QColor newColor( attrElem.attribute( QStringLiteral(
"color" ) ) );
303 newColor.setAlphaF( opacity );
304 categoryColors.append( newColor );
305 categoryAttributes.append( attrElem.attribute( QStringLiteral(
"field" ) ) );
306 categoryLabels.append( attrElem.attribute( QStringLiteral(
"label" ) ) );
307 if ( categoryLabels.constLast().isEmpty() )
309 categoryLabels.back() = categoryAttributes.back();
317 QStringList colorList = elem.attribute( QStringLiteral(
"colors" ) ).split(
'/' );
318 QStringList::const_iterator colorIt = colorList.constBegin();
319 for ( ; colorIt != colorList.constEnd(); ++colorIt )
321 QColor newColor( *colorIt );
322 newColor.setAlphaF( opacity );
323 categoryColors.append( QColor( newColor ) );
327 categoryAttributes.clear();
328 QStringList catList = elem.attribute( QStringLiteral(
"categories" ) ).split(
'/' );
329 QStringList::const_iterator catIt = catList.constBegin();
330 for ( ; catIt != catList.constEnd(); ++catIt )
332 categoryAttributes.append( *catIt );
333 categoryLabels.append( *catIt );
337 QDomElement effectElem = elem.firstChildElement( QStringLiteral(
"effect" ) );
338 if ( !effectElem.isNull() )
346 QDomElement categoryElem = doc.createElement( QStringLiteral(
"DiagramCategory" ) );
347 categoryElem.setAttribute( QStringLiteral(
"enabled" ), enabled );
349 categoryElem.setAttribute( QStringLiteral(
"backgroundColor" ), backgroundColor.name() );
350 categoryElem.setAttribute( QStringLiteral(
"backgroundAlpha" ), backgroundColor.alpha() );
351 categoryElem.setAttribute( QStringLiteral(
"width" ), QString::number( size.width() ) );
352 categoryElem.setAttribute( QStringLiteral(
"height" ), QString::number( size.height() ) );
353 categoryElem.setAttribute( QStringLiteral(
"penColor" ), penColor.name() );
354 categoryElem.setAttribute( QStringLiteral(
"penAlpha" ), penColor.alpha() );
355 categoryElem.setAttribute( QStringLiteral(
"penWidth" ), QString::number( penWidth ) );
356 categoryElem.setAttribute( QStringLiteral(
"scaleBasedVisibility" ), scaleBasedVisibility );
357 categoryElem.setAttribute( QStringLiteral(
"minScaleDenominator" ), QString::number( maximumScale ) );
358 categoryElem.setAttribute( QStringLiteral(
"maxScaleDenominator" ), QString::number( minimumScale ) );
359 categoryElem.setAttribute( QStringLiteral(
"opacity" ), QString::number( opacity ) );
360 categoryElem.setAttribute( QStringLiteral(
"spacing" ), QString::number( mSpacing ) );
363 categoryElem.setAttribute( QStringLiteral(
"direction" ), QString::number( mDirection ) );
374 if ( labelPlacementMethod == Height )
376 categoryElem.setAttribute( QStringLiteral(
"labelPlacementMethod" ), QStringLiteral(
"Height" ) );
380 categoryElem.setAttribute( QStringLiteral(
"labelPlacementMethod" ), QStringLiteral(
"XHeight" ) );
385 categoryElem.setAttribute( QStringLiteral(
"scaleDependency" ), QStringLiteral(
"Area" ) );
389 categoryElem.setAttribute( QStringLiteral(
"scaleDependency" ), QStringLiteral(
"Diameter" ) );
393 switch ( diagramOrientation )
396 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Left" ) );
400 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Right" ) );
404 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Down" ) );
408 categoryElem.setAttribute( QStringLiteral(
"diagramOrientation" ), QStringLiteral(
"Up" ) );
412 categoryElem.setAttribute( QStringLiteral(
"barWidth" ), QString::number( barWidth ) );
413 categoryElem.setAttribute( QStringLiteral(
"minimumSize" ), QString::number( minimumSize ) );
414 categoryElem.setAttribute( QStringLiteral(
"rotationOffset" ), QString::number( rotationOffset ) );
416 int nCats = std::min( categoryColors.size(), categoryAttributes.size() );
417 for (
int i = 0; i < nCats; ++i )
419 QDomElement attributeElem = doc.createElement( QStringLiteral(
"attribute" ) );
421 attributeElem.setAttribute( QStringLiteral(
"field" ), categoryAttributes.at( i ) );
422 attributeElem.setAttribute( QStringLiteral(
"color" ), categoryColors.at( i ).name() );
423 attributeElem.setAttribute( QStringLiteral(
"label" ), categoryLabels.at( i ) );
424 categoryElem.appendChild( attributeElem );
427 categoryElem.setAttribute( QStringLiteral(
"showAxis" ), mShowAxis ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
428 QDomElement axisSymbolElem = doc.createElement( QStringLiteral(
"axisSymbol" ) );
430 axisSymbolElem.appendChild( symbolElem );
431 categoryElem.appendChild( axisSymbolElem );
434 mPaintEffect->saveProperties( doc, categoryElem );
436 rendererElem.appendChild( categoryElem );
441 if ( mDiagram.get() == d )
448 : mDiagram( other.mDiagram ? other.mDiagram->clone() : nullptr )
449 , mShowAttributeLegend( other.mShowAttributeLegend )
486 std::unique_ptr< QgsEffectPainter > effectPainter;
487 if ( effect && effect->
enabled() )
489 effectPainter = qgis::make_unique< QgsEffectPainter >(
c, effect );
492 mDiagram->renderDiagram( feature, c, s, pos );
504 if ( size.isValid() )
507 size.rheight() *= width / size.width();
508 size.setWidth( width );
515 QSet< QString > referenced;
521 for (
const QString &att : constDiagramAttributes )
525 for (
const QString &field : constReferencedColumns )
535 if ( !size.isValid() )
541 size.rwidth() *= pixelToMap;
542 size.rheight() *= pixelToMap;
549 QPaintDevice *device = painter->device();
552 return device->logicalDpiX();
562 QString diagramType = elem.attribute( QStringLiteral(
"diagramType" ) );
563 if ( diagramType == QLatin1String(
"Pie" ) )
567 else if ( diagramType == QLatin1String(
"Text" ) )
571 else if ( diagramType == QLatin1String(
"Histogram" ) )
575 else if ( diagramType == QLatin1String(
"Stacked" ) )
584 mShowAttributeLegend = ( elem.attribute( QStringLiteral(
"attributeLegend" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
594 rendererElem.setAttribute( QStringLiteral(
"diagramType" ),
mDiagram->diagramName() );
618 QList<QgsDiagramSettings> settingsList;
619 settingsList.push_back( mSettings );
625 QDomElement categoryElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
626 if ( categoryElem.isNull() )
631 mSettings.readXml( categoryElem, context );
637 QDomElement rendererElem = doc.createElement( QStringLiteral(
"SingleCategoryDiagramRenderer" ) );
638 mSettings.writeXml( rendererElem, doc, context );
640 layerElem.appendChild( rendererElem );
646 mInterpolationSettings.classificationAttributeIsExpression =
false;
651 , mSettings( other.mSettings )
652 , mInterpolationSettings( other.mInterpolationSettings )
653 , mDataDefinedSizeLegend( other.mDataDefinedSizeLegend ? new
QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegend ) : nullptr )
659 delete mDataDefinedSizeLegend;
669 QList<QgsDiagramSettings> settingsList;
670 settingsList.push_back( mSettings );
693 for (
const QString &field : constReferencedColumns )
707 return mDiagram->diagramSize( feature, c, mSettings, mInterpolationSettings );
712 mInterpolationSettings.
lowerValue = elem.attribute( QStringLiteral(
"lowerValue" ) ).toDouble();
713 mInterpolationSettings.
upperValue = elem.attribute( QStringLiteral(
"upperValue" ) ).toDouble();
714 mInterpolationSettings.
lowerSize.setWidth( elem.attribute( QStringLiteral(
"lowerWidth" ) ).toDouble() );
715 mInterpolationSettings.
lowerSize.setHeight( elem.attribute( QStringLiteral(
"lowerHeight" ) ).toDouble() );
716 mInterpolationSettings.
upperSize.setWidth( elem.attribute( QStringLiteral(
"upperWidth" ) ).toDouble() );
717 mInterpolationSettings.
upperSize.setHeight( elem.attribute( QStringLiteral(
"upperHeight" ) ).toDouble() );
725 mInterpolationSettings.
classificationField = elem.attribute( QStringLiteral(
"classificationField" ) );
727 QDomElement settingsElem = elem.firstChildElement( QStringLiteral(
"DiagramCategory" ) );
728 if ( !settingsElem.isNull() )
730 mSettings.
readXml( settingsElem );
733 delete mDataDefinedSizeLegend;
735 QDomElement ddsLegendSizeElem = elem.firstChildElement( QStringLiteral(
"data-defined-size-legend" ) );
736 if ( !ddsLegendSizeElem.isNull() )
743 if ( elem.attribute( QStringLiteral(
"sizeLegend" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) )
746 QDomElement sizeLegendSymbolElem = elem.firstChildElement( QStringLiteral(
"symbol" ) );
747 if ( !sizeLegendSymbolElem.isNull() && sizeLegendSymbolElem.attribute( QStringLiteral(
"name" ) ) == QLatin1String(
"sizeSymbol" ) )
749 mDataDefinedSizeLegend->
setSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( sizeLegendSymbolElem, context ) );
754 mDataDefinedSizeLegend =
nullptr;
763 QDomElement rendererElem = doc.createElement( QStringLiteral(
"LinearlyInterpolatedDiagramRenderer" ) );
764 rendererElem.setAttribute( QStringLiteral(
"lowerValue" ), QString::number( mInterpolationSettings.
lowerValue ) );
765 rendererElem.setAttribute( QStringLiteral(
"upperValue" ), QString::number( mInterpolationSettings.
upperValue ) );
766 rendererElem.setAttribute( QStringLiteral(
"lowerWidth" ), QString::number( mInterpolationSettings.
lowerSize.width() ) );
767 rendererElem.setAttribute( QStringLiteral(
"lowerHeight" ), QString::number( mInterpolationSettings.
lowerSize.height() ) );
768 rendererElem.setAttribute( QStringLiteral(
"upperWidth" ), QString::number( mInterpolationSettings.
upperSize.width() ) );
769 rendererElem.setAttribute( QStringLiteral(
"upperHeight" ), QString::number( mInterpolationSettings.
upperSize.height() ) );
776 rendererElem.setAttribute( QStringLiteral(
"classificationField" ), mInterpolationSettings.
classificationField );
778 mSettings.
writeXml( rendererElem, doc );
780 if ( mDataDefinedSizeLegend )
782 QDomElement ddsLegendElem = doc.createElement( QStringLiteral(
"data-defined-size-legend" ) );
783 mDataDefinedSizeLegend->
writeXml( ddsLegendElem, context );
784 rendererElem.appendChild( ddsLegendElem );
788 layerElem.appendChild( rendererElem );
793 QList< QgsLayerTreeModelLegendNode * > list;
794 list.reserve( categoryLabels.size() );
795 for (
int i = 0; i < categoryLabels.size(); ++i )
797 QPixmap pix( 16, 16 );
798 pix.fill( categoryColors[i] );
799 list <<
new QgsSimpleLegendNode( nodeLayer, categoryLabels[i], QIcon( pix ),
nullptr, QStringLiteral(
"diagram_%1" ).arg( QString::number( i ) ) );
806 return mAxisLineSymbol.get();
811 if ( axisLineSymbol != mAxisLineSymbol.get() )
812 mAxisLineSymbol.reset( axisLineSymbol );
822 mShowAxis = showAxis;
827 return mPaintEffect.get();
832 if ( effect != mPaintEffect.get() )
833 mPaintEffect.reset( effect );
867 , mSpacing( other.mSpacing )
868 , mSpacingUnit( other.mSpacingUnit )
869 , mSpacingMapUnitScale( other.mSpacingMapUnitScale )
870 , mDirection( other.mDirection )
871 , mShowAxis( other.mShowAxis )
872 , mAxisLineSymbol( other.mAxisLineSymbol ? other.mAxisLineSymbol->clone() : nullptr )
873 , mPaintEffect( other.mPaintEffect ? other.mPaintEffect->clone() : nullptr )
903 mSpacing = other.mSpacing;
904 mSpacingUnit = other.mSpacingUnit;
905 mSpacingMapUnitScale = other.mSpacingMapUnitScale;
906 mDirection = other.mDirection;
907 mAxisLineSymbol.reset( other.mAxisLineSymbol ? other.mAxisLineSymbol->clone() : nullptr );
908 mShowAxis = other.mShowAxis;
909 mPaintEffect.reset( other.mPaintEffect ? other.mPaintEffect->clone() : nullptr );
925 return QList< QgsLayerTreeModelLegendNode * >();
930 QList< QgsLayerTreeModelLegendNode * > nodes;
931 if ( mShowAttributeLegend )
932 nodes = mSettings.legendItems( nodeLayer );
939 QList< QgsLayerTreeModelLegendNode * > nodes;
940 if ( mShowAttributeLegend )
941 nodes = mSettings.legendItems( nodeLayer );
943 if ( mDataDefinedSizeLegend && mDiagram )
953 QList<QgsDataDefinedSizeLegend::SizeClass> sizeClasses;
954 if ( ddSizeLegend.
classes().isEmpty() )
958 for (
double v : prettyBreaks )
960 double size = mDiagram->legendSize( v, mSettings, mInterpolationSettings );
967 const auto constClasses = ddSizeLegend.
classes();
970 double size = mDiagram->legendSize( sc.size, mSettings, mInterpolationSettings );
979 if ( si.dataDefinedSizeLegendSettings() )
991 delete mDataDefinedSizeLegend;
992 mDataDefinedSizeLegend = settings;
997 return mDataDefinedSizeLegend;
void _writeXml(QDomElement &rendererElem, QDomDocument &doc, const QgsReadWriteContext &context) const
Writes internal QgsDiagramRenderer diagram state to a DOM element.
Class for parsing and evaluation of expressions (formerly called "search strings").
static int dpiPaintDevice(const QPainter *)
Returns the paint device dpi (or -1 in case of error.
The class is used as a container of context for various read/write operations on other objects...
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...
QgsUnitTypes::RenderUnit lineSizeUnit
Line unit index.
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
void setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform associated with the layer.
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
Distance to diagram from feature.
void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes diagram state to a DOM element.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields required for diagram rendering.
void setPaintEffect(QgsPaintEffect *effect)
Sets the paint effect to use while rendering diagrams.
QgsSingleCategoryDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
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...
Diagram background color.
void setShowAxis(bool showAxis)
Sets whether the diagram axis should be shown.
void setAxisLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol to use for rendering axis in diagrams.
Definition of one class for the legend.
A stacked bar chart diagram.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
double opacity
Opacity, from 0 (transparent) to 1.0 (opaque)
Renders the diagrams for all features with the same settings.
~QgsDiagramLayerSettings()
QList< QString > categoryAttributes
QgsDiagramRenderer()=default
Constructor for QgsDiagramRenderer.
~QgsLinearlyInterpolatedDiagramRenderer() override
bool classificationAttributeIsExpression
virtual QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
Produces legend node with a marker symbol.
virtual QList< QString > diagramAttributes() const =0
Returns attribute indices needed for diagram rendering.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
bool scaleBasedVisibility
void writeXml(QDomElement &layerElem, QDomDocument &doc) const
Writes the diagram settings to a DOM element.
Base class for visual effects which can be applied to QPicture drawings.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the size map unit scale for the whole symbol (including all symbol layers).
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
Angle offset for pie diagram.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Color with alpha channel.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields referenced by the layer's diagrams.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
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...
QgsLegendSymbolList legendSymbolList() const
Generates legend symbol items according to the configuration.
Whether diagram features act as obstacles for other diagrams/labels.
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.
bool mShowAttributeLegend
Whether to show an attribute legend for the diagrams.
QMap< QString, QString > QgsStringMap
double rotationOffset
Rotation offset, in degrees clockwise from horizontal.
Rotation (value between 0-360 degrees)
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsDiagramSettings()
Constructor for QgsDiagramSettings.
void setDiagram(QgsDiagram *d)
A line symbol type, for rendering LineString and MultiLineString geometries.
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
static QString encodeColor(const QColor &color)
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
Direction direction() const
Returns the chart's angular direction.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads diagram settings from XML.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
DiagramOrientation diagramOrientation
Z-index for diagram ordering.
double maximumScale
The maximum map scale (i.e.
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...
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
QString classificationAttributeExpression
double minimumScale
The minimum map scale (i.e.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the diagrams for a specified expression context.
void readXml(const QDomElement &elem)
Reads the diagram settings from a DOM element.
void convertSizeToMapUnits(QSizeF &size, const QgsRenderContext &context) const
Converts size from mm to map units.
QgsDiagramLayerSettings()
Constructor for QgsDiagramLayerSettings.
QgsMapUnitScale sizeScale
Diagram size unit scale.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads diagram state from a DOM element.
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.
Y-coordinate data defined diagram position.
bool enabled() const
Returns whether the effect is enabled.
Implementation of legend node interface for displaying arbitrary label with icon. ...
void clear() override
Removes all properties from the collection.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
double mapUnitsPerPixel() const
Returns current map units per pixel.
Whether to show the diagram.
void writeXml(QDomElement &rendererElem, QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes diagram settings to XML.
Double value (including negative values)
QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
std::unique_ptr< QgsDiagram > mDiagram
Reference to the object that does the real diagram rendering.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the size units for the whole symbol (including all symbol layers).
QgsLinearlyInterpolatedDiagramRenderer()
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes configuration to the given XML element.
void writeXml(QDomElement &layerElem, QDomDocument &doc, const QgsReadWriteContext &context) const override
Writes diagram state to a DOM element.
void setDirection(Direction direction)
Sets the chart's angular direction.
Definition for a property.
Base class for all diagram types.
QgsLinearlyInterpolatedDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QgsUnitTypes::RenderUnit sizeType
Diagram size unit.
QgsLineSymbol * axisLineSymbol() const
Returns the line symbol to use for rendering axis in diagrams.
void setRenderer(QgsDiagramRenderer *diagramRenderer)
Sets the diagram renderer associated with the layer.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QgsExpressionContext & expressionContext()
Gets the expression context.
Stores the settings for rendering of all diagrams for a layer.
Direction
Angular directions.
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...
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the collection.
QgsDiagramSettings & operator=(const QgsDiagramSettings &other)
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Contains information about the context of a rendering operation.
X-coordinate data defined diagram position.
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend.
virtual QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields required for diagram rendering.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
virtual QSizeF diagramSize(const QgsFeature &features, const QgsRenderContext &c) const =0
Returns size of the diagram (in painter units) or an invalid size in case of error.
Diagram priority (between 0 and 10)
void setSymbol(QgsMarkerSymbol *symbol SIP_TRANSFER)
Sets marker symbol that will be used to draw markers in legend.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the diagram property definitions.
QList< QString > diagramAttributes() const override
Returns attribute indices needed for diagram rendering.
QgsDiagramRenderer & operator=(const QgsDiagramRenderer &other)
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QString classificationField
Name of the field for classification.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
QList< QString > categoryLabels
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
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...
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
LinePlacementFlag
Line placement flags for controlling line based placements.
QgsMapUnitScale lineSizeScale
Line unit scale.
QgsPaintEffect * createEffect(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
Creates a new paint effect given the effect name and properties map.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads diagram state from a DOM element.
QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend...
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend.
QList< QColor > categoryColors
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QgsPaintEffect * paintEffect() const
Returns the paint effect to use while rendering diagrams.
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...
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
QgsDiagramLayerSettings & operator=(const QgsDiagramLayerSettings &rh)
void _readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads internal QgsDiagramRenderer state from a DOM element.
Stores the settings for rendering a single diagram.
bool showAxis() const
Returns true if the diagram axis should be shown.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
LabelPlacementMethod labelPlacementMethod
virtual QgsDiagramRenderer * clone() const =0
Returns new instance that is equivalent to this one.
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...
Layer tree node points to a map layer.
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.