17 #include "diagram/qgstextdiagram.h"
18 #include "diagram/qgspiediagram.h"
19 #include "diagram/qgshistogramdiagram.h"
21 #include <QDomElement>
31 priority = elem.attribute(
"priority" ).toInt();
32 obstacle = elem.attribute(
"obstacle" ).toInt();
33 dist = elem.attribute(
"dist" ).toDouble();
34 xPosColumn = elem.attribute(
"xPosColumn" ).toInt();
35 yPosColumn = elem.attribute(
"yPosColumn" ).toInt();
42 QDomElement diagramLayerElem = doc.createElement(
"DiagramLayerSettings" );
43 diagramLayerElem.setAttribute(
"placement",
placement );
44 diagramLayerElem.setAttribute(
"linePlacementFlags",
placementFlags );
45 diagramLayerElem.setAttribute(
"priority",
priority );
46 diagramLayerElem.setAttribute(
"obstacle",
obstacle );
47 diagramLayerElem.setAttribute(
"dist", QString::number(
dist ) );
48 diagramLayerElem.setAttribute(
"xPosColumn",
xPosColumn );
49 diagramLayerElem.setAttribute(
"yPosColumn",
yPosColumn );
50 layerElem.appendChild( diagramLayerElem );
57 font.fromString( elem.attribute(
"font" ) );
59 backgroundColor.setAlpha( elem.attribute(
"backgroundAlpha" ).toInt() );
60 size.setWidth( elem.attribute(
"width" ).toDouble() );
61 size.setHeight( elem.attribute(
"height" ).toDouble() );
62 transparency = elem.attribute(
"transparency",
"0" ).toInt();
63 penColor.setNamedColor( elem.attribute(
"penColor" ) );
64 int penAlpha = elem.attribute(
"penAlpha",
"255" ).toInt();
66 penWidth = elem.attribute(
"penWidth" ).toDouble();
72 if ( elem.attribute(
"sizeType" ) ==
"MM" )
82 if ( elem.attribute(
"labelPlacementMethod" ) ==
"Height" )
92 if ( elem.attribute(
"diagramOrientation" ) ==
"Left" )
96 else if ( elem.attribute(
"diagramOrientation" ) ==
"Right" )
100 else if ( elem.attribute(
"diagramOrientation" ) ==
"Down" )
110 if ( elem.attribute(
"scaleDependency" ) ==
"Diameter" )
119 barWidth = elem.attribute(
"barWidth" ).toDouble();
121 angleOffset = elem.attribute(
"angleOffset" ).toInt();
123 minimumSize = elem.attribute(
"minimumSize" ).toDouble();
127 QDomNodeList attributes = elem.elementsByTagName(
"attribute" );
129 if ( attributes.length() > 0 )
131 for ( uint i = 0; i < attributes.length(); i++ )
133 QDomElement attrElem = attributes.at( i ).toElement();
134 QColor newColor( attrElem.attribute(
"color" ) );
144 QStringList colorList = elem.attribute(
"colors" ).split(
"/" );
145 QStringList::const_iterator colorIt = colorList.constBegin();
146 for ( ; colorIt != colorList.constEnd(); ++colorIt )
148 QColor newColor( *colorIt );
155 QStringList catList = elem.attribute(
"categories" ).split(
"/" );
156 QStringList::const_iterator catIt = catList.constBegin();
157 for ( ; catIt != catList.constEnd(); ++catIt )
168 QDomElement categoryElem = doc.createElement(
"DiagramCategory" );
169 categoryElem.setAttribute(
"font",
font.toString() );
170 categoryElem.setAttribute(
"backgroundColor",
backgroundColor.name() );
171 categoryElem.setAttribute(
"backgroundAlpha",
backgroundColor.alpha() );
172 categoryElem.setAttribute(
"width", QString::number(
size.width() ) );
173 categoryElem.setAttribute(
"height", QString::number(
size.height() ) );
174 categoryElem.setAttribute(
"penColor",
penColor.name() );
175 categoryElem.setAttribute(
"penAlpha",
penColor.alpha() );
176 categoryElem.setAttribute(
"penWidth", QString::number(
penWidth ) );
177 categoryElem.setAttribute(
"minScaleDenominator", QString::number(
minScaleDenominator ) );
178 categoryElem.setAttribute(
"maxScaleDenominator", QString::number(
maxScaleDenominator ) );
179 categoryElem.setAttribute(
"transparency", QString::number(
transparency ) );
184 categoryElem.setAttribute(
"sizeType",
"MM" );
188 categoryElem.setAttribute(
"sizeType",
"MapUnits" );
194 categoryElem.setAttribute(
"labelPlacementMethod",
"Height" );
198 categoryElem.setAttribute(
"labelPlacementMethod",
"XHeight" );
203 categoryElem.setAttribute(
"scaleDependency",
"Area" );
207 categoryElem.setAttribute(
"scaleDependency",
"Diameter" );
214 categoryElem.setAttribute(
"diagramOrientation",
"Left" );
218 categoryElem.setAttribute(
"diagramOrientation",
"Right" );
222 categoryElem.setAttribute(
"diagramOrientation",
"Down" );
226 categoryElem.setAttribute(
"diagramOrientation",
"Up" );
230 categoryElem.setAttribute(
"diagramOrientation",
"Up" );
234 categoryElem.setAttribute(
"barWidth", QString::number(
barWidth ) );
235 categoryElem.setAttribute(
"minimumSize", QString::number(
minimumSize ) );
236 categoryElem.setAttribute(
"angleOffset", QString::number(
angleOffset ) );
240 for (
int i = 0; i < nCats; ++i )
242 QDomElement attributeElem = doc.createElement(
"attribute" );
245 attributeElem.setAttribute(
"color",
categoryColors.at( i ).name() );
246 categoryElem.appendChild( attributeElem );
249 rendererElem.appendChild( categoryElem );
280 mDiagram->renderDiagram( feature, c, s, pos );
301 if ( !size.isValid() )
307 size.rwidth() *= pixelToMap;
308 size.rheight() *= pixelToMap;
315 QPaintDevice* device = painter->device();
318 return device->logicalDpiX();
329 QString diagramType = elem.attribute(
"diagramType" );
330 if ( diagramType ==
"Pie" )
334 else if ( diagramType ==
"Text" )
338 else if ( diagramType ==
"Histogram" )
340 mDiagram =
new QgsHistogramDiagram();
355 rendererElem.setAttribute(
"diagramType",
mDiagram->diagramName() );
381 QList<QgsDiagramSettings> settingsList;
388 QDomElement categoryElem = elem.firstChildElement(
"DiagramCategory" );
389 if ( categoryElem.isNull() )
400 QDomElement rendererElem = doc.createElement(
"SingleCategoryDiagramRenderer" );
403 layerElem.appendChild( rendererElem );
418 QList<QgsDiagramSettings> settingsList;
457 QDomElement settingsElem = elem.firstChildElement(
"DiagramCategory" );
458 if ( !settingsElem.isNull() )
467 QDomElement rendererElem = doc.createElement(
"LinearlyInterpolatedDiagramRenderer" );
484 layerElem.appendChild( rendererElem );