//! Update the widget that represents the curve on the legend // this was adapted from QwtPlotCurve::updateLegend() void HistogramItem::updateLegend( QwtLegend *legend ) const { if ( !legend ) return; QwtPlotItem::updateLegend( legend ); QWidget *widget = legend->find( this ); if ( !widget || !widget->inherits( "QwtLegendItem" ) ) return; QwtLegendItem *legendItem = ( QwtLegendItem * )widget; #if QT_VERSION < 0x040000 const bool doUpdate = legendItem->isUpdatesEnabled(); #else const bool doUpdate = legendItem->updatesEnabled(); #endif legendItem->setUpdatesEnabled( false ); const int policy = legend->displayPolicy(); if ( policy == QwtLegend::FixedIdentifier ) { int mode = legend->identifierMode(); legendItem->setCurvePen( QPen( color() ) ); if ( mode & QwtLegendItem::ShowText ) legendItem->setText( title() ); else legendItem->setText( QwtText() ); legendItem->setIdentifierMode( mode ); } else if ( policy == QwtLegend::AutoIdentifier ) { int mode = 0; legendItem->setCurvePen( QPen( color() ) ); mode |= QwtLegendItem::ShowLine; if ( !title().isEmpty() ) { legendItem->setText( title() ); mode |= QwtLegendItem::ShowText; } else { legendItem->setText( QwtText() ); } legendItem->setIdentifierMode( mode ); } legendItem->setUpdatesEnabled( doUpdate ); legendItem->update(); }
//! Update the widget that represents the curve on the legend void QwtPolarCurve::updateLegend( QwtLegend *legend ) const { if ( !legend ) return; QwtPolarItem::updateLegend( legend ); QWidget *widget = legend->find( this ); if ( !widget || !widget->inherits( "QwtLegendItem" ) ) return; QwtLegendItem *legendItem = ( QwtLegendItem * )widget; #if QT_VERSION < 0x040000 const bool doUpdate = legendItem->isUpdatesEnabled(); #else const bool doUpdate = legendItem->updatesEnabled(); #endif legendItem->setUpdatesEnabled( false ); const int policy = legend->displayPolicy(); if ( policy == QwtLegend::FixedIdentifier ) { int mode = legend->identifierMode(); if ( mode & QwtLegendItem::ShowLine ) legendItem->setCurvePen( pen() ); if ( mode & QwtLegendItem::ShowSymbol ) legendItem->setSymbol( symbol() ); if ( mode & QwtLegendItem::ShowText ) legendItem->setText( title() ); else legendItem->setText( QwtText() ); legendItem->setIdentifierMode( mode ); } else if ( policy == QwtLegend::AutoIdentifier ) { int mode = 0; if ( QwtPolarCurve::NoCurve != style() ) { legendItem->setCurvePen( pen() ); mode |= QwtLegendItem::ShowLine; } if ( QwtSymbol::NoSymbol != symbol().style() ) { legendItem->setSymbol( symbol() ); mode |= QwtLegendItem::ShowSymbol; } if ( !title().isEmpty() ) { legendItem->setText( title() ); mode |= QwtLegendItem::ShowText; } else { legendItem->setText( QwtText() ); } legendItem->setIdentifierMode( mode ); } legendItem->setUpdatesEnabled( doUpdate ); legendItem->update(); }