qwt_plot_legenditem.cpp 19.2 KB
Newer Older
Bryant's avatar
Bryant committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#include "qwt_plot_legenditem.h"
#include "qwt_dyngrid_layout.h"
#include "qwt_scale_map.h"
#include "qwt_painter.h"
#include <qlayoutitem.h>
#include <qpen.h>
#include <qbrush.h>
#include <qpainter.h>
#include <qmath.h>

class QwtLegendLayoutItem: public QLayoutItem
{
public:
    QwtLegendLayoutItem( const QwtPlotLegendItem *, const QwtPlotItem * );
    virtual ~QwtLegendLayoutItem();

    const QwtPlotItem *plotItem() const;

    void setData( const QwtLegendData & );
    const QwtLegendData &data() const;

    virtual Qt::Orientations expandingDirections() const;
    virtual QRect geometry() const;
    virtual bool hasHeightForWidth() const;
    virtual int heightForWidth( int w ) const;
    virtual bool isEmpty() const;
    virtual QSize maximumSize() const;
    virtual int minimumHeightForWidth( int w ) const;
    virtual QSize minimumSize() const;
    virtual void setGeometry( const QRect & r );
    virtual QSize sizeHint() const;

private:

    const QwtPlotLegendItem *d_legendItem;
    const QwtPlotItem *d_plotItem;
    QwtLegendData d_data;

    QRect d_rect;
};

QwtLegendLayoutItem::QwtLegendLayoutItem( 
        const QwtPlotLegendItem *legendItem, const QwtPlotItem *plotItem ):
    d_legendItem( legendItem ),
    d_plotItem( plotItem)
{
}

QwtLegendLayoutItem::~QwtLegendLayoutItem()
{
}

const QwtPlotItem *QwtLegendLayoutItem::plotItem() const
{
    return d_plotItem;
}

void QwtLegendLayoutItem::setData( const QwtLegendData &data )
{
    d_data = data;
}

const QwtLegendData &QwtLegendLayoutItem::data() const
{
    return d_data;
}

Qt::Orientations QwtLegendLayoutItem::expandingDirections() const
{
    return Qt::Horizontal;
}

bool QwtLegendLayoutItem::hasHeightForWidth() const
{
    return !d_data.title().isEmpty();
}

int QwtLegendLayoutItem::minimumHeightForWidth( int w ) const
{
    return d_legendItem->heightForWidth( d_data, w );
}

int QwtLegendLayoutItem::heightForWidth( int w ) const
{
    return d_legendItem->heightForWidth( d_data, w );
}

bool QwtLegendLayoutItem::isEmpty() const
{
    return false;
}

QSize QwtLegendLayoutItem::maximumSize() const
{
    return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
}

QSize QwtLegendLayoutItem::minimumSize() const
{
    return d_legendItem->minimumSize( d_data );
}

QSize QwtLegendLayoutItem::sizeHint() const
{
    return minimumSize();
}

void QwtLegendLayoutItem::setGeometry( const QRect &rect )
{
    d_rect = rect;
}

QRect QwtLegendLayoutItem::geometry() const
{
    return d_rect;
}

class QwtPlotLegendItem::PrivateData
{
public:
    PrivateData():
        itemMargin( 4 ),
        itemSpacing( 4 ),
        borderRadius( 0.0 ),
        borderPen( Qt::NoPen ),
        backgroundBrush( Qt::NoBrush ),
        backgroundMode( QwtPlotLegendItem::LegendBackground ),
        borderDistance( 10 ),
        alignment( Qt::AlignRight | Qt::AlignBottom )
    {
        layout = new QwtDynGridLayout();
        layout->setMaxColumns( 2 );

        layout->setSpacing( 0 );
        layout->setContentsMargins( 0, 0, 0, 0 );
    }

    ~PrivateData()
    {
        delete layout;
    }

    QFont font;
    QPen textPen;
    int itemMargin;
    int itemSpacing;

    double borderRadius;
    QPen borderPen;
    QBrush backgroundBrush;
    QwtPlotLegendItem::BackgroundMode backgroundMode;

    int borderDistance;
    Qt::Alignment alignment;

    QMap< const QwtPlotItem *, QList<QwtLegendLayoutItem *> > map;
    QwtDynGridLayout *layout;
};

//! Constructor 
QwtPlotLegendItem::QwtPlotLegendItem():
    QwtPlotItem( QwtText( "Legend" ) )
{
    d_data = new PrivateData;

    setItemInterest( QwtPlotItem::LegendInterest, true );
    setZ( 100.0 );
}

//! Destructor
QwtPlotLegendItem::~QwtPlotLegendItem()
{
    clearLegend();
    delete d_data;
}

//! \return QwtPlotItem::Rtti_PlotLegend
int QwtPlotLegendItem::rtti() const
{
    return QwtPlotItem::Rtti_PlotLegend;
}

/*!
  \brief Set the alignmnet

  Alignment means the position of the legend relative
  to the geometry of the plot canvas. 

  \param alignment Alignment flags

  \sa alignment(), setMaxColumns()

  \note To align a legend with many items horizontally 
        the number of columns need to be limited
 */
void QwtPlotLegendItem::setAlignment( Qt::Alignment alignment )
{
    if ( d_data->alignment != alignment )
    {
        d_data->alignment = alignment;
        itemChanged();
    }
}

/*!
  \return Alignment flags
  \sa setAlignment()
 */
Qt::Alignment QwtPlotLegendItem::alignment() const
{
    return d_data->alignment;
}

/*!
  \brief Limit the number of columns

  When aligning the legend horizontally ( Qt::AlignLeft, Qt::AlignRight )
  the number of columns needs to be limited to avoid, that
  the width of the legend grows with an increasing number of entries.

  \param maxColumns Maximum number of columns. 0 means unlimited.
  \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
 */
void QwtPlotLegendItem::setMaxColumns( uint maxColumns )
{
    if ( maxColumns != d_data->layout->maxColumns() )
    {
        d_data->layout->setMaxColumns( maxColumns );
        itemChanged();
    }
}

/*!
  \return Maximum number of columns
  \sa maxColumns(), QwtDynGridLayout::maxColumns()
 */
uint QwtPlotLegendItem::maxColumns() const
{
    return d_data->layout->maxColumns();
}

/*!
  \brief Set the margin around legend items

  The default setting for the margin is 0.

  \param margin Margin in pixels
  \sa margin(), setSpacing(), setItemMargin(), setItemSpacing
 */
void QwtPlotLegendItem::setMargin( int margin )
{
    margin = qMax( margin, 0 );
    if ( margin != this->margin() )
    {
        d_data->layout->setContentsMargins( 
            margin, margin, margin, margin );

        itemChanged();
    }
}

/*!
  \return Margin around the legend items
  \sa setMargin(), spacing(), itemMargin(), itemSpacing()
 */
int QwtPlotLegendItem::margin() const
{
    int left;
    d_data->layout->getContentsMargins( &left, NULL, NULL, NULL );

    return left;
}

/*!
  \brief Set the spacing between the legend items

  \param spacing Spacing in pixels
  \sa spacing(), setMargin()
*/
void QwtPlotLegendItem::setSpacing( int spacing )
{
    spacing = qMax( spacing, 0 );
    if ( spacing != d_data->layout->spacing() )
    {
        d_data->layout->setSpacing( spacing );
        itemChanged();
    }
}

/*!
  \return Spacing between the legend items
  \sa setSpacing(), margin(), itemSpacing(), itemMargin()
 */
int QwtPlotLegendItem::spacing() const
{
    return d_data->layout->spacing();
}

/*!
  Set the margin around each item

  \param margin Margin
  \sa itemMargin(), setItemSpacing(), setMargin(), setSpacing()
 */
void QwtPlotLegendItem::setItemMargin( int margin )
{
    margin = qMax( margin, 0 );
    if ( margin != d_data->itemMargin )
    {
        d_data->itemMargin = margin;

        d_data->layout->invalidate();
        itemChanged();
    }
}

/*!
  \return Margin around each item
  \sa setItemMargin(), itemSpacing(), margin(), spacing()
*/
int QwtPlotLegendItem::itemMargin() const
{
    return d_data->itemMargin;
}

/*!
  Set the spacing inside of each item

  \param spacing Spacing
  \sa itemSpacing(), setItemMargin(), setMargin(), setSpacing()
 */
void QwtPlotLegendItem::setItemSpacing( int spacing )
{
    spacing = qMax( spacing, 0 );
    if ( spacing != d_data->itemSpacing )
    {
        d_data->itemSpacing = spacing;

        d_data->layout->invalidate();
        itemChanged();
    }

}

/*!
  \return Spacing inside of each item
  \sa setItemSpacing(), itemMargin(), margin(), spacing()
*/
int QwtPlotLegendItem::itemSpacing() const
{
    return d_data->itemSpacing;
}

/*!
   Change the font used for drawing the text label

   \param font Legend font
   \sa font()
*/
void QwtPlotLegendItem::setFont( const QFont &font )
{
    if ( font != d_data->font )
    {
        d_data->font = font;

        d_data->layout->invalidate();
        itemChanged();
    }
}

/*!
   \return Font used for drawing the text label
   \sa setFont()
*/
QFont QwtPlotLegendItem::font() const
{
    return d_data->font;
}

/*!
  \brief Set the margin between the legend and the canvas border

  The default setting for the margin is 10 pixels.

  \param distance Margin in pixels
  \sa setMargin()
 */
void QwtPlotLegendItem::setBorderDistance( int distance )
{
    if ( distance < 0 )
        distance = -1;

    if ( distance != d_data->borderDistance )
    {
        d_data->borderDistance = distance;
        itemChanged();
    }
}

/*!
  \return Margin between the legend and the canvas border
  \sa margin()
 */
int QwtPlotLegendItem::borderDistance() const
{
    return d_data->borderDistance;
}

/*!
  Set the radius for the border
  
  \param radius A value <= 0 defines a rectangular border
  \sa borderRadius(), setBorderPen()
 */
void QwtPlotLegendItem::setBorderRadius( double radius )
{
    radius = qMax( 0.0, radius );

    if ( radius != d_data->borderRadius )
    {
        d_data->borderRadius = radius;
        itemChanged();
    }
}

/*!
  \return Radius of the border
  \sa setBorderRadius(), setBorderPen()
 */
double QwtPlotLegendItem::borderRadius() const
{
    return d_data->borderRadius;
}

/*!
  Set the pen for drawing the border

  \param pen Border pen
  \sa borderPen(), setBackgroundBrush()
 */
void QwtPlotLegendItem::setBorderPen( const QPen &pen )
{
    if ( d_data->borderPen != pen )
    {
        d_data->borderPen = pen;
        itemChanged();
    }
}

/*!
  \return Pen for drawing the border
  \sa setBorderPen(), backgroundBrush()
 */
QPen QwtPlotLegendItem::borderPen() const
{
    return d_data->borderPen;
}

/*!
  \brief Set the background brush

  The brush is used to fill the background

  \param brush Brush
  \sa backgroundBrush(), setBackgroundMode(), drawBackground()
 */
void QwtPlotLegendItem::setBackgroundBrush( const QBrush &brush )
{
    if ( d_data->backgroundBrush != brush )
    {
        d_data->backgroundBrush = brush;
        itemChanged();
    }
}

/*!
  \return Brush is used to fill the background
  \sa setBackgroundBrush(), backgroundMode(), drawBackground()
 */
QBrush QwtPlotLegendItem::backgroundBrush() const
{
    return d_data->backgroundBrush;
}

/*!
  \brief Set the background mode

  Depending on the mode the complete legend or each item 
  might have an background.

  The default setting is LegendBackground.

   \sa backgroundMode(), setBackgroundBrush(), drawBackground()
 */
void QwtPlotLegendItem::setBackgroundMode( BackgroundMode mode )
{
    if ( mode != d_data->backgroundMode )
    {
        d_data->backgroundMode = mode;
        itemChanged();
    }
}

/*! 
  \return backgroundMode
  \sa setBackgroundMode(), backgroundBrush(), drawBackground()
 */
QwtPlotLegendItem::BackgroundMode QwtPlotLegendItem::backgroundMode() const
{
    return d_data->backgroundMode;
}

/*!
  \brief Set the pen for drawing text labels

  \param pen Text pen
  \sa textPen(), setFont()
 */
void QwtPlotLegendItem::setTextPen( const QPen &pen )
{
    if ( d_data->textPen != pen )
    {
        d_data->textPen = pen;
        itemChanged();
    }
}

/*!
  \return Pen for drawing text labels
  \sa setTextPen(), font()
 */
QPen QwtPlotLegendItem::textPen() const
{
    return d_data->textPen;
}

/*!
  Draw the legend

  \param painter Painter
  \param xMap x Scale Map
  \param yMap y Scale Map
  \param canvasRect Contents rectangle of the canvas in painter coordinates
*/
void QwtPlotLegendItem::draw( QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    const QRectF &canvasRect ) const
{
    Q_UNUSED( xMap );
    Q_UNUSED( yMap );

    d_data->layout->setGeometry( geometry( canvasRect ) );

    if ( d_data->backgroundMode == QwtPlotLegendItem::LegendBackground )
        drawBackground( painter, d_data->layout->geometry() );
    
    for ( int i = 0; i <  d_data->layout->count(); i++ )
    {
        const QwtLegendLayoutItem *layoutItem = 
            static_cast<QwtLegendLayoutItem *>( d_data->layout->itemAt( i ) );

        if ( d_data->backgroundMode == QwtPlotLegendItem::ItemBackground )
            drawBackground( painter, layoutItem->geometry() );

        painter->save();

        drawLegendData( painter, layoutItem->plotItem(),
            layoutItem->data(), layoutItem->geometry() );

        painter->restore();
    }
}

/*!
  Draw a rounded rect

  \param painter Painter
  \param rect Bounding rectangle

  \sa setBorderRadius(), setBorderPen(),
      setBackgroundBrush(), setBackgroundMode()
 */
void QwtPlotLegendItem::drawBackground( 
    QPainter *painter, const QRectF &rect ) const
{
    painter->save();

    painter->setPen( d_data->borderPen );
    painter->setBrush( d_data->backgroundBrush );
    
    const double radius = d_data->borderRadius;
    painter->drawRoundedRect( rect, radius, radius );
    
    painter->restore();
}

/*!
  Calculate the geometry of the legend on the canvas

  \param canvasRect Geometry of the canvas
  \return Geometry of the legend
*/
QRect QwtPlotLegendItem::geometry( const QRectF &canvasRect ) const
{
    QRect rect;
    rect.setSize( d_data->layout->sizeHint() );

    int margin = d_data->borderDistance;
    if ( d_data->alignment & Qt::AlignHCenter )
    {
        int x = qRound( canvasRect.center().x() );
        rect.moveCenter( QPoint( x, rect.center().y() ) ); 
    }
    else if ( d_data->alignment & Qt::AlignRight )
    {
        rect.moveRight( qFloor( canvasRect.right() - margin ) );
    }
    else 
    {
        rect.moveLeft( qCeil( canvasRect.left() + margin ) );
    }

    if ( d_data->alignment & Qt::AlignVCenter )
    {
        int y = qRound( canvasRect.center().y() );
        rect.moveCenter( QPoint( rect.center().x(), y ) );
    }
    else if ( d_data->alignment & Qt::AlignBottom )
    {
        rect.moveBottom( qFloor( canvasRect.bottom() - margin ) );
    }
    else 
    {
        rect.moveTop( qCeil( canvasRect.top() + margin ) ); 
    }

    return rect;
}

/*!
  Update the legend items according to modifications of a 
  plot item

  \param plotItem Plot item
  \param data Attributes of the legend entries
 */
void QwtPlotLegendItem::updateLegend( const QwtPlotItem *plotItem,
        const QList<QwtLegendData> &data )
{
    if ( plotItem == NULL )
        return;

    QList<QwtLegendLayoutItem *> layoutItems;

    QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::iterator it = 
        d_data->map.find( plotItem );
    if ( it != d_data->map.end() )
        layoutItems = it.value();

    bool changed = false;

    if ( data.size() != layoutItems.size() )
    {
        changed = true;

        for ( int i = 0; i < layoutItems.size(); i++ )
        {
            d_data->layout->removeItem( layoutItems[i] );
            delete layoutItems[i];
        }
        if ( it != d_data->map.end() )
            d_data->map.remove( plotItem );

        if ( !data.isEmpty() )
        {
            for ( int i = 0; i < data.size(); i++ )
            {
                QwtLegendLayoutItem *layoutItem = 
                    new QwtLegendLayoutItem( this, plotItem );
                d_data->layout->addItem( layoutItem );
                layoutItems += layoutItem;
            }

            d_data->map.insert( plotItem, layoutItems );
        }
    }

    for ( int i = 0; i < data.size(); i++ )
    {
        if ( layoutItems[i]->data().values() != data[i].values() )
        {
            layoutItems[i]->setData( data[i] );
            changed = true;
        }
    }

    if ( changed )
    {
        d_data->layout->invalidate();
        itemChanged();
    }
}

//! Remove all items from the legend
void QwtPlotLegendItem::clearLegend()
{
    if ( !d_data->map.isEmpty() )
    {
        d_data->map.clear();

        for ( int i = d_data->layout->count() - 1; i >= 0; i-- )
            delete d_data->layout->takeAt( i );

        itemChanged();
    }
}

/*!
  Draw an entry on the legend

  \param painter Qt Painter
  \param plotItem Plot item, represented by the entry
  \param data Attributes of the legend entry
  \param rect Bounding rectangle for the entry
 */
void QwtPlotLegendItem::drawLegendData( QPainter *painter,
    const QwtPlotItem *plotItem, const QwtLegendData &data, 
    const QRectF &rect ) const
{
    Q_UNUSED( plotItem );

    const int m = d_data->itemMargin;
    const QRectF r = rect.toRect().adjusted( m, m, -m, -m );

    painter->setClipRect( r, Qt::IntersectClip );

    int titleOff = 0;

    const QwtGraphic graphic = data.icon();
    if ( !graphic.isEmpty() )
    {
        QRectF iconRect( r.topLeft(), graphic.defaultSize() );

        iconRect.moveCenter( 
            QPoint( iconRect.center().x(), rect.center().y() ) );

        graphic.render( painter, iconRect, Qt::KeepAspectRatio );

        titleOff += iconRect.width() + d_data->itemSpacing;
    }

    const QwtText text = data.title();
    if ( !text.isEmpty() )
    {
        painter->setPen( textPen() );
        painter->setFont( font() );

        const QRectF textRect = r.adjusted( titleOff, 0, 0, 0 );
        text.draw( painter, textRect );
    }
}

/*!
  Minimum size hint needed to display an entry

  \param data Attributes of the legend entry
  \return Minimum size
 */
QSize QwtPlotLegendItem::minimumSize( const QwtLegendData &data ) const
{
    QSize size( 2 * d_data->itemMargin, 2 * d_data->itemMargin );

    if ( !data.isValid() )
        return size;

    const QwtGraphic graphic = data.icon();
    const QwtText text = data.title();

    int w = 0;
    int h = 0;

    if ( !graphic.isNull() )
    {
        w = graphic.width();
        h = graphic.height();
    }

    if ( !text.isEmpty() )
    {
        const QSizeF sz = text.textSize( font() );

        w += qCeil( sz.width() );
        h = qMax( h, qCeil( sz.height() ) );
    }

    if ( graphic.width() > 0 && !text.isEmpty() )
        w += d_data->itemSpacing;

    size += QSize( w, h );
    return size;
}

/*!
  \return The preferred height, for a width.
  \param data Attributes of the legend entry
  \param width Width
*/
int QwtPlotLegendItem::heightForWidth( 
    const QwtLegendData &data, int width ) const
{
    width -= 2 * d_data->itemMargin;

    const QwtGraphic graphic = data.icon();
    const QwtText text = data.title();

    if ( text.isEmpty() )
        return graphic.height();

    if ( graphic.width() > 0 )
        width -= graphic.width() + d_data->itemSpacing;

    int h = text.heightForWidth( width, font() );
    h += 2 * d_data->itemMargin;

    return qMax( graphic.height(), h );
}

/*! 
  \return All plot items with an entry on the legend
  \note A plot item might have more than one entry on the legend
 */
QList< const QwtPlotItem * > QwtPlotLegendItem::plotItems() const
{
    return d_data->map.keys();
}

/*!
  \return Geometries of the items of a plot item
  \note Usually a plot item has only one entry on the legend
*/
QList< QRect > QwtPlotLegendItem::legendGeometries( 
    const QwtPlotItem *plotItem ) const
{
    QList<QwtLegendLayoutItem *> layoutItems;

    QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::iterator it =
        d_data->map.find( plotItem );
    if ( it != d_data->map.end() )
        layoutItems = it.value();

    QList<QRect> geometries;
    for ( int i = 0; i < layoutItems.size(); i++ )
        geometries += layoutItems[i]->geometry();

    return geometries;
}