Ignore:
Timestamp:
May 10, 2017, 3:20:54 PM (7 years ago)
Author:
stoecker
Message:

update qwt and qwtpolar, many QT5 fixes (unfinished)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwtpolar/qwt_polar_item.cpp

    r4272 r8127  
    1010#include "qwt_polar_item.h"
    1111#include <qwt_legend.h>
    12 #include <qwt_legend_item.h>
    1312#include <qwt_scale_div.h>
    1413#include <qpainter.h>
     
    2221        attributes( 0 ),
    2322        renderHints( 0 ),
    24         z( 0.0 )
     23        renderThreadCount( 1 ),
     24        z( 0.0 ),
     25        legendIconSize( 8, 8 )
    2526    {
    2627    }
     
    3132    QwtPolarItem::ItemAttributes attributes;
    3233    QwtPolarItem::RenderHints renderHints;
     34    uint renderThreadCount;
     35
    3336    double z;
    3437
    3538    QwtText title;
     39    QSize legendIconSize;
    3640};
    3741
     
    7478        return;
    7579
    76     // remove the item from the previous plot
    77 
    7880    if ( d_data->plot )
    79     {
    80         if ( d_data->plot->legend() )
    81             d_data->plot->legend()->remove( this );
    82 
    8381        d_data->plot->attachItem( this, false );
    8482
    85         if ( d_data->plot->autoReplot() )
    86             d_data->plot->update();
    87     }
    88 
    8983    d_data->plot = plot;
    9084
    9185    if ( d_data->plot )
    92     {
    93         // insert the item into the current plot
    94 
    9586        d_data->plot->attachItem( this, true );
    96         itemChanged();
    97     }
     87}
     88
     89/*!
     90   \brief This method detaches a QwtPolarItem from the QwtPolarPlot it
     91          has been associated with.
     92
     93   detach() is equivalent to calling attach( NULL )
     94   \sa attach()
     95*/
     96void QwtPolarItem::detach()
     97{
     98    attach( NULL );
    9899}
    99100
     
    257258}
    258259
     260/*!
     261   On multi core systems rendering of certain plot item
     262   ( f.e QwtPolarSpectrogram ) can be done in parallel in
     263   several threads.
     264
     265   The default setting is set to 1.
     266
     267   \param numThreads Number of threads to be used for rendering.
     268                     If numThreads is set to 0, the system specific
     269                     ideal thread count is used.
     270
     271   The default thread count is 1 ( = no additional threads )
     272*/
     273void QwtPolarItem::setRenderThreadCount( uint numThreads )
     274{
     275    d_data->renderThreadCount = numThreads;
     276}
     277
     278/*!
     279   \return Number of threads to be used for rendering.
     280           If numThreads() is set to 0, the system specific
     281           ideal thread count is used.
     282*/
     283uint QwtPolarItem::renderThreadCount() const
     284{
     285    return d_data->renderThreadCount;
     286}
     287
     288/*!
     289   Set the size of the legend icon
     290
     291   The default setting is 8x8 pixels
     292
     293   \param size Size
     294   \sa legendIconSize(), legendIcon()
     295*/
     296void QwtPolarItem::setLegendIconSize( const QSize &size )
     297{
     298    if ( d_data->legendIconSize != size )
     299    {
     300        d_data->legendIconSize = size;
     301        legendChanged();
     302    }
     303}
     304
     305/*!
     306   \return Legend icon size
     307   \sa setLegendIconSize(), legendIcon()
     308*/
     309QSize QwtPolarItem::legendIconSize() const
     310{
     311    return d_data->legendIconSize;
     312}
     313
    259314//! Show the item
    260315void QwtPolarItem::show()
     
    302357{
    303358    if ( d_data->plot )
    304     {
    305         if ( d_data->plot->legend() )
    306             updateLegend( d_data->plot->legend() );
    307 
    308359        d_data->plot->autoRefresh();
    309     }
     360}
     361
     362/*!
     363   Update the legend of the parent plot.
     364   \sa QwtPolarPlot::updateLegend(), itemChanged()
     365*/
     366void QwtPolarItem::legendChanged()
     367{
     368    if ( testItemAttribute( QwtPolarItem::Legend ) && d_data->plot )
     369        d_data->plot->updateLegend( this );
    310370}
    311371
     
    351411
    352412/*!
    353    \brief Update the widget that represents the item on the legend
    354 
    355    updateLegend() is called from itemChanged() to adopt the widget
    356    representing the item on the legend to its new configuration.
    357 
    358    The default implementation is made for QwtPolarCurve and updates a
    359    QwtLegendItem(), but an item could be represented by any type of widget,
    360    by overloading legendItem() and updateLegend().
    361 
    362    \sa legendItem(), itemChanged(), QwtLegend()
    363 */
    364 void QwtPolarItem::updateLegend( QwtLegend *legend ) const
    365 {
    366     if ( legend == NULL )
    367         return;
    368 
    369     QWidget *lgdItem = legend->find( this );
    370     if ( testItemAttribute( QwtPolarItem::Legend ) )
    371     {
    372         if ( lgdItem == NULL )
    373         {
    374             lgdItem = legendItem();
    375             if ( lgdItem )
    376                 legend->insert( this, lgdItem );
    377         }
    378 
    379         QwtLegendItem* label = qobject_cast<QwtLegendItem *>( lgdItem );
    380         if ( label )
    381         {
    382             // paint the identifier
    383             const QSize sz = label->identifierSize();
    384 
    385             QPixmap identifier( sz.width(), sz.height() );
    386             identifier.fill( Qt::transparent );
    387 
    388             QPainter painter( &identifier );
    389             painter.setRenderHint( QPainter::Antialiasing,
    390                 testRenderHint( QwtPolarItem::RenderAntialiased ) );
    391 
    392             drawLegendIdentifier( &painter,
    393                 QRect( 0, 0, sz.width(), sz.height() ) );
    394 
    395             painter.end();
    396 
    397             const bool doUpdate = label->updatesEnabled();
    398             if ( doUpdate )
    399                 label->setUpdatesEnabled( false );
    400 
    401             label->setText( title() );
    402             label->setIdentifier( identifier );
    403             label->setItemMode( legend->itemMode() );
    404 
    405             if ( doUpdate )
    406                 label->setUpdatesEnabled( true );
    407 
    408             label->update();
    409         }
    410     }
    411     else
    412     {
    413         if ( lgdItem )
    414         {
    415             lgdItem->hide();
    416             lgdItem->deleteLater();
    417         }
    418     }
    419 }
    420 /*!
    421    \brief Allocate the widget that represents the item on the legend
    422 
    423    The default implementation is made for QwtPolarCurve and returns a
    424    QwtLegendItem(), but an item could be represented by any type of widget,
    425    by overloading legendItem() and updateLegend().
    426 
    427    \return QwtLegendItem()
    428    \sa updateLegend() QwtLegend()
    429 */
    430 QWidget *QwtPolarItem::legendItem() const
    431 {
    432     QwtLegendItem *item = new QwtLegendItem;
    433     if ( d_data->plot )
    434     {
    435         QObject::connect( item, SIGNAL( clicked() ),
    436             d_data->plot, SLOT( legendItemClicked() ) );
    437         QObject::connect( item, SIGNAL( checked( bool ) ),
    438             d_data->plot, SLOT( legendItemChecked( bool ) ) );
    439     }
    440     return item;
     413   \brief Return all information, that is needed to represent
     414          the item on the legend
     415
     416   Most items are represented by one entry on the legend
     417   showing an icon and a text.
     418
     419   QwtLegendData is basically a list of QVariants that makes it
     420   possible to overload and reimplement legendData() to
     421   return almost any type of information, that is understood
     422   by the receiver that acts as the legend.
     423
     424   The default implementation returns one entry with
     425   the title() of the item and the legendIcon().
     426
     427   \sa title(), legendIcon(), QwtLegend
     428 */
     429QList<QwtLegendData> QwtPolarItem::legendData() const
     430{
     431    QwtLegendData data;
     432
     433    QwtText label = title();
     434    label.setRenderFlags( label.renderFlags() & Qt::AlignLeft );
     435
     436    QVariant titleValue;
     437    qVariantSetValue( titleValue, label );
     438    data.setValue( QwtLegendData::TitleRole, titleValue );
     439
     440    const QwtGraphic graphic = legendIcon( 0, legendIconSize() );
     441    if ( !graphic.isNull() )
     442    {
     443        QVariant iconValue;
     444        qVariantSetValue( iconValue, graphic );
     445        data.setValue( QwtLegendData::IconRole, iconValue );
     446    }
     447
     448    QList<QwtLegendData> list;
     449    list += data;
     450
     451    return list;
     452}
     453
     454/*!
     455   \return Icon representing the item on the legend
     456
     457   The default implementation returns an invalid icon
     458
     459   \param index Index of the legend entry
     460                ( usually there is only one )
     461   \param size Icon size
     462
     463   \sa setLegendIconSize(), legendData()
     464 */
     465QwtGraphic QwtPolarItem::legendIcon(
     466    int index, const QSizeF &size ) const
     467{
     468    Q_UNUSED( index )
     469    Q_UNUSED( size )
     470
     471    return QwtGraphic();
    441472}
    442473
Note: See TracChangeset for help on using the changeset viewer.