void QwtPlotItem::updateLegend(QwtLegend *legend) const
{
    if ( !legend )
        return;

    QWidget *lgdItem = legend->find(this);
    if ( testItemAttribute(QwtPlotItem::Legend) )
    {
        if ( lgdItem == NULL )
        {
            lgdItem = legendItem();
            if ( lgdItem )
            {
                if ( lgdItem->inherits("QwtLegendItem") )
                {
                    QwtLegendItem *label = (QwtLegendItem *)lgdItem;
                    label->setItemMode(legend->itemMode());

                    if ( d_data->plot )
                    {
                        QObject::connect(label, SIGNAL(clicked()), 
                            d_data->plot, SLOT(legendItemClicked()));
                        QObject::connect(label, SIGNAL(checked(bool)), 
                            d_data->plot, SLOT(legendItemChecked(bool)));
                    }
                }
                legend->insert(this, lgdItem);
            }
Exemplo n.º 2
0
/*!
   \brief Update the widget that represents the item on the legend

   updateLegend() is called from itemChanged() to adopt the widget
   representing the item on the legend to its new configuration.

   The default implementation is made for QwtPolarCurve and updates a
   QwtLegendItem(), but an item could be represented by any type of widget,
   by overloading legendItem() and updateLegend().

   \sa legendItem(), itemChanged(), QwtLegend()
*/
void QwtPolarItem::updateLegend( QwtLegend *legend ) const
{
    if ( legend == NULL )
        return;

    QWidget *lgdItem = legend->find( this );
    if ( testItemAttribute( QwtPolarItem::Legend ) )
    {
        if ( lgdItem == NULL )
        {
            lgdItem = legendItem();
            if ( lgdItem )
                legend->insert( this, lgdItem );
        }

        QwtLegendItem* label = qobject_cast<QwtLegendItem *>( lgdItem );
        if ( label )
        {
            // paint the identifier
            const QSize sz = label->identifierSize();

            QPixmap identifier( sz.width(), sz.height() );
            identifier.fill( Qt::transparent );

            QPainter painter( &identifier );
            painter.setRenderHint( QPainter::Antialiasing,
                testRenderHint( QwtPolarItem::RenderAntialiased ) );

            drawLegendIdentifier( &painter,
                QRect( 0, 0, sz.width(), sz.height() ) );

            painter.end();

            const bool doUpdate = label->updatesEnabled();
            if ( doUpdate )
                label->setUpdatesEnabled( false );

            label->setText( title() );
            label->setIdentifier( identifier );
            label->setItemMode( legend->itemMode() );

            if ( doUpdate )
                label->setUpdatesEnabled( true );

            label->update();
        }
    }
    else
    {
        if ( lgdItem )
        {
            lgdItem->hide();
            lgdItem->deleteLater();
        }
    }
}