Example #1
0
void QgsComposerNodesItem::drawSelectedNode( QPainter *painter ) const
{
  double rectSize = 3.0 / horizontalViewScaleFactor();

  QgsStringMap properties;
  properties.insert( "name", "square" );
  properties.insert( "color", "0, 0, 0, 0" );
  properties.insert( "color_border", "blue" );
  properties.insert( "width_border", "4" );

  QScopedPointer<QgsMarkerSymbolV2> symbol;
  symbol.reset( QgsMarkerSymbolV2::createSimple( properties ) );
  symbol.data()->setSize( rectSize );

  QgsMapSettings ms = mComposition->mapSettings();
  ms.setOutputDpi( painter->device()->logicalDpiX() );

  QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
  context.setPainter( painter );
  context.setForceVectorOutput( true );

  QScopedPointer<QgsExpressionContext> expressionContext;
  expressionContext.reset( createExpressionContext() );
  context.setExpressionContext( *expressionContext.data() );

  symbol.data()->startRender( context );
  symbol.data()->renderPoint( mPolygon.at( mSelectedNode ), nullptr, context );
  symbol.data()->stopRender( context );
}
Example #2
0
void QgsComposerNodesItem::drawNodes( QPainter *painter ) const
{
  double rectSize = 3.0 / horizontalViewScaleFactor();

  QgsStringMap properties;
  properties.insert( "name", "cross" );
  properties.insert( "color_border", "red" );

  QScopedPointer<QgsMarkerSymbolV2> symbol;
  symbol.reset( QgsMarkerSymbolV2::createSimple( properties ) );
  symbol.data()->setSize( rectSize );
  symbol.data()->setAngle( 45 );

  QgsMapSettings ms = mComposition->mapSettings();
  ms.setOutputDpi( painter->device()->logicalDpiX() );

  QgsRenderContext context = QgsRenderContext::fromMapSettings( ms );
  context.setPainter( painter );
  context.setForceVectorOutput( true );

  QScopedPointer<QgsExpressionContext> expressionContext;
  expressionContext.reset( createExpressionContext() );
  context.setExpressionContext( *expressionContext.data() );

  symbol.data()->startRender( context );

  Q_FOREACH ( QPointF pt, mPolygon )
    symbol.data()->renderPoint( pt, nullptr, context );

  symbol.data()->stopRender( context );

  if ( mSelectedNode >= 0 && mSelectedNode < mPolygon.size() )
    drawSelectedNode( painter );
}
Example #3
0
void QgsComposerNodesItem::drawNodes( QPainter *painter ) const
{
  double rectSize = 3.0 / horizontalViewScaleFactor();

  QgsStringMap properties;
  properties.insert( QStringLiteral( "name" ), QStringLiteral( "cross" ) );
  properties.insert( QStringLiteral( "color_border" ), QStringLiteral( "red" ) );

  std::unique_ptr<QgsMarkerSymbol> symbol;
  symbol.reset( QgsMarkerSymbol::createSimple( properties ) );
  symbol->setSize( rectSize );
  symbol->setAngle( 45 );

  QgsRenderContext context = QgsComposerUtils::createRenderContextForComposition( mComposition, painter );
  context.setForceVectorOutput( true );

  QgsExpressionContext expressionContext = createExpressionContext();
  context.setExpressionContext( expressionContext );

  symbol->startRender( context );

  Q_FOREACH ( QPointF pt, mPolygon )
    symbol->renderPoint( pt, nullptr, context );

  symbol->stopRender( context );

  if ( mSelectedNode >= 0 && mSelectedNode < mPolygon.size() )
    drawSelectedNode( painter );
}
Example #4
0
void QgsPaperItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
  Q_UNUSED( itemStyle );
  Q_UNUSED( pWidget );
  if ( !painter )
  {
    return;
  }

  QgsRenderContext context;
  context.setPainter( painter );
  context.setScaleFactor( 1.0 );
  if ( mComposition->plotStyle() ==  QgsComposition::Preview )
  {
    context.setRasterScaleFactor( horizontalViewScaleFactor() );
  }
  else
  {
    context.setRasterScaleFactor( mComposition->printResolution() / 25.4 );
  }

  painter->save();

  if ( mComposition->plotStyle() ==  QgsComposition::Preview )
  {
    //if in preview mode, draw page border and shadow so that it's
    //still possible to tell where pages with a transparent style begin and end
    painter->setRenderHint( QPainter::Antialiasing, false );

    //shadow
    painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
    painter->setPen( Qt::NoPen );
    painter->drawRect( QRectF( 1, 1, rect().width() + 1, rect().height() + 1 ) );

    //page area
    painter->setBrush( QColor( 215, 215, 215 ) );
    painter->setPen( QPen( QColor( 100, 100, 100 ) ) );
    painter->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
  }

  painter->setRenderHint( QPainter::Antialiasing );
  mComposition->pageStyleSymbol()->startRender( context );

  calculatePageMargin();
  QPolygonF pagePolygon = QPolygonF( QRectF( mPageMargin, mPageMargin, rect().width() - 2 * mPageMargin, rect().height() - 2 * mPageMargin ) );
  QList<QPolygonF> rings; //empty list
  mComposition->pageStyleSymbol()->renderPolygon( pagePolygon, &rings, 0, context );
  mComposition->pageStyleSymbol()->stopRender( context );
  painter->restore();

}
double QgsComposerItem::lockSymbolSize() const
{
  double lockSymbolSize = 20.0 / horizontalViewScaleFactor();

  if ( lockSymbolSize > ( rect().width() / 3 ) )
  {
    lockSymbolSize = rect().width() / 3;
  }
  if ( lockSymbolSize > ( rect().height() / 3 ) )
  {
    lockSymbolSize = rect().height() / 3;
  }
  return lockSymbolSize;
}
Example #6
0
double QgsComposerItem::rectHandlerBorderTolerance() const
{
  //size of symbol boxes depends on zoom level in composer view
  double viewScaleFactor = horizontalViewScaleFactor();
  double rectHandlerSize = 10.0 / viewScaleFactor;

  //make sure the boxes don't get too large
  if ( rectHandlerSize > ( rect().width() / 3 ) )
  {
    rectHandlerSize = rect().width() / 3;
  }
  if ( rectHandlerSize > ( rect().height() / 3 ) )
  {
    rectHandlerSize = rect().height() / 3;
  }
  return rectHandlerSize;
}
Example #7
0
void QgsComposerNodesItem::drawSelectedNode( QPainter *painter ) const
{
  double rectSize = 3.0 / horizontalViewScaleFactor();

  QgsStringMap properties;
  properties.insert( QStringLiteral( "name" ), QStringLiteral( "square" ) );
  properties.insert( QStringLiteral( "color" ), QStringLiteral( "0, 0, 0, 0" ) );
  properties.insert( QStringLiteral( "color_border" ), QStringLiteral( "blue" ) );
  properties.insert( QStringLiteral( "width_border" ), QStringLiteral( "4" ) );

  std::unique_ptr<QgsMarkerSymbol> symbol;
  symbol.reset( QgsMarkerSymbol::createSimple( properties ) );
  symbol->setSize( rectSize );

  QgsRenderContext context = QgsComposerUtils::createRenderContextForComposition( mComposition, painter );
  context.setForceVectorOutput( true );

  QgsExpressionContext expressionContext = createExpressionContext();
  context.setExpressionContext( expressionContext );

  symbol->startRender( context );
  symbol->renderPoint( mPolygon.at( mSelectedNode ), nullptr, context );
  symbol->stopRender( context );
}
Example #8
0
void QgsComposerShape::drawShapeUsingSymbol( QPainter* p )
{
  p->save();
  p->setRenderHint( QPainter::Antialiasing );

  QgsRenderContext context;
  context.setPainter( p );
  context.setScaleFactor( 1.0 );
  if ( mComposition->plotStyle() ==  QgsComposition::Preview )
  {
    //Limit resolution of symbol fill if composition is not being exported
    //otherwise zooming into composition slows down renders
    context.setRasterScaleFactor( qMin( horizontalViewScaleFactor(), 3.0 ) );
  }
  else
  {
    context.setRasterScaleFactor( mComposition->printResolution() / 25.4 );
  }

  //generate polygon to draw
  QList<QPolygonF> rings; //empty list
  QPolygonF shapePolygon;

  //shapes with curves must be enlarged before conversion to QPolygonF, or
  //the curves are approximated too much and appear jaggy
  QTransform t = QTransform::fromScale( 100, 100 );
  //inverse transform used to scale created polygons back to expected size
  QTransform ti = t.inverted();

  switch ( mShape )
  {
    case Ellipse:
    {
      //create an ellipse
      QPainterPath ellipsePath;
      ellipsePath.addEllipse( QRectF( 0, 0 , rect().width(), rect().height() ) );
      QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t );
      shapePolygon = ti.map( ellipsePoly );
      break;
    }
    case Rectangle:
    {
      //if corner radius set, then draw a rounded rectangle
      if ( mCornerRadius > 0 )
      {
        QPainterPath roundedRectPath;
        roundedRectPath.addRoundedRect( QRectF( 0, 0 , rect().width(), rect().height() ), mCornerRadius, mCornerRadius );
        QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t );
        shapePolygon = ti.map( roundedPoly );
      }
      else
      {
        shapePolygon = QPolygonF( QRectF( 0, 0, rect().width(), rect().height() ) );
      }
      break;
    }
    case Triangle:
    {
      shapePolygon << QPointF( 0, rect().height() );
      shapePolygon << QPointF( rect().width() , rect().height() );
      shapePolygon << QPointF( rect().width() / 2.0, 0 );
      shapePolygon << QPointF( 0, rect().height() );
      break;
    }
  }

  mShapeStyleSymbol->startRender( context );

  //need to render using atlas feature properties?
  if ( mComposition->atlasComposition().enabled() && mComposition->atlasMode() != QgsComposition::AtlasOff )
  {
    //using an atlas, so render using current atlas feature
    //since there may be data defined symbols using atlas feature properties
    mShapeStyleSymbol->renderPolygon( shapePolygon, &rings, mComposition->atlasComposition().currentFeature(), context );
  }
  else
  {
    mShapeStyleSymbol->renderPolygon( shapePolygon, &rings, 0, context );
  }

  mShapeStyleSymbol->stopRender( context );
  p->restore();
}