qwt_plot_item.cpp 15.6 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
5
 *
pixhawk's avatar
pixhawk committed
6 7 8 9
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

Bryant's avatar
Bryant committed
10
#include "qwt_plot_item.h"
pixhawk's avatar
pixhawk committed
11 12
#include "qwt_text.h"
#include "qwt_plot.h"
Bryant's avatar
Bryant committed
13 14 15 16
#include "qwt_legend_data.h"
#include "qwt_scale_div.h"
#include "qwt_graphic.h"
#include <qpainter.h>
pixhawk's avatar
pixhawk committed
17 18 19 20 21

class QwtPlotItem::PrivateData
{
public:
    PrivateData():
Bryant's avatar
Bryant committed
22 23 24 25 26 27 28 29 30 31 32
        plot( NULL ),
        isVisible( true ),
        attributes( 0 ),
        interests( 0 ),
        renderHints( 0 ),
        renderThreadCount( 1 ),
        z( 0.0 ),
        xAxis( QwtPlot::xBottom ),
        yAxis( QwtPlot::yLeft ),
        legendIconSize( 8, 8 )
    {
pixhawk's avatar
pixhawk committed
33 34 35 36 37
    }

    mutable QwtPlot *plot;

    bool isVisible;
Bryant's avatar
Bryant committed
38 39 40 41 42 43 44

    QwtPlotItem::ItemAttributes attributes;
    QwtPlotItem::ItemInterests interests;

    QwtPlotItem::RenderHints renderHints;
    uint renderThreadCount;

pixhawk's avatar
pixhawk committed
45 46 47 48 49 50
    double z;

    int xAxis;
    int yAxis;

    QwtText title;
Bryant's avatar
Bryant committed
51
    QSize legendIconSize;
pixhawk's avatar
pixhawk committed
52 53
};

Bryant's avatar
Bryant committed
54 55 56 57 58
/*!
   Constructor
   \param title Title of the item
*/
QwtPlotItem::QwtPlotItem( const QwtText &title )
pixhawk's avatar
pixhawk committed
59 60 61 62 63 64 65 66
{
    d_data = new PrivateData;
    d_data->title = title;
}

//! Destroy the QwtPlotItem
QwtPlotItem::~QwtPlotItem()
{
Bryant's avatar
Bryant committed
67
    attach( NULL );
pixhawk's avatar
pixhawk committed
68 69 70
    delete d_data;
}

71
/*!
pixhawk's avatar
pixhawk committed
72 73 74 75 76 77 78
  \brief Attach the item to a plot.

  This method will attach a QwtPlotItem to the QwtPlot argument. It will first
  detach the QwtPlotItem from any plot from a previous call to attach (if
  necessary). If a NULL argument is passed, it will detach from any QwtPlot it
  was attached to.

Bryant's avatar
Bryant committed
79 80
  \param plot Plot widget
  \sa detach()
pixhawk's avatar
pixhawk committed
81
*/
Bryant's avatar
Bryant committed
82
void QwtPlotItem::attach( QwtPlot *plot )
pixhawk's avatar
pixhawk committed
83 84 85 86
{
    if ( plot == d_data->plot )
        return;

Bryant's avatar
Bryant committed
87 88
    if ( d_data->plot )
        d_data->plot->attachItem( this, false );
pixhawk's avatar
pixhawk committed
89 90 91

    d_data->plot = plot;

Bryant's avatar
Bryant committed
92 93 94
    if ( d_data->plot )
        d_data->plot->attachItem( this, true );
}
pixhawk's avatar
pixhawk committed
95

Bryant's avatar
Bryant committed
96 97 98 99 100 101 102 103 104 105
/*!
   \brief This method detaches a QwtPlotItem from any 
          QwtPlot it has been associated with.

   detach() is equivalent to calling attach( NULL )
   \sa attach()
*/
void QwtPlotItem::detach()
{
    attach( NULL );
pixhawk's avatar
pixhawk committed
106 107
}

108
/*!
pixhawk's avatar
pixhawk committed
109 110 111 112
   Return rtti for the specific class represented. QwtPlotItem is simply
   a virtual interface class, and base classes will implement this method
   with specific rtti values so a user can differentiate them.

113
   The rtti value is useful for environments, where the
pixhawk's avatar
pixhawk committed
114 115
   runtime type information is disabled and it is not possible
   to do a dynamic_cast<...>.
116

pixhawk's avatar
pixhawk committed
117 118 119 120 121 122 123 124 125
   \return rtti value
   \sa RttiValues
*/
int QwtPlotItem::rtti() const
{
    return Rtti_PlotItem;
}

//! Return attached plot
126 127 128
QwtPlot *QwtPlotItem::plot() const
{
    return d_data->plot;
pixhawk's avatar
pixhawk committed
129 130 131 132 133 134 135
}

/*!
   Plot items are painted in increasing z-order.

   \return setZ(), QwtPlotDict::itemList()
*/
136 137 138
double QwtPlotItem::z() const
{
    return d_data->z;
pixhawk's avatar
pixhawk committed
139 140 141 142 143 144 145 146 147 148
}

/*!
   \brief Set the z value

   Plot items are painted in increasing z-order.

   \param z Z-value
   \sa z(), QwtPlotDict::itemList()
*/
Bryant's avatar
Bryant committed
149
void QwtPlotItem::setZ( double z )
150
{
Bryant's avatar
Bryant committed
151 152 153 154 155
    if ( d_data->z != z )
    {
        if ( d_data->plot ) // update the z order
            d_data->plot->attachItem( this, false );

156
        d_data->z = z;
Bryant's avatar
Bryant committed
157 158 159 160

        if ( d_data->plot )
            d_data->plot->attachItem( this, true );

pixhawk's avatar
pixhawk committed
161 162 163 164
        itemChanged();
    }
}

165
/*!
pixhawk's avatar
pixhawk committed
166 167 168
   Set a new title

   \param title Title
169 170
   \sa title()
*/
Bryant's avatar
Bryant committed
171
void QwtPlotItem::setTitle( const QString &title )
pixhawk's avatar
pixhawk committed
172
{
Bryant's avatar
Bryant committed
173
    setTitle( QwtText( title ) );
pixhawk's avatar
pixhawk committed
174 175
}

176
/*!
pixhawk's avatar
pixhawk committed
177 178 179
   Set a new title

   \param title Title
180 181
   \sa title()
*/
Bryant's avatar
Bryant committed
182
void QwtPlotItem::setTitle( const QwtText &title )
pixhawk's avatar
pixhawk committed
183
{
Bryant's avatar
Bryant committed
184 185
    if ( d_data->title != title )
    {
186
        d_data->title = title;
Bryant's avatar
Bryant committed
187 188 189

        legendChanged();
#if 0
pixhawk's avatar
pixhawk committed
190
        itemChanged();
Bryant's avatar
Bryant committed
191
#endif
pixhawk's avatar
pixhawk committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205
    }
}

/*!
   \return Title of the item
   \sa setTitle()
*/
const QwtText &QwtPlotItem::title() const
{
    return d_data->title;
}

/*!
   Toggle an item attribute
206

pixhawk's avatar
pixhawk committed
207 208 209
   \param attribute Attribute type
   \param on true/false

Bryant's avatar
Bryant committed
210
   \sa testItemAttribute(), ItemInterest
pixhawk's avatar
pixhawk committed
211
*/
Bryant's avatar
Bryant committed
212
void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on )
pixhawk's avatar
pixhawk committed
213
{
Bryant's avatar
Bryant committed
214 215
    if ( d_data->attributes.testFlag( attribute ) != on )
    {
pixhawk's avatar
pixhawk committed
216 217 218 219 220
        if ( on )
            d_data->attributes |= attribute;
        else
            d_data->attributes &= ~attribute;

Bryant's avatar
Bryant committed
221 222 223
        if ( attribute == QwtPlotItem::Legend )
            legendChanged();

pixhawk's avatar
pixhawk committed
224 225 226 227 228 229 230
        itemChanged();
    }
}

/*!
   Test an item attribute

Bryant's avatar
Bryant committed
231
   \param attribute Attribute type
pixhawk's avatar
pixhawk committed
232
   \return true/false
Bryant's avatar
Bryant committed
233
   \sa setItemAttribute(), ItemInterest
pixhawk's avatar
pixhawk committed
234
*/
Bryant's avatar
Bryant committed
235
bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const
pixhawk's avatar
pixhawk committed
236
{
Bryant's avatar
Bryant committed
237
    return d_data->attributes.testFlag( attribute );
pixhawk's avatar
pixhawk committed
238 239
}

Bryant's avatar
Bryant committed
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
/*!
   Toggle an item interest

   \param interest Interest type
   \param on true/false

   \sa testItemInterest(), ItemAttribute
*/
void QwtPlotItem::setItemInterest( ItemInterest interest, bool on )
{
    if ( d_data->interests.testFlag( interest ) != on )
    {
        if ( on )
            d_data->interests |= interest;
        else
            d_data->interests &= ~interest;

        itemChanged();
    }
}

/*!
   Test an item interest

   \param interest Interest type
   \return true/false
   \sa setItemInterest(), ItemAttribute
*/
bool QwtPlotItem::testItemInterest( ItemInterest interest ) const
{
    return d_data->interests.testFlag( interest );
}
pixhawk's avatar
pixhawk committed
272 273 274

/*!
   Toggle an render hint
275

pixhawk's avatar
pixhawk committed
276 277 278 279 280
   \param hint Render hint
   \param on true/false

   \sa testRenderHint(), RenderHint
*/
Bryant's avatar
Bryant committed
281
void QwtPlotItem::setRenderHint( RenderHint hint, bool on )
pixhawk's avatar
pixhawk committed
282
{
Bryant's avatar
Bryant committed
283 284
    if ( d_data->renderHints.testFlag( hint ) != on )
    {
pixhawk's avatar
pixhawk committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
        if ( on )
            d_data->renderHints |= hint;
        else
            d_data->renderHints &= ~hint;

        itemChanged();
    }
}

/*!
   Test a render hint

   \param hint Render hint
   \return true/false
   \sa setRenderHint(), RenderHint
*/
Bryant's avatar
Bryant committed
301
bool QwtPlotItem::testRenderHint( RenderHint hint ) const
pixhawk's avatar
pixhawk committed
302
{
Bryant's avatar
Bryant committed
303
    return d_data->renderHints.testFlag( hint );
pixhawk's avatar
pixhawk committed
304 305
}

Bryant's avatar
Bryant committed
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
/*!
   On multi core systems rendering of certain plot item 
   ( f.e QwtPlotRasterItem ) can be done in parallel in 
   several threads.

   The default setting is set to 1.

   \param numThreads Number of threads to be used for rendering.
                     If numThreads is set to 0, the system specific
                     ideal thread count is used.

   The default thread count is 1 ( = no additional threads )
*/
void QwtPlotItem::setRenderThreadCount( uint numThreads )
{
    d_data->renderThreadCount = numThreads;
}

/*!
   \return Number of threads to be used for rendering.
           If numThreads() is set to 0, the system specific
           ideal thread count is used.
*/
uint QwtPlotItem::renderThreadCount() const
{
    return d_data->renderThreadCount;
}

/*!
   Set the size of the legend icon

   The default setting is 8x8 pixels

   \param size Size
   \sa legendIconSize(), legendIcon()
*/
void QwtPlotItem::setLegendIconSize( const QSize &size )
{
    if ( d_data->legendIconSize != size )
    {
        d_data->legendIconSize = size;
        legendChanged();
    }
}

/*!
   \return Legend icon size
   \sa setLegendIconSize(), legendIcon()
*/
QSize QwtPlotItem::legendIconSize() const
{
    return d_data->legendIconSize;
}

/*!
   \return Icon representing the item on the legend

   The default implementation returns an invalid icon

   \param index Index of the legend entry 
                ( usually there is only one )
   \param size Icon size

   \sa setLegendIconSize(), legendData()
 */
QwtGraphic QwtPlotItem::legendIcon( 
    int index, const QSizeF &size ) const
{
    Q_UNUSED( index )
    Q_UNUSED( size )

    return QwtGraphic();
}

/*!
   \brief Return a default icon from a brush

   The default icon is a filled rectangle used
   in several derived classes as legendIcon().

   \param brush Fill brush
   \param size Icon size

   \return A filled rectangle
 */
QwtGraphic QwtPlotItem::defaultIcon( 
    const QBrush &brush, const QSizeF &size ) const
{   
    QwtGraphic icon;
    if ( !size.isEmpty() )
    {
        icon.setDefaultSize( size );
        
        QRectF r( 0, 0, size.width(), size.height() );
        
        QPainter painter( &icon );
        painter.fillRect( r, brush );
    }   
    
    return icon;
}   
pixhawk's avatar
pixhawk committed
407 408 409 410

//! Show the item
void QwtPlotItem::show()
{
Bryant's avatar
Bryant committed
411
    setVisible( true );
pixhawk's avatar
pixhawk committed
412 413 414 415 416
}

//! Hide the item
void QwtPlotItem::hide()
{
Bryant's avatar
Bryant committed
417
    setVisible( false );
pixhawk's avatar
pixhawk committed
418 419
}

420
/*!
pixhawk's avatar
pixhawk committed
421 422 423 424 425
    Show/Hide the item

    \param on Show if true, otherwise hide
    \sa isVisible(), show(), hide()
*/
Bryant's avatar
Bryant committed
426
void QwtPlotItem::setVisible( bool on )
427
{
Bryant's avatar
Bryant committed
428 429
    if ( on != d_data->isVisible )
    {
430 431
        d_data->isVisible = on;
        itemChanged();
pixhawk's avatar
pixhawk committed
432 433 434
    }
}

435
/*!
pixhawk's avatar
pixhawk committed
436 437 438 439
    \return true if visible
    \sa setVisible(), show(), hide()
*/
bool QwtPlotItem::isVisible() const
440 441
{
    return d_data->isVisible;
pixhawk's avatar
pixhawk committed
442 443
}

444
/*!
Bryant's avatar
Bryant committed
445
   Update the legend and call QwtPlot::autoRefresh() for the
pixhawk's avatar
pixhawk committed
446 447
   parent plot.

Bryant's avatar
Bryant committed
448
   \sa QwtPlot::legendChanged(), QwtPlot::autoRefresh()
pixhawk's avatar
pixhawk committed
449 450 451
*/
void QwtPlotItem::itemChanged()
{
Bryant's avatar
Bryant committed
452
    if ( d_data->plot )
pixhawk's avatar
pixhawk committed
453
        d_data->plot->autoRefresh();
Bryant's avatar
Bryant committed
454 455 456 457 458 459 460 461 462 463
}

/*!
   Update the legend of the parent plot.
   \sa QwtPlot::updateLegend(), itemChanged()
*/
void QwtPlotItem::legendChanged()
{
    if ( testItemAttribute( QwtPlotItem::Legend ) && d_data->plot )
        d_data->plot->updateLegend( this );
pixhawk's avatar
pixhawk committed
464 465
}

466
/*!
pixhawk's avatar
pixhawk committed
467 468
   Set X and Y axis

Bryant's avatar
Bryant committed
469
   The item will painted according to the coordinates of its Axes.
pixhawk's avatar
pixhawk committed
470

Bryant's avatar
Bryant committed
471 472
   \param xAxis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )
   \param yAxis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )
pixhawk's avatar
pixhawk committed
473

Bryant's avatar
Bryant committed
474
   \sa setXAxis(), setYAxis(), xAxis(), yAxis(), QwtPlot::Axis
pixhawk's avatar
pixhawk committed
475
*/
Bryant's avatar
Bryant committed
476
void QwtPlotItem::setAxes( int xAxis, int yAxis )
pixhawk's avatar
pixhawk committed
477
{
Bryant's avatar
Bryant committed
478
    if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop )
479
        d_data->xAxis = xAxis;
pixhawk's avatar
pixhawk committed
480

Bryant's avatar
Bryant committed
481
    if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight )
482
        d_data->yAxis = yAxis;
pixhawk's avatar
pixhawk committed
483

484
    itemChanged();
pixhawk's avatar
pixhawk committed
485 486
}

487
/*!
pixhawk's avatar
pixhawk committed
488 489 490 491
   Set the X axis

   The item will painted according to the coordinates its Axes.

Bryant's avatar
Bryant committed
492 493
   \param axis X Axis ( QwtPlot::xBottom or QwtPlot::xTop )
   \sa setAxes(), setYAxis(), xAxis(), QwtPlot::Axis
pixhawk's avatar
pixhawk committed
494
*/
Bryant's avatar
Bryant committed
495
void QwtPlotItem::setXAxis( int axis )
pixhawk's avatar
pixhawk committed
496
{
Bryant's avatar
Bryant committed
497 498
    if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
    {
499 500
        d_data->xAxis = axis;
        itemChanged();
pixhawk's avatar
pixhawk committed
501 502 503
    }
}

504
/*!
pixhawk's avatar
pixhawk committed
505 506 507 508
   Set the Y axis

   The item will painted according to the coordinates its Axes.

Bryant's avatar
Bryant committed
509 510
   \param axis Y Axis ( QwtPlot::yLeft or QwtPlot::yRight )
   \sa setAxes(), setXAxis(), yAxis(), QwtPlot::Axis
pixhawk's avatar
pixhawk committed
511
*/
Bryant's avatar
Bryant committed
512
void QwtPlotItem::setYAxis( int axis )
pixhawk's avatar
pixhawk committed
513
{
Bryant's avatar
Bryant committed
514 515
    if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
    {
516 517
        d_data->yAxis = axis;
        itemChanged();
pixhawk's avatar
pixhawk committed
518 519 520 521
    }
}

//! Return xAxis
522 523 524
int QwtPlotItem::xAxis() const
{
    return d_data->xAxis;
pixhawk's avatar
pixhawk committed
525 526 527
}

//! Return yAxis
528 529 530
int QwtPlotItem::yAxis() const
{
    return d_data->yAxis;
pixhawk's avatar
pixhawk committed
531 532 533
}

/*!
Bryant's avatar
Bryant committed
534 535
   \return An invalid bounding rect: QRectF(1.0, 1.0, -2.0, -2.0)
   \note A width or height < 0.0 is ignored by the autoscaler
pixhawk's avatar
pixhawk committed
536
*/
Bryant's avatar
Bryant committed
537
QRectF QwtPlotItem::boundingRect() const
pixhawk's avatar
pixhawk committed
538
{
Bryant's avatar
Bryant committed
539
    return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
pixhawk's avatar
pixhawk committed
540 541 542
}

/*!
Bryant's avatar
Bryant committed
543
   \brief Calculate a hint for the canvas margin
pixhawk's avatar
pixhawk committed
544

Bryant's avatar
Bryant committed
545 546 547 548
   When the QwtPlotItem::Margins flag is enabled the plot item
   indicates, that it needs some margins at the borders of the canvas.
   This is f.e. used by bar charts to reserve space for displaying
   the bars.
pixhawk's avatar
pixhawk committed
549

Bryant's avatar
Bryant committed
550
   The margins are in target device coordinates ( pixels on screen )
pixhawk's avatar
pixhawk committed
551

Bryant's avatar
Bryant committed
552 553 554 555 556 557 558
   \param xMap Maps x-values into pixel coordinates.
   \param yMap Maps y-values into pixel coordinates.
   \param canvasRect Contents rectangle of the canvas in painter coordinates
   \param left Returns the left margin
   \param top Returns the top margin
   \param right Returns the right margin
   \param bottom Returns the bottom margin
559

Bryant's avatar
Bryant committed
560
   \return The default implementation returns 0 for all margins
pixhawk's avatar
pixhawk committed
561

Bryant's avatar
Bryant committed
562 563 564 565 566
   \sa QwtPlot::getCanvasMarginsHint(), QwtPlot::updateCanvasMargins()
 */
void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap &xMap, 
    const QwtScaleMap &yMap, const QRectF &canvasRect,
    double &left, double &top, double &right, double &bottom ) const
pixhawk's avatar
pixhawk committed
567
{
Bryant's avatar
Bryant committed
568 569 570
    Q_UNUSED( xMap );
    Q_UNUSED( yMap );
    Q_UNUSED( canvasRect );
pixhawk's avatar
pixhawk committed
571

Bryant's avatar
Bryant committed
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
    // use QMargins, when we don't need to support Qt < 4.6 anymore
    left = top = right = bottom = 0.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, but f.e. QwtPlotMultiBarChart
   displays one entry for each bar.

   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().

   \return Data, that is needed to represent the item on the legend
   \sa title(), legendIcon(), QwtLegend, QwtPlotLegendItem
 */
QList<QwtLegendData> QwtPlotItem::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;
pixhawk's avatar
pixhawk committed
618 619 620 621 622 623 624 625 626 627
}

/*!
   \brief Update the item to changes of the axes scale division

   Update the item, when the axes of plot have changed.
   The default implementation does nothing, but items that depend
   on the scale division (like QwtPlotGrid()) have to reimplement
   updateScaleDiv()

Bryant's avatar
Bryant committed
628 629 630
   updateScaleDiv() is only called when the ScaleInterest interest
   is enabled. The default implementation does nothing.

pixhawk's avatar
pixhawk committed
631 632 633
   \param xScaleDiv Scale division of the x-axis
   \param yScaleDiv Scale division of the y-axis

Bryant's avatar
Bryant committed
634
   \sa QwtPlot::updateAxes(), ScaleInterest
pixhawk's avatar
pixhawk committed
635
*/
Bryant's avatar
Bryant committed
636 637
void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv,
    const QwtScaleDiv &yScaleDiv )
638
{
Bryant's avatar
Bryant committed
639 640
    Q_UNUSED( xScaleDiv );
    Q_UNUSED( yScaleDiv );
pixhawk's avatar
pixhawk committed
641 642 643
}

/*!
Bryant's avatar
Bryant committed
644
   \brief Update the item to changes of the legend info
pixhawk's avatar
pixhawk committed
645

Bryant's avatar
Bryant committed
646 647
   Plot items that want to display a legend ( not those, that want to
   be displayed on a legend ! ) will have to implement updateLegend().
pixhawk's avatar
pixhawk committed
648

Bryant's avatar
Bryant committed
649 650
   updateLegend() is only called when the LegendInterest interest
   is enabled. The default implementation does nothing.
pixhawk's avatar
pixhawk committed
651

Bryant's avatar
Bryant committed
652 653
   \param item Plot item to be displayed on a legend
   \param data Attributes how to display item on the legend
pixhawk's avatar
pixhawk committed
654

Bryant's avatar
Bryant committed
655
   \sa QwtPlotLegendItem
pixhawk's avatar
pixhawk committed
656

Bryant's avatar
Bryant committed
657 658 659 660 661 662
   \note Plot items, that want to be displayed on a legend
         need to enable the QwtPlotItem::Legend flag and to implement
         legendData() and legendIcon()
 */
void QwtPlotItem::updateLegend( const QwtPlotItem *item, 
    const QList<QwtLegendData> &data )
pixhawk's avatar
pixhawk committed
663
{
Bryant's avatar
Bryant committed
664 665
    Q_UNUSED( item );
    Q_UNUSED( data );
pixhawk's avatar
pixhawk committed
666 667 668
}

/*!
Bryant's avatar
Bryant committed
669
   \brief Calculate the bounding scale rectangle of 2 maps
pixhawk's avatar
pixhawk committed
670

Bryant's avatar
Bryant committed
671 672
   \param xMap Maps x-values into pixel coordinates.
   \param yMap Maps y-values into pixel coordinates.
673

Bryant's avatar
Bryant committed
674
   \return Bounding scale rect of the scale maps, not normalized
pixhawk's avatar
pixhawk committed
675
*/
Bryant's avatar
Bryant committed
676 677
QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap,
    const QwtScaleMap &yMap ) const
pixhawk's avatar
pixhawk committed
678
{
Bryant's avatar
Bryant committed
679 680
    return QRectF( xMap.s1(), yMap.s1(),
        xMap.sDist(), yMap.sDist() );
pixhawk's avatar
pixhawk committed
681 682 683
}

/*!
Bryant's avatar
Bryant committed
684
   \brief Calculate the bounding paint rectangle of 2 maps
pixhawk's avatar
pixhawk committed
685

Bryant's avatar
Bryant committed
686 687 688 689
   \param xMap Maps x-values into pixel coordinates.
   \param yMap Maps y-values into pixel coordinates.

   \return Bounding paint rectangle of the scale maps, not normalized
pixhawk's avatar
pixhawk committed
690
*/
Bryant's avatar
Bryant committed
691 692
QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap,
    const QwtScaleMap &yMap ) const
pixhawk's avatar
pixhawk committed
693
{
Bryant's avatar
Bryant committed
694 695
    const QRectF rect( xMap.p1(), yMap.p1(),
        xMap.pDist(), yMap.pDist() );
pixhawk's avatar
pixhawk committed
696

Bryant's avatar
Bryant committed
697
    return rect;
pixhawk's avatar
pixhawk committed
698
}