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, &fields );
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;
406 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
415 return attributes.toList();
420 QString s = QString(
"CATEGORIZED: idx %1\n" ).arg(
mAttrName );
448 props[
"angle" ] =
mRotation->expression();
456 it->toSld( doc, element, catProps );
470 QDomElement symbolsElem = element.firstChildElement(
"symbols" );
471 if ( symbolsElem.isNull() )
474 QDomElement catsElem = element.firstChildElement(
"categories" );
475 if ( catsElem.isNull() )
481 QDomElement catElem = catsElem.firstChildElement();
482 while ( !catElem.isNull() )
484 if ( catElem.tagName() ==
"category" )
486 QVariant value = QVariant( catElem.attribute(
"value" ) );
487 QString symbolName = catElem.attribute(
"symbol" );
488 QString label = catElem.attribute(
"label" );
489 if ( symbolMap.contains( symbolName ) )
491 QgsSymbolV2* symbol = symbolMap.take( symbolName );
495 catElem = catElem.nextSiblingElement();
498 QString attrName = element.attribute(
"attr" );
506 QDomElement sourceSymbolElem = element.firstChildElement(
"source-symbol" );
507 if ( !sourceSymbolElem.isNull() )
510 if ( sourceSymbolMap.contains(
"0" ) )
518 QDomElement sourceColorRampElem = element.firstChildElement(
"colorramp" );
519 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute(
"name" ) ==
"[source]" )
522 QDomElement invertedColorRampElem = element.firstChildElement(
"invertedcolorramp" );
523 if ( !invertedColorRampElem.isNull() )
527 QDomElement rotationElem = element.firstChildElement(
"rotation" );
528 if ( !rotationElem.isNull() )
531 QDomElement sizeScaleElem = element.firstChildElement(
"sizescale" );
532 if ( !sizeScaleElem.isNull() )
545 rendererElem.setAttribute(
"type",
"categorizedSymbol" );
547 rendererElem.setAttribute(
"attr",
mAttrName );
552 QDomElement catsElem = doc.createElement(
"categories" );
553 QgsCategoryList::const_iterator it =
mCategories.constBegin();
557 QString symbolName = QString::number( i );
558 symbols.insert( symbolName, cat.
symbol() );
560 QDomElement catElem = doc.createElement(
"category" );
561 catElem.setAttribute(
"value", cat.
value().toString() );
562 catElem.setAttribute(
"symbol", symbolName );
563 catElem.setAttribute(
"label", cat.
label() );
564 catsElem.appendChild( catElem );
568 rendererElem.appendChild( catsElem );
572 rendererElem.appendChild( symbolsElem );
580 rendererElem.appendChild( sourceSymbolElem );
587 rendererElem.appendChild( colorRampElem );
588 QDomElement invertedElem = doc.createElement(
"invertedcolorramp" );
590 rendererElem.appendChild( invertedElem );
593 QDomElement rotationElem = doc.createElement(
"rotation" );
596 rendererElem.appendChild( rotationElem );
598 QDomElement sizeScaleElem = doc.createElement(
"sizescale" );
602 rendererElem.appendChild( sizeScaleElem );
610 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
613 if ( showClassifiers )
619 for (
int i = 0; i < count; i++ )
623 lst << qMakePair( cat.
label(), pix );
630 Q_UNUSED( scaleDenominator );
632 bool showClassifiers = settings.value(
"/qgis/showLegendClassifiers",
false ).toBool();
635 if ( showClassifiers )
642 if ( rule.isEmpty() || cat.
label() == rule )
704 QgsCategoryList::const_iterator catIt =
mCategories.constBegin();
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
Class for parsing and evaluation of expressions (formerly called "search strings").
static QgsSymbolV2Map loadSymbols(QDomElement &element)
void setValue(const QVariant &value)
void setLabel(const QString &label)
#define RENDERER_TAG_NAME
QgsSymbolV2::ScaleMethod mScaleMethod
virtual QgsFeatureRendererV2 * clone()
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
const QgsCategoryList & categories() const
static QgsVectorColorRampV2 * loadColorRamp(QDomElement &element)
QgsVectorColorRampV2 * sourceColorRamp()
QList< QgsSymbolV2 * > QgsSymbolV2List
void setRotationField(QString fieldOrExpression)
QSet< QString > usedAttributes() const
void setSourceSymbol(QgsSymbolV2 *sym)
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name - case insensitive TODO: sort out case sensitive (indexFromName()) vs...
virtual QgsSymbolV2 * clone() const =0
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
QScopedPointer< QgsSymbolV2 > mSourceSymbol
virtual QgsSymbolV2List symbols()
for symbol levels
virtual QString dump() const
for debugging
QScopedPointer< QgsExpression > mRotation
Container of fields for a vector layer.
void moveCategory(int from, int to)
Moves the category at index position from to index position to.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
void setSizeScaleField(QString fieldOrExpression)
QScopedPointer< QgsSymbolV2 > mSymbol
QMap< QString, QString > QgsStringMap
void setSourceColorRamp(QgsVectorColorRampV2 *ramp)
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
void setWidth(double width)
QHash< QString, QgsSymbolV2 * > mSymbolHash
hashtable for faster access to symbols
QScopedPointer< QgsExpression > mSizeScale
QgsCategoryList mCategories
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
void updateSymbols(QgsSymbolV2 *sym)
void setColor(const QColor &color)
void deleteAllCategories()
QList< QgsRendererCategoryV2 > QgsCategoryList
static QDomElement saveColorRamp(QString name, QgsVectorColorRampV2 *ramp, QDomDocument &doc)
QScopedPointer< QgsVectorColorRampV2 > mSourceColorRamp
#define QgsDebugMsgLevel(str, level)
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
bool labelGreaterThan(const QgsRendererCategoryV2 &c1, const QgsRendererCategoryV2 &c2)
#define DEFAULT_SCALE_METHOD
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, QString function)
QgsSymbolV2 * symbolForValue(QVariant value)
virtual ~QgsCategorizedSymbolRendererV2()
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule=QString())
return a list of item text / symbol
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, QString tagName, QDomDocument &doc)
static QgsFeatureRendererV2 * create(QDomElement &element)
create renderer from XML element
QStringList referencedColumns()
Get list of columns referenced by the expression.
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)
to be overridden
int categoryIndexForValue(QVariant val)
return index of category with specified value (-1 if not found)
void setAngle(double angle)
const QgsAttributes & attributes() const
void setSize(double size)
virtual void stopRender(QgsRenderContext &context)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
bool labelLessThan(const QgsRendererCategoryV2 &c1, const QgsRendererCategoryV2 &c2)
QHash< QString, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
bool updateCategoryLabel(int catIndex, QString label)
void setUsingSymbolLevels(bool usingSymbolLevels)
void setSymbol(QgsSymbolV2 *s)
QString rotationField() const
bool valueLessThan(const QgsRendererCategoryV2 &c1, const QgsRendererCategoryV2 &c2)
Contains information about the context of a rendering operation.
QgsSymbolV2 * sourceSymbol()
QgsCategorizedSymbolRendererV2(QString attrName=QString(), QgsCategoryList categories=QgsCategoryList())
static QgsExpression * fieldOrExpressionToExpression(const QString &fieldOrExpression)
Return a new valid expression instance for given field or expression string.
QVector< QVariant > QgsAttributes
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
static QString encodeScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
bool updateCategoryValue(int catIndex, const QVariant &value)
bool deleteCategory(int catIndex)
bool valueGreaterThan(const QgsRendererCategoryV2 &c1, const QgsRendererCategoryV2 &c2)
static QString fieldOrExpressionFromExpression(QgsExpression *expression)
Return a field name if the whole expression is just a name of the field .
bool usingSymbolLevels() const
void setScaleMethodToSymbol(QgsSymbolV2 *symbol, int scaleMethod)
QString sizeScaleField() const
bool updateCategorySymbol(int catIndex, QgsSymbolV2 *symbol)
int mAttrNum
attribute index (derived from attribute name in startRender)
static QPixmap symbolPreviewPixmap(QgsSymbolV2 *symbol, QSize size)
QString classAttribute() const
void setRenderHints(int hints)
static void clearSymbolMap(QgsSymbolV2Map &symbols)
static QgsSymbolV2::ScaleMethod decodeScaleMethod(QString str)
void swap(QgsRendererCategoryV2 &other)
QgsRendererCategoryV2 & operator=(QgsRendererCategoryV2 cat)
QgsSymbolV2::ScaleMethod scaleMethod() const
virtual QList< QString > usedAttributes()
void addCategory(const QgsRendererCategoryV2 &category)
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
QgsSymbolV2 * symbol() const
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
QScopedPointer< QgsExpression > mExpression
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
void setInvertedColorRamp(bool inverted)