PDA

View Full Version : Hiding and displaying legend items not working in 6.1 as did in 6.0



EliGri
30th May 2013, 23:19
Hi,
I'm porting to Qwt 6.1 from 6.0 and am having touble getting legend items to hide and display themselves, depending on wheather they are being displayed in a QwtPlot chart. Any hints? Any help much appreciated.

Below is a method for 6.0 that worked, and below that is the same method i'm trying to implement for 6.1 that doesn't work. All of the code below implemented in a QwtPlot subclass.



void SingleLogTrack::slotSimplifyLegend(bool on) { // works for Qwt 6.0
bool showit = true;
foreach (QwtPlotItem *plt_item, itemList()) {
if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);

if (on) showit = c->isVisible();
c->setItemAttribute(QwtPlotItem::Legend,showit);

if (!on) {
QWidget *w = legend()->find(plt_item);
if ( w && w->inherits("QwtLegendItem" ) ) {
((QwtLegendItem *)w)->setChecked(c->isVisible());
}
}

}
}
}




void SingleLogTrack::slotSimplifyLegend(bool on) { // not yet working for Qwt 6.1
bool showit = true;
foreach (QwtPlotItem *plt_item, itemList()) {
if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);

if (on) showit = c->isVisible();
c->setItemAttribute(QwtPlotItem::Legend,showit);

if (!on) {
QwtLegend *lgd = qobject_cast<QwtLegend *>(legend());
QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(plt_item));

if ( legendWidgets.size() == 1 ) {
QwtLegendLabel *b = qobject_cast<QwtLegendLabel *>(legendWidgets[0]);
if ( b && b->inherits("QwtLegendLabel") )
((QwtLegendLabel *)b)->setChecked(c->isVisible());
}
}

}
}
}

Uwe
31st May 2013, 07:52
What exactly doesn't work: hiding/showing or setting of the checked state ?

Uwe

EliGri
31st May 2013, 16:58
Uwe, thanks for the reply. I immediately noticed that hide/show isn't working. The debugger tells me that plot item iteration is working, but nothing appears to happen. Sorry, can't give you more details, not in the office today.

Uwe
3rd June 2013, 06:44
When looking at the code of QwtPlotItem::legendChanged() I would expect, that the hide is not working.

Simply call "updateLegend()" manually at the end of SingleLogTrack::slotSimplifyLegend.

Uwe

EliGri
3rd June 2013, 16:36
That did it! Thank you.