37 #include <QSvgGenerator>
67 ( scaleFactorX ?
"tostring(" +
QString::number( scaleFactorX ) +
"*(" + exprString +
"))" :
"'0'" ) +
69 ( scaleFactorY ?
"tostring(" +
QString::number( scaleFactorY ) +
"*(" + exprString +
"))" :
"'0'" ) );
82 , mClipFeaturesToExtent( true )
121 if (( *it )->outputUnit() != unit )
145 if (( *it )->mapUnitScale() != scale )
158 ( *it )->setOutputUnit( u );
167 ( *it )->setMapUnitScale( scale );
188 default: defaultSymbol =
"";
break;
190 if ( defaultSymbol !=
"" )
201 default:
QgsDebugMsg(
"unknown layer's geometry type" );
return NULL;
209 if ( defaultSymbol ==
"" ||
298 ( *it )->startRender( symbolContext );
306 ( *it )->stopRender( symbolContext );
315 if ( !( *it )->isLocked() )
316 ( *it )->setColor( color );
325 if ( !( *it )->isLocked() )
326 return ( *it )->color();
352 ( *it )->drawPreviewIcon( symbolContext, size );
358 if ( format.
toLower() ==
"svg" )
378 QImage image( size, QImage::Format_ARGB32_Premultiplied );
392 QImage preview(
QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
407 if ( expressionContext )
416 static_cast<QgsLineSymbolV2*
>( this )->renderPolyline( poly, 0, context );
422 static_cast<QgsFillSymbolV2*
>( this )->renderPolygon( polygon, NULL, 0, context );
442 default: Q_ASSERT( 0 &&
"unknown symbol type" );
456 double scaleFactor = 1.0;
458 props[
"uomScale" ] = scaleFactor != 1 ?
QString::number( scaleFactor ) :
"";
462 ( *it )->toSld( doc, element, props );
487 attributes.
unite(( *sIt )->usedAttributes() );
497 : mRenderContext( c ), mOutputUnit( u ), mMapUnitScale( mapUnitScale ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints ), mFeature( f ), mFields( fields )
578 double origAngle =
angle();
579 double angleDiff = ang - origAngle;
596 return layer->
angle();
610 const double symbolRotation =
angle();
636 const double symbolRotation =
angle();
662 if ( !layerAngleDD || *layerAngleDD != *symbolDD )
668 if ( !layerAngleDD || *layerAngleDD != *( rotatedDD.
data() ) )
678 double origSize =
size();
683 if ( layer->
size() == origSize )
685 else if ( origSize != 0 )
691 if ( origSize != 0 && ( layer->
offset().
x() || layer->
offset().
y() ) )
693 layer->
offset().
y() * s / origSize ) );
704 double lsize = layer->
size();
705 if ( lsize > maxSize )
713 const double symbolSize =
size();
738 layer->
offset().
x() / symbolSize,
739 layer->
offset().
y() / symbolSize, dd ) );
747 const double symbolSize =
size();
775 if ( !layerSizeDD || *layerSizeDD != *symbolDD )
780 if ( symbolSize == 0 )
784 if ( !layerSizeDD || *layerSizeDD != *( scaledDD.
data() ) )
789 if ( layerOffsetDD && *layerOffsetDD != *( scaledOffsetDD.
data() ) )
819 static QPointF nullPoint( 0, 0 );
822 if ( effect && effect->
enabled() )
881 double origWidth =
width();
886 if ( layer->
width() == origWidth )
890 else if ( origWidth != 0 )
896 if ( origWidth != 0 && layer->
offset() )
908 if ( width > maxWidth )
916 const double symbolWidth =
width();
948 const double symbolWidth =
width();
976 if ( !layerWidthDD || *layerWidthDD != *symbolDD )
981 if ( symbolWidth == 0 )
985 if ( !layerWidthDD || *layerWidthDD != *( scaledDD.
data() ) )
990 if ( layerOffsetDD && *layerOffsetDD != *( scaledOffsetDD.
data() ) )
1023 if ( effect && effect->
enabled() )
1069 renderPolygonUsingLayer(
mLayers[layer], points, rings, symbolContext );
1076 renderPolygonUsingLayer( *it, points, rings, symbolContext );
1085 if ( effect && effect->
enabled() )
1087 QRectF bounds = polygonBounds( points, rings );
1092 p->translate( bounds.
topLeft() );
1103 delete translatedRings;
1127 for ( ; it != rings->
constEnd(); ++it )
1129 bounds = bounds.
united(( *it ).boundingRect() );
1142 for ( ; it != rings->
constEnd(); ++it )
1144 translatedRings->
append(( *it ).translated( dx, dy ) );
1146 return translatedRings;
QgsFillSymbolV2(const QgsSymbolLayerV2List &layers=QgsSymbolLayerV2List())
void setForceVectorOutput(bool force)
void setLocked(bool locked)
bool deleteSymbolLayer(int index)
delete symbol layer at specified index
QgsSymbolV2RenderContext(QgsRenderContext &c, QgsSymbolV2::OutputUnit u, qreal alpha=1.0, bool selected=false, int renderHints=0, const QgsFeature *f=0, const QgsFields *fields=0, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
void setViewBox(const QRect &viewBox)
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
static QgsMarkerSymbolV2 * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent...
OutputUnit
The unit of the output.
bool mClipFeaturesToExtent
void setDataDefinedAngle(const QgsDataDefined &dd)
Set data defined angle for whole symbol (including all symbol layers).
A container class for data source field mapping or expression.
void setSize(const QSize &size)
virtual double width() const
void setRenderHint(RenderHint hint, bool on)
const QgsVectorLayer * mLayer
QSet< QString > usedAttributes() const
QString field() const
Get the field which this QgsDataDefined represents.
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
bool save(const QString &fileName, const char *format, int quality) const
static QString encodeColor(const QColor &color)
static QString encodeSldUom(QgsSymbolV2::OutputUnit unit, double *scaleFactor)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
QgsDataDefined dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
void setOffset(QPointF offset)
QPolygonF translated(qreal dx, qreal dy) const
bool enabled() const
Returns whether the effect is enabled.
Base class for visual effects which can be applied to QPicture drawings.
bool changeSymbolLayer(int index, QgsSymbolLayerV2 *layer)
delete layer at specified index and set a new one
ScaleMethod scaleMethod()
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for data defined symbology.
void exportImage(const QString &path, const QString &format, const QSize &size)
export symbol as image format. PNG and SVG supported
QgsMapUnitScale mapUnitScale() const
Container of fields for a vector layer.
QString expressionString() const
Returns the expression string of this QgsDataDefined.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void drawLine(const QLineF &line)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
virtual void removeDataDefinedProperty(const QString &property)
Removes a data defined property from the layer.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
static double pixelSizeScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns scale factor painter units -> pixel dimensions.
void setWidth(double width)
QgsDataDefined * scaleWholeSymbol(double scaleFactor, const QgsDataDefined &dd)
QgsDataDefined dataDefinedWidth() const
Returns data defined size for whole symbol (including all symbol layers).
void setMapUnitScale(const QgsMapUnitScale &scale)
void setAngle(double angle)
const QgsVectorLayer * layer() const
virtual void startRender(QgsSymbolV2RenderContext &context)=0
QColor fromHsv(int h, int s, int v, int a)
void setUseExpression(bool use)
Controls if the field or the expression part is active.
void setColor(const QColor &color)
Mixed units in symbol layers.
static QgsRenderContext createRenderContext(QPainter *p)
Creates a render context for a pixel based device.
QString number(int n, int base)
QgsSymbolLayerV2List mLayers
int count(const T &value) const
void append(const T &value)
QgsSymbolLayerV2List cloneLayers() const
void setOffset(double offset)
bool appendSymbolLayer(QgsSymbolLayerV2 *layer)
Append symbol layer at the end of the list Ownership will be transferred.
virtual void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context)=0
void fill(uint pixelValue)
static double convertToPainterUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to painter units.
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
void setPen(const QColor &color)
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
void setRenderingPass(int renderingPass)
#define DEFAULT_SCALE_METHOD
void setLayer(const QgsVectorLayer *layer)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void setWidth(double width)
static QgsStyleV2 * defaultStyle()
return default application-wide style
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
QgsMarkerSymbolV2(const QgsSymbolLayerV2List &layers=QgsSymbolLayerV2List())
void setAngle(double angle)
void setAngle(double angle)
virtual QgsSymbolV2 * clone() const override
void setPainter(QPainter *p)
void setSize(double size)
qreal mAlpha
Symbol opacity (in the range 0 - 1)
QgsSymbolV2RenderContext & operator=(const QgsSymbolV2RenderContext &)
QRectF united(const QRectF &rectangle) const
virtual void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
QgsSymbolV2(SymbolType type, const QgsSymbolLayerV2List &layers)
QgsDataDefined * rotateWholeSymbol(double additionalRotation, const QgsDataDefined &dd)
void renderPoint(const QPointF &point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void setLineAngle(double lineAngle)
Sets the line angle modification for the symbol's angle.
QgsSymbolV2::ScaleMethod scaleMethod() const
QgsSymbolV2::SymbolType type() const
bool useExpression() const
Returns if the field or the expression part is active.
virtual QgsSymbolV2 * clone() const override
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
virtual void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context)=0
QgsSymbolV2 * symbol(const QString &name)
return a NEW copy of symbol
void setFileName(const QString &fileName)
QgsExpressionContext & expressionContext()
Gets the expression context.
SymbolType
Type of the symbol.
~QgsSymbolV2RenderContext()
bool isSymbolLayerCompatible(SymbolType t)
check whether a symbol layer type can be used within the symbol (marker-marker, line-line, fill-fill/line)
void setDataDefinedWidth(const QgsDataDefined &dd)
Set data defined width for whole symbol (including all symbol layers).
Contains information about the context of a rendering operation.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
QRectF boundingRect() const
QgsDataDefined dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
void stopRender(QgsRenderContext &context)
bool insertSymbolLayer(int index, QgsSymbolLayerV2 *layer)
Insert symbol layer to specified index Ownership will be transferred.
QSet< T > & unite(const QSet< T > &other)
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
Struct for storing maximum and minimum scales for measurements in map units.
QImage bigSymbolPreviewImage(QgsExpressionContext *expressionContext=0)
Returns a large (roughly 100x100 pixel) preview image for the symbol.
void insert(int i, const T &value)
QgsRenderContext & renderContext()
virtual QgsDataDefined * getDataDefinedProperty(const QString &property) const
Returns the data defined property corresponding to the specified property key.
static QgsProject * instance()
access to canonical QgsProject instance
QgsSymbolV2::OutputUnit outputUnit() const
void translate(const QPointF &offset)
QgsSymbolLayerV2 * takeSymbolLayer(int index)
Remove symbol layer from the list and return pointer to it.
bool hasDefaultValues() const
Returns whether the data defined container is set to all the default values, ie, disabled, with empty expression and no assigned field.
double outputPixelSize(double size) const
double outputLineWidth(double width) const
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
QImage asImage(QSize size, QgsRenderContext *customContext=0)
Generate symbol as image.
const_iterator constEnd() const
const_iterator constBegin() const
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=0)
Draw icon of the symbol that occupyies area given by size using the painter.
void setSize(double size)
void setAngle(double angle)
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
virtual QgsSymbolV2 * clone() const override
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
void setExpressionString(const QString &expr)
Sets the expression for this QgsDataDefined.
void setOutputUnit(QgsSymbolV2::OutputUnit u)
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
QgsLineSymbolV2(const QgsSymbolLayerV2List &layers=QgsSymbolLayerV2List())
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.