Menu

#305 QwtPlotBarChart deletes specialSymbol every redraw

open
nobody
None
5
2019-10-08
2019-08-28
Anonymous
No
void QwtPlotBarChart::drawBar( QPainter *painter,
    int sampleIndex, const QPointF &sample, 
    const QwtColumnRect &rect ) const

calls:

QwtColumnSymbol * QwtPlotBarChart::specialSymbol(
    int sampleIndex, const QPointF & sample) const

and deletes the symbol afterwards.

It would be great if it behaved like the normal Bar Symbol wich is deleted at the end of the QwtPlotBarChart ; I see no necessity to delete the symbol every time it is called. In the current version you have to generate a new symbol every time anything happens to the plot.

Proposed fix in qwt_plot_barchart.cpp:

void QwtPlotBarChart::drawBar( QPainter *painter,
    int sampleIndex, const QPointF &sample, 
    const QwtColumnRect &rect ) const
{
    const QwtColumnSymbol *specialSym = 
        specialSymbol( sampleIndex, sample );

    const QwtColumnSymbol *sym = specialSym;
    if ( sym == NULL )
        sym = d_data->symbol;

    if ( sym )
    {
        sym->draw( painter, rect );
    }
    else
    {
        // we build a temporary default symbol
        QwtColumnSymbol sym( QwtColumnSymbol::Box );
        sym.setLineWidth( 1 );
        sym.setFrameStyle( QwtColumnSymbol::Plain );
        sym.draw( painter, rect );
    }

    //Fix: delete this line 
    delete specialSym; // <---
}

Thank You for maintaining this awesome project!

Discussion

  • Uwe Rathmann

    Uwe Rathmann - 2019-08-30

    Agreed, the implementation is not good.

    As you can do the same with overriding QwtPlotBarChart::drawBar it is probably best to remove the specialSymbol feature as it results in an unclear ownership ( beside when using a shared pointer ).

     
  • Anonymous

    Anonymous - 2019-10-08

    Original poster here.

    The implementation would work really well without overriding anything but the QwtPlotBarChart::specialSymbol function if the "specialSym" variable wouldn't be deleted.

    Imho the ownership is clear, in that QwtPlotBarChart takes and keeps the ownership until it dies or it is replaced by another at the same position.

     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB