void QgsComposerPicture::refreshPicture( const QgsExpressionContext *context ) { QgsExpressionContext scopedContext = createExpressionContext(); const QgsExpressionContext* evalContext = context ? context : &scopedContext; QString source = mSourcePath; //data defined source set? mHasExpressionError = false; QVariant exprVal; if ( dataDefinedProperty( QgsComposerObject::PictureSource ) && dataDefinedProperty( QgsComposerObject::PictureSource )->isActive() ) { if ( dataDefinedEvaluate( QgsComposerObject::PictureSource, exprVal, *evalContext ) ) { source = exprVal.toString().trimmed(); QgsDebugMsg( QString( "exprVal PictureSource:%1" ).arg( source ) ); } else { mHasExpressionError = true; source = QString(); QgsMessageLog::logMessage( tr( "Picture expression eval error" ) ); } } loadPicture( source ); }
void QgsEllipseSymbolLayerV2::writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const { // <Graphic> QDomElement graphicElem = doc.createElement( "se:Graphic" ); element.appendChild( graphicElem ); QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, mSymbolName, mFillColor, mOutlineColor, mOutlineWidth, mSymbolWidth ); // store w/h factor in a <VendorOption> double widthHeightFactor = mSymbolWidth / mSymbolHeight; QDomElement factorElem = QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "widthHeightFactor", QString::number( widthHeightFactor ) ); graphicElem.appendChild( factorElem ); // <Rotation> const QgsExpression* rotationExpression = dataDefinedProperty( "rotation" ); QString angleFunc = props.value( "angle", "" ); if ( angleFunc.isEmpty() ) // symbol has no angle set { if ( rotationExpression ) angleFunc = rotationExpression->expression(); else if ( !qgsDoubleNear( mAngle, 0.0 ) ) angleFunc = QString::number( mAngle ); } else if ( rotationExpression ) { // the symbol has an angle and the symbol layer have a rotation // property set angleFunc = QString( "%1 + %2" ).arg( angleFunc ).arg( rotationExpression->expression() ); } else if ( !qgsDoubleNear( mAngle, 0.0 ) ) { // both the symbol and the symbol layer have angle value set bool ok; double angle = angleFunc.toDouble( &ok ); if ( !ok ) { // its a string (probably a property name or a function) angleFunc = QString( "%1 + %2" ).arg( angleFunc ).arg( mAngle ); } else if ( !qgsDoubleNear( angle + mAngle, 0.0 ) ) { // it's a double value angleFunc = QString::number( angle + mAngle ); } } QgsSymbolLayerV2Utils::createRotationElement( doc, graphicElem, angleFunc ); }
QString QgsMarkerLineSymbolLayerV2::dataDefinedPropertyString( const QString& property ) const { const QgsExpression* ex = dataDefinedProperty( property ); return ex ? ex->dump() : QString(); }
QString QgsSimpleLineSymbolLayerV2::dataDefinedPropertyString( const QString& property ) const { const QgsExpression* expression = dataDefinedProperty( property ); return expression ? expression->dump() : QString( "" ); }
bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const { return ( dataDefinedProperty( "width" ) || dataDefinedProperty( "height" ) || dataDefinedProperty( "rotation" ) || dataDefinedProperty( "outline_width" ) || dataDefinedProperty( "fill_color" ) || dataDefinedProperty( "outline_color" ) || dataDefinedProperty( "symbol_name" ) || dataDefinedProperty( "offset" ) ); }
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 ); }