Salome HOME
Fix for '54520: [TC-9.3.0]: Plot2D: Histograms: bad legend items' issue.
authorrnv <rnv@opencascade.com>
Fri, 22 Mar 2019 13:14:34 +0000 (16:14 +0300)
committerrnv <rnv@opencascade.com>
Fri, 22 Mar 2019 13:14:34 +0000 (16:14 +0300)
src/Plot2d/Plot2d_PlotItems.cxx
src/Plot2d/Plot2d_PlotItems.h

index fb8148fc5fe2768c46a99814b50c190522d17fad..c1b523c532176467d07ca7f782035f049ecd2256 100644 (file)
@@ -856,8 +856,8 @@ QList<QRect> Plot2d_HistogramItem::getBars() const
 /*!
   Set to legend item symbol with color of item
 */
-void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem,
-                                         QList<QwtLegendData>& theLegendData )
+void Plot2d_HistogramItem::updateLegend( const QwtPlotItem* thePlotItem,
+                                         const QList<QwtLegendData>& theLegendData )
 {
   if ( !thePlotItem || !thePlotItem->plot() )
     return;
@@ -868,15 +868,18 @@ void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem,
   QwtLegend *legend = dynamic_cast<QwtLegend *>( thePlotItem->plot()->legend() );
   QWidget* widget = legend->legendWidget( itemInfo );
 
-  if ( !widget || !widget->inherits( "QwtLegendItem" ) )
+  if ( !widget || !widget->inherits( "QwtLegendLabel" ) )
     return;
 
   QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( 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<Plot2d_Plot2d*>( 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 )
 {
index 3646a72c75672336e03d69d039702706c8c4de05..59102f65ec134861a2d618ae42420428952486c1 100644 (file)
@@ -180,11 +180,16 @@ public:
 
   QList<QRect>     getBars() const;
 
-  virtual void     updateLegend( QwtPlotItem*,
-                                 QList<QwtLegendData>& );
+
+  virtual void     updateLegend( const QwtPlotItem *,
+                                  const QList<QwtLegendData> & );
   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;