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 );
55 font.fromString( elem.attribute(
"font" ) );
57 backgroundColor.setAlpha( elem.attribute(
"backgroundAlpha" ).toInt() );
58 size.setWidth( elem.attribute(
"width" ).toDouble() );
59 size.setHeight( elem.attribute(
"height" ).toDouble() );
60 transparency = elem.attribute(
"transparency",
"0" ).toInt();
61 penColor.setNamedColor( elem.attribute(
"penColor" ) );
62 int penAlpha = elem.attribute(
"penAlpha",
"255" ).toInt();
64 penWidth = elem.attribute(
"penWidth" ).toDouble();
70 if ( elem.attribute(
"sizeType" ) ==
"MM" )
80 if ( elem.attribute(
"labelPlacementMethod" ) ==
"Height" )
90 if ( elem.attribute(
"diagramOrientation" ) ==
"Left" )
94 else if ( elem.attribute(
"diagramOrientation" ) ==
"Right" )
98 else if ( elem.attribute(
"diagramOrientation" ) ==
"Down" )
108 if ( elem.attribute(
"scaleDependency" ) ==
"Diameter" )
117 barWidth = elem.attribute(
"barWidth" ).toDouble();
119 angleOffset = elem.attribute(
"angleOffset" ).toInt();
121 minimumSize = elem.attribute(
"minimumSize" ).toDouble();
125 QDomNodeList attributes = elem.elementsByTagName(
"attribute" );
127 if ( attributes.length() > 0 )
129 for ( uint i = 0; i < attributes.length(); i++ )
131 QDomElement attrElem = attributes.at( i ).toElement();
132 QColor newColor( attrElem.attribute(
"color" ) );
142 QStringList colorList = elem.attribute(
"colors" ).split(
"/" );
143 QStringList::const_iterator colorIt = colorList.constBegin();
144 for ( ; colorIt != colorList.constEnd(); ++colorIt )
146 QColor newColor( *colorIt );
153 QStringList catList = elem.attribute(
"categories" ).split(
"/" );
154 QStringList::const_iterator catIt = catList.constBegin();
155 for ( ; catIt != catList.constEnd(); ++catIt )
164 QDomElement categoryElem = doc.createElement(
"DiagramCategory" );
165 categoryElem.setAttribute(
"font",
font.toString() );
166 categoryElem.setAttribute(
"backgroundColor",
backgroundColor.name() );
167 categoryElem.setAttribute(
"backgroundAlpha",
backgroundColor.alpha() );
168 categoryElem.setAttribute(
"width", QString::number(
size.width() ) );
169 categoryElem.setAttribute(
"height", QString::number(
size.height() ) );
170 categoryElem.setAttribute(
"penColor",
penColor.name() );
171 categoryElem.setAttribute(
"penAlpha",
penColor.alpha() );
172 categoryElem.setAttribute(
"penWidth", QString::number(
penWidth ) );
173 categoryElem.setAttribute(
"minScaleDenominator", QString::number(
minScaleDenominator ) );
174 categoryElem.setAttribute(
"maxScaleDenominator", QString::number(
maxScaleDenominator ) );
175 categoryElem.setAttribute(
"transparency", QString::number(
transparency ) );
180 categoryElem.setAttribute(
"sizeType",
"MM" );
184 categoryElem.setAttribute(
"sizeType",
"MapUnits" );
190 categoryElem.setAttribute(
"labelPlacementMethod",
"Height" );
194 categoryElem.setAttribute(
"labelPlacementMethod",
"XHeight" );
199 categoryElem.setAttribute(
"scaleDependency",
"Area" );
203 categoryElem.setAttribute(
"scaleDependency",
"Diameter" );
210 categoryElem.setAttribute(
"diagramOrientation",
"Left" );
214 categoryElem.setAttribute(
"diagramOrientation",
"Right" );
218 categoryElem.setAttribute(
"diagramOrientation",
"Down" );
222 categoryElem.setAttribute(
"diagramOrientation",
"Up" );
226 categoryElem.setAttribute(
"diagramOrientation",
"Up" );
230 categoryElem.setAttribute(
"barWidth", QString::number(
barWidth ) );
231 categoryElem.setAttribute(
"minimumSize", QString::number(
minimumSize ) );
232 categoryElem.setAttribute(
"angleOffset", QString::number(
angleOffset ) );
236 for (
int i = 0; i < nCats; ++i )
238 QDomElement attributeElem = doc.createElement(
"attribute" );
241 attributeElem.setAttribute(
"color",
categoryColors.at( i ).name() );
242 categoryElem.appendChild( attributeElem );
245 rendererElem.appendChild( categoryElem );
276 mDiagram->renderDiagram( att, c, s, pos );
297 if ( !size.isValid() )
303 size.rwidth() *= pixelToMap;
304 size.rheight() *= pixelToMap;
311 QPaintDevice* device = painter->device();
314 return device->logicalDpiX();
325 QString diagramType = elem.attribute(
"diagramType" );
326 if ( diagramType ==
"Pie" )
330 else if ( diagramType ==
"Text" )
334 else if ( diagramType ==
"Histogram" )
336 mDiagram =
new QgsHistogramDiagram();
351 rendererElem.setAttribute(
"diagramType",
mDiagram->diagramName() );
377 QList<QgsDiagramSettings> settingsList;
384 QDomElement categoryElem = elem.firstChildElement(
"DiagramCategory" );
385 if ( categoryElem.isNull() )
396 QDomElement rendererElem = doc.createElement(
"SingleCategoryDiagramRenderer" );
399 layerElem.appendChild( rendererElem );
413 QList<QgsDiagramSettings> settingsList;
449 QDomElement settingsElem = elem.firstChildElement(
"DiagramCategory" );
450 if ( !settingsElem.isNull() )
459 QDomElement rendererElem = doc.createElement(
"LinearlyInterpolatedDiagramRenderer" );
469 layerElem.appendChild( rendererElem );