qwt_plot_item.cpp
Go to the documentation of this file.
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #include "qwt_plot_item.h"
00011 #include "qwt_text.h"
00012 #include "qwt_plot.h"
00013 #include "qwt_legend_data.h"
00014 #include "qwt_scale_div.h"
00015 #include "qwt_graphic.h"
00016 #include <qpainter.h>
00017 
00018 class QwtPlotItem::PrivateData
00019 {
00020 public:
00021     PrivateData():
00022         plot( NULL ),
00023         isVisible( true ),
00024         attributes( 0 ),
00025         interests( 0 ),
00026         renderHints( 0 ),
00027         renderThreadCount( 1 ),
00028         z( 0.0 ),
00029         xAxis( QwtPlot::xBottom ),
00030         yAxis( QwtPlot::yLeft ),
00031         legendIconSize( 8, 8 )
00032     {
00033     }
00034 
00035     mutable QwtPlot *plot;
00036 
00037     bool isVisible;
00038 
00039     QwtPlotItem::ItemAttributes attributes;
00040     QwtPlotItem::ItemInterests interests;
00041 
00042     QwtPlotItem::RenderHints renderHints;
00043     uint renderThreadCount;
00044 
00045     double z;
00046 
00047     int xAxis;
00048     int yAxis;
00049 
00050     QwtText title;
00051     QSize legendIconSize;
00052 };
00053 
00058 QwtPlotItem::QwtPlotItem( const QwtText &title )
00059 {
00060     d_data = new PrivateData;
00061     d_data->title = title;
00062 }
00063 
00065 QwtPlotItem::~QwtPlotItem()
00066 {
00067     attach( NULL );
00068     delete d_data;
00069 }
00070 
00082 void QwtPlotItem::attach( QwtPlot *plot )
00083 {
00084     if ( plot == d_data->plot )
00085         return;
00086 
00087     if ( d_data->plot )
00088         d_data->plot->attachItem( this, false );
00089 
00090     d_data->plot = plot;
00091 
00092     if ( d_data->plot )
00093         d_data->plot->attachItem( this, true );
00094 }
00095 
00103 void QwtPlotItem::detach()
00104 {
00105     attach( NULL );
00106 }
00107 
00120 int QwtPlotItem::rtti() const
00121 {
00122     return Rtti_PlotItem;
00123 }
00124 
00126 QwtPlot *QwtPlotItem::plot() const
00127 {
00128     return d_data->plot;
00129 }
00130 
00136 double QwtPlotItem::z() const
00137 {
00138     return d_data->z;
00139 }
00140 
00149 void QwtPlotItem::setZ( double z )
00150 {
00151     if ( d_data->z != z )
00152     {
00153         if ( d_data->plot ) // update the z order
00154             d_data->plot->attachItem( this, false );
00155 
00156         d_data->z = z;
00157 
00158         if ( d_data->plot )
00159             d_data->plot->attachItem( this, true );
00160 
00161         itemChanged();
00162     }
00163 }
00164 
00171 void QwtPlotItem::setTitle( const QString &title )
00172 {
00173     setTitle( QwtText( title ) );
00174 }
00175 
00182 void QwtPlotItem::setTitle( const QwtText &title )
00183 {
00184     if ( d_data->title != title )
00185     {
00186         d_data->title = title;
00187 
00188         legendChanged();
00189 #if 0
00190         itemChanged();
00191 #endif
00192     }
00193 }
00194 
00199 const QwtText &QwtPlotItem::title() const
00200 {
00201     return d_data->title;
00202 }
00203 
00212 void QwtPlotItem::setItemAttribute( ItemAttribute attribute, bool on )
00213 {
00214     if ( d_data->attributes.testFlag( attribute ) != on )
00215     {
00216         if ( on )
00217             d_data->attributes |= attribute;
00218         else
00219             d_data->attributes &= ~attribute;
00220 
00221         if ( attribute == QwtPlotItem::Legend )
00222             legendChanged();
00223 
00224         itemChanged();
00225     }
00226 }
00227 
00235 bool QwtPlotItem::testItemAttribute( ItemAttribute attribute ) const
00236 {
00237     return d_data->attributes.testFlag( attribute );
00238 }
00239 
00248 void QwtPlotItem::setItemInterest( ItemInterest interest, bool on )
00249 {
00250     if ( d_data->interests.testFlag( interest ) != on )
00251     {
00252         if ( on )
00253             d_data->interests |= interest;
00254         else
00255             d_data->interests &= ~interest;
00256 
00257         itemChanged();
00258     }
00259 }
00260 
00268 bool QwtPlotItem::testItemInterest( ItemInterest interest ) const
00269 {
00270     return d_data->interests.testFlag( interest );
00271 }
00272 
00281 void QwtPlotItem::setRenderHint( RenderHint hint, bool on )
00282 {
00283     if ( d_data->renderHints.testFlag( hint ) != on )
00284     {
00285         if ( on )
00286             d_data->renderHints |= hint;
00287         else
00288             d_data->renderHints &= ~hint;
00289 
00290         itemChanged();
00291     }
00292 }
00293 
00301 bool QwtPlotItem::testRenderHint( RenderHint hint ) const
00302 {
00303     return d_data->renderHints.testFlag( hint );
00304 }
00305 
00319 void QwtPlotItem::setRenderThreadCount( uint numThreads )
00320 {
00321     d_data->renderThreadCount = numThreads;
00322 }
00323 
00329 uint QwtPlotItem::renderThreadCount() const
00330 {
00331     return d_data->renderThreadCount;
00332 }
00333 
00342 void QwtPlotItem::setLegendIconSize( const QSize &size )
00343 {
00344     if ( d_data->legendIconSize != size )
00345     {
00346         d_data->legendIconSize = size;
00347         legendChanged();
00348     }
00349 }
00350 
00355 QSize QwtPlotItem::legendIconSize() const
00356 {
00357     return d_data->legendIconSize;
00358 }
00359 
00371 QwtGraphic QwtPlotItem::legendIcon( 
00372     int index, const QSizeF &size ) const
00373 {
00374     Q_UNUSED( index )
00375     Q_UNUSED( size )
00376 
00377     return QwtGraphic();
00378 }
00379 
00391 QwtGraphic QwtPlotItem::defaultIcon( 
00392     const QBrush &brush, const QSizeF &size ) const
00393 {   
00394     QwtGraphic icon;
00395     if ( !size.isEmpty() )
00396     {
00397         icon.setDefaultSize( size );
00398         
00399         QRectF r( 0, 0, size.width(), size.height() );
00400         
00401         QPainter painter( &icon );
00402         painter.fillRect( r, brush );
00403     }   
00404     
00405     return icon;
00406 }   
00407 
00409 void QwtPlotItem::show()
00410 {
00411     setVisible( true );
00412 }
00413 
00415 void QwtPlotItem::hide()
00416 {
00417     setVisible( false );
00418 }
00419 
00426 void QwtPlotItem::setVisible( bool on )
00427 {
00428     if ( on != d_data->isVisible )
00429     {
00430         d_data->isVisible = on;
00431         itemChanged();
00432     }
00433 }
00434 
00439 bool QwtPlotItem::isVisible() const
00440 {
00441     return d_data->isVisible;
00442 }
00443 
00450 void QwtPlotItem::itemChanged()
00451 {
00452     if ( d_data->plot )
00453         d_data->plot->autoRefresh();
00454 }
00455 
00460 void QwtPlotItem::legendChanged()
00461 {
00462     if ( testItemAttribute( QwtPlotItem::Legend ) && d_data->plot )
00463         d_data->plot->updateLegend( this );
00464 }
00465 
00476 void QwtPlotItem::setAxes( int xAxis, int yAxis )
00477 {
00478     if ( xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop )
00479         d_data->xAxis = xAxis;
00480 
00481     if ( yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight )
00482         d_data->yAxis = yAxis;
00483 
00484     itemChanged();
00485 }
00486 
00495 void QwtPlotItem::setXAxis( int axis )
00496 {
00497     if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
00498     {
00499         d_data->xAxis = axis;
00500         itemChanged();
00501     }
00502 }
00503 
00512 void QwtPlotItem::setYAxis( int axis )
00513 {
00514     if ( axis == QwtPlot::yLeft || axis == QwtPlot::yRight )
00515     {
00516         d_data->yAxis = axis;
00517         itemChanged();
00518     }
00519 }
00520 
00522 int QwtPlotItem::xAxis() const
00523 {
00524     return d_data->xAxis;
00525 }
00526 
00528 int QwtPlotItem::yAxis() const
00529 {
00530     return d_data->yAxis;
00531 }
00532 
00537 QRectF QwtPlotItem::boundingRect() const
00538 {
00539     return QRectF( 1.0, 1.0, -2.0, -2.0 ); // invalid
00540 }
00541 
00564 void QwtPlotItem::getCanvasMarginHint( const QwtScaleMap &xMap, 
00565     const QwtScaleMap &yMap, const QRectF &canvasRect,
00566     double &left, double &top, double &right, double &bottom ) const
00567 {
00568     Q_UNUSED( xMap );
00569     Q_UNUSED( yMap );
00570     Q_UNUSED( canvasRect );
00571 
00572     // use QMargins, when we don't need to support Qt < 4.6 anymore
00573     left = top = right = bottom = 0.0;
00574 }
00575 
00595 QList<QwtLegendData> QwtPlotItem::legendData() const
00596 {
00597     QwtLegendData data;
00598 
00599     QwtText label = title();
00600     label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
00601             
00602     QVariant titleValue;
00603     qVariantSetValue( titleValue, label );
00604     data.setValue( QwtLegendData::TitleRole, titleValue );
00605         
00606     const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
00607     if ( !graphic.isNull() )
00608     {   
00609         QVariant iconValue;
00610         qVariantSetValue( iconValue, graphic );
00611         data.setValue( QwtLegendData::IconRole, iconValue );
00612     }   
00613         
00614     QList<QwtLegendData> list;
00615     list += data;
00616 
00617     return list;
00618 }
00619 
00636 void QwtPlotItem::updateScaleDiv( const QwtScaleDiv &xScaleDiv,
00637     const QwtScaleDiv &yScaleDiv )
00638 {
00639     Q_UNUSED( xScaleDiv );
00640     Q_UNUSED( yScaleDiv );
00641 }
00642 
00661 void QwtPlotItem::updateLegend( const QwtPlotItem *item, 
00662     const QList<QwtLegendData> &data )
00663 {
00664     Q_UNUSED( item );
00665     Q_UNUSED( data );
00666 }
00667 
00676 QRectF QwtPlotItem::scaleRect( const QwtScaleMap &xMap,
00677     const QwtScaleMap &yMap ) const
00678 {
00679     return QRectF( xMap.s1(), yMap.s1(),
00680         xMap.sDist(), yMap.sDist() );
00681 }
00682 
00691 QRectF QwtPlotItem::paintRect( const QwtScaleMap &xMap,
00692     const QwtScaleMap &yMap ) const
00693 {
00694     const QRectF rect( xMap.p1(), yMap.p1(),
00695         xMap.pDist(), yMap.pDist() );
00696 
00697     return rect;
00698 }


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56