26 #include <QDomElement> 31 : placement( AroundPoint )
32 , placementFlags( OnLine )
57 ,
ct( rh.
ct ? rh.
ct->clone() : nullptr )
169 enabled = ( elem.
attribute(
"enabled",
"1" ) !=
"0" );
172 font.fromString( elem.
attribute(
"font" ) );
174 backgroundColor.setNamedColor( elem.
attribute(
"backgroundColor" ) );
175 backgroundColor.setAlpha( elem.
attribute(
"backgroundAlpha" ).
toInt() );
179 penColor.setNamedColor( elem.
attribute(
"penColor" ) );
181 penColor.setAlpha( penAlpha );
188 scaleBasedVisibility = ( elem.
attribute(
"scaleBasedVisibility",
"1" ) !=
"0" );
192 scaleBasedVisibility = minScaleDenominator >= 0 && maxScaleDenominator >= 0;
196 if ( elem.
attribute(
"sizeType" ) ==
"MapUnits" )
212 if ( elem.
attribute(
"labelPlacementMethod" ) ==
"Height" )
214 labelPlacementMethod = Height;
218 labelPlacementMethod = XHeight;
222 if ( elem.
attribute(
"diagramOrientation" ) ==
"Left" )
224 diagramOrientation = Left;
226 else if ( elem.
attribute(
"diagramOrientation" ) ==
"Right" )
228 diagramOrientation = Right;
230 else if ( elem.
attribute(
"diagramOrientation" ) ==
"Down" )
232 diagramOrientation = Down;
236 diagramOrientation = Up;
240 if ( elem.
attribute(
"scaleDependency" ) ==
"Diameter" )
256 categoryColors.clear();
259 if ( attributes.
length() > 0 )
261 for (
int i = 0; i < attributes.
size(); i++ )
265 newColor.
setAlpha( 255 - transparency );
266 categoryColors.append( newColor );
267 categoryAttributes.append( attrElem.
attribute(
"field" ) );
268 categoryLabels.append( attrElem.
attribute(
"label" ) );
269 if ( categoryLabels.back().isEmpty() )
271 categoryLabels.back() = categoryAttributes.back();
281 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
283 QColor newColor( *colorIt );
284 newColor.
setAlpha( 255 - transparency );
285 categoryColors.append(
QColor( newColor ) );
289 categoryAttributes.clear();
292 for ( ; catIt != catList.
constEnd(); ++catIt )
294 categoryAttributes.append( *catIt );
295 categoryLabels.append( *catIt );
307 categoryElem.
setAttribute(
"backgroundColor", backgroundColor.name() );
308 categoryElem.
setAttribute(
"backgroundAlpha", backgroundColor.alpha() );
311 categoryElem.
setAttribute(
"penColor", penColor.name() );
312 categoryElem.
setAttribute(
"penAlpha", penColor.alpha() );
314 categoryElem.
setAttribute(
"scaleBasedVisibility", scaleBasedVisibility );
328 if ( labelPlacementMethod == Height )
330 categoryElem.
setAttribute(
"labelPlacementMethod",
"Height" );
334 categoryElem.
setAttribute(
"labelPlacementMethod",
"XHeight" );
343 categoryElem.
setAttribute(
"scaleDependency",
"Diameter" );
347 switch ( diagramOrientation )
350 categoryElem.
setAttribute(
"diagramOrientation",
"Left" );
354 categoryElem.
setAttribute(
"diagramOrientation",
"Right" );
358 categoryElem.
setAttribute(
"diagramOrientation",
"Down" );
362 categoryElem.
setAttribute(
"diagramOrientation",
"Up" );
366 categoryElem.
setAttribute(
"diagramOrientation",
"Up" );
374 int nCats = qMin( categoryColors.size(), categoryAttributes.size() );
375 for (
int i = 0; i < nCats; ++i )
379 attributeElem.
setAttribute(
"field", categoryAttributes.at( i ) );
380 attributeElem.
setAttribute(
"color", categoryColors.at( i ).name() );
381 attributeElem.
setAttribute(
"label", categoryLabels.at( i ) );
389 : mDiagram( nullptr )
390 , mShowAttributeLegend( true )
391 , mShowSizeLegend( false )
486 size.
rwidth() *= pixelToMap;
509 if ( diagramType ==
"Pie" )
513 else if ( diagramType ==
"Text" )
517 else if ( diagramType ==
"Histogram" )
528 if ( !sizeLegendSymbolElem.
isNull() && sizeLegendSymbolElem.
attribute(
"name" ) ==
"sizeSymbol" )
584 if ( categoryElem.
isNull() )
589 mSettings.
readXML( categoryElem, layer );
596 mSettings.
writeXML( rendererElem, doc, layer );
676 if ( !settingsElem.
isNull() )
678 mSettings.
readXML( settingsElem, layer );
700 mSettings.
writeXML( rendererElem, doc, layer );
708 list.
reserve( categoryLabels.size() );
709 for (
int i = 0 ; i < categoryLabels.size(); ++i )
712 pix.
fill( categoryColors[i] );
747 s->setSizeUnit( mSettings.
sizeType );
748 s->setSizeMapUnitScale( mSettings.
sizeScale );
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
double zIndex
Z-index of diagrams, where diagrams with a higher z-index are drawn on top of diagrams with a lower z...
Class for parsing and evaluation of expressions (formerly called "search strings").
QDomNodeList elementsByTagName(const QString &tagname) const
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const override
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c) const
Returns size of the diagram for a feature in map units.
QgsAttributes attributes() const
Returns the feature's attributes.
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...
bool showAll
Whether to show all diagrams, including overlapping diagrams.
QgsSingleCategoryDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
QDomNode appendChild(const QDomNode &newChild)
void fill(const QColor &color)
void push_back(const T &value)
void _readXML(const QDomElement &elem, const QgsVectorLayer *layer)
Renders the diagrams for all features with the same settings.
QString attribute(const QString &name, const QString &defValue) const
QList< QString > categoryAttributes
virtual QList< QString > diagramAttributes() const =0
Returns attribute indices needed for diagram rendering.
Q_DECL_DEPRECATED QgsExpression * getExpression(const QString &expression, const QgsFields *fields)
int yPosColumn
Attribute index for y coordinate (or -1 if position not data defined)
virtual QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
bool classificationAttributeIsExpression
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QStringList referencedColumns() const
Get list of columns referenced by the expression.
unsigned int placementFlags
Diagram placement flags.
#define Q_NOWARN_DEPRECATED_PUSH
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QgsSingleCategoryDiagramRenderer()
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
~QgsLinearlyInterpolatedDiagramRenderer()
Container of fields for a vector layer.
bool mShowAttributeLegend
Whether to show an attribute legend for the diagrams.
static int dpiPaintDevice(const QPainter *)
Returns the paint device dpi (or -1 in case of error.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool mShowSizeLegend
Whether to show a size legend for the diagrams.
double toDouble(bool *ok) const
QgsCoordinateTransform * ct
Associated coordinate transform. Owned by this object.
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.
int count() const
Return number of items.
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
static QgsSymbolV2::OutputUnit decodeOutputUnit(const QString &str)
QDomElement toElement() const
QString number(int n, int base)
void readXML(const QDomElement &elem, const QgsVectorLayer *layer) override
QgsDiagramLayerSettings & operator=(const QgsDiagramLayerSettings &rh)
int xPosColumn
Attribute index for x coordinate (or -1 if position not data defined)
QgsSymbolV2::OutputUnit sizeType
Diagram size unit.
bool hasAttribute(const QString &name) const
bool obstacle
Whether associated feature acts as an obstacle for other labels or diagrams.
virtual double legendSize(double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is) const =0
Returns the size of the legend item for the diagram corresponding to a specified value.
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
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.
void setAttribute(const QString &name, const QString &value)
QScopedPointer< QgsMarkerSymbolV2 > mSizeLegendSymbol
Marker symbol to use in size legends.
void setWidth(qreal width)
QString classificationAttributeExpression
int toInt(bool *ok, int base) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The output shall be in map unitx.
QPaintDevice * device() const
LinePlacementFlags
Line placement flags for controlling line based placements.
void setSize(double size)
Sets the size for the whole symbol.
QgsMapUnitScale sizeScale
Diagram size unit scale.
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.
Q_DECL_DEPRECATED QgsFields fields
QgsDiagramRendererV2 * renderer
Associated diagram renderer. Owned by this object.
~QgsSingleCategoryDiagramRenderer()
Implementation of legend node interface for displaying arbitrary label with icon. ...
Placement placement
Diagram placement.
double mapUnitsPerPixel() const
Return current map units per pixel.
static double convertToMapUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to map units.
virtual QSizeF diagramSize(const QgsAttributes &attributes, const QgsRenderContext &c, const QgsDiagramSettings &s)=0
Returns the size in map units the diagram will use to render.
QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
void convertSizeToMapUnits(QSizeF &size, const QgsRenderContext &context) const
Converts size from mm to map units.
QgsLinearlyInterpolatedDiagramRenderer()
Base class for all diagram types.
QgsLinearlyInterpolatedDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
double dist
Distance between diagram and the feature (in mm)
Stores the settings for rendering of all diagrams for a layer.
virtual QString diagramName() const =0
void setCoordinateTransform(QgsCoordinateTransform *transform)
Sets the coordinate transform associated with the layer.
void _writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const override
virtual QgsDiagram * clone() const =0
Returns an instance that is equivalent to this one.
#define Q_NOWARN_DEPRECATED_POP
void writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
void readXML(const QDomElement &elem, const QgsVectorLayer *layer) override
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos) const
Contains information about the context of a rendering operation.
void setRenderer(QgsDiagramRendererV2 *diagramRenderer)
Sets the diagram renderer associated with the layer.
const QgsMapToPixel & mapToPixel() const
QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
virtual Q_DECL_DEPRECATED void renderDiagram(const QgsAttributes &att, QgsRenderContext &c, const QgsDiagramSettings &s, QPointF position)
virtual ~QgsDiagramRendererV2()
QList< QString > diagramAttributes() const override
Returns attribute indices needed for diagram rendering.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), const QgsFields &fields=QgsFields()) const
Returns the set of any fields referenced by the layer's diagrams.
QDomElement firstChildElement(const QString &tagName) const
int showColumn
Attribute index for visibility (or -1 if visibility not data defined)
virtual QgsDiagramRendererV2 * clone() const =0
Returns new instance that is equivalent to this one.
QgsDiagramLayerSettings()
int priority
Placement priority, where 0 = low and 10 = high.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
~QgsDiagramLayerSettings()
virtual QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), const QgsFields &fields=QgsFields()) const override
Returns the set of any fields required for diagram rendering.
int classificationAttribute
Index of the classification attribute.
Q_DECL_DEPRECATED const QgsMapToPixel * xform
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
QList< QgsLayerTreeModelLegendNode *> legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
void setDiagram(QgsDiagram *d)
double scaleFactor() const
Represents a vector layer which manages a vector based data sets.
void setHeight(qreal height)
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QgsDiagram * mDiagram
Reference to the object that does the real diagram rendering.
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
Stores the settings for rendering a single diagram.
virtual QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), const QgsFields &fields=QgsFields()) const
Returns the set of any fields required for diagram rendering.
QgsDiagramRendererV2 & operator=(const QgsDiagramRendererV2 &other)
Layer tree node points to a map layer.
QDomNode at(int index) const
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.