PDA

View Full Version : Qwt Legend



maxpayne
14th October 2008, 14:34
hello,

i was observing the cpu plot example. On executing the binary i noticed that the "user" and the "system" legend items were already checked and the corresponding curves were shown. However i would like only one curve to be shown when the widget starts.

1. How do i change this default behavior ?
2. Secondly, when a legend item is clicked..say "total" i would like the previous selection to be unchecked automatically. This does not happen in the example.

The code looks something like this:


connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
SLOT(showCurve(QwtPlotItem *, bool)));

and


void CpuPlot::showCurve(QwtPlotItem *item, bool on)
{
item->setVisible(on);
QWidget *w = legend()->find(item);
if ( w && w->inherits("QwtLegendItem") )
((QwtLegendItem *)w)->setChecked(on);

replot();
}

maxpayne
15th October 2008, 10:43
any body??...this is kinda important...:)

Uwe
15th October 2008, 12:43
Change the implementation of showCurve:

When on is true iterate over all curves (plot->itemList( QwtPlotItem::Rtti_PlotCurve) and call showCurve(curve, false) for all other curves.

Uwe

maxpayne
15th October 2008, 13:50
thanks a lot for your reply,i know you must be busy.I followed your advice and:



showCurve(data[System].curve,true);
showCurve(data[User].curve, false);
showCurve(data[Total].curve, false);
showCurve(data[Idle].curve, false);

this should ensure that i get only the system curve at the beginning.Next:



void CpuPlot::showCurve(QwtPlotItem *item, bool on)
{
const QwtPlotItemList &list = this->itemList();
for (QwtPlotItemIterator it = list.begin();it!=list.end();++it)
{
QwtPlotItem *item2 = *it;
if (item2->rtti() == QwtPlotItem::Rtti_PlotCurve)
item2->setVisible(false);
}
item->setVisible(on);
QWidget *w = legend()->find(item);
if ( w && w->inherits("QwtLegendItem") )
((QwtLegendItem *)w)->setChecked(on);

replot();
}

this removes a curve when the legend item is checked and displays the new curve.

however i don't see the system curve at the start of the application...even though its legend item is checked.

Uwe
15th October 2008, 18:17
Hide the curves only when "on" is true, otherwise a showCurve(..., false) hides all curves.

Uwe