Beispiel #1
0
void PlotMarkerLegend::updateLegend(QwtLegend* legend) const
{
	if ( legend == NULL )
		return;

	if ( legend && testItemAttribute( QwtPlotItem::Legend ) && symbol() && symbol()->style() != QwtSymbol::NoSymbol )
	{
		QWidget *lgdItem = legend->find( this );
		if ( lgdItem == NULL )
		{
			lgdItem = legendItem();
			if ( lgdItem )
				legend->insert( this, lgdItem );
		}

		LegendItem *l = qobject_cast<LegendItem *>( lgdItem );
		if ( l )
			l->setIdentifierSize( symbol()->boundingSize() );
	}

	QWidget *lgdItem = legend->find( this );
	if ( testItemAttribute( QwtPlotItem::Legend ) )
	{
		LegendItem *label = qobject_cast<LegendItem *>( 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( QwtPlotItem::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();
		}
	}
}
Beispiel #2
0
//!  Update the widget that represents the curve on the legend
void QwtPolarCurve::updateLegend( QwtLegend *legend ) const
{
    if ( legend && testItemAttribute( QwtPolarCurve::Legend )
            && ( d_data->legendAttributes & QwtPolarCurve::LegendShowSymbol )
            && d_data->symbol
            && d_data->symbol->style() != QwtSymbol::NoSymbol )
    {
        QWidget *lgdItem = legend->find( this );
        if ( lgdItem == NULL )
        {
            lgdItem = legendItem();
            if ( lgdItem )
                legend->insert( this, lgdItem );
        }

        QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem );
        if ( l )
        {
            QSize sz = d_data->symbol->boundingSize();
            sz += QSize( 2, 2 ); // margin

            if ( d_data->legendAttributes & QwtPolarCurve::LegendShowLine )
            {
                // Avoid, that the line is completely covered by the symbol

                int w = qCeil( 1.5 * sz.width() );
                if ( w % 2 )
                    w++;

                sz.setWidth( qMax( 8, w ) );
            }

            l->setIdentifierSize( sz );
        }
    }

    QwtPolarItem::updateLegend( legend );
}
/*!
   \brief Update the widget that represents the item on the legend

   \param legend Legend
   \sa drawLegendIdentifier(), legendItem(), itemChanged(), QwtLegend()
*/
void QwtPlotCurve::updateLegend( QwtLegend *legend ) const
{
    if ( legend && testItemAttribute( QwtPlotItem::Legend )
        && ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
        && d_data->symbol
        && d_data->symbol->style() != QwtSymbol::NoSymbol )
    {
        QWidget *lgdItem = legend->find( this );
        if ( lgdItem == NULL )
        {
            lgdItem = legendItem();
            if ( lgdItem )
                legend->insert( this, lgdItem );
        }
        if ( lgdItem && lgdItem->inherits( "QwtLegendItem" ) )
        {
            QwtLegendItem *l = ( QwtLegendItem * )lgdItem;
            l->setIdentifierSize( d_data->symbol->boundingSize() );
        }
    }

    QwtPlotItem::updateLegend( legend );
}
Beispiel #4
0
/*!
   Update the legend of the parent plot.
   \sa QwtPolarPlot::updateLegend(), itemChanged()
*/
void QwtPolarItem::legendChanged()
{
    if ( testItemAttribute( QwtPolarItem::Legend ) && d_data->plot )
        d_data->plot->updateLegend( this );
}