//Standard slot call by legendLabel, so why no pointer to the label?
void GraphB::legendChecked( const QVariant &itemInfo, bool on )
{
QwtPlotItem *plotItem = infoToItem( itemInfo );
if ( plotItem )
showCurve( plotItem, on );
}
//Standard private function called by legendChecked
void GraphB::showCurve( QwtPlotItem *item, bool on )
{
// Montre ou cache la courbe/l'item désiré
item->setVisible( on );
// On récupère le QwtLegend ... mais pourquoi faire?
QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );
// On récupère une liste de widget à partir de QwtLegend
QList<QWidget *> legendWidgets =
lgd->legendWidgets( itemToInfo( item ) );
// ????
if ( legendWidgets.size() == 1 )
{
// legendLabel représente la zone de la légende associé à une courbe
QwtLegendLabel *legendLabel =
qobject_cast<QwtLegendLabel *>( legendWidgets[0] );
// Si on a réussi à créer l'objet on check/uncheck
if ( legendLabel )
legendLabel->setChecked( on );
}
replot();
}
//I use this function to set/reset the legendLabel, I just add the "setVisible( on )" function to have the curve as the legend.
//But I am not sure about the reliability of this funchtion, is there plotItem without "setVisible" method?
void GraphB::setLegendChecked( QwtPlotItem *plotItem , bool on )
{
plotItem->setVisible( on );
const QwtPlotItemList items = itemList();
for ( int i = 0; i < items.size(); i++ )
{
QwtPlotItem *item = items[ i ];
if ( item->testItemAttribute( QwtPlotItem::Legend ) )
{
QwtLegend *lgd = qobject_cast<QwtLegend *>( legend() );
QwtLegendLabel *label = qobject_cast< QwtLegendLabel *>(
lgd->legendWidget( itemToInfo( item ) ) );
if ( label )
{
lgd->blockSignals( true );
if( item == plotItem )
label->setChecked( on );//item == plotItem );
lgd->blockSignals( false );
}
}
}
}
Bookmarks