QwtPlotBarChart deletes specialSymbol every redraw
Brought to you by:
rathmann
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!
Anonymous
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 ).
Original poster here.
The implementation would work really well without overriding anything but the
QwtPlotBarChart::specialSymbolfunction 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.