17 #include "diagram/qgstextdiagram.h"
18 #include "diagram/qgspiediagram.h"
19 #include "diagram/qgshistogramdiagram.h"
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" ) );
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();
86 penWidth = elem.attribute(
"penWidth" ).toDouble();
92 if ( elem.attribute(
"sizeType" ) ==
"MM" )
102 if ( elem.attribute(
"labelPlacementMethod" ) ==
"Height" )
112 if ( elem.attribute(
"diagramOrientation" ) ==
"Left" )
116 else if ( elem.attribute(
"diagramOrientation" ) ==
"Right" )
120 else if ( elem.attribute(
"diagramOrientation" ) ==
"Down" )
130 if ( elem.attribute(
"scaleDependency" ) ==
"Diameter" )
139 barWidth = elem.attribute(
"barWidth" ).toDouble();
141 angleOffset = elem.attribute(
"angleOffset" ).toInt();
143 minimumSize = elem.attribute(
"minimumSize" ).toDouble();
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" ) );
164 QStringList colorList = elem.attribute(
"colors" ).split(
"/" );
165 QStringList::const_iterator colorIt = colorList.constBegin();
166 for ( ; colorIt != colorList.constEnd(); ++colorIt )
168 QColor newColor( *colorIt );
175 QStringList catList = elem.attribute(
"categories" ).split(
"/" );
176 QStringList::const_iterator catIt = catList.constBegin();
177 for ( ; catIt != catList.constEnd(); ++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 ) );
204 categoryElem.setAttribute(
"sizeType",
"MM" );
208 categoryElem.setAttribute(
"sizeType",
"MapUnits" );
214 categoryElem.setAttribute(
"labelPlacementMethod",
"Height" );
218 categoryElem.setAttribute(
"labelPlacementMethod",
"XHeight" );
223 categoryElem.setAttribute(
"scaleDependency",
"Area" );
227 categoryElem.setAttribute(
"scaleDependency",
"Diameter" );
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 ) );
260 for (
int i = 0; i < nCats; ++i )
262 QDomElement attributeElem = doc.createElement(
"attribute" );
265 attributeElem.setAttribute(
"color",
categoryColors.at( i ).name() );
266 categoryElem.appendChild( attributeElem );
269 rendererElem.appendChild( categoryElem );
289 : mDiagram( other.mDiagram ? other.mDiagram->clone() : 0 )
306 mDiagram->renderDiagram( feature, c, s, pos );
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" )
366 mDiagram =
new QgsHistogramDiagram();
381 rendererElem.setAttribute(
"diagramType",
mDiagram->diagramName() );
412 QList<QgsDiagramSettings> settingsList;
419 QDomElement categoryElem = elem.firstChildElement(
"DiagramCategory" );
420 if ( categoryElem.isNull() )
431 QDomElement rendererElem = doc.createElement(
"SingleCategoryDiagramRenderer" );
434 layerElem.appendChild( rendererElem );
454 QList<QgsDiagramSettings> settingsList;
493 QDomElement settingsElem = elem.firstChildElement(
"DiagramCategory" );
494 if ( !settingsElem.isNull() )
503 QDomElement rendererElem = doc.createElement(
"LinearlyInterpolatedDiagramRenderer" );
520 layerElem.appendChild( rendererElem );
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
double minScaleDenominator
QList< QString > diagramAttributes() const
Returns attribute indices needed for diagram rendering.
void _readXML(const QDomElement &elem, const QgsVectorLayer *layer)
~QgsDiagramLayerSettings()
QList< QgsDiagramSettings > diagramSettings() const
Returns list with all diagram settings in the renderer.
QList< QString > categoryAttributes
bool classificationAttributeIsExpression
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QList< QgsDiagramSettings > diagramSettings() const
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...
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
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.
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c)
Returns size of the diagram (in painter units) or an invalid size in case of error.
DiagramOrientation diagramOrientation
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
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
QgsDiagramLayerSettings()
const QgsAttributes & attributes() const
double mapUnitsPerPixel() const
Return current map units per pixel.
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
QgsDiagramRendererV2 * renderer
~QgsSingleCategoryDiagramRenderer()
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
void readXML(const QDomElement &elem, const QgsVectorLayer *layer)
QgsLinearlyInterpolatedDiagramRenderer()
QgsDiagramSettings mSettings
QgsDiagramRendererV2 * clone() const
Returns new instance that is equivalent to this one.
QSizeF diagramSize(const QgsFeature &, const QgsRenderContext &c)
Returns size of the diagram (in painter units) or an invalid size in case of error.
Contains information about the context of a rendering operation.
QgsDiagramInterpolationSettings mInterpolationSettings
QgsDiagramSettings mSettings
virtual ~QgsDiagramRendererV2()
double maxScaleDenominator
void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const
const QgsMapToPixel & mapToPixel() const
QgsDiagramRendererV2 * clone() const
Returns new instance that is equivalent to this one.
int classificationAttribute
Index of the classification attribute.
void setDiagram(QgsDiagram *d)
Represents a vector layer which manages a vector based data sets.
QList< QColor > categoryColors
void writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
QgsDiagram * mDiagram
Reference to the object that does the real diagram rendering.
void _writeXML(QDomElement &rendererElem, QDomDocument &doc, const QgsVectorLayer *layer) const
LabelPlacementMethod labelPlacementMethod
LinePlacementFlags placementFlags