void QwtPlotItem::updateLegend(QwtLegend *legend) const
{
    if ( !legend )
        return;

    QWidget *lgdItem = legend->find(this);
    if ( testItemAttribute(QwtPlotItem::Legend) )
    {
        if ( lgdItem == NULL )
        {
            lgdItem = legendItem();
            if ( lgdItem )
            {
                if ( lgdItem->inherits("QwtLegendItem") )
                {
                    QwtLegendItem *label = (QwtLegendItem *)lgdItem;
                    label->setItemMode(legend->itemMode());

                    if ( d_data->plot )
                    {
                        QObject::connect(label, SIGNAL(clicked()), 
                            d_data->plot, SLOT(legendItemClicked()));
                        QObject::connect(label, SIGNAL(checked(bool)), 
                            d_data->plot, SLOT(legendItemChecked(bool)));
                    }
                }
                legend->insert(this, lgdItem);
            }
示例#2
0
/*!
   \brief Allocate the widget that represents the item on the legend

   The default implementation returns a QwtLegendItem(), but an item 
   could be represented by any type of widget,
   by overloading legendItem() and updateLegend().

   \return QwtLegendItem()
   \sa updateLegend() QwtLegend()
*/
QWidget *QwtPlotItem::legendItem() const
{
    QwtLegendItem *item = new QwtLegendItem;
    if ( d_data->plot )
    {
        QObject::connect( item, SIGNAL( clicked() ),
            d_data->plot, SLOT( legendItemClicked() ) );
        QObject::connect( item, SIGNAL( checked( bool ) ),
            d_data->plot, SLOT( legendItemChecked( bool ) ) );
    }
示例#3
0
QWidget* PlotMarkerLegend::legendItem() const
{
	LegendItem* item = new LegendItem;
	if(plot())
	{
		QObject::connect(item, SIGNAL(clicked()), plot(), SLOT(legendItemClicked()));
		QObject::connect(item, SIGNAL(checked(bool)), plot(), SLOT(legendItemChecked(bool)));
	}

	return item;
}