//! 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(); }
void VectorPlot::addDotPlot(const MarkupQwtAdapter&adapter, QColor color, const QString &name, bool addToLegend) { QwtPlotCurve *curve = new QwtPlotCurve(name); QwtSymbol sym; sym.setPen(QColor(color)); sym.setBrush(QColor(color)); sym.setStyle(QwtSymbol::Rect); sym.setSize( QSize(1, 20) ); curve->setSymbol(sym); curve->setStyle(QwtPlotCurve::NoCurve); if(adapter.size() > 0) { setupPlot(adapter.boundingRect()); curve->setData(adapter); curve->attach(plot); } if(!legend) { return; } // Добавляем кривую в легенду QwtLegendItem *item = new QwtLegendItem(0); item->setText(curve->title()); item->setSymbol(sym); item->setIdentifierMode(QwtLegendItem::ShowLine | QwtLegendItem::ShowSymbol | QwtLegendItem::ShowText); legend->insert(curve, item); }
void PlotCurve::updateLegend(QwtLegend *legend) const { QwtPlotCurve::updateLegend(legend); QwtLegendItem *pQwtLegendItem = dynamic_cast<QwtLegendItem*>(legend->find(this)); if (pQwtLegendItem) { pQwtLegendItem->setIdentifierMode(QwtLegendItem::ShowLine); pQwtLegendItem->setIdentifierWidth(30); } QwtPlotItem::updateLegend(legend); }
//! 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(); }