22 #include <QDomElement> 26 : placement( AroundPoint )
27 , placementFlags( OnLine )
51 priority = elem.attribute(
"priority" ).toInt();
52 obstacle = elem.attribute(
"obstacle" ).toInt();
53 dist = elem.attribute(
"dist" ).toDouble();
54 xPosColumn = elem.attribute(
"xPosColumn" ).toInt();
55 yPosColumn = elem.attribute(
"yPosColumn" ).toInt();
62 QDomElement diagramLayerElem = doc.createElement(
"DiagramLayerSettings" );
63 diagramLayerElem.setAttribute(
"placement",
placement );
64 diagramLayerElem.setAttribute(
"linePlacementFlags",
placementFlags );
65 diagramLayerElem.setAttribute(
"priority",
priority );
66 diagramLayerElem.setAttribute(
"obstacle",
obstacle );
67 diagramLayerElem.setAttribute(
"dist", QString::number(
dist ) );
68 diagramLayerElem.setAttribute(
"xPosColumn",
xPosColumn );
69 diagramLayerElem.setAttribute(
"yPosColumn",
yPosColumn );
70 layerElem.appendChild( diagramLayerElem );
77 font.fromString( elem.attribute(
"font" ) );
78 backgroundColor.setNamedColor( elem.attribute(
"backgroundColor" ) );
79 backgroundColor.setAlpha( elem.attribute(
"backgroundAlpha" ).toInt() );
80 size.setWidth( elem.attribute(
"width" ).toDouble() );
81 size.setHeight( elem.attribute(
"height" ).toDouble() );
82 transparency = elem.attribute(
"transparency",
"0" ).toInt();
83 penColor.setNamedColor( elem.attribute(
"penColor" ) );
84 int penAlpha = elem.attribute(
"penAlpha",
"255" ).toInt();
85 penColor.setAlpha( penAlpha );
86 penWidth = elem.attribute(
"penWidth" ).toDouble();
88 minScaleDenominator = elem.attribute(
"minScaleDenominator",
"-1" ).toDouble();
89 maxScaleDenominator = elem.attribute(
"maxScaleDenominator",
"-1" ).toDouble();
92 if ( elem.attribute(
"sizeType" ) ==
"MM" )
102 if ( elem.attribute(
"labelPlacementMethod" ) ==
"Height" )
104 labelPlacementMethod = Height;
108 labelPlacementMethod = XHeight;
112 if ( elem.attribute(
"diagramOrientation" ) ==
"Left" )
114 diagramOrientation = Left;
116 else if ( elem.attribute(
"diagramOrientation" ) ==
"Right" )
118 diagramOrientation = Right;
120 else if ( elem.attribute(
"diagramOrientation" ) ==
"Down" )
122 diagramOrientation = Down;
126 diagramOrientation = Up;
130 if ( elem.attribute(
"scaleDependency" ) ==
"Diameter" )
139 barWidth = elem.attribute(
"barWidth" ).toDouble();
141 angleOffset = elem.attribute(
"angleOffset" ).toInt();
143 minimumSize = elem.attribute(
"minimumSize" ).toDouble();
146 categoryColors.clear();
147 QDomNodeList attributes = elem.elementsByTagName(
"attribute" );
149 if ( attributes.length() > 0 )
151 for ( uint i = 0; i < attributes.length(); i++ )
153 QDomElement attrElem = attributes.at( i ).toElement();
154 QColor newColor( attrElem.attribute(
"color" ) );
155 newColor.setAlpha( 255 - transparency );
156 categoryColors.append( newColor );
157 categoryAttributes.append( attrElem.attribute(
"field" ) );
164 QStringList colorList = elem.attribute(
"colors" ).split(
"/" );
165 QStringList::const_iterator colorIt = colorList.constBegin();
166 for ( ; colorIt != colorList.constEnd(); ++colorIt )
168 QColor newColor( *colorIt );
169 newColor.setAlpha( 255 - transparency );
170 categoryColors.append( QColor( newColor ) );
174 categoryAttributes.clear();
175 QStringList catList = elem.attribute(
"categories" ).split(
"/" );
176 QStringList::const_iterator catIt = catList.constBegin();
177 for ( ; catIt != catList.constEnd(); ++catIt )
179 categoryAttributes.append( *catIt );
188 QDomElement categoryElem = doc.createElement(
"DiagramCategory" );
189 categoryElem.setAttribute(
"font", font.toString() );
190 categoryElem.setAttribute(
"backgroundColor", backgroundColor.name() );
191 categoryElem.setAttribute(
"backgroundAlpha", backgroundColor.alpha() );
192 categoryElem.setAttribute(
"width", QString::number( size.width() ) );
193 categoryElem.setAttribute(
"height", QString::number( size.height() ) );
194 categoryElem.setAttribute(
"penColor", penColor.name() );
195 categoryElem.setAttribute(
"penAlpha", penColor.alpha() );
196 categoryElem.setAttribute(
"penWidth", QString::number( penWidth ) );
197 categoryElem.setAttribute(
"minScaleDenominator", QString::number( minScaleDenominator ) );
198 categoryElem.setAttribute(
"maxScaleDenominator", QString::number( maxScaleDenominator ) );
199 categoryElem.setAttribute(
"transparency", QString::number( transparency ) );
202 if ( sizeType == MM )
204 categoryElem.setAttribute(
"sizeType",
"MM" );
208 categoryElem.setAttribute(
"sizeType",
"MapUnits" );
212 if ( labelPlacementMethod == Height )
214 categoryElem.setAttribute(
"labelPlacementMethod",
"Height" );
218 categoryElem.setAttribute(
"labelPlacementMethod",
"XHeight" );
223 categoryElem.setAttribute(
"scaleDependency",
"Area" );
227 categoryElem.setAttribute(
"scaleDependency",
"Diameter" );
231 switch ( diagramOrientation )
234 categoryElem.setAttribute(
"diagramOrientation",
"Left" );
238 categoryElem.setAttribute(
"diagramOrientation",
"Right" );
242 categoryElem.setAttribute(
"diagramOrientation",
"Down" );
246 categoryElem.setAttribute(
"diagramOrientation",
"Up" );
250 categoryElem.setAttribute(
"diagramOrientation",
"Up" );
254 categoryElem.setAttribute(
"barWidth", QString::number( barWidth ) );
255 categoryElem.setAttribute(
"minimumSize", QString::number( minimumSize ) );
256 categoryElem.setAttribute(
"angleOffset", QString::number( angleOffset ) );
259 int nCats = qMin( categoryColors.size(), categoryAttributes.size() );
260 for (
int i = 0; i < nCats; ++i )
262 QDomElement attributeElem = doc.createElement(
"attribute" );
264 attributeElem.setAttribute(
"field", categoryAttributes.at( i ) );
265 attributeElem.setAttribute(
"color", categoryColors.at( i ).name() );
266 categoryElem.appendChild( attributeElem );
269 rendererElem.appendChild( categoryElem );
327 if ( !size.isValid() )
333 size.rwidth() *= pixelToMap;
334 size.rheight() *= pixelToMap;
341 QPaintDevice* device = painter->device();
344 return device->logicalDpiX();
355 QString diagramType = elem.attribute(
"diagramType" );
356 if ( diagramType ==
"Pie" )
360 else if ( diagramType ==
"Text" )
364 else if ( diagramType ==
"Histogram" )
412 QList<QgsDiagramSettings> settingsList;
413 settingsList.push_back( mSettings );
419 QDomElement categoryElem = elem.firstChildElement(
"DiagramCategory" );
420 if ( categoryElem.isNull() )
425 mSettings.
readXML( categoryElem, layer );
431 QDomElement rendererElem = doc.createElement(
"SingleCategoryDiagramRenderer" );
432 mSettings.
writeXML( rendererElem, doc, layer );
434 layerElem.appendChild( rendererElem );
454 QList<QgsDiagramSettings> settingsList;
455 settingsList.push_back( mSettings );
478 mInterpolationSettings.
lowerValue = elem.attribute(
"lowerValue" ).toDouble();
479 mInterpolationSettings.
upperValue = elem.attribute(
"upperValue" ).toDouble();
480 mInterpolationSettings.
lowerSize.setWidth( elem.attribute(
"lowerWidth" ).toDouble() );
481 mInterpolationSettings.
lowerSize.setHeight( elem.attribute(
"lowerHeight" ).toDouble() );
482 mInterpolationSettings.
upperSize.setWidth( elem.attribute(
"upperWidth" ).toDouble() );
483 mInterpolationSettings.
upperSize.setHeight( elem.attribute(
"upperHeight" ).toDouble() );
493 QDomElement settingsElem = elem.firstChildElement(
"DiagramCategory" );
494 if ( !settingsElem.isNull() )
496 mSettings.
readXML( settingsElem, layer );
503 QDomElement rendererElem = doc.createElement(
"LinearlyInterpolatedDiagramRenderer" );
504 rendererElem.setAttribute(
"lowerValue", QString::number( mInterpolationSettings.
lowerValue ) );
505 rendererElem.setAttribute(
"upperValue", QString::number( mInterpolationSettings.
upperValue ) );
506 rendererElem.setAttribute(
"lowerWidth", QString::number( mInterpolationSettings.
lowerSize.width() ) );
507 rendererElem.setAttribute(
"lowerHeight", QString::number( mInterpolationSettings.
lowerSize.height() ) );
508 rendererElem.setAttribute(
"upperWidth", QString::number( mInterpolationSettings.
upperSize.width() ) );
509 rendererElem.setAttribute(
"upperHeight", QString::number( mInterpolationSettings.
upperSize.height() ) );
518 mSettings.
writeXML( rendererElem, doc, layer );
520 layerElem.appendChild( rendererElem );
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const override
QgsDiagramRendererV2 * clone() const override
Returns new instance that is equivalent to this one.
void _readXML(const QDomElement &elem, const QgsVectorLayer *layer)
~QgsDiagramLayerSettings()
QList< QString > categoryAttributes
bool classificationAttributeIsExpression
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, const QPointF &pos)
double scaleFactor() const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual Q_DECL_DEPRECATED void renderDiagram(const QgsAttributes &att, QgsRenderContext &c, const QgsDiagramSettings &s, const QPointF &position)
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.
void convertSizeToMapUnits(QSizeF &size, const QgsRenderContext &context) const
Converts size from mm to map units.
void readXML(const QDomElement &elem, const QgsVectorLayer *layer) override
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c)
Returns size of the diagram for a feature in map units.
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
QString classificationAttributeExpression
QgsDiagramLayerSettings()
const QgsAttributes & attributes() const
double mapUnitsPerPixel() const
Return current map units per pixel.
QgsDiagramRendererV2 * renderer
~QgsSingleCategoryDiagramRenderer()
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.
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 ~QgsDiagramRendererV2()
QList< QString > diagramAttributes() const override
Returns attribute indices needed for diagram rendering.
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
virtual QgsDiagramRendererV2 * clone() const =0
Returns new instance that is equivalent to this one.
QgsDiagramRendererV2 * clone() const override
Returns new instance that is equivalent to this one.
const QgsMapToPixel & mapToPixel() const
int classificationAttribute
Index of the classification attribute.
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 writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
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 &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.
LinePlacementFlags placementFlags