void QgsFontMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) { QPainter *p = context.renderContext().painter(); if ( !p ) return; QColor penColor = context.selected() ? context.renderContext().selectionColor() : mColor; penColor.setAlphaF( mColor.alphaF() * context.alpha() ); p->setPen( penColor ); p->setFont( mFont ); p->save(); //offset double offsetX = 0; double offsetY = 0; markerOffset( context, offsetX, offsetY ); QPointF outputOffset( offsetX, offsetY ); if ( mAngle ) outputOffset = _rotatedOffset( outputOffset, mAngle ); p->translate( point + outputOffset ); if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { double s = mSize / mOrigSize; p->scale( s, s ); } if ( mAngle != 0 ) p->rotate( mAngle ); p->drawText( -mChrOffset, mChr ); p->restore(); }
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) { QPainter* p = context.renderContext().painter(); if ( !p ) { return; } if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { double scaledWidth = context.outputLineWidth( mWidth ); mPen.setWidthF( scaledWidth ); mSelPen.setWidthF( scaledWidth ); } p->setPen( context.selected() ? mSelPen : mPen ); if ( mOffset == 0 ) { p->drawPolyline( points ); } else { double scaledOffset = context.outputLineWidth( mOffset ); p->drawPolyline( ::offsetLine( points, scaledOffset ) ); } }
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset ) { //data defined properties double scaledWidth = 0; if ( mStrokeWidthExpression ) { scaledWidth = mStrokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } //color if ( mStrokeColorExpression ) { pen.setColor( QgsSymbolLayerV2Utils::decodeColor( mStrokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); } //offset offset = mOffset; if ( mLineOffsetExpression ) { offset = mLineOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } //dash dot vector if ( mDashPatternExpression ) { QVector<qreal> dashVector; QStringList dashList = mDashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" ); QStringList::const_iterator dashIt = dashList.constBegin(); for ( ; dashIt != dashList.constEnd(); ++dashIt ) { dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit ) / mPen.widthF() ); } pen.setDashPattern( dashVector ); } //join style if ( mJoinStyleExpression ) { QString joinStyleString = mJoinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) ); } //cap style if ( mCapStyleExpression ) { QString capStyleString = mCapStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) ); } }
QSizeF QgsEllipseSymbolLayerV2::calculateSize( QgsSymbolV2RenderContext& context, double* scaledWidth, double* scaledHeight ) { double width = 0; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le { context.setOriginalValueVariable( mSymbolWidth ); width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mSymbolWidth ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { width = mSize; } else //3. priority: global width setting { width = mSymbolWidth; } if ( scaledWidth ) { *scaledWidth = width; } width = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), width, mSymbolWidthUnit, mSymbolHeightMapUnitScale ); double height = 0; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level { context.setOriginalValueVariable( mSymbolHeight ); height = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, context, mSymbolHeight ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { height = mSize; } else //3. priority: global height setting { height = mSymbolHeight; } if ( scaledHeight ) { *scaledHeight = height; } height = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), height, mSymbolHeightUnit, mSymbolHeightMapUnitScale ); return QSizeF( width, height ); }
double QgsSimpleLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const { double width = mWidth; QgsExpression* strokeWidthExpression = expression( "width" ); if ( strokeWidthExpression ) { width = strokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); } return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ); }
void QgsMarkerLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context ) { mMarker->setAlpha( context.alpha() ); mMarker->setOutputUnit( context.outputUnit() ); // if being rotated, it gets initialized with every line segment int hints = 0; if ( mRotateMarker ) hints |= QgsSymbolV2::DataDefinedRotation; if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) hints |= QgsSymbolV2::DataDefinedSizeScale; mMarker->setRenderHints( hints ); mMarker->startRender( context.renderContext() ); }
double QgsSimpleLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const { double width = mWidth; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) { context.setOriginalValueVariable( mWidth ); width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { width = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale ); } return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ); }
void QgsMarkerLineSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context ) { mMarker->setAlpha( context.alpha() ); // if being rotated, it gets initialized with every line segment int hints = 0; if ( mRotateMarker ) hints |= QgsSymbolV2::DataDefinedRotation; if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) hints |= QgsSymbolV2::DataDefinedSizeScale; mMarker->setRenderHints( hints ); mMarker->startRender( context.renderContext(), context.fields() ); //prepare expressions for data defined properties prepareExpressions( context.fields(), context.renderContext().rendererScale() ); }
void QgsEllipseSymbolLayerV2::calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledWidth, double scaledHeight, bool& hasDataDefinedRotation, QPointF& offset, double& angle ) const { double offsetX = 0; double offsetY = 0; markerOffset( context, scaledWidth, scaledHeight, mSymbolWidthUnit, mSymbolHeightUnit, offsetX, offsetY, mSymbolWidthMapUnitScale, mSymbolHeightMapUnitScale ); offset = QPointF( offsetX, offsetY ); //priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle) bool ok = true; angle = mAngle + mLineAngle; bool usingDataDefinedRotation = false; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) ) { context.setOriginalValueVariable( angle ); angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, context, mAngle, &ok ).toDouble() + mLineAngle; usingDataDefinedRotation = ok; } hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || usingDataDefinedRotation; if ( hasDataDefinedRotation ) { // For non-point markers, "dataDefinedRotation" means following the // shape (shape-data defined). For them, "field-data defined" does // not work at all. TODO: if "field-data defined" ever gets implemented // we'll need a way to distinguish here between the two, possibly // using another flag in renderHints() const QgsFeature* f = context.feature(); if ( f ) { const QgsGeometry *g = f->constGeometry(); if ( g && g->type() == QGis::Point ) { const QgsMapToPixel& m2p = context.renderContext().mapToPixel(); angle += m2p.mapRotation(); } } } if ( angle ) offset = _rotatedOffset( offset, angle ); }
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context ) { QPainter* p = context.renderContext().painter(); if ( !p ) { return; } //size scaling by field if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { applySizeScale( context, mPen, mSelPen ); } double offset = mOffset; applyDataDefinedSymbology( context, mPen, mSelPen, offset ); p->setPen( context.selected() ? mSelPen : mPen ); // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points). if ( points.size() <= 2 && ( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) ) { p->setRenderHint( QPainter::Antialiasing, false ); p->drawPolyline( points ); p->setRenderHint( QPainter::Antialiasing, true ); return; } if ( qgsDoubleNear( offset, 0 ) ) { p->drawPolyline( points ); } else { double scaledOffset = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), offset, mOffsetUnit, mOffsetMapUnitScale ); QList<QPolygonF> mline = ::offsetLine( points, scaledOffset, context.feature() ? context.feature()->constGeometry()->type() : QGis::Line ); for ( int part = 0; part < mline.count(); ++part ) p->drawPolyline( mline[ part ] ); } }
void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) { QgsRenderContext& rc = context.renderContext(); QPainter* p = rc.painter(); if ( !p ) { return; } QPointF off( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) ); if ( mAngle ) off = _rotatedOffset( off, mAngle ); if ( mUsingCache ) { // we will use cached image QImage &img = context.selected() ? mSelCache : mCache; double s = img.width() / context.renderContext().rasterScaleFactor(); p->drawImage( QRectF( point.x() - s / 2.0 + off.x(), point.y() - s / 2.0 + off.y(), s, s ), img ); } else { QMatrix transform; bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation; bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale; // move to the desired position transform.translate( point.x() + off.x(), point.y() + off.y() ); // resize if necessary if ( hasDataDefinedSize ) { double scaledSize = context.outputLineWidth( mSize ); switch ( mScaleMethod ) { case QgsSymbolV2::ScaleArea: scaledSize = sqrt( scaledSize ); break; case QgsSymbolV2::ScaleDiameter: break; } double half = scaledSize / 2.0; transform.scale( half, half ); } // rotate if necessary if ( mAngle != 0 && hasDataDefinedRotation ) { transform.rotate( mAngle ); } p->setBrush( context.selected() ? mSelBrush : mBrush ); p->setPen( context.selected() ? mSelPen : mPen ); if ( !mPolygon.isEmpty() ) p->drawPolygon( transform.map( mPolygon ) ); else p->drawPath( transform.map( mPath ) ); } }
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const { //width double symbolWidth = mSymbolWidth; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le { context.setOriginalValueVariable( mSymbolWidth ); symbolWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mSymbolWidth ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { symbolWidth = mSize; } if ( mSymbolWidthUnit == QgsSymbolV2::MM ) { symbolWidth *= mmMapUnitScaleFactor; } //height double symbolHeight = mSymbolHeight; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level { context.setOriginalValueVariable( mSymbolHeight ); symbolHeight = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, context, mSymbolHeight ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { symbolHeight = mSize; } if ( mSymbolHeightUnit == QgsSymbolV2::MM ) { symbolHeight *= mmMapUnitScaleFactor; } //outline width double outlineWidth = mOutlineWidth; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) ) { context.setOriginalValueVariable( mOutlineWidth ); outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble(); } if ( mOutlineWidthUnit == QgsSymbolV2::MM ) { outlineWidth *= outlineWidth; } //fill color bool ok; QColor fc = mColor; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) ); QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, context, QVariant(), &ok ).toString(); if ( ok ) fc = QgsSymbolLayerV2Utils::decodeColor( colorString ); } //outline color QColor oc = mOutlineColor; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) ); QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, context, QVariant(), &ok ).toString(); if ( ok ) oc = QgsSymbolLayerV2Utils::decodeColor( colorString ); } //symbol name QString symbolName = mSymbolName; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME ) ) { context.setOriginalValueVariable( mSymbolName ); symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, context, mSymbolName ).toString(); } //offset double offsetX = 0; double offsetY = 0; markerOffset( context, offsetX, offsetY ); QPointF off( offsetX, offsetY ); //priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle) double rotation = 0.0; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) ) { context.setOriginalValueVariable( mAngle ); rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, context, mAngle ).toDouble() + mLineAngle; } else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) ) { rotation = mAngle + mLineAngle; } rotation = -rotation; //rotation in Qt is counterclockwise if ( rotation ) off = _rotatedOffset( off, rotation ); QTransform t; t.translate( shift.x() + offsetX, shift.y() + offsetY ); if ( !qgsDoubleNear( rotation, 0.0 ) ) t.rotate( rotation ); double halfWidth = symbolWidth / 2.0; double halfHeight = symbolHeight / 2.0; if ( symbolName == "circle" ) { if ( qgsDoubleNear( halfWidth, halfHeight ) ) { QgsPointV2 pt( t.map( QPointF( 0, 0 ) ) ); e.writeFilledCircle( layerName, oc, pt, halfWidth ); } else { QgsPointSequenceV2 line; double stepsize = 2 * M_PI / 40; for ( int i = 0; i < 39; ++i ) { double angle = stepsize * i; double x = halfWidth * cos( angle ); double y = halfHeight * sin( angle ); line << QgsPointV2( t.map( QPointF( x, y ) ) ); } //close ellipse with first point line << line.at( 0 ); if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsRingSequenceV2() << line, layerName, "SOLID", fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth ); } } else if ( symbolName == "rectangle" ) { QgsPointSequenceV2 p; p << QgsPointV2( t.map( QPointF( -halfWidth, -halfHeight ) ) ) << QgsPointV2( t.map( QPointF( halfWidth, -halfHeight ) ) ) << QgsPointV2( t.map( QPointF( halfWidth, halfHeight ) ) ) << QgsPointV2( t.map( QPointF( -halfWidth, halfHeight ) ) ); p << p[0]; if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsRingSequenceV2() << p, layerName, "SOLID", fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( p, layerName, "CONTINUOUS", oc, outlineWidth ); return true; } else if ( symbolName == "cross" && mPen.style() != Qt::NoPen ) { e.writePolyline( QgsPointSequenceV2() << QgsPointV2( t.map( QPointF( -halfWidth, 0 ) ) ) << QgsPointV2( t.map( QPointF( halfWidth, 0 ) ) ), layerName, "CONTINUOUS", oc, outlineWidth ); e.writePolyline( QgsPointSequenceV2() << QgsPointV2( t.map( QPointF( 0, halfHeight ) ) ) << QgsPointV2( t.map( QPointF( 0, -halfHeight ) ) ), layerName, "CONTINUOUS", oc, outlineWidth ); return true; } else if ( symbolName == "triangle" ) { QgsPointSequenceV2 p; p << QgsPointV2( t.map( QPointF( -halfWidth, -halfHeight ) ) ) << QgsPointV2( t.map( QPointF( halfWidth, -halfHeight ) ) ) << QgsPointV2( t.map( QPointF( 0, halfHeight ) ) ); p << p[0]; if ( mBrush.style() != Qt::NoBrush ) e.writePolygon( QgsRingSequenceV2() << p, layerName, "SOLID", fc ); if ( mPen.style() != Qt::NoPen ) e.writePolyline( p, layerName, "CONTINUOUS", oc, outlineWidth ); return true; } return false; //soon... }
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset ) { if ( mDataDefinedProperties.isEmpty() ) return; // shortcut //data defined properties double scaledWidth = 0; QgsExpression* strokeWidthExpression = expression( "width" ); if ( strokeWidthExpression ) { scaledWidth = strokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) { scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); } //color QgsExpression* strokeColorExpression = expression( "color" ); if ( strokeColorExpression ) { pen.setColor( QgsSymbolLayerV2Utils::decodeColor( strokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); } //offset QgsExpression* lineOffsetExpression = expression( "offset" ); if ( lineOffsetExpression ) { offset = lineOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } //dash dot vector QgsExpression* dashPatternExpression = expression( "customdash" ); if ( dashPatternExpression ) { double scaledWidth = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit, mWidthMapUnitScale ); double dashWidthDiv = mPen.widthF(); if ( strokeWidthExpression ) { dashWidthDiv = pen.widthF(); scaledWidth = pen.widthF(); } //fix dash pattern width in Qt 4.8 QStringList versionSplit = QString( qVersion() ).split( "." ); if ( versionSplit.size() > 1 && versionSplit.at( 1 ).toInt() >= 8 && ( scaledWidth * context.renderContext().rasterScaleFactor() ) < 1.0 ) { dashWidthDiv = 1.0; } QVector<qreal> dashVector; QStringList dashList = dashPatternExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString().split( ";" ); QStringList::const_iterator dashIt = dashList.constBegin(); for ( ; dashIt != dashList.constEnd(); ++dashIt ) { dashVector.push_back( dashIt->toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv ); } pen.setDashPattern( dashVector ); } //join style QgsExpression* joinStyleExpression = expression( "joinstyle" ); if ( joinStyleExpression ) { QString joinStyleString = joinStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) ); } //cap style QgsExpression* capStyleExpression = expression( "capstyle" ); if ( capStyleExpression ) { QString capStyleString = capStyleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) ); } }
void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context ) { QColor brushColor = mColor; QColor penColor = mBorderColor; brushColor.setAlphaF( mColor.alphaF() * context.alpha() ); penColor.setAlphaF( mBorderColor.alphaF() * context.alpha() ); mBrush = QBrush( brushColor ); mPen = QPen( penColor ); mPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) ); QColor selBrushColor = context.renderContext().selectionColor(); QColor selPenColor = selBrushColor == mColor ? selBrushColor : mBorderColor; if ( context.alpha() < 1 ) { selBrushColor.setAlphaF( context.alpha() ); selPenColor.setAlphaF( context.alpha() ); } mSelBrush = QBrush( selBrushColor ); mSelPen = QPen( selPenColor ); mSelPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) ); bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || dataDefinedProperty( "angle" ); bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || dataDefinedProperty( "size" ); // use caching only when: // - size, rotation, shape, color, border color is not data-defined // - drawing to screen (not printer) mUsingCache = !hasDataDefinedRotation && !hasDataDefinedSize && !context.renderContext().forceVectorOutput() && !dataDefinedProperty( "name" ) && !dataDefinedProperty( "color" ) && !dataDefinedProperty( "color_border" ) && !dataDefinedProperty( "outline_width" ) && !dataDefinedProperty( "size" ); // use either QPolygonF or QPainterPath for drawing // TODO: find out whether drawing directly doesn't bring overhead - if not, use it for all shapes if ( !prepareShape() ) // drawing as a polygon { if ( preparePath() ) // drawing as a painter path { // some markers can't be drawn as a polygon (circle, cross) // For these set the selected border color to the selected color if ( mName != "circle" ) mSelPen.setColor( selBrushColor ); } else { QgsDebugMsg( "unknown symbol" ); return; } } QMatrix transform; // scale the shape (if the size is not going to be modified) if ( !hasDataDefinedSize ) { double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ); if ( mUsingCache ) scaledSize *= context.renderContext().rasterScaleFactor(); double half = scaledSize / 2.0; transform.scale( half, half ); } // rotate if the rotation is not going to be changed during the rendering if ( !hasDataDefinedRotation && mAngle != 0 ) { transform.rotate( mAngle ); } if ( !mPolygon.isEmpty() ) mPolygon = transform.map( mPolygon ); else mPath = transform.map( mPath ); if ( mUsingCache ) { if ( !prepareCache( context ) ) { mUsingCache = false; } } else { mCache = QImage(); mSelCache = QImage(); } prepareExpressions( context.layer(), context.renderContext().rendererScale() ); mAngleExpression = expression( "angle" ); mNameExpression = expression( "name" ); QgsMarkerSymbolLayerV2::startRender( context ); }
void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f ) { mPainterPath = QPainterPath(); const QgsRenderContext& ct = context.renderContext(); double width = 0; QgsExpression* widthExpression = expression( "width" ); if ( widthExpression ) //1. priority: data defined setting on symbol layer level { width = widthExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { width = mSize; } else //3. priority: global width setting { width = mSymbolWidth; } width *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit ); double height = 0; QgsExpression* heightExpression = expression( "height" ); if ( heightExpression ) //1. priority: data defined setting on symbol layer level { height = heightExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { height = mSize; } else //3. priority: global height setting { height = mSymbolHeight; } height *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit ); if ( symbolName == "circle" ) { mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) ); } else if ( symbolName == "rectangle" ) { mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) ); } else if ( symbolName == "cross" ) { mPainterPath.moveTo( 0, -height / 2.0 ); mPainterPath.lineTo( 0, height / 2.0 ); mPainterPath.moveTo( -width / 2.0, 0 ); mPainterPath.lineTo( width / 2.0, 0 ); } else if ( symbolName == "triangle" ) { mPainterPath.moveTo( 0, -height / 2.0 ); mPainterPath.lineTo( -width / 2.0, height / 2.0 ); mPainterPath.lineTo( width / 2.0, height / 2.0 ); mPainterPath.lineTo( 0, -height / 2.0 ); } }
void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) { QPainter *p = context.renderContext().painter(); if ( !p ) { return; } //offset double offsetX = 0; double offsetY = 0; markerOffset( context, offsetX, offsetY ); QPointF off( offsetX, offsetY ); //angle double angle = mAngle; if ( mAngleExpression ) { angle = mAngleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } if ( angle ) off = _rotatedOffset( off, angle ); //data defined shape? if ( mNameExpression ) { QString name = mNameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); if ( !prepareShape( name ) ) // drawing as a polygon { preparePath( name ); // drawing as a painter path } } if ( mUsingCache ) { // we will use cached image QImage &img = context.selected() ? mSelCache : mCache; double s = img.width() / context.renderContext().rasterScaleFactor(); p->drawImage( QRectF( point.x() - s / 2.0 + off.x(), point.y() - s / 2.0 + off.y(), s, s ), img ); } else { QMatrix transform; // move to the desired position transform.translate( point.x() + off.x(), point.y() + off.y() ); QgsExpression *sizeExpression = expression( "size" ); bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression; // resize if necessary if ( hasDataDefinedSize ) { double scaledSize = mSize; if ( sizeExpression ) { scaledSize = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } scaledSize *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ); switch ( mScaleMethod ) { case QgsSymbolV2::ScaleArea: scaledSize = sqrt( scaledSize ); break; case QgsSymbolV2::ScaleDiameter: break; } double half = scaledSize / 2.0; transform.scale( half, half ); } bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || mAngleExpression; if ( angle != 0 && hasDataDefinedRotation ) transform.rotate( angle ); QgsExpression* colorExpression = expression( "color" ); QgsExpression* colorBorderExpression = expression( "color_border" ); QgsExpression* outlineWidthExpression = expression( "outline_width" ); if ( colorExpression ) { mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); } if ( colorBorderExpression ) { mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); mSelPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) ); } if ( outlineWidthExpression ) { double outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); mPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) ); mSelPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) ); } p->setBrush( context.selected() ? mSelBrush : mBrush ); p->setPen( context.selected() ? mSelPen : mPen ); if ( !mPolygon.isEmpty() ) p->drawPolygon( transform.map( mPolygon ) ); else p->drawPath( transform.map( mPath ) ); } }
void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, double* scaledWidth, double* scaledHeight, const QgsFeature* ) { mPainterPath = QPainterPath(); const QgsRenderContext& ct = context.renderContext(); double width = 0; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le { context.setOriginalValueVariable( mSymbolWidth ); width = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mSymbolWidth ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { width = mSize; } else //3. priority: global width setting { width = mSymbolWidth; } if ( scaledWidth ) { *scaledWidth = width; } width = QgsSymbolLayerV2Utils::convertToPainterUnits( ct, width, mSymbolWidthUnit, mSymbolHeightMapUnitScale ); double height = 0; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level { context.setOriginalValueVariable( mSymbolHeight ); height = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, context, mSymbolHeight ).toDouble(); } else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level { height = mSize; } else //3. priority: global height setting { height = mSymbolHeight; } if ( scaledHeight ) { *scaledHeight = height; } height = QgsSymbolLayerV2Utils::convertToPainterUnits( ct, height, mSymbolHeightUnit, mSymbolHeightMapUnitScale ); if ( symbolName == "circle" ) { mPainterPath.addEllipse( QRectF( -width / 2.0, -height / 2.0, width, height ) ); } else if ( symbolName == "rectangle" ) { mPainterPath.addRect( QRectF( -width / 2.0, -height / 2.0, width, height ) ); } else if ( symbolName == "cross" ) { mPainterPath.moveTo( 0, -height / 2.0 ); mPainterPath.lineTo( 0, height / 2.0 ); mPainterPath.moveTo( -width / 2.0, 0 ); mPainterPath.lineTo( width / 2.0, 0 ); } else if ( symbolName == "triangle" ) { mPainterPath.moveTo( 0, -height / 2.0 ); mPainterPath.lineTo( -width / 2.0, height / 2.0 ); mPainterPath.lineTo( width / 2.0, height / 2.0 ); mPainterPath.lineTo( 0, -height / 2.0 ); } }
void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) { QPainter *p = context.renderContext().painter(); if ( !p ) return; double size = mSize; QgsExpression* sizeExpression = expression( "size" ); bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression; if ( sizeExpression ) { size = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } size *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ); if ( hasDataDefinedSize ) { switch ( mScaleMethod ) { case QgsSymbolV2::ScaleArea: size = sqrt( size ); break; case QgsSymbolV2::ScaleDiameter: break; } } //don't render symbols with size below one or above 10,000 pixels if (( int )size < 1 || 10000.0 < size ) { return; } p->save(); //offset double offsetX = 0; double offsetY = 0; markerOffset( context, offsetX, offsetY ); QPointF outputOffset( offsetX, offsetY ); double angle = mAngle; QgsExpression* angleExpression = expression( "angle" ); if ( angleExpression ) { angle = angleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } if ( angle ) outputOffset = _rotatedOffset( outputOffset, angle ); p->translate( point + outputOffset ); bool rotated = !qgsDoubleNear( angle, 0 ); bool drawOnScreen = qgsDoubleNear( context.renderContext().rasterScaleFactor(), 1.0, 0.1 ); if ( rotated ) p->rotate( angle ); QString path = mPath; QgsExpression* nameExpression = expression( "name" ); if ( nameExpression ) { path = nameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString(); } double outlineWidth = mOutlineWidth; QgsExpression* outlineWidthExpression = expression( "outline_width" ); if ( outlineWidthExpression ) { outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble(); } QColor fillColor = mFillColor; QgsExpression* fillExpression = expression( "fill" ); if ( fillExpression ) { fillColor = QgsSymbolLayerV2Utils::decodeColor( fillExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ); } QColor outlineColor = mOutlineColor; QgsExpression* outlineExpression = expression( "outline" ); if ( outlineExpression ) { outlineColor = QgsSymbolLayerV2Utils::decodeColor( outlineExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ); } bool fitsInCache = true; bool usePict = true; double hwRatio = 1.0; if ( drawOnScreen && !rotated ) { usePict = false; const QImage& img = QgsSvgCache::instance()->svgAsImage( path, size, fillColor, outlineColor, outlineWidth, context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor(), fitsInCache ); if ( fitsInCache && img.width() > 1 ) { //consider transparency if ( !qgsDoubleNear( context.alpha(), 1.0 ) ) { QImage transparentImage = img.copy(); QgsSymbolLayerV2Utils::multiplyImageOpacity( &transparentImage, context.alpha() ); p->drawImage( -transparentImage.width() / 2.0, -transparentImage.height() / 2.0, transparentImage ); hwRatio = ( double )transparentImage.height() / ( double )transparentImage.width(); } else { p->drawImage( -img.width() / 2.0, -img.height() / 2.0, img ); hwRatio = ( double )img.height() / ( double )img.width(); } } } if ( usePict || !fitsInCache ) { p->setOpacity( context.alpha() ); const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( path, size, fillColor, outlineColor, outlineWidth, context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor(), context.renderContext().forceVectorOutput() ); if ( pct.width() > 1 ) { p->drawPicture( 0, 0, pct ); hwRatio = ( double )pct.height() / ( double )pct.width(); } } if ( context.selected() ) { QPen pen( context.renderContext().selectionColor() ); double penWidth = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), QgsSymbolV2::MM ); if ( penWidth > size / 20 ) { // keep the pen width from covering symbol penWidth = size / 20; } double penOffset = penWidth / 2; pen.setWidth( penWidth ); p->setPen( pen ); p->setBrush( Qt::NoBrush ); double wSize = size + penOffset; double hSize = size * hwRatio + penOffset; p->drawRect( QRectF( -wSize / 2.0, -hSize / 2.0, wSize, hSize ) ); } p->restore(); }