Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_marker.cpp


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/qwt/qwt_plot_marker.cpp

    r4271 r8127  
    1414#include "qwt_text.h"
    1515#include "qwt_math.h"
    16 #include "qwt_legend.h"
    17 #include "qwt_legend_item.h"
    1816#include <qpainter.h>
    1917
     
    5149
    5250//! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine
    53 QwtPlotMarker::QwtPlotMarker():
    54     QwtPlotItem( QwtText( "Marker" ) )
     51QwtPlotMarker::QwtPlotMarker( const QString &title ):
     52    QwtPlotItem( QwtText( title ) )
     53{
     54    d_data = new PrivateData;
     55    setZ( 30.0 );
     56}
     57
     58//! Sets alignment to Qt::AlignCenter, and style to QwtPlotMarker::NoLine
     59QwtPlotMarker::QwtPlotMarker( const QwtText &title ):
     60    QwtPlotItem( title )
    5561{
    5662    d_data = new PrivateData;
     
    123129  \param xMap x Scale Map
    124130  \param yMap y Scale Map
    125   \param canvasRect Contents rect of the canvas in painter coordinates
     131  \param canvasRect Contents rectangle of the canvas in painter coordinates
    126132*/
    127133void QwtPlotMarker::draw( QPainter *painter,
     
    140146        ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
    141147    {
    142         d_data->symbol->drawSymbol( painter, pos );
     148        const QSizeF sz = d_data->symbol->size();
     149
     150        const QRectF clipRect = canvasRect.adjusted(
     151            -sz.width(), -sz.height(), sz.width(), sz.height() );
     152
     153        if ( clipRect.contains( pos ) )
     154            d_data->symbol->drawSymbol( painter, pos );
    143155    }
    144156
     
    150162
    151163  \param painter Painter
    152   \param canvasRect Contents rect of the canvas in painter coordinates
     164  \param canvasRect Contents rectangle of the canvas in painter coordinates
    153165  \param pos Position of the marker, translated into widget coordinates
    154166
     
    190202
    191203  \param painter Painter
    192   \param canvasRect Contents rect of the canvas in painter coordinates
     204  \param canvasRect Contents rectangle of the canvas in painter coordinates
    193205  \param pos Position of the marker, translated into widget coordinates
    194206
     
    334346    {
    335347        d_data->style = style;
     348
     349        legendChanged();
    336350        itemChanged();
    337351    }
     
    358372        delete d_data->symbol;
    359373        d_data->symbol = symbol;
     374
     375        if ( symbol )
     376            setLegendIconSize( symbol->boundingRect().size() );
     377
     378        legendChanged();
    360379        itemChanged();
    361380    }
     
    373392/*!
    374393  \brief Set the label
    375   \param label label text
     394  \param label Label text
    376395  \sa label()
    377396*/
     
    484503}
    485504
     505/*!
     506  Build and assign a line pen
     507   
     508  In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     509  non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     510  to hide this incompatibility.
     511   
     512  \param color Pen color
     513  \param width Pen width
     514  \param style Pen style
     515   
     516  \sa pen(), brush()
     517 */
     518void QwtPlotMarker::setLinePen( const QColor &color, qreal width, Qt::PenStyle style )
     519{   
     520    setLinePen( QPen( color, width, style ) );
     521}
     522
    486523/*!
    487524  Specify a pen for the line.
     
    495532    {
    496533        d_data->pen = pen;
     534
     535        legendChanged();
    497536        itemChanged();
    498537    }
     
    514553
    515554/*!
    516    \brief Update the widget that represents the item on the legend
    517 
    518    \param legend Legend
    519    \sa drawLegendIdentifier(), legendItem(), itemChanged(), QwtLegend()
    520 
    521    \note In the default setting QwtPlotItem::Legend is disabled
    522 */
    523 void QwtPlotMarker::updateLegend( QwtLegend *legend ) const
    524 {
    525     if ( legend && testItemAttribute( QwtPlotItem::Legend )
    526         && d_data->symbol && d_data->symbol->style() != QwtSymbol::NoSymbol )
    527     {
    528         QWidget *lgdItem = legend->find( this );
    529         if ( lgdItem == NULL )
    530         {
    531             lgdItem = legendItem();
    532             if ( lgdItem )
    533                 legend->insert( this, lgdItem );
    534         }
    535 
    536         QwtLegendItem *l = qobject_cast<QwtLegendItem *>( lgdItem );
    537         if ( l )
    538             l->setIdentifierSize( d_data->symbol->boundingSize() );
    539     }
    540 
    541     QwtPlotItem::updateLegend( legend );
    542 }
    543 
    544 /*!
    545   \brief Draw the identifier representing the marker on the legend
    546 
    547   \param painter Painter
    548   \param rect Bounding rectangle for the identifier
    549 
    550   \sa updateLegend(), QwtPlotItem::Legend
    551 */
    552 void QwtPlotMarker::drawLegendIdentifier(
    553     QPainter *painter, const QRectF &rect ) const
    554 {
    555     if ( rect.isEmpty() )
    556         return;
    557 
    558     painter->save();
    559     painter->setClipRect( rect, Qt::IntersectClip );
     555   \return Icon representing the marker on the legend
     556
     557   \param index Index of the legend entry
     558                ( usually there is only one )
     559   \param size Icon size
     560
     561   \sa setLegendIconSize(), legendData()
     562*/
     563QwtGraphic QwtPlotMarker::legendIcon( int index,
     564    const QSizeF &size ) const
     565{
     566    Q_UNUSED( index );
     567
     568    if ( size.isEmpty() )
     569        return QwtGraphic();
     570
     571    QwtGraphic icon;
     572    icon.setDefaultSize( size );
     573    icon.setRenderHint( QwtGraphic::RenderPensUnscaled, true );
     574
     575    QPainter painter( &icon );
     576    painter.setRenderHint( QPainter::Antialiasing,
     577        testRenderHint( QwtPlotItem::RenderAntialiased ) );
    560578
    561579    if ( d_data->style != QwtPlotMarker::NoLine )
    562580    {
    563         painter->setPen( d_data->pen );
     581        painter.setPen( d_data->pen );
    564582
    565583        if ( d_data->style == QwtPlotMarker::HLine ||
    566584            d_data->style == QwtPlotMarker::Cross )
    567585        {
    568             QwtPainter::drawLine( painter, rect.left(), rect.center().y(),
    569                 rect.right(), rect.center().y() );
     586            const double y = 0.5 * size.height();
     587
     588            QwtPainter::drawLine( &painter,
     589                0.0, y, size.width(), y );
    570590        }
    571591
     
    573593            d_data->style == QwtPlotMarker::Cross )
    574594        {
    575             QwtPainter::drawLine( painter, rect.center().x(), rect.top(),
    576                 rect.center().x(), rect.bottom() );
     595            const double x = 0.5 * size.width();
     596
     597            QwtPainter::drawLine( &painter,
     598                x, 0.0, x, size.height() );
    577599        }
    578600    }
    579601
    580     if ( d_data->symbol && d_data->symbol->style() != QwtSymbol::NoSymbol )
    581     {
    582         QSize symbolSize = d_data->symbol->boundingSize();
    583         symbolSize -= QSize( 2, 2 );
    584 
    585         // scale the symbol size down if it doesn't fit into rect.
    586 
    587         double xRatio = 1.0;
    588         if ( rect.width() < symbolSize.width() )
    589             xRatio = rect.width() / symbolSize.width();
    590         double yRatio = 1.0;
    591         if ( rect.height() < symbolSize.height() )
    592             yRatio = rect.height() / symbolSize.height();
    593 
    594         const double ratio = qMin( xRatio, yRatio );
    595 
    596         painter->scale( ratio, ratio );
    597         d_data->symbol->drawSymbol( painter, rect.center() / ratio );
    598     }
    599 
    600     painter->restore();
    601 }
    602 
     602    if ( d_data->symbol )
     603    {
     604        const QRect r( 0.0, 0.0, size.width(), size.height() );
     605        d_data->symbol->drawSymbol( &painter, r );
     606    }
     607
     608    return icon;
     609}
     610
Note: See TracChangeset for help on using the changeset viewer.