本文整理汇总了C++中QgsSymbolRenderContext::renderContext方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsSymbolRenderContext::renderContext方法的具体用法?C++ QgsSymbolRenderContext::renderContext怎么用?C++ QgsSymbolRenderContext::renderContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsSymbolRenderContext
的用法示例。
在下文中一共展示了QgsSymbolRenderContext::renderContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderPoint
void QgsVectorFieldSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext& context )
{
if ( !mLineSymbol )
{
return;
}
const QgsRenderContext& ctx = context.renderContext();
const QgsFeature* f = context.feature();
if ( !f )
{
//preview
QPolygonF line;
line << QPointF( 0, 50 );
line << QPointF( 100, 50 );
mLineSymbol->renderPolyline( line, nullptr, context.renderContext() );
}
double xComponent = 0;
double yComponent = 0;
double xVal = 0;
if ( f && mXIndex != -1 )
{
xVal = f->attribute( mXIndex ).toDouble();
}
double yVal = 0;
if ( f && mYIndex != -1 )
{
yVal = f->attribute( mYIndex ).toDouble();
}
switch ( mVectorFieldType )
{
case Cartesian:
xComponent = QgsSymbolLayerUtils::convertToPainterUnits( ctx, xVal, mDistanceUnit, mDistanceMapUnitScale );
yComponent = QgsSymbolLayerUtils::convertToPainterUnits( ctx, yVal, mDistanceUnit, mDistanceMapUnitScale );
break;
case Polar:
convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
xComponent = QgsSymbolLayerUtils::convertToPainterUnits( ctx, xComponent, mDistanceUnit, mDistanceMapUnitScale );
yComponent = QgsSymbolLayerUtils::convertToPainterUnits( ctx, yComponent, mDistanceUnit, mDistanceMapUnitScale );
break;
case Height:
xComponent = 0;
yComponent = QgsSymbolLayerUtils::convertToPainterUnits( ctx, yVal, mDistanceUnit, mDistanceMapUnitScale );
break;
default:
break;
}
xComponent *= mScale;
yComponent *= mScale;
QPolygonF line;
line << point;
line << QPointF( point.x() + xComponent, point.y() - yComponent );
mLineSymbol->renderPolyline( line, f, context.renderContext() );
}
示例2: markerOffset
void QgsMarkerSymbolLayer::markerOffset( QgsSymbolRenderContext& context, double width, double height,
QgsUnitTypes::RenderUnit widthUnit, QgsUnitTypes::RenderUnit heightUnit,
double& offsetX, double& offsetY, const QgsMapUnitScale& widthMapUnitScale, const QgsMapUnitScale& heightMapUnitScale ) const
{
offsetX = mOffset.x();
offsetY = mOffset.y();
if ( hasDataDefinedProperty( QgsSymbolLayer::EXPR_OFFSET ) )
{
context.setOriginalValueVariable( QgsSymbolLayerUtils::encodePoint( mOffset ) );
QPointF offset = QgsSymbolLayerUtils::decodePoint( evaluateDataDefinedProperty( QgsSymbolLayer::EXPR_OFFSET, context ).toString() );
offsetX = offset.x();
offsetY = offset.y();
}
offsetX = QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), offsetX, mOffsetUnit, mOffsetMapUnitScale );
offsetY = QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), offsetY, mOffsetUnit, mOffsetMapUnitScale );
HorizontalAnchorPoint horizontalAnchorPoint = mHorizontalAnchorPoint;
VerticalAnchorPoint verticalAnchorPoint = mVerticalAnchorPoint;
if ( hasDataDefinedProperty( QgsSymbolLayer::EXPR_HORIZONTAL_ANCHOR_POINT ) )
{
horizontalAnchorPoint = decodeHorizontalAnchorPoint( evaluateDataDefinedProperty( QgsSymbolLayer::EXPR_HORIZONTAL_ANCHOR_POINT , context ).toString() );
}
if ( hasDataDefinedProperty( QgsSymbolLayer::EXPR_VERTICAL_ANCHOR_POINT ) )
{
verticalAnchorPoint = decodeVerticalAnchorPoint( evaluateDataDefinedProperty( QgsSymbolLayer::EXPR_VERTICAL_ANCHOR_POINT, context ).toString() );
}
//correct horizontal position according to anchor point
if ( horizontalAnchorPoint == HCenter && verticalAnchorPoint == VCenter )
{
return;
}
double anchorPointCorrectionX = QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), width, widthUnit, widthMapUnitScale ) / 2.0;
double anchorPointCorrectionY = QgsSymbolLayerUtils::convertToPainterUnits( context.renderContext(), height, heightUnit, heightMapUnitScale ) / 2.0;
if ( horizontalAnchorPoint == Left )
{
offsetX += anchorPointCorrectionX;
}
else if ( horizontalAnchorPoint == Right )
{
offsetX -= anchorPointCorrectionX;
}
//correct vertical position according to anchor point
if ( verticalAnchorPoint == Top )
{
offsetY += anchorPointCorrectionY;
}
else if ( verticalAnchorPoint == Bottom )
{
offsetY -= anchorPointCorrectionY;
}
}
示例3: stopRender
void QgsVectorFieldSymbolLayer::stopRender( QgsSymbolRenderContext& context )
{
if ( mLineSymbol )
{
mLineSymbol->stopRender( context.renderContext() );
}
}
示例4: drawGrid
void QgsPointDisplacementRenderer::drawGrid( int gridSizeUnits, QgsSymbolRenderContext &context,
QList<QPointF> pointSymbolPositions, int nSymbols )
{
QPainter *p = context.renderContext().painter();
if ( nSymbols < 2 || !p ) //draw grid only if multiple features
{
return;
}
QPen gridPen( mCircleColor );
gridPen.setWidthF( context.outputLineWidth( mCircleWidth ) );
p->setPen( gridPen );
for ( int i = 0; i < pointSymbolPositions.size(); ++i )
{
if ( i + 1 < pointSymbolPositions.size() && 0 != ( i + 1 ) % gridSizeUnits )
{
QLineF gridLineRow( pointSymbolPositions[i], pointSymbolPositions[i + 1] );
p->drawLine( gridLineRow );
}
if ( i + gridSizeUnits < pointSymbolPositions.size() )
{
QLineF gridLineColumn( pointSymbolPositions[i], pointSymbolPositions[i + gridSizeUnits] );
p->drawLine( gridLineColumn );
}
}
}
示例5: drawPreviewIcon
void QgsVectorFieldSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext& context, QSize size )
{
if ( mLineSymbol )
{
mLineSymbol->drawPreviewIcon( context.renderContext().painter(), size );
}
}
示例6: _renderPolygon
void QgsFillSymbolLayer::_renderPolygon( QPainter* p, const QPolygonF& points, const QList<QPolygonF>* rings, QgsSymbolRenderContext& context )
{
if ( !p )
{
return;
}
// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points).
if ( points.size() <= 5 &&
( context.renderContext().vectorSimplifyMethod().simplifyHints() & QgsVectorSimplifyMethod::AntialiasingSimplification ) &&
QgsAbstractGeometrySimplifier::isGeneralizableByDeviceBoundingBox( points, context.renderContext().vectorSimplifyMethod().threshold() ) &&
( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawRect( points.boundingRect() );
p->setRenderHint( QPainter::Antialiasing, true );
return;
}
// polygons outlines are sometimes rendered wrongly with drawPolygon, when
// clipped (see #13343), so use drawPath instead.
if ( !rings && p->pen().style() == Qt::NoPen )
{
// simple polygon without holes
p->drawPolygon( points );
}
else
{
// polygon with holes must be drawn using painter path
QPainterPath path;
QPolygonF outerRing = points;
path.addPolygon( outerRing );
if ( rings )
{
QList<QPolygonF>::const_iterator it = rings->constBegin();
for ( ; it != rings->constEnd(); ++it )
{
QPolygonF ring = *it;
path.addPolygon( ring );
}
}
p->drawPath( path );
}
}
示例7: calculateOffsetAndRotation
void QgsEllipseSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContext &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 ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle ) )
{
context.setOriginalValueVariable( angle );
angle = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyAngle, context.renderContext().expressionContext(), 0 ) + mLineAngle;
usingDataDefinedRotation = ok;
}
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || 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->geometry();
if ( !g.isNull() && g.type() == QgsWkbTypes::PointGeometry )
{
const QgsMapToPixel &m2p = context.renderContext().mapToPixel();
angle += m2p.mapRotation();
}
}
}
if ( angle )
offset = _rotatedOffset( offset, angle );
}
示例8: bounds
QRectF QgsEllipseSymbolLayer::bounds( QPointF point, QgsSymbolRenderContext &context )
{
QSizeF size = calculateSize( context );
bool hasDataDefinedRotation = false;
QPointF offset;
double angle = 0;
calculateOffsetAndRotation( context, size.width(), size.height(), hasDataDefinedRotation, offset, angle );
QMatrix transform;
// move to the desired position
transform.translate( point.x() + offset.x(), point.y() + offset.y() );
if ( !qgsDoubleNear( angle, 0.0 ) )
transform.rotate( angle );
double penWidth = 0.0;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyStrokeWidth ) )
{
context.setOriginalValueVariable( mStrokeWidth );
QVariant exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyStrokeWidth, context.renderContext().expressionContext() );
if ( exprVal.isValid() )
{
bool ok;
double strokeWidth = exprVal.toDouble( &ok );
if ( ok )
{
penWidth = context.renderContext().convertToPainterUnits( strokeWidth, mStrokeWidthUnit, mStrokeWidthMapUnitScale );
}
}
}
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyStrokeStyle ) )
{
context.setOriginalValueVariable( QgsSymbolLayerUtils::encodePenStyle( mStrokeStyle ) );
QVariant exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyStrokeStyle, context.renderContext().expressionContext() );
if ( exprVal.isValid() && exprVal.toString() == QLatin1String( "no" ) )
{
penWidth = 0.0;
}
}
//antialiasing, add 1 pixel
penWidth += 1;
QRectF symbolBounds = transform.mapRect( QRectF( -size.width() / 2.0,
-size.height() / 2.0,
size.width(),
size.height() ) );
//extend bounds by pen width / 2.0
symbolBounds.adjust( -penWidth / 2.0, -penWidth / 2.0,
penWidth / 2.0, penWidth / 2.0 );
return symbolBounds;
}
示例9: prepareExpressions
void QgsSymbolLayer::prepareExpressions( const QgsSymbolRenderContext &context )
{
mDataDefinedProperties.prepare( context.renderContext().expressionContext() );
if ( !context.fields().isEmpty() )
{
//QgsFields is implicitly shared, so it's cheap to make a copy
mFields = context.fields();
}
}
示例10: startRender
void QgsEllipseSymbolLayer::startRender( QgsSymbolRenderContext &context )
{
QgsMarkerSymbolLayer::startRender( context ); // get anchor point expressions
if ( !context.feature() || !dataDefinedProperties().hasActiveProperties() )
{
preparePath( mSymbolName, context );
}
mPen.setColor( mStrokeColor );
mPen.setStyle( mStrokeStyle );
mPen.setJoinStyle( mPenJoinStyle );
mPen.setWidthF( context.renderContext().convertToPainterUnits( mStrokeWidth, mStrokeWidthUnit, mStrokeWidthMapUnitScale ) );
mBrush.setColor( mColor );
}
示例11: drawCircle
void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSymbolRenderContext &context, QPointF centerPoint, int nSymbols )
{
QPainter *p = context.renderContext().painter();
if ( nSymbols < 2 || !p ) //draw circle only if multiple features
{
return;
}
//draw Circle
QPen circlePen( mCircleColor );
circlePen.setWidthF( context.outputLineWidth( mCircleWidth ) );
p->setPen( circlePen );
p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
}
示例12: calculateSize
QSizeF QgsEllipseSymbolLayer::calculateSize( QgsSymbolRenderContext &context, double *scaledWidth, double *scaledHeight )
{
double width = 0;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyWidth ) ) //1. priority: data defined setting on symbol layer le
{
context.setOriginalValueVariable( mSymbolWidth );
width = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyWidth, context.renderContext().expressionContext(), mSymbolWidth );
}
else //2. priority: global width setting
{
width = mSymbolWidth;
}
if ( scaledWidth )
{
*scaledWidth = width;
}
width = context.renderContext().convertToPainterUnits( width, mSymbolWidthUnit, mSymbolHeightMapUnitScale );
double height = 0;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyHeight ) ) //1. priority: data defined setting on symbol layer level
{
context.setOriginalValueVariable( mSymbolHeight );
height = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyHeight, context.renderContext().expressionContext(), mSymbolHeight );
}
else //2. priority: global height setting
{
height = mSymbolHeight;
}
if ( scaledHeight )
{
*scaledHeight = height;
}
height = context.renderContext().convertToPainterUnits( height, mSymbolHeightUnit, mSymbolHeightMapUnitScale );
return QSizeF( width, height );
}
示例13: drawPreviewIcon
void QgsMarkerSymbolLayer::drawPreviewIcon( QgsSymbolRenderContext &context, QSize size )
{
startRender( context );
QgsPaintEffect *effect = paintEffect();
if ( effect && effect->enabled() )
{
QgsEffectPainter p( context.renderContext(), effect );
renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
}
else
{
renderPoint( QPointF( size.width() / 2, size.height() / 2 ), context );
}
stopRender( context );
}
示例14: prepareExpressions
void QgsSymbolLayer::prepareExpressions( const QgsSymbolRenderContext& context )
{
QMap< QString, QgsDataDefined* >::const_iterator it = mDataDefinedProperties.constBegin();
for ( ; it != mDataDefinedProperties.constEnd(); ++it )
{
if ( it.value() )
{
it.value()->prepareExpression( context.renderContext().expressionContext() );
}
}
if ( !context.fields().isEmpty() )
{
//QgsFields is implicitly shared, so it's cheap to make a copy
mFields = context.fields();
}
}
示例15: startRender
void QgsVectorFieldSymbolLayer::startRender( QgsSymbolRenderContext& context )
{
if ( mLineSymbol )
{
mLineSymbol->startRender( context.renderContext(), context.fields() );
}
QgsFields fields = context.fields();
if ( !fields.isEmpty() )
{
mXIndex = fields.lookupField( mXAttribute );
mYIndex = fields.lookupField( mYAttribute );
}
else
{
mXIndex = -1;
mYIndex = -1;
}
}