/*!
  \return Information to be displayed on the legend

  The chart is represented by a list of entries - one for each bar title.
  Each element contains a bar title and an icon showing its corresponding bar.

  \sa barTitles(), legendIcon(), legendIconSize()
*/
QList<QwtLegendData> QwtPlotMultiBarChart::legendData() const
{
    QList<QwtLegendData> list;

    for ( int i = 0; i < d_data->barTitles.size(); i++ )
    {
        QwtLegendData data;

        QVariant titleValue;
        qVariantSetValue( titleValue, d_data->barTitles[i] );
        data.setValue( QwtLegendData::TitleRole, titleValue );

        if ( !legendIconSize().isEmpty() )
        {
            QVariant iconValue;
            qVariantSetValue( iconValue, 
                legendIcon( i, legendIconSize() ) );

            data.setValue( QwtLegendData::IconRole, iconValue );
        }

        list += data;
    }

    return list;
}
Пример #2
0
/*!
   \brief Return all information, that is needed to represent
          the item on the legend

   In case of LegendBarTitles an entry for each bar is returned,
   otherwise the chart is represented like any other plot item
   from its title() and the legendIcon().

   \sa title(), setLegendMode(), barTitle(), QwtLegend, QwtPlotLegendItem
 */
QList<QwtLegendData> QwtPlotBarChart::legendData() const
{
    QList<QwtLegendData> list;

    if ( d_data->legendMode == LegendBarTitles )
    {
        const size_t numSamples = dataSize();
        for ( size_t i = 0; i < numSamples; i++ )
        {
            QwtLegendData data;

            QVariant titleValue;
            qVariantSetValue( titleValue, barTitle( i ) );
            data.setValue( QwtLegendData::TitleRole, titleValue );

            if ( !legendIconSize().isEmpty() )
            {
                QVariant iconValue;
                qVariantSetValue( iconValue,
                    legendIcon( i, legendIconSize() ) );

                data.setValue( QwtLegendData::IconRole, iconValue );
            }

            list += data;
        }
    }
    else
    {
        return QwtPlotAbstractBarChart::legendData();
    }

    return list;
}
Пример #3
0
/*!
   \brief Return all information, that is needed to represent
          the item on the legend

   Most items are represented by one entry on the legend
   showing an icon and a text.

   QwtLegendData is basically a list of QVariants that makes it
   possible to overload and reimplement legendData() to 
   return almost any type of information, that is understood
   by the receiver that acts as the legend.

   The default implementation returns one entry with 
   the title() of the item and the legendIcon().

   \sa title(), legendIcon(), QwtLegend
 */
QList<QwtLegendData> QwtPolarItem::legendData() const
{
    QwtLegendData data;

    QwtText label = title();
    label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );

    QVariant titleValue;
    qVariantSetValue( titleValue, label );
    data.setValue( QwtLegendData::TitleRole, titleValue );

    const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
    if ( !graphic.isNull() )
    {
        QVariant iconValue;
        qVariantSetValue( iconValue, graphic );
        data.setValue( QwtLegendData::IconRole, iconValue );
    }

    QList<QwtLegendData> list;
    list += data;

    return list;
}