コード例 #1
0
ファイル: qgshighlight.cpp プロジェクト: ColeCummins/QGIS
void QgsHighlight::paintPolygon( QPainter *p, QgsPolygon polygon )
{
  // OddEven fill rule by default
  QPainterPath path;

  p->setPen( mPen );
  p->setBrush( mBrush );

  for ( int i = 0; i < polygon.size(); i++ )
  {
    if ( polygon[i].empty() ) continue;

    QPolygonF ring;
    ring.reserve( polygon[i].size() + 1 );

    for ( int j = 0; j < polygon[i].size(); j++ )
    {
      //adding point only if it is more than a pixel appart from the previous one
      const QPointF cur = toCanvasCoordinates( polygon[i][j] ) - pos();
      if ( 0 == j || std::abs( ring.back().x() - cur.x() ) > 1 || std::abs( ring.back().y() - cur.y() ) > 1 )
      {
        ring.push_back( cur );
      }
    }

    ring.push_back( ring[ 0 ] );

    path.addPolygon( ring );
  }

  p->drawPath( path );
}
コード例 #2
0
ファイル: geometry.cpp プロジェクト: ASabina/qreal
qreal Geometry::square(QPolygonF const &polygon)
{
	qreal result = 0;
	for (int i = 0; i < polygon.size(); ++i) {
		QPointF const p1 = i ? polygon[i-1] : polygon.back();
		QPointF const p2 = polygon[i];
		result += (p1.x() - p2.x()) * (p1.y() + p2.y());
	}

	return fabs(result) / 2;
}
コード例 #3
0
void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  Q_UNUSED( points );

  if ( !context.renderContext().painter() )
  {
    return;
  }

  context.renderContext().expressionContext().appendScope( mExpressionScope.data() );
  mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size() + 1 );
  mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, 1 );
  if ( isCurved() )
  {
    _resolveDataDefined( context );

    if ( ! isRepeated() )
    {
      if ( points.size() >= 3 )
      {
        // origin point
        QPointF po( points.at( 0 ) );
        // middle point
        QPointF pm( points.at( points.size() / 2 ) );
        // destination point
        QPointF pd( points.back() );

        QPolygonF poly = curvedArrow( po, pm, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
        mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
      }
      // straight arrow
      else if ( points.size() == 2 )
      {
        // origin point
        QPointF po( points.at( 0 ) );
        // destination point
        QPointF pd( points.at( 1 ) );

        QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
        mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
      }
    }
    else
    {
      for ( int pIdx = 0; pIdx < points.size() - 1; pIdx += 2 )
      {
        mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 );
        _resolveDataDefined( context );

        if ( points.size() - pIdx >= 3 )
        {
          // origin point
          QPointF po( points.at( pIdx ) );
          // middle point
          QPointF pm( points.at( pIdx + 1 ) );
          // destination point
          QPointF pd( points.at( pIdx + 2 ) );

          QPolygonF poly = curvedArrow( po, pm, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
          mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
        }
        // straight arrow
        else if ( points.size() - pIdx == 2 )
        {
          // origin point
          QPointF po( points.at( pIdx ) );
          // destination point
          QPointF pd( points.at( pIdx + 1 ) );

          QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
          mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
        }
      }
    }
  }
  else
  {
    if ( !isRepeated() )
    {
      _resolveDataDefined( context );

      // origin point
      QPointF po( points.at( 0 ) );
      // destination point
      QPointF pd( points.back() );

      QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
      mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
    }
    else
    {
      // only straight arrows
      for ( int pIdx = 0; pIdx < points.size() - 1; pIdx++ )
      {
        mExpressionScope->setVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 );
        _resolveDataDefined( context );

        // origin point
        QPointF po( points.at( pIdx ) );
        // destination point
        QPointF pd( points.at( pIdx + 1 ) );

        QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
        mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
      }
    }
  }
  context.renderContext().expressionContext().popScope();
}