[QWT] Plotting curves with gaps with QWT 6.1.0
-
So far, I have been using qwt v6.0.1 and v6.0.2 without problems. Because of Qt 5 I had to upgrade to v 6.1.0 and the statement above does not seem to do its job anymore.
For about two years I am plotting curves with gaps and I do not like to have an additional entry in the legend. In order to suppress the additional entries, the second and subsequent entries are marked using following statement:
QwtPlotItem::setItemAttribute( QwtPlotItem::Legend, false );Every single snippet of the curve will have a separate entry in the legend.
QWT has been compiled using MinGW 4.8 as supplied with Qt 5.1 SDK.
Anyone an idea what is wrong or what I have to change?
-
Hi,
IIRC there have been some changes in between, some function renaming at least.
Do you have a little example that could be tested ?
-
Unfortunately, No small example.
I have done a bit of debugging today. In the mean time I have a solution by changing the init method of QwtPlotCurve contructor. Doing a bit more checks tomorrow. Maybe I can change one of the examples to demonstrate show the issue.
-
That looks almost like a regression then
-
I have isolated the issue for the bode example.
Changes in plot.h:
@
QwtPlotCurve *d_curve11;
QwtPlotCurve *d_curve12;
QwtPlotCurve *d_curve21;
QwtPlotCurve *d_curve22;
QwtPlotMarker *d_marker1;
QwtPlotMarker *d_marker2;
@plot.cpp:
@
Plot::Plot( QWidget *parent ):
QwtPlot( parent )
{
setAutoReplot( false );...
// curves
d_curve11 = new QwtPlotCurve( "Amplitude" );
d_curve11->setRenderHint( QwtPlotItem::RenderAntialiased );
d_curve11->setPen( Qt::yellow );
d_curve11->setLegendAttribute( QwtPlotCurve::LegendShowLine );#define QWT_CURVE_CHECK0
#if defined ( QWT_CURVE_CHECK )
d_curve11->setItemAttribute( QwtPlotItem::Legend, true );
#endif
d_curve11->setYAxis( QwtPlot::yLeft );
d_curve11->attach( this );
d_curve12 = new QwtPlotCurve( "Amplitude" );
d_curve12->setRenderHint( QwtPlotItem::RenderAntialiased );
d_curve12->setPen( Qt::yellow );
d_curve12->setLegendAttribute( QwtPlotCurve::LegendShowLine );
#if defined ( QWT_CURVE_CHECK )
d_curve12->setItemAttribute( QwtPlotItem::Legend, false );
#endif
d_curve12->setYAxis( QwtPlot::yLeft );
d_curve12->attach( this );d_curve21 = new QwtPlotCurve( "Phase" ); d_curve21->setRenderHint( QwtPlotItem::RenderAntialiased ); d_curve21->setPen( Qt::cyan ); d_curve21->setLegendAttribute( QwtPlotCurve::LegendShowLine );
#if defined ( QWT_CURVE_CHECK )
d_curve21->setItemAttribute( QwtPlotItem::Legend, true );
#endif
d_curve21->setYAxis( QwtPlot::yRight );
d_curve21->attach( this );
d_curve22 = new QwtPlotCurve( "Phase" );
d_curve22->setRenderHint( QwtPlotItem::RenderAntialiased );
d_curve22->setPen( Qt::cyan );
d_curve22->setLegendAttribute( QwtPlotCurve::LegendShowLine );
#if defined ( QWT_CURVE_CHECK )
d_curve22->setItemAttribute( QwtPlotItem::Legend, false );
#endif
d_curve22->setYAxis( QwtPlot::yRight );
d_curve22->attach( this );
// marker
...
setAutoReplot( true );
}void Plot::showData( const double *frequency, const double *amplitude,
const double *phase, int count )
{
int cnt2 = count / 2;
int count2 = count - cnt2;
#if ! defined ( QWT_CURVE_CHECK )
d_curve11->setItemAttribute( QwtPlotItem::Legend, true );
d_curve12->setItemAttribute( QwtPlotItem::Legend, false );
d_curve21->setItemAttribute( QwtPlotItem::Legend, true );
d_curve22->setItemAttribute( QwtPlotItem::Legend, false );
#endif
d_curve11->setSamples( frequency, amplitude, cnt2 );
d_curve21->setSamples( frequency, phase, cnt2 );
d_curve12->setSamples( &frequency[cnt2], &litude[cnt2], count2 );
d_curve22->setSamples( &frequency[cnt2], &phase[cnt2], count2 );
}
@The example as given above shows duplicated legend entries, when qwt is untouched.
When QWT_CURVE_CHECK macro is defined only single entries are shown.
There is a dependency when
@
d_curveX2->setItemAttribute( QwtPlotItem::Legend, false );
@
are called.The example has also proper legend entries when the QWT_CURVE_CHECK macro is not defined, but qwt is slightly changed in qwt_plot_curve.cpp from
@
void QwtPlotCurve::init()
{
setItemAttribute( QwtPlotItem::Legend );
setItemAttribute( QwtPlotItem::AutoScale );
@to:
@
void QwtPlotCurve::init()
{
setItemAttribute( QwtPlotItem::Legend, false );
setItemAttribute( QwtPlotItem::AutoScale );
@in qwt-6.0.1 it did not matter where the actual entries for the legend were set to false. At least not in my plotting setup.
-
Hi,
I tried with Qt 4.8.6 and had the same results. It might be a good idea to check with the Qwt guys
-
HI,
Thanks for feedback.I had placed the question on the QWT mailing list before posting here. Without any feedback and not even showing my entry in the archive next day, I decided to place here.
Nevertheless," Uwe has answered":http://sourceforge.net/p/qwt/mailman/qwt-interest/?viewmonth=201308&viewday=10 and I am going to guide him to here.
-
As an update Uwe responded on the qwt mailing list:
[quote]
This is an update issue - it has to do with the fact, that Qwt 6.1 is
more accurate with item and legend changes ( see
QwtPlotItem::legenChanged(), QwtPlotItem::itemChanged() to avoid
pointless expensive replots.I have to check what goes wrong in the example, but an easy workaround
is to call QwtPlot::updateLegend() manually after changing the
QwtPlotItem::Legend flags.Uwe
[/quote]Just verified with the prepared "bode" example. Changing showData to:
@
void Plot::showData( const double *frequency, const double *amplitude,
const double *phase, int count )
{
int cnt2 = count / 2;
int count2 = count - cnt2;
#if ! defined ( QWT_CURVE_CHECK )
d_curve11->setItemAttribute( QwtPlotItem::Legend, true );
d_curve12->setItemAttribute( QwtPlotItem::Legend, false );
d_curve21->setItemAttribute( QwtPlotItem::Legend, true );
d_curve22->setItemAttribute( QwtPlotItem::Legend, false );
#endif
d_curve11->setSamples( frequency, amplitude, cnt2 );
d_curve21->setSamples( frequency, phase, cnt2 );
d_curve12->setSamples( &frequency[cnt2], &litude[cnt2], count2 );
d_curve22->setSamples( &frequency[cnt2], &phase[cnt2], count2 );QwtPlot::updateLegend();
}
@does also solve the problem.
-
This might be a good trick to add in their documentation