Salome HOME
updated copyright message
[modules/gui.git] / src / Plot2d / Plot2d_PlotItems.cxx
index 2d585c08cc34bc7c0654c8f34a3f38d74e584ced..4d4296e35d3ba6213a5171d4735f45b6b4041b82 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -104,6 +104,7 @@ Plot2d_QwtLegendLabel::Plot2d_QwtLegendLabel( QWidget* parent ) :
 */
 Plot2d_QwtLegendLabel::~Plot2d_QwtLegendLabel()
 {
+  delete mySymbol;
 }
 
 /*!
@@ -204,6 +205,7 @@ void  Plot2d_QwtLegendLabel::drawText( QPainter * painter, const QRectF &rect )
 */
 void Plot2d_QwtLegendLabel::setSymbol( const QwtSymbol* theSymbol )
 {
+  delete mySymbol;
   mySymbol = new QwtSymbol( theSymbol->style(), theSymbol->brush(),
                             theSymbol->pen(), theSymbol->size() );
 }
@@ -249,11 +251,12 @@ void Plot2d_QwtLegendLabel::paintEvent( QPaintEvent *e )
   QRect iconRect = cr;
   if ( !icon().isNull() )
   {
-    if ( itemMode() != QwtLegendData::ReadOnly )
+    if ( itemMode() != QwtLegendData::ReadOnly ) {
       iconRect.setX( iconRect.x() + ButtonFrame );
       iconRect.setSize( QSize( icon().size().width() + spacing() ,
-                                  icon().size().height() + spacing() ) );
+                                   icon().size().height() + spacing() ) );
       iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
+    }
   }
 
   drawIdentifier( &painter, iconRect );
@@ -295,9 +298,9 @@ public:
     return qwtMin(myMin.size(), myMax.size());
   }
   bool values(size_t i, double &min, double &max) {
-    if(myMin.contains(i) && myMax.contains(i)) {
-      min = myMin[i];
-      max = myMax[i];
+    if(myMin.contains((int)i) && myMax.contains((int)i)) { //!< TODO: conversion from size_t to int
+      min = myMin[(int)i];
+      max = myMax[(int)i];
       return true;
     }
     return false;
@@ -313,8 +316,8 @@ private:
 */
 Plot2d_QwtPlotCurve::Plot2d_QwtPlotCurve( const QString& title,
                                           QwtPlot::Axis yAxis /*const int index*/ ) :
-  Plot2d_SelectableItem(),
   QwtPlotCurve( title ),
+  Plot2d_SelectableItem(),
   myYAxis( yAxis ),
   myYAxisIdentifierEnabled( false ),
   myDeviationData(0)
@@ -356,21 +359,21 @@ void Plot2d_QwtPlotCurve::updateLegend( const QwtPlotItem* thePlotItem,
     if( QWidget* widget = legend->legendWidget( itemInfo ) ) {
       QwtLegendLabel* label = dynamic_cast<QwtLegendLabel*>( widget );
       if( Plot2d_QwtLegendLabel* anItem = (Plot2d_QwtLegendLabel*)label ) {
-       int aMode = Plot2d_QwtLegendLabel::IM_None;
-       if( myYAxisIdentifierEnabled )
-         aMode = myYAxis == QwtPlot::yRight ?
-           Plot2d_QwtLegendLabel::IM_Right :
-           Plot2d_QwtLegendLabel::IM_Left;
-       anItem->setYAxisIdentifierMode( aMode );
-       
-       anItem->setSymbol( legendSymbol() );
-       if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
-         anItem->setSymbolType( plot->getLegendSymbolType() );
-       anItem->setPen( legendPen() );
-       
-       anItem->setSelected( isSelected() );
-       anItem->updateHighlit();
-       anItem->repaint();
+        int aMode = Plot2d_QwtLegendLabel::IM_None;
+        if( myYAxisIdentifierEnabled )
+          aMode = myYAxis == QwtPlot::yRight ?
+            Plot2d_QwtLegendLabel::IM_Right :
+            Plot2d_QwtLegendLabel::IM_Left;
+        anItem->setYAxisIdentifierMode( aMode );
+        
+        anItem->setSymbol( legendSymbol() );
+        if( Plot2d_Plot2d* plot = dynamic_cast<Plot2d_Plot2d*>( thePlotItem->plot() ) )
+          anItem->setSymbolType( plot->getLegendSymbolType() );
+        anItem->setPen( legendPen() );
+        
+        anItem->setSelected( isSelected() );
+        anItem->updateHighlit();
+        anItem->repaint();
       }
     }
   }
@@ -397,7 +400,7 @@ void Plot2d_QwtPlotCurve::drawSeries( QPainter *painter,
                                       int from, int to) const
 {
   if (to < 0)
-    to = dataSize() - 1;
+    to = (int)dataSize() - 1; //!< TODO: conversion from size_t to int
   QwtPlotCurve::drawSeries(painter, xMap, yMap, canvasRect, from, to);
 
   //draw deviation data
@@ -424,7 +427,7 @@ void Plot2d_QwtPlotCurve::drawSeries( QPainter *painter,
       painter->drawLine(xp,ytop,xp,ybtm);
       painter->drawLine(tickl,ybtm,tickr,ybtm);
     }
-         painter->restore();
+          painter->restore();
   }
 }
 
@@ -499,8 +502,8 @@ void Plot2d_QwtPlotCurve::clearDeviationData()
 */
 Plot2d_SelectableItem::Plot2d_SelectableItem():
   myIsSelected(false),
-  myLegendSymbol( new QwtSymbol() ),
-  myLegendPen( QPen() )
+  myLegendPen( QPen() ),
+  myLegendSymbol( new QwtSymbol() )
 {
 }
 
@@ -690,7 +693,7 @@ int Plot2d_HistogramQwtItem::rtti() const
   Sets histogram attributes
 */
 void Plot2d_HistogramQwtItem::setHistogramAttribute( HistogramAttribute theAttr,
-                                                    bool isOn )
+                                                     bool isOn )
 {
   if ( testHistogramAttribute( theAttr ) != isOn ) {
     if ( isOn )
@@ -714,9 +717,9 @@ bool Plot2d_HistogramQwtItem::testHistogramAttribute( HistogramAttribute theAttr
   Draws histogram object
 */
 void Plot2d_HistogramQwtItem::draw( QPainter* thePainter,
-                                   const QwtScaleMap& theXMap,
-                                   const QwtScaleMap& theYMap,
-                                   const QRectF& ) const
+                                    const QwtScaleMap& theXMap,
+                                    const QwtScaleMap& theYMap,
+                                    const QRectF& ) const
 {
   thePainter->setPen( QPen( myColor ) );
 
@@ -777,8 +780,8 @@ void Plot2d_HistogramQwtItem::draw( QPainter* thePainter,
   Draws single bar of histogram
 */
 void Plot2d_HistogramQwtItem::drawBar( QPainter* thePainter,
-                                      Qt::Orientation,
-                                      const QRect& theRect ) const
+                                       Qt::Orientation,
+                                       const QRect& theRect ) const
 {
   thePainter->save();
 
@@ -854,8 +857,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;
@@ -866,15 +869,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() );
@@ -889,9 +895,9 @@ void Plot2d_HistogramItem::updateLegend( QwtPlotItem* thePlotItem,
   Draws histogram object
 */
 void Plot2d_HistogramItem::draw( QPainter* thePainter,
-                                const QwtScaleMap& theXMap,
-                                const QwtScaleMap& theYMap,
-                                const QRectF& ) const
+                                 const QwtScaleMap& theXMap,
+                                 const QwtScaleMap& theYMap,
+                                 const QRectF& ) const
 {
   // nds: clear list of bar items
   Plot2d_HistogramItem* anItem = (Plot2d_HistogramItem*)this;
@@ -979,8 +985,8 @@ bool Plot2d_HistogramItem::isCrossItems() const
   Draws bar of histogram and on it bars of histograms with lower height.
 */
 void Plot2d_HistogramItem::drawRectAndLowers( QPainter* thePainter,
-                                             Qt::Orientation theOr,
-                                             const QRect& theRect ) const
+                                              Qt::Orientation /*theOr*/,
+                                              const QRect& theRect ) const
 {
   QRect aRect = theRect;
   // theRect has inversed coordinates on Y axis.
@@ -992,6 +998,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.
 
@@ -1020,7 +1035,7 @@ int Plot2d_HistogramItem::getCrossedTop( const QRect& theRect ) const
              qMin( theRect.left(), aRects[i].left() ) ) {
           if ( theRect.bottom() < aRects[i].bottom() )
             if ( aRects[i].bottom() < aRes )
-             aRes = aRects[i].bottom();
+              aRes = aRects[i].bottom();
         }
       }
     }
@@ -1028,6 +1043,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 )
 {
@@ -1041,10 +1061,8 @@ Plot2d_QwtLegend::~Plot2d_QwtLegend()
 /*!
   Redefined method, which create a widget to be inserted into the legend.
 */
-QWidget *Plot2d_QwtLegend::createWidget( const QwtLegendData &data ) const
+QWidget *Plot2d_QwtLegend::createWidget( const QwtLegendData& /*data*/ ) const
 {
-  Q_UNUSED( data );
-
   Plot2d_QwtLegendLabel *label = new Plot2d_QwtLegendLabel();
   label->setItemMode( defaultItemMode() );