12 #include <QDomDocument>
13 #include <QDomElement>
17 : mValue( value ), mSymbol( symbol ), mLabel( label )
22 : mValue( cat.mValue ), mLabel( cat.mLabel )
75 mAttrName( attrName ),
76 mCategories( categories ),
77 mSourceSymbol( NULL ),
78 mSourceColorRamp( NULL ),
79 mRotationFieldIdx( -1 ),
80 mSizeScaleFieldIdx( -1 )
85 if ( cat.
symbol() == NULL )
87 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
116 QHash<QString, QgsSymbolV2*>::iterator it =
mSymbolHash.find( value.toString() );
122 QgsDebugMsg(
"attribute value not found: " + value.toString() );
132 QgsAttributeMap::const_iterator ita = attrMap.find(
mAttrNum );
133 if ( ita == attrMap.end() )
141 if ( symbol == NULL )
152 double sizeScale = 1;
168 markerSymbol->
setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->size() );
174 lineSymbol->
setWidth( sizeScale * static_cast<QgsLineSymbolV2*>( symbol )->width() );
192 if ( catIndex < 0 || catIndex >=
mCategories.size() )
200 if ( catIndex < 0 || catIndex >=
mCategories.size() )
208 if ( catIndex < 0 || catIndex >=
mCategories.size() )
216 if ( cat.
symbol() == NULL )
218 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
228 if ( catIndex < 0 || catIndex >=
mCategories.size() )
251 QgsCategoryList::iterator it =
mCategories.begin();
254 it->symbol()->startRender( context );
270 QgsCategoryList::iterator it =
mCategories.begin();
272 it->symbol()->stopRender( context );
275 QHash<QString, QgsSymbolV2*>::iterator it2 =
mTempSymbols.begin();
278 it2.value()->stopRender( context );
297 QString s = QString(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
326 QDomElement symbolsElem = element.firstChildElement(
"symbols" );
327 if ( symbolsElem.isNull() )
330 QDomElement catsElem = element.firstChildElement(
"categories" );
331 if ( catsElem.isNull() )
337 QDomElement catElem = catsElem.firstChildElement();
338 while ( !catElem.isNull() )
340 if ( catElem.tagName() ==
"category" )
342 QVariant value = QVariant( catElem.attribute(
"value" ) );
343 QString symbolName = catElem.attribute(
"symbol" );
344 QString label = catElem.attribute(
"label" );
345 if ( symbolMap.contains( symbolName ) )
347 QgsSymbolV2* symbol = symbolMap.take( symbolName );
351 catElem = catElem.nextSiblingElement();
354 QString attrName = element.attribute(
"attr" );
362 QDomElement sourceSymbolElem = element.firstChildElement(
"source-symbol" );
363 if ( !sourceSymbolElem.isNull() )
366 if ( sourceSymbolMap.contains(
"0" ) )
374 QDomElement sourceColorRampElem = element.firstChildElement(
"colorramp" );
375 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute(
"name" ) ==
"[source]" )
380 QDomElement rotationElem = element.firstChildElement(
"rotation" );
381 if ( !rotationElem.isNull() )
384 QDomElement sizeScaleElem = element.firstChildElement(
"sizescale" );
385 if ( !sizeScaleElem.isNull() )
395 rendererElem.setAttribute(
"type",
"categorizedSymbol" );
397 rendererElem.setAttribute(
"attr",
mAttrName );
402 QDomElement catsElem = doc.createElement(
"categories" );
403 QgsCategoryList::const_iterator it =
mCategories.constBegin();
407 QString symbolName = QString::number( i );
408 symbols.insert( symbolName, cat.
symbol() );
410 QDomElement catElem = doc.createElement(
"category" );
411 catElem.setAttribute(
"value", cat.
value().toString() );
412 catElem.setAttribute(
"symbol", symbolName );
413 catElem.setAttribute(
"label", cat.
label() );
414 catsElem.appendChild( catElem );
418 rendererElem.appendChild( catsElem );
422 rendererElem.appendChild( symbolsElem );
430 rendererElem.appendChild( sourceSymbolElem );
437 rendererElem.appendChild( colorRampElem );
440 QDomElement rotationElem = doc.createElement(
"rotation" );
442 rendererElem.appendChild( rotationElem );
444 QDomElement sizeScaleElem = doc.createElement(
"sizescale" );
446 rendererElem.appendChild( sizeScaleElem );
454 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
457 if ( showClassifiers )
463 for (
int i = 0; i < count; i++ )
467 lst << qMakePair( cat.
label(), pix );
475 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
478 if ( showClassifiers )
483 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
486 lst << qMakePair( catIt->label(), catIt->symbol() );