void QwtPolarRenderer::renderLegend(
    QPainter *painter, const QRectF &rect ) const
{
    QwtLegend *legend = d_data->plot->legend();
    if ( legend == NULL || legend->isEmpty() )
        return;

    const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>(
        legend->contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    uint numCols = legendLayout->columnsForWidth( rect.width() );
    const QList<QRect> itemRects =
        legendLayout->layoutItems( rect.toRect(), numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index] );
            renderLegendItem( painter, w, itemRects[index] );

            index++;
            painter->restore();
        }
    }

}
/*!
  Print the legend into a given rectangle.

  \param plot Plot widget
  \param painter Painter
  \param rect Bounding rectangle
*/
void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    QPainter *painter, const QRectF &rect ) const
{
    if ( !plot->legend() || plot->legend()->isEmpty() )
        return;

    QLayout *l = plot->legend()->contentsWidget()->layout();
    if ( l == 0 || !l->inherits( "QwtDynGridLayout" ) )
        return;

    QwtDynGridLayout *legendLayout = ( QwtDynGridLayout * )l;

    uint numCols = legendLayout->columnsForWidth( rect.width() );
    QList<QRect> itemRects =
        legendLayout->layoutItems( rect.toRect(), numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index] );
            renderLegendItem( plot, painter, w, itemRects[index] );

            index++;
            painter->restore();
        }
    }
}
/*!
  Render the legend into a given rectangle.

  \param plot Plot widget
  \param painter Painter
  \param rect Bounding rectangle
*/
void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    QPainter *painter, const QRectF &rect ) const
{
    if ( !plot->legend() || plot->legend()->isEmpty() )
        return;

    if ( !( d_data->discardFlags & DiscardBackground ) )
    {
        if ( plot->legend()->autoFillBackground() ||
            plot->legend()->testAttribute( Qt::WA_StyledBackground ) )
        {
            qwtRenderBackground( painter, rect, plot->legend() );
        }
    }

    const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( 
        plot->legend()->contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    int left, right, top, bottom;
    plot->legend()->getContentsMargins( &left, &top, &right, &bottom );

    QRect layoutRect;
    layoutRect.setLeft( qCeil( rect.left() ) + left );
    layoutRect.setTop( qCeil( rect.top() ) + top );
    layoutRect.setRight( qFloor( rect.right() ) - right );
    layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );

    uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
    QList<QRect> itemRects =
        legendLayout->layoutItems( layoutRect, numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index] );
            renderLegendItem( plot, painter, w, itemRects[index] );

            index++;
            painter->restore();
        }
    }
}
/*!
  Render the legend into a given rectangle.

  \param plot Plot widget
  \param painter Painter
  \param rect Bounding rectangle
*/
void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    QPainter *painter, const QRectF &rect ) const
{
    if ( !plot->legend() || plot->legend()->isEmpty() )
        return;

    if ( !( d_data->discardFlags & DiscardBackground ) )
    {
        if ( plot->legend()->autoFillBackground() ||
            plot->legend()->testAttribute( Qt::WA_StyledBackground ) )
        {
            qwtRenderBackground( painter, rect, plot->legend() );
        }
    }

    const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( 
        plot->legend()->contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    uint numCols = legendLayout->columnsForWidth( rect.width() );
    QList<QRect> itemRects =
        legendLayout->layoutItems( rect.toRect(), numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index] );
            renderLegendItem( plot, painter, w, itemRects[index] );

            index++;
            painter->restore();
        }
    }
}
Beispiel #5
0
void QwtPolarPlot::renderLegend( QPainter *painter, const QRect &rect ) const
{
#if 1
  // Shift this code into QwtLegend, so that Qwt/QwtPolar can share it
#endif

  if ( !legend() || legend()->isEmpty() )
    return;

  QLayout *l = legend()->contentsWidget()->layout();
  if ( l == 0 || !l->inherits( "QwtDynGridLayout" ) )
    return;

  QwtDynGridLayout *legendLayout = ( QwtDynGridLayout * )l;

  uint numCols = legendLayout->columnsForWidth( rect.width() );
#if QT_VERSION < 0x040000
  QValueList<QRect> itemRects =
    legendLayout->layoutItems( rect, numCols );
#else
  QList<QRect> itemRects =
    legendLayout->layoutItems( rect, numCols );
#endif

  int index = 0;

#if QT_VERSION < 0x040000
  QLayoutIterator layoutIterator = legendLayout->iterator();
  for ( QLayoutItem *item = layoutIterator.current();
        item != 0; item = ++layoutIterator )
  {
#else
  for ( int i = 0; i < legendLayout->count(); i++ )
  {
    QLayoutItem *item = legendLayout->itemAt( i );
#endif
    QWidget *w = item->widget();
    if ( w )
    {
      painter->save();
      painter->setClipping( true );
      QwtPainter::setClipRect( painter, itemRects[index] );

      renderLegendItem( painter, w, itemRects[index] );

      index++;
      painter->restore();
    }
  }
}

/*!
  Render the legend item into a given rectangle.

  \param painter Painter
  \param w Widget representing a legend item
  \param rect Bounding rectangle
*/

void QwtPolarPlot::renderLegendItem( QPainter *painter,
                                     const QWidget *w, const QRect &rect ) const
{
#if 1
  // Shift this code into QwtLegend, so that Qwt/QwtPolar can share it
#endif
  if ( w->inherits( "QwtLegendItem" ) )
  {
    QwtLegendItem *item = ( QwtLegendItem * )w;

    painter->setFont( item->font() );
    item->drawItem( painter, rect );
  }
}