29 #include <QDomDocument>
30 #include <QDomElement>
47 : mValue( cat.mValue )
48 , mSymbol( cat.mSymbol.data() ? cat.mSymbol->clone() : NULL )
49 , mLabel( cat.mLabel )
50 , mRender( cat.mRender )
115 if ( !
mSymbol.data() || props.value(
"attribute",
"" ).isEmpty() )
118 QString attrName = props[
"attribute" ];
120 QDomElement ruleElem = doc.createElement(
"se:Rule" );
121 element.appendChild( ruleElem );
123 QDomElement nameElem = doc.createElement(
"se:Name" );
124 nameElem.appendChild( doc.createTextNode(
mLabel ) );
125 ruleElem.appendChild( nameElem );
127 QDomElement descrElem = doc.createElement(
"se:Description" );
128 QDomElement titleElem = doc.createElement(
"se:Title" );
129 QString descrStr = QString(
"%1 is '%2'" ).arg( attrName ).arg(
mValue.toString() );
130 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
131 descrElem.appendChild( titleElem );
132 ruleElem.appendChild( descrElem );
135 QString filterFunc = QString(
"%1 = '%2'" )
136 .arg( attrName.replace(
"\"",
"\"\"" ) )
137 .arg(
mValue.toString().replace(
"'",
"''" ) );
140 mSymbol->toSld( doc, ruleElem, props );
147 , mAttrName( attrName )
148 , mCategories( categories )
149 , mInvertedColorRamp( false )
157 if ( cat.
symbol() == NULL )
159 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
184 QHash<QString, QgsSymbolV2*>::iterator it =
mSymbolHash.find( value.isNull() ?
"" : value.toString() );
211 const double rotation =
mRotation.data() ?
mRotation->evaluate( feature ).toDouble() : 0;
222 markerSymbol->
setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->
size() );
228 lineSymbol->
setWidth( sizeScale * static_cast<QgsLineSymbolV2*>( symbol )->width() );
292 if ( catIndex < 0 || catIndex >=
mCategories.size() )
300 if ( catIndex < 0 || catIndex >=
mCategories.size() )
308 if ( catIndex < 0 || catIndex >=
mCategories.size() )
316 if ( catIndex < 0 || catIndex >=
mCategories.size() )
326 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
335 if ( catIndex < 0 || catIndex >=
mCategories.size() )
364 if ( order == Qt::AscendingOrder )
376 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
386 if ( order == Qt::AscendingOrder )
411 QgsCategoryList::iterator it =
mCategories.begin();
414 it->symbol()->startRender( context, &fields );
429 QgsCategoryList::iterator it =
mCategories.begin();
431 it->symbol()->stopRender( context );
434 QHash<QgsSymbolV2*, QgsSymbolV2*>::iterator it2 =
mTempSymbols.begin();
437 it2.value()->stopRender( context );
446 QSet<QString> attributes;
461 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
470 return attributes.toList();
475 QString s = QString(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
503 props[
"angle" ] =
mRotation->expression();
511 it->toSld( doc, element, catProps );
525 QDomElement symbolsElem = element.firstChildElement(
"symbols" );
526 if ( symbolsElem.isNull() )
529 QDomElement catsElem = element.firstChildElement(
"categories" );
530 if ( catsElem.isNull() )
536 QDomElement catElem = catsElem.firstChildElement();
537 while ( !catElem.isNull() )
539 if ( catElem.tagName() ==
"category" )
541 QVariant value = QVariant( catElem.attribute(
"value" ) );
542 QString symbolName = catElem.attribute(
"symbol" );
543 QString label = catElem.attribute(
"label" );
544 bool render = catElem.attribute(
"render" ) !=
"false";
545 if ( symbolMap.contains( symbolName ) )
547 QgsSymbolV2* symbol = symbolMap.take( symbolName );
551 catElem = catElem.nextSiblingElement();
554 QString attrName = element.attribute(
"attr" );
562 QDomElement sourceSymbolElem = element.firstChildElement(
"source-symbol" );
563 if ( !sourceSymbolElem.isNull() )
566 if ( sourceSymbolMap.contains(
"0" ) )
574 QDomElement sourceColorRampElem = element.firstChildElement(
"colorramp" );
575 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute(
"name" ) ==
"[source]" )
578 QDomElement invertedColorRampElem = element.firstChildElement(
"invertedcolorramp" );
579 if ( !invertedColorRampElem.isNull() )
583 QDomElement rotationElem = element.firstChildElement(
"rotation" );
584 if ( !rotationElem.isNull() )
587 QDomElement sizeScaleElem = element.firstChildElement(
"sizescale" );
588 if ( !sizeScaleElem.isNull() )
601 rendererElem.setAttribute(
"type",
"categorizedSymbol" );
603 rendererElem.setAttribute(
"attr",
mAttrName );
608 QDomElement catsElem = doc.createElement(
"categories" );
609 QgsCategoryList::const_iterator it =
mCategories.constBegin();
613 QString symbolName = QString::number( i );
614 symbols.insert( symbolName, cat.
symbol() );
616 QDomElement catElem = doc.createElement(
"category" );
617 catElem.setAttribute(
"value", cat.
value().toString() );
618 catElem.setAttribute(
"symbol", symbolName );
619 catElem.setAttribute(
"label", cat.
label() );
620 catElem.setAttribute(
"render", cat.
renderState() ?
"true" :
"false" );
621 catsElem.appendChild( catElem );
625 rendererElem.appendChild( catsElem );
629 rendererElem.appendChild( symbolsElem );
637 rendererElem.appendChild( sourceSymbolElem );
644 rendererElem.appendChild( colorRampElem );
645 QDomElement invertedElem = doc.createElement(
"invertedcolorramp" );
647 rendererElem.appendChild( invertedElem );
650 QDomElement rotationElem = doc.createElement(
"rotation" );
653 rendererElem.appendChild( rotationElem );
655 QDomElement sizeScaleElem = doc.createElement(
"sizescale" );
659 rendererElem.appendChild( sizeScaleElem );
668 for (
int i = 0; i < count; i++ )
672 lst << qMakePair( cat.
label(), pix );
679 Q_UNUSED( scaleDenominator );
684 if ( rule.isEmpty() || cat.
label() == rule )
729 double value = count / num;
771 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
786 int index = key.toInt( &ok );
787 if ( ok && index >= 0 && index <
mCategories.size() )
796 int index = key.toInt( &ok );
805 if ( renderer->
type() ==
"categorizedSymbol" )
809 if ( renderer->
type() ==
"pointDisplacement" )
812 if ( pointDisplacementRenderer )
815 if ( renderer->
type() ==
"invertedPolygonRenderer" )
818 if ( invertedPolygonRenderer )
827 if ( symbols.size() > 0 )