24 #include <QDomElement> 28 : placement( AroundPoint )
29 , placementFlags( OnLine )
119 enabled = ( elem.
attribute(
"enabled",
"1" ) !=
"0" );
122 font.fromString( elem.
attribute(
"font" ) );
124 backgroundColor.setNamedColor( elem.
attribute(
"backgroundColor" ) );
125 backgroundColor.setAlpha( elem.
attribute(
"backgroundAlpha" ).
toInt() );
129 penColor.setNamedColor( elem.
attribute(
"penColor" ) );
131 penColor.setAlpha( penAlpha );
138 scaleBasedVisibility = ( elem.
attribute(
"scaleBasedVisibility",
"1" ) !=
"0" );
142 scaleBasedVisibility = minScaleDenominator >= 0 && maxScaleDenominator >= 0;
146 if ( elem.
attribute(
"sizeType" ) ==
"MM" )
156 if ( elem.
attribute(
"labelPlacementMethod" ) ==
"Height" )
158 labelPlacementMethod = Height;
162 labelPlacementMethod = XHeight;
166 if ( elem.
attribute(
"diagramOrientation" ) ==
"Left" )
168 diagramOrientation = Left;
170 else if ( elem.
attribute(
"diagramOrientation" ) ==
"Right" )
172 diagramOrientation = Right;
174 else if ( elem.
attribute(
"diagramOrientation" ) ==
"Down" )
176 diagramOrientation = Down;
180 diagramOrientation = Up;
184 if ( elem.
attribute(
"scaleDependency" ) ==
"Diameter" )
200 categoryColors.clear();
203 if ( attributes.
length() > 0 )
205 for (
int i = 0; i < attributes.
size(); i++ )
209 newColor.
setAlpha( 255 - transparency );
210 categoryColors.append( newColor );
211 categoryAttributes.append( attrElem.
attribute(
"field" ) );
212 categoryLabels.append( attrElem.
attribute(
"label" ) );
213 if ( categoryLabels.back().isEmpty() )
215 categoryLabels.back() = categoryAttributes.back();
225 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
227 QColor newColor( *colorIt );
228 newColor.
setAlpha( 255 - transparency );
229 categoryColors.append(
QColor( newColor ) );
233 categoryAttributes.clear();
236 for ( ; catIt != catList.
constEnd(); ++catIt )
238 categoryAttributes.append( *catIt );
239 categoryLabels.append( *catIt );
251 categoryElem.
setAttribute(
"backgroundColor", backgroundColor.name() );
252 categoryElem.
setAttribute(
"backgroundAlpha", backgroundColor.alpha() );
255 categoryElem.
setAttribute(
"penColor", penColor.name() );
256 categoryElem.
setAttribute(
"penAlpha", penColor.alpha() );
258 categoryElem.
setAttribute(
"scaleBasedVisibility", scaleBasedVisibility );
264 if ( sizeType == MM )
274 if ( labelPlacementMethod == Height )
276 categoryElem.
setAttribute(
"labelPlacementMethod",
"Height" );
280 categoryElem.
setAttribute(
"labelPlacementMethod",
"XHeight" );
289 categoryElem.
setAttribute(
"scaleDependency",
"Diameter" );
293 switch ( diagramOrientation )
296 categoryElem.
setAttribute(
"diagramOrientation",
"Left" );
300 categoryElem.
setAttribute(
"diagramOrientation",
"Right" );
304 categoryElem.
setAttribute(
"diagramOrientation",
"Down" );
308 categoryElem.
setAttribute(
"diagramOrientation",
"Up" );
312 categoryElem.
setAttribute(
"diagramOrientation",
"Up" );
321 int nCats = qMin( categoryColors.size(), categoryAttributes.size() );
322 for (
int i = 0; i < nCats; ++i )
326 attributeElem.
setAttribute(
"field", categoryAttributes.at( i ) );
327 attributeElem.
setAttribute(
"color", categoryColors.at( i ).name() );
328 attributeElem.
setAttribute(
"label", categoryLabels.at( i ) );
336 : mDiagram( nullptr )
396 size.
rwidth() *= pixelToMap;
419 if ( diagramType ==
"Pie" )
423 else if ( diagramType ==
"Text" )
427 else if ( diagramType ==
"Histogram" )
483 if ( categoryElem.
isNull() )
488 mSettings.
readXML( categoryElem, layer );
495 mSettings.
writeXML( rendererElem, doc, layer );
557 if ( !settingsElem.
isNull() )
559 mSettings.
readXML( settingsElem, layer );
581 mSettings.
writeXML( rendererElem, doc, layer );
589 list.
reserve( categoryLabels.size() );
590 for (
int i = 0 ; i < categoryLabels.size(); ++i )
593 pix.
fill( categoryColors[i] );
double zIndex
Z-index of diagrams, where diagrams with a higher z-index are drawn on top of diagrams with a lower z...
QDomNodeList elementsByTagName(const QString &tagname) const
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const override
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)
virtual QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
Renders the diagrams for all features with the same settings.
~QgsDiagramLayerSettings()
QString attribute(const QString &name, const QString &defValue) const
QList< QString > categoryAttributes
bool classificationAttributeIsExpression
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
unsigned int placementFlags
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QgsSingleCategoryDiagramRenderer()
~QgsLinearlyInterpolatedDiagramRenderer()
static int dpiPaintDevice(const QPainter *)
Returns the paint device dpi (or -1 in case of error.
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos)
double scaleFactor() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
double toDouble(bool *ok) const
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
Returns diagram settings for a feature.
virtual QSizeF diagramSize(const QgsFeature &features, const QgsRenderContext &c)=0
Returns size of the diagram (in painter units) or an invalid size in case of error.
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const override
Returns list of legend nodes for the diagram.
void convertSizeToMapUnits(QSizeF &size, const QgsRenderContext &context) const
Converts size from mm to map units.
QDomElement toElement() const
QString number(int n, int base)
const QgsMapToPixel * xform
void readXML(const QDomElement &elem, const QgsVectorLayer *layer) override
bool hasAttribute(const QString &name) const
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c)
Returns size of the diagram for a feature in map units.
QgsAttributes attributes() const
Returns the feature's attributes.
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
void setAttribute(const QString &name, const QString &value)
void setWidth(qreal width)
QString classificationAttributeExpression
int toInt(bool *ok, int base) const
QPaintDevice * device() const
QgsDiagramLayerSettings()
QList< QgsLayerTreeModelLegendNode * > legendItems(QgsLayerTreeLayer *nodeLayer) const
Returns list of legend nodes for the diagram.
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.
double mapUnitsPerPixel() const
Return current map units per pixel.
QgsDiagramRendererV2 * renderer
~QgsSingleCategoryDiagramRenderer()
Implementation of legend node interface for displaying arbitrary label with icon. ...
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.
QgsLinearlyInterpolatedDiagramRenderer()
Base class for all diagram types.
QgsLinearlyInterpolatedDiagramRenderer * clone() const override
Returns new instance that is equivalent to this one.
virtual QString diagramName() const =0
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const override
void readXML(const QDomElement &elem, const QgsVectorLayer *layer) override
Contains information about the context of a rendering operation.
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.
QDomElement firstChildElement(const QString &tagName) const
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
virtual QgsDiagramRendererV2 * clone() const =0
Returns new instance that is equivalent to this one.
const QgsMapToPixel & mapToPixel() const
int classificationAttribute
Index of the classification attribute.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
void setDiagram(QgsDiagram *d)
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c) override
Returns size of the diagram (in painter units) or an invalid size in case of error.
Represents a vector layer which manages a vector based data sets.
void setHeight(qreal height)
void writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
QgsDiagram * mDiagram
Reference to the object that does the real diagram rendering.
const QgsCoordinateTransform * ct
QList< QgsDiagramSettings > diagramSettings() const override
Returns list with all diagram settings in the renderer.
QgsDiagramLayerSettings & operator=(const QgsDiagramLayerSettings &rh)
void _writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c) override
Returns size of the diagram (in painter units) or an invalid size in case of error.
Layer tree node points to a map layer.
QDomNode at(int index) const