32 #include <QDomElement> 33 #include <QDomDocument> 42 wkbPtr >> wkbType >> pt.rx() >> pt.ry();
45 wkbPtr +=
sizeof( double );
61 unsigned int wkbType, nPoints;
62 wkbPtr >> wkbType >> nPoints;
74 double cw = e.
width() / 10;
double ch = e.
height() / 10;
80 pts.resize( nPoints );
82 QPointF* ptr = pts.data();
83 for (
unsigned int i = 0; i < nPoints; ++i, ++ptr )
87 wkbPtr +=
sizeof( double );
89 *ptr = QPointF( x, y );
99 QPointF* ptr = pts.data();
100 for (
int i = 0; i < pts.size(); ++i, ++ptr )
112 unsigned int wkbType, numRings;
113 wkbPtr >> wkbType >> numRings;
126 double cw = e.
width() / 10;
double ch = e.
height() / 10;
129 for (
unsigned int idx = 0; idx < numRings; idx++ )
131 unsigned int nPoints;
134 QPolygonF poly( nPoints );
137 QPointF* ptr = poly.data();
138 for (
unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
142 wkbPtr +=
sizeof( double );
144 *ptr = QPointF( x, y );
151 QRectF ptsRect = poly.boundingRect();
162 for (
int i = 0; i < poly.size(); ++i, ++ptr )
170 holes.append( poly );
213 if ( symbol == NULL )
232 QgsDebugMsg(
"point can be drawn only with marker symbol!" );
237 ((
QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
249 QgsDebugMsg(
"linestring can be drawn only with line symbol!" );
254 ((
QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
256 if ( drawVertexMarker )
266 QgsDebugMsg(
"polygon can be drawn only with fill symbol!" );
270 QList<QPolygonF> holes;
272 ((
QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
274 if ( drawVertexMarker )
284 QgsDebugMsg(
"multi-point can be drawn only with marker symbol!" );
291 const unsigned char* ptr = wkbPtr;
294 for (
unsigned int i = 0; i < num; ++i )
297 ((
QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
310 QgsDebugMsg(
"multi-linestring can be drawn only with line symbol!" );
317 const unsigned char* ptr = wkbPtr;
320 for (
unsigned int i = 0; i < num; ++i )
323 ((
QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
325 if ( drawVertexMarker )
336 QgsDebugMsg(
"multi-polygon can be drawn only with fill symbol!" );
343 const unsigned char* ptr = wkbPtr;
345 QList<QPolygonF> holes;
347 for (
unsigned int i = 0; i < num; ++i )
350 ((
QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
352 if ( drawVertexMarker )
359 QgsDebugMsg( QString(
"feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.
id() ).arg( geom->
wkbType(), 0, 16 ) );
365 return "UNKNOWN RENDERER\n";
373 if ( element.isNull() )
377 QString rendererType = element.attribute(
"type" );
399 QDomElement element = node.toElement();
400 if ( element.isNull() )
404 QDomElement userStyleElem = element.firstChildElement(
"UserStyle" );
405 if ( userStyleElem.isNull() )
408 errorMessage =
"Info: UserStyle element not found.";
413 QDomElement featTypeStyleElem = userStyleElem.firstChildElement(
"FeatureTypeStyle" );
414 if ( featTypeStyleElem.isNull() )
416 errorMessage =
"Info: FeatureTypeStyle element not found.";
423 bool needRuleRenderer =
false;
426 QDomElement ruleElem = featTypeStyleElem.firstChildElement(
"Rule" );
427 while ( !ruleElem.isNull() )
434 QgsDebugMsg(
"more Rule elements found: need a RuleRenderer" );
435 needRuleRenderer =
true;
439 QDomElement ruleChildElem = ruleElem.firstChildElement();
440 while ( !ruleChildElem.isNull() )
443 if ( ruleChildElem.localName() ==
"Filter" ||
444 ruleChildElem.localName() ==
"MinScaleDenominator" ||
445 ruleChildElem.localName() ==
"MaxScaleDenominator" )
447 QgsDebugMsg(
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
448 needRuleRenderer =
true;
452 ruleChildElem = ruleChildElem.nextSiblingElement();
455 if ( needRuleRenderer )
460 ruleElem = ruleElem.nextSiblingElement(
"Rule" );
463 QString rendererType;
464 if ( needRuleRenderer )
466 rendererType =
"RuleRenderer";
470 rendererType =
"singleSymbol";
472 QgsDebugMsg( QString(
"Instantiating a '%1' renderer..." ).arg( rendererType ) );
478 errorMessage = QString(
"Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
493 QDomElement userStyleElem = doc.createElement(
"UserStyle" );
495 QDomElement nameElem = doc.createElement(
"se:Name" );
496 nameElem.appendChild( doc.createTextNode( styleName ) );
497 userStyleElem.appendChild( nameElem );
499 QDomElement featureTypeStyleElem = doc.createElement(
"se:FeatureTypeStyle" );
500 toSld( doc, featureTypeStyleElem );
501 userStyleElem.appendChild( featureTypeStyleElem );
503 return userStyleElem;
508 Q_UNUSED( iconSize );
532 Q_UNUSED( scaleDenominator );
542 for ( QgsLegendSymbolList::const_iterator it = lst.begin(); it != lst.end(); ++it, ++i )
564 foreach ( QPointF pt, pts )
570 foreach ( QPointF pt, pts )
575 foreach ( QPolygonF ring, *rings )
577 foreach ( QPointF pt, ring )
587 if ( s ) lst.append( s );
595 if ( s ) lst.append( s );
QgsFeatureId id() const
Get the feature id for this feature.
static QgsRendererV2Registry * instance()
#define RENDERER_TAG_NAME
A rectangle specified with double values.
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
QList< QgsSymbolV2 * > QgsSymbolV2List
QgsRendererV2AbstractMetadata * rendererMetadata(QString rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
static QgsFeatureRendererV2 * loadSld(const QDomNode &node, QGis::GeometryType geomType, QString &errorMessage)
create a new renderer according to the information contained in the UserStyle element of a SLD style ...
static const unsigned char * _getPoint(QPointF &pt, QgsRenderContext &context, const unsigned char *wkb)
virtual QString dump() const
for debugging
double yMaximum() const
Get the y maximum value (top side of rectangle)
void transformInPlace(qreal &x, qreal &y) const
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
static const unsigned char * clippedLineWKB(const unsigned char *wkb, const QgsRectangle &clipExtent, QPolygonF &line)
Reads a polyline from WKB and clips it to clipExtent.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
VertexMarkerType
Editing vertex markers.
static const unsigned char * _getLineString(QPolygonF &pts, QgsRenderContext &context, const unsigned char *wkb)
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
const QgsRectangle & extent() const
void renderVertexMarkerPolyline(QPolygonF &pts, QgsRenderContext &context)
render editing vertex marker for a polyline
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateTransform * coordinateTransform() const
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
void renderFeatureWithSymbol(QgsFeature &feature, QgsSymbolV2 *symbol, QgsRenderContext &context, int layer, bool selected, bool drawVertexMarker)
const QString & name() const
Get the display name of the layer.
virtual QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Perform transforms between map coordinates and device coordinates.
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
static const unsigned char * _getPolygon(QPolygonF &pts, QList< QPolygonF > &holes, QgsRenderContext &context, const unsigned char *wkb)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
int mCurrentVertexMarkerSize
The current size of editing marker.
int mCurrentVertexMarkerType
The current type of editing marker.
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
static QgsFeatureRendererV2 * defaultRenderer(QGis::GeometryType geomType)
return a new renderer - used by default in vector layers
static void drawVertexMarker(double x, double y, QPainter &p, QgsVectorLayer::VertexMarkerType type, int vertexSize)
Draws a vertex symbol at (screen) coordinates x, y.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
QgsFeatureRendererV2(QString type)
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
void setUsingSymbolLevels(bool usingSymbolLevels)
Contains information about the context of a rendering operation.
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
virtual QgsSymbolV2List symbolsForFeature(QgsFeature &feat)
return list of symbols used for rendering the feature.
static QgsFeatureRendererV2 * load(QDomElement &symbologyElem)
create a renderer from XML element
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const
Return a list of symbology items for the legend.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
void setScaleMethodToSymbol(QgsSymbolV2 *symbol, int scaleMethod)
virtual Q_DECL_DEPRECATED QDomElement writeSld(QDomDocument &doc, const QgsVectorLayer &layer) const
create the SLD UserStyle element following the SLD v1.1 specs
void renderVertexMarkerPolygon(QPolygonF &pts, QList< QPolygonF > *rings, QgsRenderContext &context)
render editing vertex marker for a polygon
const QgsMapToPixel & mapToPixel() const
QList< QgsLegendSymbolItemV2 > QgsLegendSymbolListV2
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
double width() const
Width of the rectangle.
static void trimPolygon(QPolygonF &pts, const QgsRectangle &clipRect)
Represents a vector layer which manages a vector based data sets.
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
double xMinimum() const
Get the x minimum value (left side of rectangle)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
void renderVertexMarker(QPointF &pt, QgsRenderContext &context)
render editing vertex marker at specified point
double height() const
Height of the rectangle.