Exemplo n.º 1
0
QPolygonF Shape::vertices() const
{
  QPolygonF result = vertices_;

  switch (type_) {
    case SEGMENT:
    case POLYLINE:
    case CLOSED_POLYLINE:
    case POLYGON:
      break;

    case RECTANGLE:
      if (result.size() == 2) {
        result = QPolygonF(QRectF(result[0], result[1]));
        result.pop_back();
      }
      break;
  }
  return result;
}
Exemplo n.º 2
0
void QgsComposerMapOverview::draw( QPainter *painter )
{
  if ( !mEnabled || mFrameMapId == -1 || !mComposerMap || !mComposerMap->composition() )
  {
    return;
  }
  if ( !painter )
  {
    return;
  }

  const QgsComposerMap* overviewFrameMap = mComposerMap->composition()->getComposerMapById( mFrameMapId );
  if ( !overviewFrameMap )
  {
    return;
  }

  //get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
  QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();

  //get current map's extent as a QPolygonF
  QPolygonF thisExtent = mComposerMap->visibleExtentPolygon();
  //intersect the two
  QPolygonF intersectExtent = thisExtent.intersected( otherExtent );

  //setup painter scaling to dots so that raster symbology is drawn to scale
  double dotsPerMM = painter->device()->logicalDpiX() / 25.4;

  //setup render context
  QgsMapSettings ms = mComposerMap->composition()->mapSettings();
  //context units should be in dots
  ms.setOutputSize( QSizeF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM ).toSize() );
  ms.setExtent( *mComposerMap->currentMapExtent() );
  ms.setOutputDpi( painter->device()->logicalDpiX() );
  QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
  context.setForceVectorOutput( true );
  context.setPainter( painter );
  QgsExpressionContext* expressionContext = createExpressionContext();
  context.setExpressionContext( *expressionContext );
  delete expressionContext;

  painter->save();
  painter->setCompositionMode( mBlendMode );
  painter->translate( mComposerMap->mXOffset, mComposerMap->mYOffset );
  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
  painter->setRenderHint( QPainter::Antialiasing );

  mFrameSymbol->startRender( context );

  //construct a polygon corresponding to the intersecting map extent
  //need to scale line to dots, rather then mm, since the painter has been scaled to dots
  QTransform mapTransform;
  QPolygonF thisRectPoly = QPolygonF( QRectF( 0, 0, dotsPerMM * mComposerMap->rect().width(), dotsPerMM * mComposerMap->rect().height() ) );

  //workaround QT Bug #21329
  thisRectPoly.pop_back();
  thisExtent.pop_back();

  //create transform from map coordinates to painter coordinates
  QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
  QPolygonF intersectPolygon;
  intersectPolygon = mapTransform.map( intersectExtent );

  QList<QPolygonF> rings; //empty list
  if ( !mInverted )
  {
    //Render the intersecting map extent
    mFrameSymbol->renderPolygon( intersectPolygon, &rings, nullptr, context );
  }
  else
  {
    //We are inverting the overview frame (ie, shading outside the intersecting extent)
    //Construct a polygon corresponding to the overview map extent
    QPolygonF outerPolygon;
    outerPolygon << QPointF( 0, 0 )
    << QPointF( mComposerMap->rect().width() * dotsPerMM, 0 )
    << QPointF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM )
    << QPointF( 0, mComposerMap->rect().height() * dotsPerMM )
    << QPointF( 0, 0 );

    //Intersecting extent is an inner ring for the shaded area
    rings.append( intersectPolygon );
    mFrameSymbol->renderPolygon( outerPolygon, &rings, nullptr, context );
  }

  mFrameSymbol->stopRender( context );
  painter->restore();
}
Exemplo n.º 3
0
bool DataConverter::digitalPattern_Rotate(QPolygonF &points, qreal angle)
{
	if (angle == 0.0)
		return true;

	if (angle < -180.0 || angle > 180.0)
	{
		qDebug("[DataConverter::digitalPattern_Rotate] Error: Angle: [%f]", angle);
		return false;
	}

	if (points.size() < 10)
	{
		qDebug("[DataConverter::digitalPattern_Rotate] Error: Polygon Point Count: [%d]", points.size());
		return false;
	}

	//
	QTransform transform;

	transform.rotate(angle);

	points = transform.map(points);

	//
	int bottomIndex = 0;

	{
		qreal tmpX = -9999.99;

		for (int i = 0; i < points.size(); i++)
		{
			if (points.at(i).y() < 0.0)
				continue;

			if (points.at(i).x() > 0.0)
				continue;

			if (points.at(i).x() > tmpX)
			{
				tmpX = points.at(i).x();
				bottomIndex = i;
			}
		}
	}

	qDebug("** bottomIndex: [%d]", bottomIndex);

	if (bottomIndex > 0)
	{
		QPointF tmpPoint;

		for (int i = points.size() - 1; i >= bottomIndex; i--)
		{
			tmpPoint = points.last();
			points.pop_back();
			points.push_front(tmpPoint);
		}
	}

	return true;
}