From 85b9f10c565906dcf297019c107c17f051f9095f Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 22 Mar 2019 16:14:34 +0300 Subject: [PATCH] Fix for '54520: [TC-9.3.0]: Plot2D: Histograms: bad legend items' issue. --- src/Plot2d/Plot2d_PlotItems.cxx | 25 +++++++++++++++++++++---- src/Plot2d/Plot2d_PlotItems.h | 9 +++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Plot2d/Plot2d_PlotItems.cxx b/src/Plot2d/Plot2d_PlotItems.cxx index fb8148fc5..c1b523c53 100644 --- a/src/Plot2d/Plot2d_PlotItems.cxx +++ b/src/Plot2d/Plot2d_PlotItems.cxx @@ -856,8 +856,8 @@ QList Plot2d_HistogramItem::getBars() const /*! Set to legend item symbol with color of item */ -void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem, - QList& theLegendData ) +void Plot2d_HistogramItem::updateLegend( const QwtPlotItem* thePlotItem, + const QList& theLegendData ) { if ( !thePlotItem || !thePlotItem->plot() ) return; @@ -868,15 +868,18 @@ void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem, QwtLegend *legend = dynamic_cast( thePlotItem->plot()->legend() ); QWidget* widget = legend->legendWidget( itemInfo ); - if ( !widget || !widget->inherits( "QwtLegendItem" ) ) + if ( !widget || !widget->inherits( "QwtLegendLabel" ) ) return; QwtLegendLabel* label = dynamic_cast( widget ); if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)( label ) ) { QFontMetrics aFMetrics( anItem->font() ); int aSize = aFMetrics.height(); + QPen aPen( legendPen().color() ); + aPen.setStyle(Qt::NoPen); + anItem->setPen(aPen); QwtSymbol* aSymbol = new QwtSymbol( QwtSymbol::Rect, QBrush( legendPen().color() ), - QPen( legendPen().color() ), QSize( aSize, aSize ) ); + aPen, QSize( aSize, aSize ) ); anItem->setSymbol( aSymbol ); if( Plot2d_Plot2d* plot = dynamic_cast( thePlotItem->plot() ) ) anItem->setSymbolType( plot->getLegendSymbolType() ); @@ -994,6 +997,15 @@ void Plot2d_HistogramItem::drawRectAndLowers( QPainter* thePainter, drawBar( thePainter, Qt::Horizontal, aRect ); } +void Plot2d_HistogramItem::itemChanged() +{ + if ( plot() ) + updateLegend( this, legendData() ); + + QwtPlotItem::itemChanged(); +} + + /*! Returns top value of the given rect in the context of other bars. @@ -1030,6 +1042,11 @@ int Plot2d_HistogramItem::getCrossedTop( const QRect& theRect ) const return aRes; } +QwtGraphic Plot2d_HistogramItem::legendIcon( int index, const QSizeF &size ) const +{ + return defaultIcon( color(), size ); +} + Plot2d_QwtLegend::Plot2d_QwtLegend( QWidget *parent ): QwtLegend( parent ) { diff --git a/src/Plot2d/Plot2d_PlotItems.h b/src/Plot2d/Plot2d_PlotItems.h index 3646a72c7..59102f65e 100644 --- a/src/Plot2d/Plot2d_PlotItems.h +++ b/src/Plot2d/Plot2d_PlotItems.h @@ -180,11 +180,16 @@ public: QList getBars() const; - virtual void updateLegend( QwtPlotItem*, - QList& ); + + virtual void updateLegend( const QwtPlotItem *, + const QList & ); virtual void draw( QPainter*, const QwtScaleMap&, const QwtScaleMap&, const QRectF& ) const; + virtual void itemChanged(); + + virtual QwtGraphic legendIcon( int index, const QSizeF & ) const; + void setCrossItems( bool theCross ); bool isCrossItems() const; -- 2.39.2