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();
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
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
QSet< QString > usedAttributes() const
void setSourceSymbol(QgsSymbolV2 *sym)
virtual QgsSymbolV2 * clone() const =0
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual QgsSymbolV2List symbols()
for symbol levels
virtual QString dump() const
for debugging
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)
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
QgsRendererCategoryV2 & operator=(const QgsRendererCategoryV2 &cat)
virtual QgsLegendSymbolList legendSymbolItems()
return a list of item text / symbol
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)
#define QgsDebugMsgLevel(str, level)
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
bool labelGreaterThan(const QgsRendererCategoryV2 &c1, const QgsRendererCategoryV2 &c2)
#define DEFAULT_SCALE_METHOD
virtual QgsVectorColorRampV2 * clone() const =0
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, QString function)
QgsSymbolV2 * symbolForValue(QVariant value)
virtual ~QgsCategorizedSymbolRendererV2()
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, QString tagName, QDomDocument &doc)
static QgsFeatureRendererV2 * create(QDomElement &element)
create renderer from XML element
void setSizeScaleField(QString fieldName)
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 setRotationField(QString fieldName)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
QgsVectorColorRampV2 * mSourceColorRamp
bool labelLessThan(const QgsRendererCategoryV2 &c1, const QgsRendererCategoryV2 &c2)
QHash< QString, QgsSymbolV2 * > mTempSymbols
temporary symbols, used for data-defined rotation and scaling
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())
QgsSymbolV2 * mSourceSymbol
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)
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)
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)