27 #include <QDomDocument>
28 #include <QDomElement>
43 : mValue( cat.mValue )
44 , mSymbol( cat.mSymbol.data() ? cat.mSymbol->clone() : NULL )
45 , mLabel( cat.mLabel )
95 return QString(
"%1::%2::%3\n" ).arg(
mValue.toString() ).arg(
mLabel ).arg(
mSymbol->dump() );
100 if ( !
mSymbol.data() || props.value(
"attribute",
"" ).isEmpty() )
103 QString attrName = props[
"attribute" ];
105 QDomElement ruleElem = doc.createElement(
"se:Rule" );
106 element.appendChild( ruleElem );
108 QDomElement nameElem = doc.createElement(
"se:Name" );
109 nameElem.appendChild( doc.createTextNode(
mLabel ) );
110 ruleElem.appendChild( nameElem );
112 QDomElement descrElem = doc.createElement(
"se:Description" );
113 QDomElement titleElem = doc.createElement(
"se:Title" );
114 QString descrStr = QString(
"%1 is '%2'" ).arg( attrName ).arg(
mValue.toString() );
115 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
116 descrElem.appendChild( titleElem );
117 ruleElem.appendChild( descrElem );
120 QString filterFunc = QString(
"%1 = '%2'" )
121 .arg( attrName.replace(
"\"",
"\"\"" ) )
122 .arg(
mValue.toString().replace(
"'",
"''" ) );
125 mSymbol->toSld( doc, ruleElem, props );
132 , mAttrName( attrName )
133 , mCategories( categories )
134 , mInvertedColorRamp( false )
140 if ( cat.
symbol() == NULL )
142 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
167 QHash<QString, QgsSymbolV2*>::iterator it =
mSymbolHash.find( value.toString() );
200 if ( symbol == NULL )
210 const double rotation =
mRotation.data() ?
mRotation->evaluate( feature ).toDouble() : 0;
221 markerSymbol->
setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->
size() );
227 lineSymbol->
setWidth( sizeScale * static_cast<QgsLineSymbolV2*>( symbol )->width() );
245 if ( catIndex < 0 || catIndex >=
mCategories.size() )
253 if ( catIndex < 0 || catIndex >=
mCategories.size() )
261 if ( catIndex < 0 || catIndex >=
mCategories.size() )
269 if ( cat.
symbol() == NULL )
271 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
281 if ( catIndex < 0 || catIndex >=
mCategories.size() )
310 if ( order == Qt::AscendingOrder )
322 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
332 if ( order == Qt::AscendingOrder )
355 QgsCategoryList::iterator it =
mCategories.begin();
358 it->symbol()->startRender( context, vlayer );
374 QgsCategoryList::iterator it =
mCategories.begin();
376 it->symbol()->stopRender( context );
379 QHash<QString, QgsSymbolV2*>::iterator it2 =
mTempSymbols.begin();
382 it2.value()->stopRender( context );
391 QSet<QString> attributes;
395 attributes.unite( exp->referencedColumns().toSet() );
402 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
411 return attributes.toList();
416 QString s = QString(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
444 props[
"angle" ] =
mRotation->expression();
452 it->toSld( doc, element, catProps );
466 QDomElement symbolsElem = element.firstChildElement(
"symbols" );
467 if ( symbolsElem.isNull() )
470 QDomElement catsElem = element.firstChildElement(
"categories" );
471 if ( catsElem.isNull() )
477 QDomElement catElem = catsElem.firstChildElement();
478 while ( !catElem.isNull() )
480 if ( catElem.tagName() ==
"category" )
482 QVariant value = QVariant( catElem.attribute(
"value" ) );
483 QString symbolName = catElem.attribute(
"symbol" );
484 QString label = catElem.attribute(
"label" );
485 if ( symbolMap.contains( symbolName ) )
487 QgsSymbolV2* symbol = symbolMap.take( symbolName );
491 catElem = catElem.nextSiblingElement();
494 QString attrName = element.attribute(
"attr" );
502 QDomElement sourceSymbolElem = element.firstChildElement(
"source-symbol" );
503 if ( !sourceSymbolElem.isNull() )
506 if ( sourceSymbolMap.contains(
"0" ) )
514 QDomElement sourceColorRampElem = element.firstChildElement(
"colorramp" );
515 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute(
"name" ) ==
"[source]" )
518 QDomElement invertedColorRampElem = element.firstChildElement(
"invertedcolorramp" );
519 if ( !invertedColorRampElem.isNull() )
523 QDomElement rotationElem = element.firstChildElement(
"rotation" );
524 if ( !rotationElem.isNull() )
527 QDomElement sizeScaleElem = element.firstChildElement(
"sizescale" );
528 if ( !sizeScaleElem.isNull() )
541 rendererElem.setAttribute(
"type",
"categorizedSymbol" );
543 rendererElem.setAttribute(
"attr",
mAttrName );
548 QDomElement catsElem = doc.createElement(
"categories" );
549 QgsCategoryList::const_iterator it =
mCategories.constBegin();
553 QString symbolName = QString::number( i );
554 symbols.insert( symbolName, cat.
symbol() );
556 QDomElement catElem = doc.createElement(
"category" );
557 catElem.setAttribute(
"value", cat.
value().toString() );
558 catElem.setAttribute(
"symbol", symbolName );
559 catElem.setAttribute(
"label", cat.
label() );
560 catsElem.appendChild( catElem );
564 rendererElem.appendChild( catsElem );
568 rendererElem.appendChild( symbolsElem );
576 rendererElem.appendChild( sourceSymbolElem );
583 rendererElem.appendChild( colorRampElem );
584 QDomElement invertedElem = doc.createElement(
"invertedcolorramp" );
586 rendererElem.appendChild( invertedElem );
589 QDomElement rotationElem = doc.createElement(
"rotation" );
592 rendererElem.appendChild( rotationElem );
594 QDomElement sizeScaleElem = doc.createElement(
"sizescale" );
598 rendererElem.appendChild( sizeScaleElem );
606 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
609 if ( showClassifiers )
615 for (
int i = 0; i < count; i++ )
619 lst << qMakePair( cat.
label(), pix );
626 Q_UNUSED( scaleDenominator );
628 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
631 if ( showClassifiers )
638 if ( rule.isEmpty() || cat.
label() == rule )
700 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();