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();
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()
static QgsVectorColorRampV2 * loadColorRamp(QDomElement &element)
QgsVectorColorRampV2 * sourceColorRamp()
QList< QgsSymbolV2 * > QgsSymbolV2List
void setRotationField(QString fieldOrExpression)
QSet< QString > usedAttributes() const
void setSourceSymbol(QgsSymbolV2 *sym)
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
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)
const QgsCategoryList & categories()
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)
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
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)
virtual void startRender(QgsRenderContext &context, const QgsVectorLayer *vlayer)
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)
void startRender(QgsRenderContext &context, const QgsVectorLayer *layer=0)
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)
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
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
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
QgsSymbolV2 * symbol() const
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
QScopedPointer< QgsExpression > mExpression
void setInvertedColorRamp(bool inverted)