31 #include <QDomElement>
32 #include <QDomDocument>
40 unsigned int wkbType = *((
int* ) wkb );
41 wkb +=
sizeof(
unsigned int );
43 double x = *((
double * ) wkb ); wkb +=
sizeof( double );
44 double y = *((
double * ) wkb ); wkb +=
sizeof( double );
47 wkb +=
sizeof( double );
64 unsigned int wkbType = *((
int* ) wkb );
65 wkb +=
sizeof(
unsigned int );
66 unsigned int nPoints = *((
int* ) wkb );
67 wkb +=
sizeof(
unsigned int );
78 double cw = e.
width() / 10;
double ch = e.
height() / 10;
84 pts.resize( nPoints );
86 QPointF* ptr = pts.data();
87 for (
unsigned int i = 0; i < nPoints; ++i, ++ptr )
89 x = *((
double * ) wkb );
90 wkb +=
sizeof( double );
91 y = *((
double * ) wkb );
92 wkb +=
sizeof( double );
95 wkb +=
sizeof( double );
97 *ptr = QPointF( x, y );
107 QPointF* ptr = pts.data();
108 for (
int i = 0; i < pts.size(); ++i, ++ptr )
120 unsigned int wkbType = *((
int* ) wkb );
121 wkb +=
sizeof(
unsigned int );
122 unsigned int numRings = *((
int* ) wkb );
123 wkb +=
sizeof(
unsigned int );
135 double cw = e.
width() / 10;
double ch = e.
height() / 10;
138 for (
unsigned int idx = 0; idx < numRings; idx++ )
140 unsigned int nPoints = *((
int* )wkb );
141 wkb +=
sizeof(
unsigned int );
143 QPolygonF poly( nPoints );
146 QPointF* ptr = poly.data();
147 for (
unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
149 x = *((
double * ) wkb ); wkb +=
sizeof( double );
150 y = *((
double * ) wkb ); wkb +=
sizeof( double );
152 *ptr = QPointF( x, y );
155 wkb +=
sizeof( double );
172 for (
int i = 0; i < poly.size(); ++i, ++ptr )
180 holes.append( poly );
203 : mType( type ), mUsingSymbolLevels( false ),
205 mCurrentVertexMarkerSize( 3 )
218 if ( symbol == NULL )
237 QgsDebugMsg(
"point can be drawn only with marker symbol!" );
242 ((
QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
254 QgsDebugMsg(
"linestring can be drawn only with line symbol!" );
259 ((
QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
261 if ( drawVertexMarker )
271 QgsDebugMsg(
"polygon can be drawn only with fill symbol!" );
275 QList<QPolygonF> holes;
277 ((
QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
279 if ( drawVertexMarker )
289 QgsDebugMsg(
"multi-point can be drawn only with marker symbol!" );
293 const unsigned char* wkb = geom->
asWkb();
294 unsigned int num = *((
int* )( wkb + 5 ) );
295 const unsigned char* ptr = wkb + 9;
298 for (
unsigned int i = 0; i < num; ++i )
301 ((
QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
314 QgsDebugMsg(
"multi-linestring can be drawn only with line symbol!" );
318 const unsigned char* wkb = geom->
asWkb();
319 unsigned int num = *((
int* )( wkb + 5 ) );
320 const unsigned char* ptr = wkb + 9;
323 for (
unsigned int i = 0; i < num; ++i )
326 ((
QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
328 if ( drawVertexMarker )
339 QgsDebugMsg(
"multi-polygon can be drawn only with fill symbol!" );
343 const unsigned char* wkb = geom->
asWkb();
344 unsigned int num = *((
int* )( wkb + 5 ) );
345 const unsigned char* ptr = wkb + 9;
347 QList<QPolygonF> holes;
349 for (
unsigned int i = 0; i < num; ++i )
352 ((
QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
354 if ( drawVertexMarker )
361 QgsDebugMsg( QString(
"feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.
id() ).arg( geom->
wkbType(), 0, 16 ) );
367 return "UNKNOWN RENDERER\n";
375 if ( element.isNull() )
379 QString rendererType = element.attribute(
"type" );
401 QDomElement element = node.toElement();
402 if ( element.isNull() )
406 QDomElement userStyleElem = element.firstChildElement(
"UserStyle" );
407 if ( userStyleElem.isNull() )
410 errorMessage =
"Info: UserStyle element not found.";
415 QDomElement featTypeStyleElem = userStyleElem.firstChildElement(
"FeatureTypeStyle" );
416 if ( featTypeStyleElem.isNull() )
418 errorMessage =
"Info: FeatureTypeStyle element not found.";
425 bool needRuleRenderer =
false;
428 QDomElement ruleElem = featTypeStyleElem.firstChildElement(
"Rule" );
429 while ( !ruleElem.isNull() )
436 QgsDebugMsg(
"more Rule elements found: need a RuleRenderer" );
437 needRuleRenderer =
true;
441 QDomElement ruleChildElem = ruleElem.firstChildElement();
442 while ( !ruleChildElem.isNull() )
445 if ( ruleChildElem.localName() ==
"Filter" ||
446 ruleChildElem.localName() ==
"MinScaleDenominator" ||
447 ruleChildElem.localName() ==
"MaxScaleDenominator" )
449 QgsDebugMsg(
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
450 needRuleRenderer =
true;
454 ruleChildElem = ruleChildElem.nextSiblingElement();
457 if ( needRuleRenderer )
462 ruleElem = ruleElem.nextSiblingElement(
"Rule" );
465 QString rendererType;
466 if ( needRuleRenderer )
468 rendererType =
"RuleRenderer";
472 rendererType =
"singleSymbol";
474 QgsDebugMsg( QString(
"Instantiating a '%1' renderer..." ).arg( rendererType ) );
480 errorMessage = QString(
"Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
490 QDomElement userStyleElem = doc.createElement(
"UserStyle" );
492 QDomElement nameElem = doc.createElement(
"se:Name" );
493 nameElem.appendChild( doc.createTextNode( layer.
name() ) );
494 userStyleElem.appendChild( nameElem );
496 QDomElement featureTypeStyleElem = doc.createElement(
"se:FeatureTypeStyle" );
497 toSld( doc, featureTypeStyleElem );
498 userStyleElem.appendChild( featureTypeStyleElem );
500 return userStyleElem;
505 Q_UNUSED( iconSize );
530 foreach ( QPointF pt, pts )
536 foreach ( QPointF pt, pts )
541 foreach ( QPolygonF ring, *rings )
543 foreach ( QPointF pt, ring )
553 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.
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)
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.
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
VertexMarkerType
Editing vertex markers.
static const unsigned char * _getLineString(QPolygonF &pts, QgsRenderContext &context, const unsigned char *wkb)
A geometry is the spatial representation of a feature.
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
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.
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)
void transformInPlace(double &x, double &y) const
virtual QgsLegendSymbolList legendSymbolItems()
return a list of item text / symbol
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
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.
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
void setVertexMarkerAppearance(int type, int size)
set type and size of editing vertex markers for subsequent rendering
void setScaleMethodToSymbol(QgsSymbolV2 *symbol, int scaleMethod)
virtual 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
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
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.