27 #include <QDomDocument>
28 #include <QDomElement>
32 : mValue(), mSymbol( 0 ), mLabel()
37 : mValue( value ), mSymbol( symbol ), mLabel( label )
42 : mValue( cat.mValue ), mSymbol( 0 ), mLabel( cat.mLabel )
107 if ( !
mSymbol || props.value(
"attribute",
"" ).isEmpty() )
110 QString attrName = props[
"attribute" ];
112 QDomElement ruleElem = doc.createElement(
"se:Rule" );
113 element.appendChild( ruleElem );
115 QDomElement nameElem = doc.createElement(
"se:Name" );
116 nameElem.appendChild( doc.createTextNode(
mLabel ) );
117 ruleElem.appendChild( nameElem );
119 QDomElement descrElem = doc.createElement(
"se:Description" );
120 QDomElement titleElem = doc.createElement(
"se:Title" );
121 QString descrStr = QString(
"%1 is '%2'" ).arg( attrName ).arg(
mValue.toString() );
122 titleElem.appendChild( doc.createTextNode( !
mLabel.isEmpty() ?
mLabel : descrStr ) );
123 descrElem.appendChild( titleElem );
124 ruleElem.appendChild( descrElem );
127 QString filterFunc = QString(
"%1 = '%2'" )
128 .arg( attrName.replace(
"\"",
"\"\"" ) )
129 .arg(
mValue.toString().replace(
"'",
"''" ) );
139 mAttrName( attrName ),
140 mCategories( categories ),
141 mSourceSymbol( NULL ),
142 mSourceColorRamp( NULL ),
144 mRotationFieldIdx( -1 ),
145 mSizeScaleFieldIdx( -1 )
150 if ( cat.
symbol() == NULL )
152 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
180 QHash<QString, QgsSymbolV2*>::iterator it =
mSymbolHash.find( value.toString() );
200 if ( mAttrNum < 0 || mAttrNum >= attrs.count() )
208 if ( symbol == NULL )
219 double sizeScale = 1;
235 markerSymbol->
setSize( sizeScale * static_cast<QgsMarkerSymbolV2*>( symbol )->
size() );
242 lineSymbol->
setWidth( sizeScale * static_cast<QgsLineSymbolV2*>( symbol )->width() );
260 if ( catIndex < 0 || catIndex >=
mCategories.size() )
268 if ( catIndex < 0 || catIndex >=
mCategories.size() )
276 if ( catIndex < 0 || catIndex >=
mCategories.size() )
284 if ( cat.
symbol() == NULL )
286 QgsDebugMsg(
"invalid symbol in a category! ignoring..." );
296 if ( catIndex < 0 || catIndex >=
mCategories.size() )
325 if ( order == Qt::AscendingOrder )
337 return QString::localeAwareCompare( c1.
label(), c2.
label() ) < 0;
347 if ( order == Qt::AscendingOrder )
368 QgsCategoryList::iterator it =
mCategories.begin();
371 it->symbol()->startRender( context, vlayer );
387 QgsCategoryList::iterator it =
mCategories.begin();
389 it->symbol()->stopRender( context );
392 QHash<QString, QgsSymbolV2*>::iterator it2 =
mTempSymbols.begin();
395 it2.value()->stopRender( context );
403 QSet<QString> attributes;
414 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
423 return attributes.toList();
428 QString s = QString(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
453 props[
"angle" ] = QString(
mRotationField ).append(
"\"" ).prepend(
"\"" );
455 props[
"scale" ] = QString(
mSizeScaleField ).append(
"\"" ).prepend(
"\"" );
461 it->toSld( doc, element, catProps );
475 QDomElement symbolsElem = element.firstChildElement(
"symbols" );
476 if ( symbolsElem.isNull() )
479 QDomElement catsElem = element.firstChildElement(
"categories" );
480 if ( catsElem.isNull() )
486 QDomElement catElem = catsElem.firstChildElement();
487 while ( !catElem.isNull() )
489 if ( catElem.tagName() ==
"category" )
491 QVariant value = QVariant( catElem.attribute(
"value" ) );
492 QString symbolName = catElem.attribute(
"symbol" );
493 QString label = catElem.attribute(
"label" );
494 if ( symbolMap.contains( symbolName ) )
496 QgsSymbolV2* symbol = symbolMap.take( symbolName );
500 catElem = catElem.nextSiblingElement();
503 QString attrName = element.attribute(
"attr" );
511 QDomElement sourceSymbolElem = element.firstChildElement(
"source-symbol" );
512 if ( !sourceSymbolElem.isNull() )
515 if ( sourceSymbolMap.contains(
"0" ) )
523 QDomElement sourceColorRampElem = element.firstChildElement(
"colorramp" );
524 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute(
"name" ) ==
"[source]" )
529 QDomElement rotationElem = element.firstChildElement(
"rotation" );
530 if ( !rotationElem.isNull() )
533 QDomElement sizeScaleElem = element.firstChildElement(
"sizescale" );
534 if ( !sizeScaleElem.isNull() )
547 rendererElem.setAttribute(
"type",
"categorizedSymbol" );
549 rendererElem.setAttribute(
"attr",
mAttrName );
554 QDomElement catsElem = doc.createElement(
"categories" );
555 QgsCategoryList::const_iterator it =
mCategories.constBegin();
559 QString symbolName = QString::number( i );
560 symbols.insert( symbolName, cat.
symbol() );
562 QDomElement catElem = doc.createElement(
"category" );
563 catElem.setAttribute(
"value", cat.
value().toString() );
564 catElem.setAttribute(
"symbol", symbolName );
565 catElem.setAttribute(
"label", cat.
label() );
566 catsElem.appendChild( catElem );
570 rendererElem.appendChild( catsElem );
574 rendererElem.appendChild( symbolsElem );
582 rendererElem.appendChild( sourceSymbolElem );
589 rendererElem.appendChild( colorRampElem );
592 QDomElement rotationElem = doc.createElement(
"rotation" );
594 rendererElem.appendChild( rotationElem );
596 QDomElement sizeScaleElem = doc.createElement(
"sizescale" );
599 rendererElem.appendChild( sizeScaleElem );
607 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
610 if ( showClassifiers )
616 for (
int i = 0; i < count; i++ )
620 lst << qMakePair( cat.
label(), pix );
628 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
631 if ( showClassifiers )
679 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();