void QgsDxfExport::writeBlocks() { startSection(); writeGroup( 2, "BLOCKS" ); //iterate through all layers and get symbol layer pointers QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > slList; if ( mSymbologyExport != NoSymbology ) { slList = symbolLayers(); } QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > >::const_iterator slIt = slList.constBegin(); for ( ; slIt != slList.constEnd(); ++slIt ) { QgsMarkerSymbolLayerV2* ml = dynamic_cast< QgsMarkerSymbolLayerV2*>( slIt->first ); if ( ml ) { //if point symbol layer and no data defined properties: write block QgsRenderContext ct; QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, slIt->second->alpha(), false, slIt->second->renderHints(), 0 ); ml->startRender( ctx ); //markers with data defined properties are inserted inline if ( hasDataDefinedProperties( ml, slIt->second ) ) { continue; // ml->stopRender( ctx ); } writeGroup( 0, "BLOCK" ); writeGroup( 8, 0 ); QString blockName = QString( "symbolLayer%1" ).arg( mBlockCounter++ ); writeGroup( 2, blockName ); writeGroup( 70, 64 ); //x/y/z coordinates of reference point //todo: consider anchor point // double size = ml->size(); // size *= mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ); writeGroup( 10, 0 ); writeGroup( 20, 0 ); writeGroup( 30, 0 ); writeGroup( 3, blockName ); ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0", &ctx, 0 ); //maplayer 0 -> block receives layer from INSERT statement writeGroup( 0, "ENDBLK" ); writeGroup( 8, 0 ); mPointSymbolBlocks.insert( ml, blockName ); ml->stopRender( ctx ); } } endSection(); }
void QgsArrowSymbolLayer::_resolveDataDefined( QgsSymbolV2RenderContext& context ) { if ( !hasDataDefinedProperties() ) return; // shortcut if case there is no data defined properties at all bool ok; if ( hasDataDefinedProperty( "arrow_width" ) ) { context.setOriginalValueVariable( arrowWidth() ); double w = evaluateDataDefinedProperty( "arrow_width", context, QVariant(), &ok ).toDouble(); if ( ok ) { mScaledArrowWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, arrowWidthUnit(), arrowWidthUnitScale() ); } } if ( hasDataDefinedProperty( "arrow_start_width" ) ) { context.setOriginalValueVariable( arrowStartWidth() ); double w = evaluateDataDefinedProperty( "arrow_start_width", context, QVariant(), &ok ).toDouble(); if ( ok ) { mScaledArrowStartWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, arrowStartWidthUnit(), arrowStartWidthUnitScale() ); } } if ( hasDataDefinedProperty( "head_size" ) ) { context.setOriginalValueVariable( headSize() ); double w = evaluateDataDefinedProperty( "head_size", context, QVariant(), &ok ).toDouble(); if ( ok ) { mScaledHeadSize = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, headSizeUnit(), headSizeUnitScale() ); } } if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET ) ) { context.setOriginalValueVariable( offset() ); double w = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, context, QVariant(), &ok ).toDouble(); if ( ok ) { mScaledOffset = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, offsetUnit(), offsetMapUnitScale() ); } } if ( hasDataDefinedProperty( "head_type" ) ) { context.setOriginalValueVariable( headType() ); int h = evaluateDataDefinedProperty( "head_type", context, QVariant(), &ok ).toInt(); if ( ok ) { mComputedHeadType = static_cast<HeadType>( h ); } } }
void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context ) { QgsMarkerSymbolLayerV2::startRender( context ); // get anchor point expressions if ( !context.feature() || !hasDataDefinedProperties() ) { preparePath( mSymbolName, context ); } mPen.setColor( mOutlineColor ); mPen.setStyle( mOutlineStyle ); mPen.setWidthF( QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mOutlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale ) ); mBrush.setColor( mFillColor ); prepareExpressions( context ); }
void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderContext& context, QPen& pen, QPen& selPen, double& offset ) { if ( !hasDataDefinedProperties() ) return; // shortcut //data defined properties bool hasStrokeWidthExpression = false; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) { context.setOriginalValueVariable( mWidth ); double scaledWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mWidth ).toDouble(), mWidthUnit, mWidthMapUnitScale ); pen.setWidthF( scaledWidth ); selPen.setWidthF( scaledWidth ); hasStrokeWidthExpression = true; } //color bool ok; if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( pen.color() ) ); QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR, context, QVariant(), &ok ).toString(); if ( ok ) pen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ); } //offset if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET ) ) { context.setOriginalValueVariable( mOffset ); offset = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, context, offset ).toDouble(); } //dash dot vector if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_CUSTOMDASH ) ) { double scaledWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mWidth, mWidthUnit, mWidthMapUnitScale ); double dashWidthDiv = mPen.widthF(); if ( hasStrokeWidthExpression ) { 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 = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_CUSTOMDASH, context, QVariant(), &ok ).toString().split( ';' ); if ( ok ) { QStringList::const_iterator dashIt = dashList.constBegin(); for ( ; dashIt != dashList.constEnd(); ++dashIt ) { dashVector.push_back( QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), dashIt->toDouble(), mCustomDashPatternUnit, mCustomDashPatternMapUnitScale ) / dashWidthDiv ); } pen.setDashPattern( dashVector ); } } //line style if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_LINE_STYLE ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenStyle( pen.style() ) ); QString lineStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_LINE_STYLE, context, QVariant(), &ok ).toString(); if ( ok ) pen.setStyle( QgsSymbolLayerV2Utils::decodePenStyle( lineStyleString ) ); } //join style if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOINSTYLE ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenJoinStyle( pen.joinStyle() ) ); QString joinStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOINSTYLE, context, QVariant(), &ok ).toString(); if ( ok ) pen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( joinStyleString ) ); } //cap style if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_CAPSTYLE ) ) { context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenCapStyle( pen.capStyle() ) ); QString capStyleString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_CAPSTYLE, context, QVariant(), &ok ).toString(); if ( ok ) pen.setCapStyle( QgsSymbolLayerV2Utils::decodePenCapStyle( capStyleString ) ); } }