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_histogram.cpp

    r4271 r8127  
    1010#include "qwt_plot_histogram.h"
    1111#include "qwt_plot.h"
    12 #include "qwt_legend.h"
    13 #include "qwt_legend_item.h"
    1412#include "qwt_painter.h"
    1513#include "qwt_column_symbol.h"
     
    1816#include <qpainter.h>
    1917
    20 static inline bool isCombinable( const QwtInterval &d1,
     18static inline bool qwtIsCombinable( const QwtInterval &d1,
    2119    const QwtInterval &d2 )
    2220{
     
    6361  \param title Title of the histogram.
    6462*/
    65 
    6663QwtPlotHistogram::QwtPlotHistogram( const QwtText &title ):
    67     QwtPlotSeriesItem<QwtIntervalSample>( title )
     64    QwtPlotSeriesItem( title )
    6865{
    6966    init();
     
    7572*/
    7673QwtPlotHistogram::QwtPlotHistogram( const QString &title ):
    77     QwtPlotSeriesItem<QwtIntervalSample>( title )
     74    QwtPlotSeriesItem( title )
    7875{
    7976    init();
     
    9087{
    9188    d_data = new PrivateData();
    92     d_series = new QwtIntervalSeriesData();
     89    setData( new QwtIntervalSeriesData() );
    9390
    9491    setItemAttribute( QwtPlotItem::AutoScale, true );
     
    109106    {
    110107        d_data->style = style;
     108
     109        legendChanged();
    111110        itemChanged();
    112111    }
     
    114113
    115114/*!
    116     Return the current style
     115    \return Style of the histogram
    117116    \sa HistogramStyle, setStyle()
    118117*/
     
    121120    return d_data->style;
    122121}
     122
     123/*!
     124  Build and assign a pen
     125   
     126  In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     127  non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     128  to hide this incompatibility.
     129   
     130  \param color Pen color
     131  \param width Pen width
     132  \param style Pen style
     133   
     134  \sa pen(), brush()
     135 */
     136void QwtPlotHistogram::setPen( const QColor &color, qreal width, Qt::PenStyle style )
     137{   
     138    setPen( QPen( color, width, style ) );
     139}   
    123140
    124141/*!
     
    133150    {
    134151        d_data->pen = pen;
     152
     153        legendChanged();
    135154        itemChanged();
    136155    }
     
    157176    {
    158177        d_data->brush = brush;
     178
     179        legendChanged();
    159180        itemChanged();
    160181    }
     
    181202
    182203  \note In applications, where different intervals need to be displayed
    183         in a different way ( f.e different colors or even using differnt symbols)
     204        in a different way ( f.e different colors or even using different symbols)
    184205        it is recommended to overload drawColumn().
    185206*/
     
    190211        delete d_data->symbol;
    191212        d_data->symbol = symbol;
     213
     214        legendChanged();
    192215        itemChanged();
    193216    }
     
    238261QRectF QwtPlotHistogram::boundingRect() const
    239262{
    240     QRectF rect = d_series->boundingRect();
     263    QRectF rect = data()->boundingRect();
    241264    if ( !rect.isValid() )
    242265        return rect;
     
    276299    const QVector<QwtIntervalSample> &samples )
    277300{
    278     delete d_series;
    279     d_series = new QwtIntervalSeriesData( samples );
    280     itemChanged();
     301    setData( new QwtIntervalSeriesData( samples ) );
     302}
     303
     304/*!
     305  Assign a series of samples
     306   
     307  setSamples() is just a wrapper for setData() without any additional
     308  value - beside that it is easier to find for the developer.
     309   
     310  \param data Data
     311  \warning The item takes ownership of the data object, deleting
     312           it when its not used anymore.
     313*/
     314void QwtPlotHistogram::setSamples(
     315    QwtSeriesData<QwtIntervalSample> *data )
     316{
     317    setData( data );
    281318}
    282319
     
    287324  \param xMap Maps x-values into pixel coordinates.
    288325  \param yMap Maps y-values into pixel coordinates.
    289   \param canvasRect Contents rect of the canvas
     326  \param canvasRect Contents rectangle of the canvas
    290327  \param from Index of the first sample to be painted
    291328  \param to Index of the last sample to be painted. If to < 0 the
     
    350387    for ( int i = from; i <= to; i++ )
    351388    {
    352         const QwtIntervalSample sample = d_series->sample( i );
     389        const QwtIntervalSample sample = this->sample( i );
    353390
    354391        if ( !sample.interval.isValid() )
     
    361398        if ( previous.interval.isValid() )
    362399        {
    363             if ( !isCombinable( previous.interval, sample.interval ) )
     400            if ( !qwtIsCombinable( previous.interval, sample.interval ) )
    364401                flushPolygon( painter, v0, polygon );
    365402        }
     
    426463    painter->setBrush( d_data->brush );
    427464
     465    const QwtSeriesData<QwtIntervalSample> *series = data();
     466
    428467    for ( int i = from; i <= to; i++ )
    429468    {
    430         const QwtIntervalSample sample = d_series->sample( i );
     469        const QwtIntervalSample sample = series->sample( i );
    431470        if ( !sample.interval.isNull() )
    432471        {
     
    458497    painter->setBrush( Qt::NoBrush );
    459498
     499    const QwtSeriesData<QwtIntervalSample> *series = data();
     500
    460501    for ( int i = from; i <= to; i++ )
    461502    {
    462         const QwtIntervalSample sample = d_series->sample( i );
     503        const QwtIntervalSample sample = series->sample( i );
    463504        if ( !sample.interval.isNull() )
    464505        {
     
    532573            polygon += QPointF( baseLine, polygon.first().y() );
    533574        }
     575
    534576        QwtPainter::drawPolygon( painter, polygon );
    535         polygon.resize( polygon.size() - 2 );
     577
     578        polygon.pop_back();
     579        polygon.pop_back();
    536580    }
    537581    if ( d_data->pen.style() != Qt::NoPen )
     
    601645
    602646  \note In applications, where different intervals need to be displayed
    603         in a different way ( f.e different colors or even using differnt symbols)
     647        in a different way ( f.e different colors or even using different symbols)
    604648        it is recommended to overload drawColumn().
    605649*/
     
    630674
    631675/*!
    632   Draw a plain rectangle without pen using the brush() as identifier
    633 
    634   \param painter Painter
    635   \param rect Bounding rectangle for the identifier
    636 */
    637 void QwtPlotHistogram::drawLegendIdentifier(
    638     QPainter *painter, const QRectF &rect ) const
    639 {
    640     const double dim = qMin( rect.width(), rect.height() );
    641 
    642     QSizeF size( dim, dim );
    643 
    644     QRectF r( 0, 0, size.width(), size.height() );
    645     r.moveCenter( rect.center() );
    646 
    647     painter->fillRect( r, d_data->brush );
    648 }
     676  A plain rectangle without pen using the brush()
     677
     678  \param index Index of the legend entry
     679                ( ignored as there is only one )
     680  \param size Icon size
     681  \return A graphic displaying the icon
     682   
     683  \sa QwtPlotItem::setLegendIconSize(), QwtPlotItem::legendData()
     684*/
     685QwtGraphic QwtPlotHistogram::legendIcon( int index,
     686    const QSizeF &size ) const
     687{
     688    Q_UNUSED( index );
     689    return defaultIcon( d_data->brush, size );
     690}
Note: See TracChangeset for help on using the changeset viewer.