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 );
71 int sizeOfDoubleX =
sizeof( double );
72 int sizeOfDoubleY = hasZValue ? 2 *
sizeof( double ) :
sizeof(
double );
82 double cw = e.
width() / 10;
double ch = e.
height() / 10;
88 pts.resize( nPoints );
90 QPointF* ptr = pts.data();
91 for (
unsigned int i = 0; i < nPoints; ++i, ++ptr )
93 memcpy( &x, wkb,
sizeof(
double ) ); wkb += sizeOfDoubleX;
94 memcpy( &y, wkb,
sizeof(
double ) ); wkb += sizeOfDoubleY;
96 *ptr = QPointF( x, y );
106 QPointF* ptr = pts.data();
107 for (
int i = 0; i < pts.size(); ++i, ++ptr )
119 unsigned int wkbType = *((
int* ) wkb );
120 wkb +=
sizeof(
unsigned int );
121 unsigned int numRings = *((
int* ) wkb );
122 wkb +=
sizeof(
unsigned int );
129 int sizeOfDoubleX =
sizeof( double );
130 int sizeOfDoubleY = hasZValue ? 2 *
sizeof( double ) :
sizeof(
double );
138 double cw = e.
width() / 10;
double ch = e.
height() / 10;
141 for (
unsigned int idx = 0; idx < numRings; idx++ )
143 unsigned int nPoints = *((
int* )wkb );
144 wkb +=
sizeof(
unsigned int );
146 QPolygonF poly( nPoints );
149 QPointF* ptr = poly.data();
150 for (
unsigned int jdx = 0; jdx < nPoints; ++jdx, ++ptr )
152 memcpy( &x, wkb,
sizeof(
double ) ); wkb += sizeOfDoubleX;
153 memcpy( &y, wkb,
sizeof(
double ) ); wkb += sizeOfDoubleY;
155 *ptr = QPointF( x, y );
162 QRectF ptsRect = poly.boundingRect();
173 for (
int i = 0; i < poly.size(); ++i, ++ptr )
181 holes.append( poly );
204 : mType( type ), mUsingSymbolLevels( false ),
206 mCurrentVertexMarkerSize( 3 )
224 if ( symbol == NULL )
243 QgsDebugMsg(
"point can be drawn only with marker symbol!" );
248 ((
QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
260 QgsDebugMsg(
"linestring can be drawn only with line symbol!" );
265 ((
QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
267 if ( drawVertexMarker )
277 QgsDebugMsg(
"polygon can be drawn only with fill symbol!" );
281 QList<QPolygonF> holes;
283 ((
QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
285 if ( drawVertexMarker )
295 QgsDebugMsg(
"multi-point can be drawn only with marker symbol!" );
299 const unsigned char* wkb = geom->
asWkb();
300 unsigned int num = *((
int* )( wkb + 5 ) );
301 const unsigned char* ptr = wkb + 9;
304 for (
unsigned int i = 0; i < num; ++i )
307 ((
QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
320 QgsDebugMsg(
"multi-linestring can be drawn only with line symbol!" );
324 const unsigned char* wkb = geom->
asWkb();
325 unsigned int num = *((
int* )( wkb + 5 ) );
326 const unsigned char* ptr = wkb + 9;
329 for (
unsigned int i = 0; i < num; ++i )
332 ((
QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
334 if ( drawVertexMarker )
345 QgsDebugMsg(
"multi-polygon can be drawn only with fill symbol!" );
349 const unsigned char* wkb = geom->
asWkb();
350 unsigned int num = *((
int* )( wkb + 5 ) );
351 const unsigned char* ptr = wkb + 9;
353 QList<QPolygonF> holes;
355 for (
unsigned int i = 0; i < num; ++i )
358 ((
QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( holes.count() ? &holes : NULL ), &feature, context, layer, selected );
360 if ( drawVertexMarker )
367 QgsDebugMsg( QString(
"feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.
id() ).arg( geom->
wkbType(), 0, 16 ) );
373 return "UNKNOWN RENDERER\n";
381 if ( element.isNull() )
385 QString rendererType = element.attribute(
"type" );
407 QDomElement element = node.toElement();
408 if ( element.isNull() )
412 QDomElement userStyleElem = element.firstChildElement(
"UserStyle" );
413 if ( userStyleElem.isNull() )
416 errorMessage =
"Info: UserStyle element not found.";
421 QDomElement featTypeStyleElem = userStyleElem.firstChildElement(
"FeatureTypeStyle" );
422 if ( featTypeStyleElem.isNull() )
424 errorMessage =
"Info: FeatureTypeStyle element not found.";
431 bool needRuleRenderer =
false;
434 QDomElement ruleElem = featTypeStyleElem.firstChildElement(
"Rule" );
435 while ( !ruleElem.isNull() )
442 QgsDebugMsg(
"more Rule elements found: need a RuleRenderer" );
443 needRuleRenderer =
true;
447 QDomElement ruleChildElem = ruleElem.firstChildElement();
448 while ( !ruleChildElem.isNull() )
451 if ( ruleChildElem.localName() ==
"Filter" ||
452 ruleChildElem.localName() ==
"MinScaleDenominator" ||
453 ruleChildElem.localName() ==
"MaxScaleDenominator" )
455 QgsDebugMsg(
"Filter or Min/MaxScaleDenominator element found: need a RuleRenderer" );
456 needRuleRenderer =
true;
460 ruleChildElem = ruleChildElem.nextSiblingElement();
463 if ( needRuleRenderer )
468 ruleElem = ruleElem.nextSiblingElement(
"Rule" );
471 QString rendererType;
472 if ( needRuleRenderer )
474 rendererType =
"RuleRenderer";
478 rendererType =
"singleSymbol";
480 QgsDebugMsg( QString(
"Instantiating a '%1' renderer..." ).arg( rendererType ) );
486 errorMessage = QString(
"Error: Unable to get metadata for '%1' renderer." ).arg( rendererType );
496 QDomElement userStyleElem = doc.createElement(
"UserStyle" );
498 QDomElement nameElem = doc.createElement(
"se:Name" );
499 nameElem.appendChild( doc.createTextNode( layer.
name() ) );
500 userStyleElem.appendChild( nameElem );
502 QDomElement featureTypeStyleElem = doc.createElement(
"se:FeatureTypeStyle" );
503 toSld( doc, featureTypeStyleElem );
504 userStyleElem.appendChild( featureTypeStyleElem );
506 return userStyleElem;
511 Q_UNUSED( iconSize );
518 Q_UNUSED( scaleDenominator );
538 foreach ( QPointF pt, pts )
544 foreach ( QPointF pt, pts )
549 foreach ( QPolygonF ring, *rings )
551 foreach ( QPointF pt, ring )
561 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.
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.
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
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.
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
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
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
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.