PDA

View Full Version : passing 'const QwtSymbol' as 'this' argument of ... discard qualifiers



HappyCoder
25th September 2015, 12:02
Hi,

i subclassed QwtPlotCurve to add new functions that we need.
One point is adding QwtPlotMarker into plot that belong to the curve and
will be attached, detached, setVisible together with the curve. Is all working.

But if some one change the color of the curve, all QwtPlotMarker should change
the color also. The marker has a custom symbol and if i try to set the brush color
o got this error:

passing 'const QwtSymbol' as 'this' argument of void::QwtSymbol::setBrush(const QBrush&) discards qualifiers

What i'm doing wrong?



curve->setPen(color,2.0); // change curve color
curve->setMarkerColor( color ) // change marker color




// in class PlotCurve::PrivateData
QList<QwtPlotMarker *> qlMarkerError1;


void PlotCurve::setMarkerColor( QColor color ) const
{
foreach (QwtPlotMarker *marker, d_data->qlMarkerError1)
{
QBrush brush = marker->symbol()->brush();
brush.setColor( color );
marker->symbol()->setBrush( brush ); // ERROR LINE
}
}

HappyCoder
30th September 2015, 15:10
I guess it is not possible to change the color af a symbol once attached to plot.
This can my seen in examples/sinusplot. There an ArrawSymbol was attached to plot
pointing to a curve. We add other symbols to our plot in the same way, but they
are using the color of the curve. The user is allowed to change the color of the curve
and the symbols chould change the color in the same way, which is not possible by
original Qwt code, it is const ?

The only workaround was to detach the old symbols from plot, generate new symbols
that are added as QwtPlotMarker (like in example) with the new color of the curve.
The old objects are still in memory, not deleteable dynamically and unused.
They are deleted later by QwtPlotDict when the deconstructor of plot is called.
That is a memory leak of Qwt.

Plz tell me, if i'm wrong.

Uwe
30th September 2015, 15:31
The reason for being const is, that changing attributes of a symbol behind the back of the plot item doesn't trigger an auto-replot.
But of course you can simply cast the constness away, set the color and do the missing replot manually.

The "auto-replot aware" way to change the symbol of a marker would be to assign a new symbol with QwtPlotMarker::setSymbol(). This call deletes the old symbol - not sure, where you see a memory leak.

Uwe