Changeset 8127 in ntrip


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

update qwt and qwtpolar, many QT5 fixes (unfinished)

Location:
trunk/BNC
Files:
73 added
3 deleted
155 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt.h

    r4271 r8127  
    1818namespace Qwt
    1919{
    20 };
     20}
    2121
    2222#endif
  • trunk/BNC/qwt/qwt.pro

    r5182 r8127  
    77CONFIG -= debug
    88CONFIG += release
    9 
    10 ###DEFINES += QWT_NO_SVG
    11 QT += svg
     9QWT_CONFIG = QwtPlot QwtWidgets QwtSvg
    1210
    1311OBJECTS_DIR = .obj
    1412MOC_DIR     = .moc
    1513
    16 HEADERS += \
    17     qwt.h \
    18     qwt_abstract_scale_draw.h \
    19     qwt_interval_symbol.h \
    20     qwt_clipper.h \
    21     qwt_color_map.h \
    22     qwt_compat.h \
    23     qwt_column_symbol.h \
    24     qwt_interval.h \
    25     qwt_dyngrid_layout.h \
    26     qwt_global.h \
    27     qwt_math.h \
    28     qwt_magnifier.h \
    29     qwt_null_paintdevice.h \
    30     qwt_painter.h \
    31     qwt_panner.h \
    32     qwt_picker.h \
    33     qwt_picker_machine.h \
    34     qwt_point_3d.h \
    35     qwt_point_polar.h \
    36     qwt_round_scale_draw.h \
    37     qwt_scale_div.h \
    38     qwt_scale_draw.h \
    39     qwt_scale_engine.h \
    40     qwt_scale_map.h \
    41     qwt_spline.h \
    42     qwt_symbol.h \
    43     qwt_system_clock.h \
    44     qwt_text_engine.h \
    45     qwt_text_label.h \
    46     qwt_text.h \
    47     qwt_curve_fitter.h \
    48     qwt_event_pattern.h \
    49     qwt_legend.h \
    50     qwt_legend_item.h \
    51     qwt_legend_itemmanager.h \
    52     qwt_plot.h \
    53     qwt_plot_renderer.h \
    54     qwt_plot_curve.h \
    55     qwt_plot_dict.h \
    56     qwt_plot_directpainter.h \
    57     qwt_plot_grid.h \
    58     qwt_plot_histogram.h \
    59     qwt_plot_item.h \
    60     qwt_plot_intervalcurve.h \
    61     qwt_plot_layout.h \
    62     qwt_plot_marker.h \
    63     qwt_plot_rasteritem.h \
    64     qwt_plot_spectrogram.h \
    65     qwt_plot_spectrocurve.h \
    66     qwt_plot_scaleitem.h \
    67     qwt_plot_seriesitem.h \
    68     qwt_plot_canvas.h \
    69     qwt_plot_panner.h \
    70     qwt_plot_picker.h \
    71     qwt_plot_zoomer.h \
    72     qwt_plot_magnifier.h \
    73     qwt_plot_rescaler.h \
    74     qwt_raster_data.h \
    75     qwt_matrix_raster_data.h \
    76     qwt_sampling_thread.h \
    77     qwt_series_data.h \
    78     qwt_scale_widget.h \
    79     qwt_plot_svgitem.h
    80 
    81 SOURCES += \
    82     qwt_abstract_scale_draw.cpp \
    83     qwt_interval_symbol.cpp \
    84     qwt_clipper.cpp \
    85     qwt_color_map.cpp \
    86     qwt_column_symbol.cpp \
    87     qwt_interval.cpp \
    88     qwt_dyngrid_layout.cpp \
    89     qwt_math.cpp \
    90     qwt_magnifier.cpp \
    91     qwt_panner.cpp \
    92     qwt_null_paintdevice.cpp \
    93     qwt_painter.cpp \
    94     qwt_picker.cpp \
    95     qwt_round_scale_draw.cpp \
    96     qwt_scale_div.cpp \
    97     qwt_scale_draw.cpp \
    98     qwt_scale_map.cpp \
    99     qwt_spline.cpp \
    100     qwt_text_engine.cpp \
    101     qwt_text_label.cpp \
    102     qwt_text.cpp \
    103     qwt_event_pattern.cpp \
    104     qwt_picker_machine.cpp \
    105     qwt_point_3d.cpp \
    106     qwt_point_polar.cpp \
    107     qwt_scale_engine.cpp \
    108     qwt_symbol.cpp \
    109     qwt_system_clock.cpp \
    110     qwt_curve_fitter.cpp \
    111     qwt_legend.cpp \
    112     qwt_legend_item.cpp \
    113     qwt_plot.cpp \
    114     qwt_plot_renderer.cpp \
    115     qwt_plot_xml.cpp \
    116     qwt_plot_axis.cpp \
    117     qwt_plot_curve.cpp \
    118     qwt_plot_dict.cpp \
    119     qwt_plot_directpainter.cpp \
    120     qwt_plot_grid.cpp \
    121     qwt_plot_histogram.cpp \
    122     qwt_plot_item.cpp \
    123     qwt_plot_intervalcurve.cpp \
    124     qwt_plot_spectrogram.cpp \
    125     qwt_plot_spectrocurve.cpp \
    126     qwt_plot_scaleitem.cpp \
    127     qwt_plot_seriesitem.cpp \
    128     qwt_plot_marker.cpp \
    129     qwt_plot_layout.cpp \
    130     qwt_plot_canvas.cpp \
    131     qwt_plot_panner.cpp \
    132     qwt_plot_rasteritem.cpp \
    133     qwt_plot_picker.cpp \
    134     qwt_plot_zoomer.cpp \
    135     qwt_plot_magnifier.cpp \
    136     qwt_plot_rescaler.cpp \
    137     qwt_raster_data.cpp \
    138     qwt_matrix_raster_data.cpp \
    139     qwt_sampling_thread.cpp \
    140     qwt_series_data.cpp \
    141     qwt_scale_widget.cpp \
    142     qwt_plot_svgitem.cpp
     14include ( src.pri )
  • trunk/BNC/qwt/qwt_abstract_scale_draw.cpp

    r4271 r8127  
    3838
    3939    QwtScaleMap map;
    40     QwtScaleDiv scldiv;
     40    QwtScaleDiv scaleDiv;
    4141
    4242    double spacing;
     
    8686/*!
    8787  Check if a component is enabled
     88
     89  \param component Component type
     90  \return true, when component is enabled
    8891  \sa enableComponent()
    8992*/
     
    9598/*!
    9699  Change the scale division
    97   \param sd New scale division
    98 */
    99 void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &sd )
    100 {
    101     d_data->scldiv = sd;
    102     d_data->map.setScaleInterval( sd.lowerBound(), sd.upperBound() );
     100  \param scaleDiv New scale division
     101*/
     102void QwtAbstractScaleDraw::setScaleDiv( const QwtScaleDiv &scaleDiv )
     103{
     104    d_data->scaleDiv = scaleDiv;
     105    d_data->map.setScaleInterval( scaleDiv.lowerBound(), scaleDiv.upperBound() );
    103106    d_data->labelCache.clear();
    104107}
     
    109112*/
    110113void QwtAbstractScaleDraw::setTransformation(
    111     QwtScaleTransformation *transformation )
     114    QwtTransform *transformation )
    112115{
    113116    d_data->map.setTransformation( transformation );
     
    129132const QwtScaleDiv& QwtAbstractScaleDraw::scaleDiv() const
    130133{
    131     return d_data->scldiv;
     134    return d_data->scaleDiv;
    132135}
    133136
     
    179182
    180183        const QList<double> &majorTicks =
    181             d_data->scldiv.ticks( QwtScaleDiv::MajorTick );
     184            d_data->scaleDiv.ticks( QwtScaleDiv::MajorTick );
    182185
    183186        for ( int i = 0; i < majorTicks.count(); i++ )
    184187        {
    185188            const double v = majorTicks[i];
    186             if ( d_data->scldiv.contains( v ) )
    187                 drawLabel( painter, majorTicks[i] );
     189            if ( d_data->scaleDiv.contains( v ) )
     190                drawLabel( painter, v );
    188191        }
    189192
     
    204207            tickType < QwtScaleDiv::NTickTypes; tickType++ )
    205208        {
    206             const QList<double> &ticks = d_data->scldiv.ticks( tickType );
     209            const double tickLen = d_data->tickLength[tickType];
     210            if ( tickLen <= 0.0 )
     211                continue;
     212
     213            const QList<double> &ticks = d_data->scaleDiv.ticks( tickType );
    207214            for ( int i = 0; i < ticks.count(); i++ )
    208215            {
    209216                const double v = ticks[i];
    210                 if ( d_data->scldiv.contains( v ) )
    211                     drawTick( painter, v, d_data->tickLength[tickType] );
     217                if ( d_data->scaleDiv.contains( v ) )
     218                    drawTick( painter, v, tickLen );
    212219            }
    213220        }
     
    258265  The default spacing is 4 pixels.
    259266
     267  \return Spacing
    260268  \sa setSpacing()
    261269*/
     
    268276  \brief Set a minimum for the extent
    269277
    270   The extent is calculated from the coomponents of the
     278  The extent is calculated from the components of the
    271279  scale draw. In situations, where the labels are
    272280  changing and the layout depends on the extent (f.e scrolling
     
    288296/*!
    289297  Get the minimum extent
     298  \return Minimum extent
    290299  \sa extent(), setMinimumExtent()
    291300*/
     
    323332
    324333/*!
    325     Return the length of the ticks
    326 
     334    \return Length of the ticks
    327335    \sa setTickLength(), maxTickLength()
    328336*/
     
    357365
    358366  The value is converted to a plain text using
    359   QLocale::system().toString(value).
     367  QLocale().toString(value).
    360368  This method is often overloaded by applications to have individual
    361369  labels.
     
    401409
    402410/*!
    403    Invalidate the cache used by QwtAbstractScaleDraw::tickLabel
     411   Invalidate the cache used by tickLabel()
    404412
    405413   The cache is invalidated, when a new QwtScaleDiv is set. If
  • trunk/BNC/qwt/qwt_abstract_scale_draw.h

    r4271 r8127  
    1818class QPainter;
    1919class QFont;
    20 class QwtScaleTransformation;
     20class QwtTransform;
    2121class QwtScaleMap;
    2222
     
    2727
    2828  After a scale division has been specified as a QwtScaleDiv object
    29   using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
    30   the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
     29  using setScaleDiv(), the scale can be drawn with the draw() member.
    3130*/
    3231class QWT_EXPORT QwtAbstractScaleDraw
     
    5958    const QwtScaleDiv& scaleDiv() const;
    6059
    61     void setTransformation( QwtScaleTransformation * );
     60    void setTransformation( QwtTransform * );
    6261    const QwtScaleMap &scaleMap() const;
    6362    QwtScaleMap &scaleMap();
     
    8382      Calculate the extent
    8483
    85       The extent is the distcance from the baseline to the outermost
     84      The extent is the distance from the baseline to the outermost
    8685      pixel of the scale draw in opposite to its orientation.
    8786      It is at least minimumExtent() pixels.
    8887
     88      \param font Font used for drawing the tick labels
     89      \return Number of pixels
     90
    8991      \sa setMinimumExtent(), minimumExtent()
    9092    */
    91     virtual double extent( const QFont & ) const = 0;
     93    virtual double extent( const QFont &font ) const = 0;
    9294
    9395    void setMinimumExtent( double );
     
    100102       \param painter Painter
    101103       \param value Value of the tick
    102        \param len Lenght of the tick
     104       \param len Length of the tick
    103105
    104106       \sa drawBackbone(), drawLabel()
  • trunk/BNC/qwt/qwt_clipper.cpp

    r4271 r8127  
    1111#include "qwt_point_polar.h"
    1212#include <qrect.h>
     13#include <string.h>
     14#include <stdlib.h>
    1315
    1416#if QT_VERSION < 0x040601
     
    4446    {
    4547        double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() );
    46         return Point( d_x1, ( Value ) ( p2.y() + ( d_x1 - p2.x() ) * dy ) );
     48        return Point( d_x1, static_cast< Value >( p2.y() + ( d_x1 - p2.x() ) * dy ) );
    4749    }
    4850private:
     
    6769    {
    6870        double dy = ( p1.y() - p2.y() ) / double( p1.x() - p2.x() );
    69         return Point( d_x2, ( Value ) ( p2.y() + ( d_x2 - p2.x() ) * dy ) );
     71        return Point( d_x2, static_cast<Value>( p2.y() + ( d_x2 - p2.x() ) * dy ) );
    7072    }
    7173
     
    9193    {
    9294        double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() );
    93         return Point( ( Value )( p2.x() + ( d_y1 - p2.y() ) * dx ), d_y1 );
     95        return Point( static_cast<Value>( p2.x() + ( d_y1 - p2.y() ) * dx ), d_y1 );
    9496    }
    9597
     
    115117    {
    116118        double dx = ( p1.x() - p2.x() ) / double( p1.y() - p2.y() );
    117         return Point( ( Value )( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 );
     119        return Point( static_cast<Value>( p2.x() + ( d_y2 - p2.y() ) * dx ), d_y2 );
    118120    }
    119121
     
    138140    {
    139141        if ( m_buffer )
    140             qFree( m_buffer );
     142            ::free( m_buffer );
    141143    }
    142144
     
    146148
    147149        m_size = numPoints;
    148         qMemCopy( m_buffer, points, m_size * sizeof( Point ) );
     150        ::memcpy( m_buffer, points, m_size * sizeof( Point ) );
    149151    }
    150152
     
    191193            m_capacity *= 2;
    192194
    193         m_buffer = ( Point * ) qRealloc(
    194             m_buffer, m_capacity * sizeof( Point ) );
     195        m_buffer = static_cast<Point *>(
     196            ::realloc( m_buffer, m_capacity * sizeof( Point ) ) );
    195197    }
    196198
     
    230232        Polygon p;
    231233        p.resize( points1.size() );
    232         qMemCopy( p.data(), points1.data(), points1.size() * sizeof( Point ) );
     234        ::memcpy( p.data(), points1.data(), points1.size() * sizeof( Point ) );
    233235
    234236        return p;
     
    335337    QList<QPointF> points;
    336338    for ( int edge = 0; edge < NEdges; edge++ )
    337         points += cuttingPoints( ( Edge )edge, pos, radius );
     339        points += cuttingPoints( static_cast<Edge>(edge), pos, radius );
    338340
    339341    QVector<QwtInterval> intv;
     
    444446*/
    445447QPolygon QwtClipper::clipPolygon(
     448    const QRectF &clipRect, const QPolygon &polygon, bool closePolygon )
     449{
     450    const int minX = qCeil( clipRect.left() );
     451    const int maxX = qFloor( clipRect.right() );
     452    const int minY = qCeil( clipRect.top() );
     453    const int maxY = qFloor( clipRect.bottom() );
     454
     455    const QRect r( minX, minY, maxX - minX, maxY - minY );
     456
     457    QwtPolygonClipper<QPolygon, QRect, QPoint, int> clipper( r );
     458    return clipper.clipPolygon( polygon, closePolygon );
     459}
     460/*!
     461   Sutherland-Hodgman polygon clipping
     462
     463   \param clipRect Clip rectangle
     464   \param polygon Polygon
     465   \param closePolygon True, when the polygon is closed
     466
     467   \return Clipped polygon
     468*/
     469QPolygon QwtClipper::clipPolygon(
    446470    const QRect &clipRect, const QPolygon &polygon, bool closePolygon )
    447471{
     
    469493   Circle clipping
    470494
    471    clipCircle() devides a circle into intervals of angles representing arcs
     495   clipCircle() divides a circle into intervals of angles representing arcs
    472496   of the circle. When the circle is completely inside the clip rectangle
    473497   an interval [0.0, 2 * M_PI] is returned.
  • trunk/BNC/qwt/qwt_clipper.h

    r4271 r8127  
    2020
    2121/*!
    22   \brief Some clipping algos
     22  \brief Some clipping algorithms
    2323*/
    2424
     
    2828    static QPolygon clipPolygon( const QRect &,
    2929        const QPolygon &, bool closePolygon = false );
     30    static QPolygon clipPolygon( const QRectF &,
     31        const QPolygon &, bool closePolygon = false );
     32
    3033    static QPolygonF clipPolygonF( const QRectF &,
    3134        const QPolygonF &, bool closePolygon = false );
  • trunk/BNC/qwt/qwt_color_map.cpp

    r4271 r8127  
    1616{
    1717public:
    18     ColorStops()
    19     {
    20         _stops.reserve( 256 );
     18    ColorStops():
     19        d_doAlpha( false )
     20    {
     21        d_stops.reserve( 256 );
    2122    }
    2223
     
    3940        ColorStop( double p, const QColor &c ):
    4041            pos( p ),
    41             rgb( c.rgb() )
     42            rgb( c.rgba() )
    4243        {
    4344            r = qRed( rgb );
    4445            g = qGreen( rgb );
    4546            b = qBlue( rgb );
     47            a = qAlpha( rgb );
     48
     49            /*
     50                when mapping a value to rgb we will have to calcualate:
     51                   - const int v = int( ( s1.v0 + ratio * s1.vStep ) + 0.5 );
     52
     53                Thus adding 0.5 ( for rounding ) can be done in advance
     54             */
     55            r0 = r + 0.5;
     56            g0 = g + 0.5;
     57            b0 = b + 0.5;
     58            a0 = a + 0.5;
     59
     60            rStep = gStep = bStep = aStep = 0.0;
     61            posStep = 0.0;
     62        }
     63
     64        void updateSteps( const ColorStop &nextStop )
     65        {
     66            rStep = nextStop.r - r;
     67            gStep = nextStop.g - g;
     68            bStep = nextStop.b - b;
     69            aStep = nextStop.a - a;
     70            posStep = nextStop.pos - pos;
    4671        }
    4772
    4873        double pos;
    4974        QRgb rgb;
    50         int r, g, b;
     75        int r, g, b, a;
     76
     77        // precalculated values
     78        double rStep, gStep, bStep, aStep;
     79        double r0, g0, b0, a0;
     80        double posStep;
    5181    };
    5282
    5383    inline int findUpper( double pos ) const;
    54     QVector<ColorStop> _stops;
     84    QVector<ColorStop> d_stops;
     85    bool d_doAlpha;
    5586};
    5687
     
    6495
    6596    int index;
    66     if ( _stops.size() == 0 )
     97    if ( d_stops.size() == 0 )
    6798    {
    6899        index = 0;
    69         _stops.resize( 1 );
     100        d_stops.resize( 1 );
    70101    }
    71102    else
    72103    {
    73104        index = findUpper( pos );
    74         if ( index == _stops.size() ||
    75                 qAbs( _stops[index].pos - pos ) >= 0.001 )
    76         {
    77             _stops.resize( _stops.size() + 1 );
    78             for ( int i = _stops.size() - 1; i > index; i-- )
    79                 _stops[i] = _stops[i-1];
    80         }
    81     }
    82 
    83     _stops[index] = ColorStop( pos, color );
     105        if ( index == d_stops.size() ||
     106                qAbs( d_stops[index].pos - pos ) >= 0.001 )
     107        {
     108            d_stops.resize( d_stops.size() + 1 );
     109            for ( int i = d_stops.size() - 1; i > index; i-- )
     110                d_stops[i] = d_stops[i-1];
     111        }
     112    }
     113
     114    d_stops[index] = ColorStop( pos, color );
     115    if ( color.alpha() != 255 )
     116        d_doAlpha = true;
     117
     118    if ( index > 0 )
     119        d_stops[index-1].updateSteps( d_stops[index] );
     120
     121    if ( index < d_stops.size() - 1 )
     122        d_stops[index].updateSteps( d_stops[index+1] );
    84123}
    85124
    86125inline QVector<double> QwtLinearColorMap::ColorStops::stops() const
    87126{
    88     QVector<double> positions( _stops.size() );
    89     for ( int i = 0; i < _stops.size(); i++ )
    90         positions[i] = _stops[i].pos;
     127    QVector<double> positions( d_stops.size() );
     128    for ( int i = 0; i < d_stops.size(); i++ )
     129        positions[i] = d_stops[i].pos;
    91130    return positions;
    92131}
     
    95134{
    96135    int index = 0;
    97     int n = _stops.size();
    98 
    99     const ColorStop *stops = _stops.data();
     136    int n = d_stops.size();
     137
     138    const ColorStop *stops = d_stops.data();
    100139
    101140    while ( n > 0 )
     
    120159{
    121160    if ( pos <= 0.0 )
    122         return _stops[0].rgb;
     161        return d_stops[0].rgb;
    123162    if ( pos >= 1.0 )
    124         return _stops[ _stops.size() - 1 ].rgb;
     163        return d_stops[ d_stops.size() - 1 ].rgb;
    125164
    126165    const int index = findUpper( pos );
    127166    if ( mode == FixedColors )
    128167    {
    129         return _stops[index-1].rgb;
     168        return d_stops[index-1].rgb;
    130169    }
    131170    else
    132171    {
    133         const ColorStop &s1 = _stops[index-1];
    134         const ColorStop &s2 = _stops[index];
    135 
    136         const double ratio = ( pos - s1.pos ) / ( s2.pos - s1.pos );
    137 
    138         const int r = s1.r + qRound( ratio * ( s2.r - s1.r ) );
    139         const int g = s1.g + qRound( ratio * ( s2.g - s1.g ) );
    140         const int b = s1.b + qRound( ratio * ( s2.b - s1.b ) );
    141 
    142         return qRgb( r, g, b );
     172        const ColorStop &s1 = d_stops[index-1];
     173
     174        const double ratio = ( pos - s1.pos ) / ( s1.posStep );
     175
     176        const int r = int( s1.r0 + ratio * s1.rStep );
     177        const int g = int( s1.g0 + ratio * s1.gStep );
     178        const int b = int( s1.b0 + ratio * s1.bStep );
     179
     180        if ( d_doAlpha )
     181        {
     182            if ( s1.aStep )
     183            {
     184                const int a = int( s1.a0 + ratio * s1.aStep );
     185                return qRgba( r, g, b, a );
     186            }
     187            else
     188            {
     189                return qRgba( r, g, b, s1.a );
     190            }
     191        }
     192        else
     193        {
     194            return qRgb( r, g, b );
     195        }
    143196    }
    144197}
     
    205258   \param color1 Color used for the minimum value of the value interval
    206259   \param color2 Color used for the maximum value of the value interval
    207    \param format Preferred format of the coor map
     260   \param format Preferred format for the color map
    208261*/
    209262QwtLinearColorMap::QwtLinearColorMap( const QColor &color1,
     
    280333
    281334/*!
    282    Return all positions of color stops in increasing order
     335   \return Positions of color stops in increasing order
    283336*/
    284337QVector<double> QwtLinearColorMap::colorStops() const
     
    306359
    307360/*!
    308   Map a value of a given interval into a rgb value
     361  Map a value of a given interval into a RGB value
    309362
    310363  \param interval Range for all values
    311   \param value Value to map into a rgb value
     364  \param value Value to map into a RGB value
     365
     366  \return RGB value for value
    312367*/
    313368QRgb QwtLinearColorMap::rgb(
     
    315370{
    316371    if ( qIsNaN(value) )
    317         return qRgba(0, 0, 0, 0);
     372        return 0u;
    318373
    319374    const double width = interval.width();
    320 
    321     double ratio = 0.0;
    322     if ( width > 0.0 )
    323         ratio = ( value - interval.minValue() ) / width;
    324 
     375    if ( width <= 0.0 )
     376        return 0u;
     377
     378    const double ratio = ( value - interval.minValue() ) / width;
    325379    return d_data->colorStops.rgb( d_data->mode, ratio );
    326380}
    327381
    328382/*!
    329   Map a value of a given interval into a color index, between 0 and 255
     383  \brief Map a value of a given interval into a color index
    330384
    331385  \param interval Range for all values
    332386  \param value Value to map into a color index
     387
     388  \return Index, between 0 and 255
    333389*/
    334390unsigned char QwtLinearColorMap::colorIndex(
     
    341397
    342398    if ( value >= interval.maxValue() )
    343         return ( unsigned char )255;
     399        return 255;
    344400
    345401    const double ratio = ( value - interval.minValue() ) / width;
     
    347403    unsigned char index;
    348404    if ( d_data->mode == FixedColors )
    349         index = ( unsigned char )( ratio * 255 ); // always floor
     405        index = static_cast<unsigned char>( ratio * 255 ); // always floor
    350406    else
    351         index = ( unsigned char )qRound( ratio * 255 );
     407        index = static_cast<unsigned char>( ratio * 255 + 0.5 );
    352408
    353409    return index;
     
    359415    QColor color;
    360416    QRgb rgb;
     417    QRgb rgbMax;
    361418};
    362419
     
    370427{
    371428    d_data = new PrivateData;
     429    setColor( color );
     430}
     431
     432//! Destructor
     433QwtAlphaColorMap::~QwtAlphaColorMap()
     434{
     435    delete d_data;
     436}
     437
     438/*!
     439   Set the color
     440
     441   \param color Color
     442   \sa color()
     443*/
     444void QwtAlphaColorMap::setColor( const QColor &color )
     445{
    372446    d_data->color = color;
    373447    d_data->rgb = color.rgb() & qRgba( 255, 255, 255, 0 );
    374 }
    375 
    376 //! Destructor
    377 QwtAlphaColorMap::~QwtAlphaColorMap()
    378 {
    379     delete d_data;
    380 }
    381 
    382 /*!
    383    Set the color
    384 
    385    \param color Color
    386    \sa color()
    387 */
    388 void QwtAlphaColorMap::setColor( const QColor &color )
    389 {
    390     d_data->color = color;
    391     d_data->rgb = color.rgb();
     448    d_data->rgbMax = d_data->rgb | ( 255 << 24 );
    392449}
    393450
     
    407464
    408465  \param interval Range for all values
    409   \param value Value to map into a rgb value
    410   \return rgb value, with an alpha value
     466  \param value Value to map into a RGB value
     467  \return RGB value, with an alpha value
    411468*/
    412469QRgb QwtAlphaColorMap::rgb( const QwtInterval &interval, double value ) const
    413470{
     471    if ( qIsNaN(value) )
     472        return 0u;
     473
    414474    const double width = interval.width();
    415     if ( !qIsNaN(value) && width >= 0.0 )
    416     {
    417         const double ratio = ( value - interval.minValue() ) / width;
    418         int alpha = qRound( 255 * ratio );
    419         if ( alpha < 0 )
    420             alpha = 0;
    421         if ( alpha > 255 )
    422             alpha = 255;
    423 
    424         return d_data->rgb | ( alpha << 24 );
    425     }
    426     return d_data->rgb;
     475    if ( width <= 0.0 )
     476        return 0u;
     477
     478    if ( value <= interval.minValue() )
     479        return d_data->rgb;
     480
     481    if ( value >= interval.maxValue() )
     482        return d_data->rgbMax;
     483
     484    const double ratio = ( value - interval.minValue() ) / width;
     485    return d_data->rgb | ( qRound( 255 * ratio ) << 24 );
    427486}
    428487
  • trunk/BNC/qwt/qwt_color_map.h

    r4271 r8127  
    4141    enum Format
    4242    {
    43         //! The map is intended to map into QRgb values.
     43        //! The map is intended to map into RGB values.
    4444        RGB,
    4545
     
    5757
    5858    /*!
    59        Map a value of a given interval into a rgb value.
     59       Map a value of a given interval into a RGB value.
     60
    6061       \param interval Range for the values
    6162       \param value Value
    62        \return rgb value, corresponding to value
     63       \return RGB value, corresponding to value
    6364    */
    6465    virtual QRgb rgb( const QwtInterval &interval,
     
    6768    /*!
    6869       Map a value of a given interval into a color index
     70
    6971       \param interval Range for the values
    7072       \param value Value
     
    136138
    137139/*!
    138   \brief QwtAlphaColorMap variies the alpha value of a color
     140  \brief QwtAlphaColorMap varies the alpha value of a color
    139141*/
    140142class QWT_EXPORT QwtAlphaColorMap: public QwtColorMap
     
    178180    if ( d_format == RGB )
    179181    {
    180         return QColor( rgb( interval, value ) );
     182        return QColor::fromRgba( rgb( interval, value ) );
    181183    }
    182184    else
  • trunk/BNC/qwt/qwt_column_symbol.cpp

    r4271 r8127  
    1010#include "qwt_column_symbol.h"
    1111#include "qwt_math.h"
    12 #include "qwt_text.h"
    1312#include "qwt_painter.h"
    1413#include <qpainter.h>
    1514#include <qpalette.h>
    1615
    17 static void drawBox( QPainter *p, const QRectF &rect,
     16static void qwtDrawBox( QPainter *p, const QRectF &rect,
    1817    const QPalette &pal, double lw )
    1918{
     
    5857}
    5958
    60 static void drawPanel( QPainter *painter, const QRectF &rect,
     59static void qwtDrawPanel( QPainter *painter, const QRectF &rect,
    6160    const QPalette &pal, double lw )
    6261{
     
    125124
    126125    QPalette palette;
    127     QwtText label;
    128 
    129126    int lineWidth;
    130127};
     
    281278        case QwtColumnSymbol::Raised:
    282279        {
    283             ::drawPanel( painter, r, d_data->palette, d_data->lineWidth );
     280            qwtDrawPanel( painter, r, d_data->palette, d_data->lineWidth );
    284281            break;
    285282        }
    286283        case QwtColumnSymbol::Plain:
    287284        {
    288             ::drawBox( painter, r, d_data->palette, d_data->lineWidth );
     285            qwtDrawBox( painter, r, d_data->palette, d_data->lineWidth );
    289286            break;
    290287        }
  • trunk/BNC/qwt/qwt_column_symbol.h

    r4271 r8127  
    2323
    2424/*!
    25     \brief Directed rectangle representing bounding rectangle und orientation
     25    \brief Directed rectangle representing bounding rectangle and orientation
    2626    of a column.
    2727*/
  • trunk/BNC/qwt/qwt_compat.h

    r4271 r8127  
    1212
    1313#include "qwt_global.h"
     14#include "qwt_interval.h"
     15#include "qwt_point_3d.h"
    1416#include <qlist.h>
    1517#include <qvector.h>
  • trunk/BNC/qwt/qwt_curve_fitter.cpp

    r4271 r8127  
    247247public:
    248248    PrivateData():
    249         tolerance( 1.0 )
     249        tolerance( 1.0 ),
     250        chunkSize( 0 )
    250251    {
    251252    }
    252253
    253254    double tolerance;
     255    uint chunkSize;
    254256};
    255257
     
    288290 Assign the tolerance
    289291
    290  The tolerance is the maximum distance, that is accaptable
     292 The tolerance is the maximum distance, that is acceptable
    291293 between the original curve and the smoothed curve.
    292294
     
    313315
    314316/*!
     317 Limit the number of points passed to a run of the algorithm
     318
     319 The runtime of the Douglas Peucker algorithm increases non linear
     320 with the number of points. For a chunk size > 0 the polygon
     321 is split into pieces passed to the algorithm one by one.
     322
     323 \param numPoints Maximum for the number of points passed to the algorithm
     324
     325 \sa chunkSize()
     326*/
     327void QwtWeedingCurveFitter::setChunkSize( uint numPoints )
     328{
     329    if ( numPoints > 0 )
     330        numPoints = qMax( numPoints, 3U );
     331
     332    d_data->chunkSize = numPoints;
     333}
     334
     335/*!
     336 
     337  \return Maximum for the number of points passed to a run
     338          of the algorithm - or 0, when unlimited
     339  \sa setChunkSize()
     340*/
     341uint QwtWeedingCurveFitter::chunkSize() const
     342{
     343    return d_data->chunkSize;
     344}
     345
     346/*!
    315347  \param points Series of data points
    316348  \return Curve points
     
    318350QPolygonF QwtWeedingCurveFitter::fitCurve( const QPolygonF &points ) const
    319351{
     352    QPolygonF fittedPoints;
     353
     354    if ( d_data->chunkSize == 0 )
     355    {
     356        fittedPoints = simplify( points );
     357    }
     358    else
     359    {
     360        for ( int i = 0; i < points.size(); i += d_data->chunkSize )
     361        {
     362            const QPolygonF p = points.mid( i, d_data->chunkSize );
     363            fittedPoints += simplify( p );
     364        }
     365    }
     366
     367    return fittedPoints;
     368}
     369
     370QPolygonF QwtWeedingCurveFitter::simplify( const QPolygonF &points ) const
     371{
     372    const double toleranceSqr = d_data->tolerance * d_data->tolerance;
     373
    320374    QStack<Line> stack;
    321375    stack.reserve( 500 );
     
    325379
    326380    QVector<bool> usePoint( nPoints, false );
    327 
    328     double distToSegment;
    329381
    330382    stack.push( Line( 0, nPoints - 1 ) );
     
    343395        const double unitVecY = ( vecLength != 0.0 ) ? vecY / vecLength : 0.0;
    344396
    345         double maxDist = 0.0;
     397        double maxDistSqr = 0.0;
    346398        int nVertexIndexMaxDistance = r.from + 1;
    347399        for ( int i = r.from + 1; i < r.to; i++ )
     
    350402            const double fromVecX = p[i].x() - p[r.from].x();
    351403            const double fromVecY = p[i].y() - p[r.from].y();
    352             const double fromVecLength =
    353                 qSqrt( fromVecX * fromVecX + fromVecY * fromVecY );
    354 
     404
     405            double distToSegmentSqr;
    355406            if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
    356407            {
    357                 distToSegment = fromVecLength;
    358             }
    359             if ( fromVecX * unitVecX + fromVecY * unitVecY < 0.0 )
    360             {
    361                 distToSegment = fromVecLength;
     408                distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY;
    362409            }
    363410            else
     
    365412                const double toVecX = p[i].x() - p[r.to].x();
    366413                const double toVecY = p[i].y() - p[r.to].y();
    367                 const double toVecLength = qSqrt( toVecX * toVecX + toVecY * toVecY );
     414                const double toVecLength = toVecX * toVecX + toVecY * toVecY;
     415
    368416                const double s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY );
    369417                if ( s < 0.0 )
    370                     distToSegment = toVecLength;
     418                {
     419                    distToSegmentSqr = toVecLength;
     420                }
    371421                else
    372422                {
    373                     distToSegment = qSqrt( qFabs( toVecLength * toVecLength - s * s ) );
     423                    distToSegmentSqr = qFabs( toVecLength - s * s );
    374424                }
    375425            }
    376426
    377             if ( maxDist < distToSegment )
     427            if ( maxDistSqr < distToSegmentSqr )
    378428            {
    379                 maxDist = distToSegment;
     429                maxDistSqr = distToSegmentSqr;
    380430                nVertexIndexMaxDistance = i;
    381431            }
    382432        }
    383         if ( maxDist <= d_data->tolerance )
     433        if ( maxDistSqr <= toleranceSqr )
    384434        {
    385435            usePoint[r.from] = true;
     
    393443    }
    394444
    395     int cnt = 0;
    396 
    397     QPolygonF stripped( nPoints );
     445    QPolygonF stripped;
    398446    for ( int i = 0; i < nPoints; i++ )
    399447    {
    400448        if ( usePoint[i] )
    401             stripped[cnt++] = p[i];
    402     }
    403     stripped.resize( cnt );
     449            stripped += p[i];
     450    }
     451
    404452    return stripped;
    405453}
  • trunk/BNC/qwt/qwt_curve_fitter.h

    r4271 r8127  
    100100  smoothed curve.
    101101
     102  The runtime of the algorithm increases non linear ( worst case O( n*n ) )
     103  and might be very slow for huge polygons. To avoid performance issues
     104  it might be useful to split the polygon ( setChunkSize() ) and to run the algorithm
     105  for these smaller parts. The disadvantage of having no interpolation
     106  at the borders is for most use cases irrelevant.
     107
    102108  The smoothed curve consists of a subset of the points that defined the
    103109  original curve.
     
    117123    double tolerance() const;
    118124
     125    void setChunkSize( uint );
     126    uint chunkSize() const;
     127
    119128    virtual QPolygonF fitCurve( const QPolygonF & ) const;
    120129
    121130private:
     131    virtual QPolygonF simplify( const QPolygonF & ) const;
     132
    122133    class Line;
    123134
  • trunk/BNC/qwt/qwt_dyngrid_layout.cpp

    r4271 r8127  
    1010#include "qwt_dyngrid_layout.h"
    1111#include "qwt_math.h"
    12 #include <qwidget.h>
     12#include <qvector.h>
    1313#include <qlist.h>
    1414
     
    2525    mutable QList<QLayoutItem*> itemList;
    2626
    27     uint maxCols;
     27    uint maxColumns;
    2828    uint numRows;
    29     uint numCols;
     29    uint numColumns;
    3030
    3131    Qt::Orientations expanding;
     
    8282{
    8383    d_data = new QwtDynGridLayout::PrivateData;
    84     d_data->maxCols = d_data->numRows = d_data->numCols = 0;
     84    d_data->maxColumns = d_data->numRows = d_data->numColumns = 0;
    8585    d_data->expanding = 0;
    8686}
     
    105105/*!
    106106  Limit the number of columns.
    107   \param maxCols upper limit, 0 means unlimited
    108   \sa maxCols()
    109 */
    110 void QwtDynGridLayout::setMaxCols( uint maxCols )
    111 {
    112     d_data->maxCols = maxCols;
    113 }
    114 
    115 /*!
    116   Return the upper limit for the number of columns.
     107  \param maxColumns upper limit, 0 means unlimited
     108  \sa maxColumns()
     109*/
     110void QwtDynGridLayout::setMaxColumns( uint maxColumns )
     111{
     112    d_data->maxColumns = maxColumns;
     113}
     114
     115/*!
     116  \brief Return the upper limit for the number of columns.
     117
    117118  0 means unlimited, what is the default.
    118   \sa setMaxCols()
    119 */
    120 
    121 uint QwtDynGridLayout::maxCols() const
    122 {
    123     return d_data->maxCols;
    124 }
    125 
    126 //! Adds item to the next free position.
    127 
     119
     120  \return Upper limit for the number of columns
     121  \sa setMaxColumns()
     122*/
     123uint QwtDynGridLayout::maxColumns() const
     124{
     125    return d_data->maxColumns;
     126}
     127
     128/*!
     129  \brief Add an item to the next free position.
     130  \param item Layout item
     131 */
    128132void QwtDynGridLayout::addItem( QLayoutItem *item )
    129133{
     
    135139  \return true if this layout is empty.
    136140*/
    137 
    138141bool QwtDynGridLayout::isEmpty() const
    139142{
     
    144147  \return number of layout items
    145148*/
    146 
    147149uint QwtDynGridLayout::itemCount() const
    148150{
     
    151153
    152154/*!
    153   Find the item at a spcific index
     155  Find the item at a specific index
    154156
    155157  \param index Index
     158  \return Item at a specific index
    156159  \sa takeAt()
    157160*/
     
    165168
    166169/*!
    167   Find the item at a spcific index and remove it from the layout
     170  Find the item at a specific index and remove it from the layout
    168171
    169172  \param index Index
     173  \return Layout item, removed from the layout
    170174  \sa itemAt()
    171175*/
     
    200204
    201205/*!
    202   Returns whether this layout can make use of more space than sizeHint().
     206  \brief Returns whether this layout can make use of more space than sizeHint().
     207
    203208  A value of Qt::Vertical or Qt::Horizontal means that it wants to grow in only
    204209  one dimension, while Qt::Vertical | Qt::Horizontal means that it wants
    205210  to grow in both dimensions.
     211
     212  \return Orientations, where the layout expands
    206213  \sa setExpandingDirections()
    207214*/
     
    212219
    213220/*!
    214   Reorganizes columns and rows and resizes managed widgets within
    215   the rectangle rect.
     221  Reorganizes columns and rows and resizes managed items within
     222  a rectangle.
    216223
    217224  \param rect Layout geometry
     
    224231        return;
    225232
    226     d_data->numCols = columnsForWidth( rect.width() );
    227     d_data->numRows = itemCount() / d_data->numCols;
    228     if ( itemCount() % d_data->numCols )
     233    d_data->numColumns = columnsForWidth( rect.width() );
     234    d_data->numRows = itemCount() / d_data->numColumns;
     235    if ( itemCount() % d_data->numColumns )
    229236        d_data->numRows++;
    230237
    231     QList<QRect> itemGeometries = layoutItems( rect, d_data->numCols );
     238    QList<QRect> itemGeometries = layoutItems( rect, d_data->numColumns );
    232239
    233240    int index = 0;
     
    235242        it != d_data->itemList.end(); ++it )
    236243    {
    237         QWidget *w = ( *it )->widget();
    238         if ( w )
    239         {
    240             w->setGeometry( itemGeometries[index] );
    241             index++;
    242         }
    243     }
    244 }
    245 
    246 /*!
    247   Calculate the number of columns for a given width. It tries to
    248   use as many columns as possible (limited by maxCols())
     244        ( *it )->setGeometry( itemGeometries[index] );
     245        index++;
     246    }
     247}
     248
     249/*!
     250  \brief Calculate the number of columns for a given width.
     251
     252  The calculation tries to use as many columns as possible
     253  ( limited by maxColumns() )
    249254
    250255  \param width Available width for all columns
    251   \sa maxCols(), setMaxCols()
    252 */
    253 
     256  \return Number of columns for a given width
     257
     258  \sa maxColumns(), setMaxColumns()
     259*/
    254260uint QwtDynGridLayout::columnsForWidth( int width ) const
    255261{
     
    257263        return 0;
    258264
    259     const int maxCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount();
    260     if ( maxRowWidth( maxCols ) <= width )
    261         return maxCols;
    262 
    263     for ( int numCols = 2; numCols <= maxCols; numCols++ )
    264     {
    265         const int rowWidth = maxRowWidth( numCols );
     265    uint maxColumns = itemCount();
     266    if ( d_data->maxColumns > 0 )
     267        maxColumns = qMin( d_data->maxColumns, maxColumns );
     268
     269    if ( maxRowWidth( maxColumns ) <= width )
     270        return maxColumns;
     271
     272    for ( uint numColumns = 2; numColumns <= maxColumns; numColumns++ )
     273    {
     274        const int rowWidth = maxRowWidth( numColumns );
    266275        if ( rowWidth > width )
    267             return numCols - 1;
     276            return numColumns - 1;
    268277    }
    269278
     
    275284  columns.
    276285
    277   \param numCols Given number of columns
     286  \param numColumns Given number of columns
    278287  \param itemWidth Array of the width hints for all items
    279288*/
    280 int QwtDynGridLayout::maxRowWidth( int numCols ) const
     289int QwtDynGridLayout::maxRowWidth( int numColumns ) const
    281290{
    282291    int col;
    283292
    284     QVector<int> colWidth( numCols );
    285     for ( col = 0; col < numCols; col++ )
     293    QVector<int> colWidth( numColumns );
     294    for ( col = 0; col < numColumns; col++ )
    286295        colWidth[col] = 0;
    287296
     
    292301        index < d_data->itemSizeHints.count(); index++ )
    293302    {
    294         col = index % numCols;
     303        col = index % numColumns;
    295304        colWidth[col] = qMax( colWidth[col],
    296305            d_data->itemSizeHints[int( index )].width() );
    297306    }
    298307
    299     int rowWidth = 2 * margin() + ( numCols - 1 ) * spacing();
    300     for ( col = 0; col < numCols; col++ )
     308    int rowWidth = 2 * margin() + ( numColumns - 1 ) * spacing();
     309    for ( col = 0; col < numColumns; col++ )
    301310        rowWidth += colWidth[col];
    302311
     
    328337/*!
    329338  Calculate the geometries of the layout items for a layout
    330   with numCols columns and a given rect.
     339  with numColumns columns and a given rectangle.
    331340
    332341  \param rect Rect where to place the items
    333   \param numCols Number of columns
     342  \param numColumns Number of columns
    334343  \return item geometries
    335344*/
    336345
    337346QList<QRect> QwtDynGridLayout::layoutItems( const QRect &rect,
    338     uint numCols ) const
     347    uint numColumns ) const
    339348{
    340349    QList<QRect> itemGeometries;
    341     if ( numCols == 0 || isEmpty() )
     350    if ( numColumns == 0 || isEmpty() )
    342351        return itemGeometries;
    343352
    344     uint numRows = itemCount() / numCols;
    345     if ( numRows % itemCount() )
     353    uint numRows = itemCount() / numColumns;
     354    if ( numColumns % itemCount() )
    346355        numRows++;
    347356
     357    if ( numRows == 0 )
     358        return itemGeometries;
     359
    348360    QVector<int> rowHeight( numRows );
    349     QVector<int> colWidth( numCols );
    350 
    351     layoutGrid( numCols, rowHeight, colWidth );
     361    QVector<int> colWidth( numColumns );
     362
     363    layoutGrid( numColumns, rowHeight, colWidth );
    352364
    353365    bool expandH, expandV;
     
    356368
    357369    if ( expandH || expandV )
    358         stretchGrid( rect, numCols, rowHeight, colWidth );
    359 
    360     const int maxCols = d_data->maxCols;
    361     d_data->maxCols = numCols;
     370        stretchGrid( rect, numColumns, rowHeight, colWidth );
     371
     372    const int maxColumns = d_data->maxColumns;
     373    d_data->maxColumns = numColumns;
    362374    const QRect alignedRect = alignmentRect( rect );
    363     d_data->maxCols = maxCols;
     375    d_data->maxColumns = maxColumns;
    364376
    365377    const int xOffset = expandH ? 0 : alignedRect.x();
    366378    const int yOffset = expandV ? 0 : alignedRect.y();
    367379
    368     QVector<int> colX( numCols );
     380    QVector<int> colX( numColumns );
    369381    QVector<int> rowY( numRows );
    370382
     
    372384
    373385    rowY[0] = yOffset + margin();
    374     for ( int r = 1; r < ( int )numRows; r++ )
     386    for ( uint r = 1; r < numRows; r++ )
    375387        rowY[r] = rowY[r-1] + rowHeight[r-1] + xySpace;
    376388
    377389    colX[0] = xOffset + margin();
    378     for ( int c = 1; c < ( int )numCols; c++ )
     390    for ( uint c = 1; c < numColumns; c++ )
    379391        colX[c] = colX[c-1] + colWidth[c-1] + xySpace;
    380392
     
    382394    for ( int i = 0; i < itemCount; i++ )
    383395    {
    384         const int row = i / numCols;
    385         const int col = i % numCols;
     396        const int row = i / numColumns;
     397        const int col = i % numColumns;
    386398
    387399        QRect itemGeometry( colX[col], rowY[row],
     
    396408/*!
    397409  Calculate the dimensions for the columns and rows for a grid
    398   of numCols columns.
    399 
    400   \param numCols Number of columns.
     410  of numColumns columns.
     411
     412  \param numColumns Number of columns.
    401413  \param rowHeight Array where to fill in the calculated row heights.
    402414  \param colWidth Array where to fill in the calculated column widths.
    403415*/
    404416
    405 void QwtDynGridLayout::layoutGrid( uint numCols,
     417void QwtDynGridLayout::layoutGrid( uint numColumns,
    406418    QVector<int>& rowHeight, QVector<int>& colWidth ) const
    407419{
    408     if ( numCols <= 0 )
     420    if ( numColumns <= 0 )
    409421        return;
    410422
     
    412424        d_data->updateLayoutCache();
    413425
    414     for ( uint index = 0;
    415         index < ( uint )d_data->itemSizeHints.count(); index++ )
    416     {
    417         const int row = index / numCols;
    418         const int col = index % numCols;
     426    for ( int index = 0; index < d_data->itemSizeHints.count(); index++ )
     427    {
     428        const int row = index / numColumns;
     429        const int col = index % numColumns;
    419430
    420431        const QSize &size = d_data->itemSizeHints[int( index )];
     
    428439
    429440/*!
    430   \return true: QwtDynGridLayout implements heightForWidth.
     441  \return true: QwtDynGridLayout implements heightForWidth().
    431442  \sa heightForWidth()
    432443*/
     
    437448
    438449/*!
    439   \return The preferred height for this layout, given the width w.
     450  \return The preferred height for this layout, given a width.
    440451  \sa hasHeightForWidth()
    441452*/
     
    445456        return 0;
    446457
    447     const uint numCols = columnsForWidth( width );
    448     uint numRows = itemCount() / numCols;
    449     if ( itemCount() % numCols )
     458    const uint numColumns = columnsForWidth( width );
     459    uint numRows = itemCount() / numColumns;
     460    if ( itemCount() % numColumns )
    450461        numRows++;
    451462
    452463    QVector<int> rowHeight( numRows );
    453     QVector<int> colWidth( numCols );
    454 
    455     layoutGrid( numCols, rowHeight, colWidth );
     464    QVector<int> colWidth( numColumns );
     465
     466    layoutGrid( numColumns, rowHeight, colWidth );
    456467
    457468    int h = 2 * margin() + ( numRows - 1 ) * spacing();
    458     for ( int row = 0; row < ( int )numRows; row++ )
     469    for ( uint row = 0; row < numRows; row++ )
    459470        h += rowHeight[row];
    460471
     
    467478  rect. Rows and columns are stretched with the same factor.
    468479
     480  \param rect Bounding rectangle
     481  \param numColumns Number of columns
     482  \param rowHeight Array to be filled with the calculated row heights
     483  \param colWidth Array to be filled with the calculated column widths
     484
    469485  \sa setExpanding(), expanding()
    470486*/
    471487void QwtDynGridLayout::stretchGrid( const QRect &rect,
    472     uint numCols, QVector<int>& rowHeight, QVector<int>& colWidth ) const
    473 {
    474     if ( numCols == 0 || isEmpty() )
     488    uint numColumns, QVector<int>& rowHeight, QVector<int>& colWidth ) const
     489{
     490    if ( numColumns == 0 || isEmpty() )
    475491        return;
    476492
     
    481497    if ( expandH )
    482498    {
    483         int xDelta = rect.width() - 2 * margin() - ( numCols - 1 ) * spacing();
    484         for ( int col = 0; col < ( int )numCols; col++ )
     499        int xDelta = rect.width() - 2 * margin() - ( numColumns - 1 ) * spacing();
     500        for ( uint col = 0; col < numColumns; col++ )
    485501            xDelta -= colWidth[col];
    486502
    487503        if ( xDelta > 0 )
    488504        {
    489             for ( int col = 0; col < ( int )numCols; col++ )
     505            for ( uint col = 0; col < numColumns; col++ )
    490506            {
    491                 const int space = xDelta / ( numCols - col );
     507                const int space = xDelta / ( numColumns - col );
    492508                colWidth[col] += space;
    493509                xDelta -= space;
     
    498514    if ( expandV )
    499515    {
    500         uint numRows = itemCount() / numCols;
    501         if ( itemCount() % numCols )
     516        uint numRows = itemCount() / numColumns;
     517        if ( itemCount() % numColumns )
    502518            numRows++;
    503519
    504520        int yDelta = rect.height() - 2 * margin() - ( numRows - 1 ) * spacing();
    505         for ( int row = 0; row < ( int )numRows; row++ )
     521        for ( uint row = 0; row < numRows; row++ )
    506522            yDelta -= rowHeight[row];
    507523
    508524        if ( yDelta > 0 )
    509525        {
    510             for ( int row = 0; row < ( int )numRows; row++ )
     526            for ( uint row = 0; row < numRows; row++ )
    511527            {
    512528                const int space = yDelta / ( numRows - row );
     
    519535
    520536/*!
    521    Return the size hint. If maxCols() > 0 it is the size for
    522    a grid with maxCols() columns, otherwise it is the size for
     537   Return the size hint. If maxColumns() > 0 it is the size for
     538   a grid with maxColumns() columns, otherwise it is the size for
    523539   a grid with only one row.
    524540
    525    \sa maxCols(), setMaxCols()
     541   \return Size hint
     542   \sa maxColumns(), setMaxColumns()
    526543*/
    527544QSize QwtDynGridLayout::sizeHint() const
     
    530547        return QSize();
    531548
    532     const uint numCols = ( d_data->maxCols > 0 ) ? d_data->maxCols : itemCount();
    533     uint numRows = itemCount() / numCols;
    534     if ( itemCount() % numCols )
     549    uint numColumns = itemCount();
     550    if ( d_data->maxColumns > 0 )
     551        numColumns = qMin( d_data->maxColumns, numColumns );
     552
     553    uint numRows = itemCount() / numColumns;
     554    if ( itemCount() % numColumns )
    535555        numRows++;
    536556
    537557    QVector<int> rowHeight( numRows );
    538     QVector<int> colWidth( numCols );
    539 
    540     layoutGrid( numCols, rowHeight, colWidth );
     558    QVector<int> colWidth( numColumns );
     559
     560    layoutGrid( numColumns, rowHeight, colWidth );
    541561
    542562    int h = 2 * margin() + ( numRows - 1 ) * spacing();
    543     for ( int row = 0; row < ( int )numRows; row++ )
     563    for ( uint row = 0; row < numRows; row++ )
    544564        h += rowHeight[row];
    545565
    546     int w = 2 * margin() + ( numCols - 1 ) * spacing();
    547     for ( int col = 0; col < ( int )numCols; col++ )
     566    int w = 2 * margin() + ( numColumns - 1 ) * spacing();
     567    for ( uint col = 0; col < numColumns; col++ )
    548568        w += colWidth[col];
    549569
     
    553573/*!
    554574  \return Number of rows of the current layout.
    555   \sa numCols()
     575  \sa numColumns()
    556576  \warning The number of rows might change whenever the geometry changes
    557577*/
     
    566586  \warning The number of columns might change whenever the geometry changes
    567587*/
    568 uint QwtDynGridLayout::numCols() const
    569 {
    570     return d_data->numCols;
    571 }
     588uint QwtDynGridLayout::numColumns() const
     589{
     590    return d_data->numColumns;
     591}
  • trunk/BNC/qwt/qwt_dyngrid_layout.h

    r4271 r8127  
    2222  QwtDynGridLayout takes the space it gets, divides it up into rows and
    2323  columns, and puts each of the widgets it manages into the correct cell(s).
    24   It lays out as many number of columns as possible (limited by maxCols()).
     24  It lays out as many number of columns as possible (limited by maxColumns()).
    2525*/
    2626
     
    3636    virtual void invalidate();
    3737
    38     void setMaxCols( uint maxCols );
    39     uint maxCols() const;
     38    void setMaxColumns( uint maxCols );
     39    uint maxColumns() const;
    4040
    4141    uint numRows () const;
    42     uint numCols () const;
     42    uint numColumns () const;
    4343
    4444    virtual void addItem( QLayoutItem * );
  • trunk/BNC/qwt/qwt_event_pattern.cpp

    r4271 r8127  
    3838void QwtEventPattern::initMousePattern( int numButtons )
    3939{
    40     const int altButton = Qt::AltModifier;
    41     const int controlButton = Qt::ControlModifier;
    42     const int shiftButton = Qt::ShiftModifier;
    43 
    4440    d_mousePattern.resize( MousePatternCount );
    4541
     
    4945        {
    5046            setMousePattern( MouseSelect1, Qt::LeftButton );
    51             setMousePattern( MouseSelect2, Qt::LeftButton, controlButton );
    52             setMousePattern( MouseSelect3, Qt::LeftButton, altButton );
     47            setMousePattern( MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
     48            setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
    5349            break;
    5450        }
     
    5753            setMousePattern( MouseSelect1, Qt::LeftButton );
    5854            setMousePattern( MouseSelect2, Qt::RightButton );
    59             setMousePattern( MouseSelect3, Qt::LeftButton, altButton );
     55            setMousePattern( MouseSelect3, Qt::LeftButton, Qt::AltModifier );
    6056            break;
    6157        }
     
    6763        }
    6864    }
    69     for ( int i = 0; i < 3; i++ )
    70     {
    71         setMousePattern( MouseSelect4 + i,
    72                          d_mousePattern[MouseSelect1 + i].button,
    73                          d_mousePattern[MouseSelect1 + i].state | shiftButton );
    74     }
     65
     66    setMousePattern( MouseSelect4, d_mousePattern[MouseSelect1].button,
     67        d_mousePattern[MouseSelect1].modifiers | Qt::ShiftModifier );
     68
     69    setMousePattern( MouseSelect5, d_mousePattern[MouseSelect2].button,
     70        d_mousePattern[MouseSelect2].modifiers | Qt::ShiftModifier );
     71
     72    setMousePattern( MouseSelect6, d_mousePattern[MouseSelect3].button,
     73        d_mousePattern[MouseSelect3].modifiers | Qt::ShiftModifier );
    7574}
    7675
     
    103102  \param pattern Index of the pattern
    104103  \param button Button
    105   \param state State
     104  \param modifiers Keyboard modifiers
    106105
    107106  \sa QMouseEvent
    108107*/
    109 void QwtEventPattern::setMousePattern( uint pattern, int button, int state )
    110 {
    111     if ( pattern < ( uint )d_mousePattern.count() )
     108void QwtEventPattern::setMousePattern( MousePatternCode pattern,
     109    Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
     110{
     111    if ( pattern >= 0 && pattern < MousePatternCount )
    112112    {
    113         d_mousePattern[int( pattern )].button = button;
    114         d_mousePattern[int( pattern )].state = state;
     113        d_mousePattern[ pattern ].button = button;
     114        d_mousePattern[ pattern ].modifiers = modifiers;
    115115    }
    116116}
     
    121121  \param pattern Index of the pattern
    122122  \param key Key
    123   \param state State
     123  \param modifiers Keyboard modifiers
    124124
    125125  \sa QKeyEvent
    126126*/
    127 void QwtEventPattern::setKeyPattern( uint pattern, int key, int state )
    128 {
    129     if ( pattern < ( uint )d_keyPattern.count() )
     127void QwtEventPattern::setKeyPattern( KeyPatternCode pattern,
     128    int key, Qt::KeyboardModifiers modifiers )
     129{
     130    if ( pattern >= 0 && pattern < KeyPatternCount )
    130131    {
    131         d_keyPattern[int( pattern )].key = key;
    132         d_keyPattern[int( pattern )].state = state;
     132        d_keyPattern[ pattern ].key = key;
     133        d_keyPattern[ pattern ].modifiers = modifiers;
    133134    }
    134135}
     
    146147}
    147148
    148 //! Return mouse patterns
     149//! \return Mouse pattern
    149150const QVector<QwtEventPattern::MousePattern> &
    150151QwtEventPattern::mousePattern() const
     
    153154}
    154155
    155 //! Return key patterns
     156//! \return Key pattern
    156157const QVector<QwtEventPattern::KeyPattern> &
    157158QwtEventPattern::keyPattern() const
     
    160161}
    161162
    162 //! Return ,ouse patterns
     163//! \return Mouse pattern
    163164QVector<QwtEventPattern::MousePattern> &QwtEventPattern::mousePattern()
    164165{
     
    166167}
    167168
    168 //! Return Key patterns
     169//! \return Key pattern
    169170QVector<QwtEventPattern::KeyPattern> &QwtEventPattern::keyPattern()
    170171{
     
    179180  are set.
    180181
    181   \param pattern Index of the event pattern
     182  \param code Index of the event pattern
    182183  \param event Mouse event
    183184  \return true if matches
     
    185186  \sa keyMatch()
    186187*/
    187 bool QwtEventPattern::mouseMatch( uint pattern,
     188bool QwtEventPattern::mouseMatch( MousePatternCode code,
    188189    const QMouseEvent *event ) const
    189190{
    190     bool ok = false;
    191 
    192     if ( event && pattern < ( uint )d_mousePattern.count() )
    193         ok = mouseMatch( d_mousePattern[int( pattern )], event );
    194 
    195     return ok;
     191    if ( code >= 0 && code < MousePatternCount )
     192        return mouseMatch( d_mousePattern[ code ], event );
     193
     194    return false;
    196195}
    197196
     
    213212    const QMouseEvent *event ) const
    214213{
    215     if ( event->button() != pattern.button )
     214    if ( event == NULL )
    216215        return false;
    217216
    218     const bool matched =
    219         ( event->modifiers() & Qt::KeyboardModifierMask ) ==
    220             ( int )( pattern.state & Qt::KeyboardModifierMask );
    221 
    222     return matched;
     217    const MousePattern mousePattern( event->button(), event->modifiers() );
     218    return mousePattern == pattern;
    223219}
    224220
     
    230226  are set.
    231227
    232   \param pattern Index of the event pattern
     228  \param code Index of the event pattern
    233229  \param event Key event
    234230  \return true if matches
     
    236232  \sa mouseMatch()
    237233*/
    238 bool QwtEventPattern::keyMatch( uint pattern,
     234bool QwtEventPattern::keyMatch( KeyPatternCode code,
    239235    const QKeyEvent *event ) const
    240236{
    241     bool ok = false;
    242 
    243     if ( event && pattern < ( uint )d_keyPattern.count() )
    244         ok = keyMatch( d_keyPattern[int( pattern )], event );
    245 
    246     return ok;
     237    if ( code >= 0 && code < KeyPatternCount )
     238        return keyMatch( d_keyPattern[ code ], event );
     239
     240    return false;
    247241}
    248242
     
    264258    const KeyPattern &pattern, const QKeyEvent *event ) const
    265259{
    266     if ( event->key() != pattern.key )
     260    if ( event == NULL )
    267261        return false;
    268262
    269     const bool matched =
    270         ( event->modifiers() & Qt::KeyboardModifierMask ) ==
    271             ( int )( pattern.state & Qt::KeyboardModifierMask );
    272 
    273     return matched;
    274 }
     263    const KeyPattern keyPattern( event->key(), event->modifiers() );
     264    return keyPattern == pattern;
     265}
  • trunk/BNC/qwt/qwt_event_pattern.h

    r4271 r8127  
    3333      \brief Symbolic mouse input codes
    3434
    35       The default initialization for 3 button mice is:
    36       - MouseSelect1\n
    37         Qt::LeftButton
    38       - MouseSelect2\n
    39         Qt::RightButton
    40       - MouseSelect3\n
    41         Qt::MidButton
    42       - MouseSelect4\n
    43         Qt::LeftButton + Qt::ShiftButton
    44       - MouseSelect5\n
    45         Qt::RightButton + Qt::ShiftButton
    46       - MouseSelect6\n
    47         Qt::MidButton + Qt::ShiftButton
    48 
    49       The default initialization for 2 button mice is:
    50       - MouseSelect1\n
    51         Qt::LeftButton
    52       - MouseSelect2\n
    53         Qt::RightButton
    54       - MouseSelect3\n
    55         Qt::LeftButton + Qt::AltButton
    56       - MouseSelect4\n
    57         Qt::LeftButton + Qt::ShiftButton
    58       - MouseSelect5\n
    59         Qt::RightButton + Qt::ShiftButton
    60       - MouseSelect6\n
    61         Qt::LeftButton + Qt::AltButton + Qt::ShiftButton
    62 
    63       The default initialization for 1 button mice is:
    64       - MouseSelect1\n
    65         Qt::LeftButton
    66       - MouseSelect2\n
    67         Qt::LeftButton + Qt::ControlButton
    68       - MouseSelect3\n
    69         Qt::LeftButton + Qt::AltButton
    70       - MouseSelect4\n
    71         Qt::LeftButton + Qt::ShiftButton
    72       - MouseSelect5\n
    73         Qt::LeftButton + Qt::ControlButton + Qt::ShiftButton
    74       - MouseSelect6\n
    75         Qt::LeftButton + Qt::AltButton + Qt::ShiftButton
    76 
    77       \sa initMousePattern()
     35      QwtEventPattern implements 3 different settings for
     36      mice with 1, 2, or 3 buttons that can be activated
     37      using initMousePattern(). The default setting is for
     38      3 button mice.
     39
     40      Individual settings can be configured using setMousePattern().
     41
     42      \sa initMousePattern(), setMousePattern(), setKeyPattern()
    7843    */
    79 
    8044    enum MousePatternCode
    8145    {
     46        /*!
     47          The default setting for 1, 2 and 3 button mice is:
     48
     49          - Qt::LeftButton
     50          - Qt::LeftButton
     51          - Qt::LeftButton
     52         */
    8253        MouseSelect1,
     54
     55        /*!
     56          The default setting for 1, 2 and 3 button mice is:
     57
     58          - Qt::LeftButton + Qt::ControlModifier
     59          - Qt::RightButton
     60          - Qt::RightButton
     61         */
    8362        MouseSelect2,
     63
     64        /*!
     65          The default setting for 1, 2 and 3 button mice is:
     66
     67          - Qt::LeftButton + Qt::AltModifier
     68          - Qt::LeftButton + Qt::AltModifier
     69          - Qt::MidButton
     70         */
    8471        MouseSelect3,
     72
     73        /*!
     74          The default setting for 1, 2 and 3 button mice is:
     75
     76          - Qt::LeftButton + Qt::ShiftModifier
     77          - Qt::LeftButton + Qt::ShiftModifier
     78          - Qt::LeftButton + Qt::ShiftModifier
     79         */
    8580        MouseSelect4,
     81
     82        /*!
     83          The default setting for 1, 2 and 3 button mice is:
     84
     85          - Qt::LeftButton + Qt::ControlButton | Qt::ShiftModifier
     86          - Qt::RightButton + Qt::ShiftModifier
     87          - Qt::RightButton + Qt::ShiftModifier
     88         */
    8689        MouseSelect5,
     90
     91        /*!
     92          The default setting for 1, 2 and 3 button mice is:
     93
     94          - Qt::LeftButton + Qt::AltModifier + Qt::ShiftModifier
     95          - Qt::LeftButton + Qt::AltModifier | Qt::ShiftModifier
     96          - Qt::MidButton + Qt::ShiftModifier
     97         */
    8798        MouseSelect6,
    8899
     100        //! Number of mouse patterns
    89101        MousePatternCount
    90102    };
     
    93105      \brief Symbolic keyboard input codes
    94106
    95       Default initialization:
    96       - KeySelect1\n
    97         Qt::Key_Return
    98       - KeySelect2\n
    99         Qt::Key_Space
    100       - KeyAbort\n
    101         Qt::Key_Escape
    102 
    103       - KeyLeft\n
    104         Qt::Key_Left
    105       - KeyRight\n
    106         Qt::Key_Right
    107       - KeyUp\n
    108         Qt::Key_Up
    109       - KeyDown\n
    110         Qt::Key_Down
    111 
    112       - KeyUndo\n
    113         Qt::Key_Minus
    114       - KeyRedo\n
    115         Qt::Key_Plus
    116       - KeyHome\n
    117         Qt::Key_Escape
     107      Individual settings can be configured using setKeyPattern()
     108
     109      \sa setKeyPattern(), setMousePattern()
    118110    */
    119111    enum KeyPatternCode
    120112    {
     113        //! Qt::Key_Return
    121114        KeySelect1,
     115
     116        //! Qt::Key_Space
    122117        KeySelect2,
     118
     119        //! Qt::Key_Escape
    123120        KeyAbort,
    124121
     122        //! Qt::Key_Left
    125123        KeyLeft,
     124
     125        //! Qt::Key_Right
    126126        KeyRight,
     127
     128        //! Qt::Key_Up
    127129        KeyUp,
     130
     131        //! Qt::Key_Down
    128132        KeyDown,
    129133
     134        //! Qt::Key_Plus
    130135        KeyRedo,
     136
     137        //! Qt::Key_Minus
    131138        KeyUndo,
     139
     140        //! Qt::Key_Escape
    132141        KeyHome,
    133142
     143        //! Number of key patterns
    134144        KeyPatternCount
    135145    };
     
    140150    public:
    141151        //! Constructor
    142         MousePattern( int btn = Qt::NoButton, int st = Qt::NoButton )
     152        MousePattern( Qt::MouseButton btn = Qt::NoButton,
     153                Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
     154            button( btn ),
     155            modifiers( modifierCodes )
    143156        {
    144             button = btn;
    145             state = st;
    146157        }
    147158
    148         //! Button code
    149         int button;
    150 
    151         //! State
    152         int state;
     159        //! Button
     160        Qt::MouseButton button;
     161
     162        //! Keyboard modifier
     163        Qt::KeyboardModifiers modifiers;
    153164    };
    154165
     
    158169    public:
    159170        //! Constructor
    160         KeyPattern( int k = 0, int st = Qt::NoButton )
     171        KeyPattern( int keyCode = Qt::Key_unknown,
     172                Qt::KeyboardModifiers modifierCodes = Qt::NoModifier ):
     173            key( keyCode ),
     174            modifiers( modifierCodes )
    161175        {
    162             key = k;
    163             state = st;
    164176        }
    165177
     
    167179        int key;
    168180
    169         //! State
    170         int state;
     181        //! Modifiers
     182        Qt::KeyboardModifiers modifiers;
    171183    };
    172184
     
    177189    void initKeyPattern();
    178190
    179     void setMousePattern( uint pattern, int button, int state = Qt::NoButton );
    180     void setKeyPattern( uint pattern, int key, int state = Qt::NoButton );
     191    void setMousePattern( MousePatternCode, Qt::MouseButton button,
     192        Qt::KeyboardModifiers = Qt::NoModifier );
     193
     194    void setKeyPattern( KeyPatternCode, int keyCode,
     195        Qt::KeyboardModifiers modifierCodes = Qt::NoModifier );
    181196
    182197    void setMousePattern( const QVector<MousePattern> & );
     
    189204    QVector<KeyPattern> &keyPattern();
    190205
    191     bool mouseMatch( uint pattern, const QMouseEvent * ) const;
    192     bool keyMatch( uint pattern, const QKeyEvent * ) const;
     206    bool mouseMatch( MousePatternCode, const QMouseEvent * ) const;
     207    bool keyMatch( KeyPatternCode, const QKeyEvent * ) const;
    193208
    194209protected:
     
    213228    QwtEventPattern::MousePattern  b2 )
    214229{
    215     return b1.button == b2.button && b1.state == b2.state;
     230    return b1.button == b2.button && b1.modifiers == b2.modifiers;
    216231}
    217232
     
    220235   QwtEventPattern::KeyPattern  b2 )
    221236{
    222     return b1.key == b2.key && b1.state == b2.state;
     237    return b1.key == b2.key && b1.modifiers == b2.modifiers;
    223238}
    224239
  • trunk/BNC/qwt/qwt_global.h

    r4271 r8127  
    1515// QWT_VERSION is (major << 16) + (minor << 8) + patch.
    1616
    17 #define QWT_VERSION       0x060001
    18 #define QWT_VERSION_STR   "6.0.1"
    19 
    20 #if defined(Q_WS_WIN) || defined(Q_WS_S60)
     17#define QWT_VERSION       0x060104
     18#define QWT_VERSION_STR   "6.1.4"
    2119
    2220#if defined(_MSC_VER) /* MSVC Compiler */
    2321/* template-class specialization 'identifier' is already instantiated */
    2422#pragma warning(disable: 4660)
     23/* inherits via dominance */
     24#pragma warning(disable: 4250)
    2525#endif // _MSC_VER
    2626
     
    2828
    2929#if defined(QWT_MAKEDLL)     // create a Qwt DLL library
    30 #define QWT_EXPORT  __declspec(dllexport)
    31 #define QWT_TEMPLATEDLL
     30#define QWT_EXPORT Q_DECL_EXPORT
    3231#else                        // use a Qwt DLL library
    33 #define QWT_EXPORT  __declspec(dllimport)
     32#define QWT_EXPORT Q_DECL_IMPORT
    3433#endif
    3534
    3635#endif // QWT_DLL
    37 
    38 #endif // Q_WS_WIN || Q_WS_S60
    3936
    4037#ifndef QWT_EXPORT
     
    4239#endif
    4340
    44 // #define QWT_NO_COMPAT 1 // disable withdrawn functionality
    45 
    4641#endif
  • trunk/BNC/qwt/qwt_interval.cpp

    r4271 r8127  
    1313
    1414/*!
    15    \brief Normalize the limits of the interval
    16 
    17    If maxValue() < minValue() the limits will be inverted.
    18    \return Normalized interval
    19 
    20    \sa isValid(), inverted()
     15  \brief Normalize the limits of the interval
     16
     17  If maxValue() < minValue() the limits will be inverted.
     18  \return Normalized interval
     19
     20  \sa isValid(), inverted()
    2121*/
    2222QwtInterval QwtInterval::normalized() const
     
    3535
    3636/*!
    37    Invert the limits of the interval
    38    \return Inverted interval
    39    \sa normalized()
     37  Invert the limits of the interval
     38  \return Inverted interval
     39  \sa normalized()
    4040*/
    4141QwtInterval QwtInterval::inverted() const
     
    131131}
    132132
    133 //! Intersect 2 intervals
     133/*!
     134  \brief Intersect 2 intervals
     135 
     136  \param other Interval to be intersect with
     137  \return Intersection
     138 */
    134139QwtInterval QwtInterval::intersect( const QwtInterval &other ) const
    135140{
     
    193198}
    194199
    195 //! Unites this interval with the given interval.
    196 QwtInterval& QwtInterval::operator|=( const QwtInterval & interval )
    197 {
    198     *this = *this | interval;
     200/*!
     201  \brief Unite this interval with the given interval.
     202
     203  \param other Interval to be united with
     204  \return This interval
     205 */
     206QwtInterval& QwtInterval::operator|=( const QwtInterval &other )
     207{
     208    *this = *this | other;
    199209    return *this;
    200210}
    201211
    202 //! Intersects this interval with the given interval.
    203 QwtInterval& QwtInterval::operator&=( const QwtInterval & interval )
    204 {
    205     *this = *this & interval;
     212/*!
     213  \brief Intersect this interval with the given interval.
     214
     215  \param other Interval to be intersected with
     216  \return This interval
     217 */
     218QwtInterval& QwtInterval::operator&=( const QwtInterval &other )
     219{
     220    *this = *this & other;
    206221    return *this;
    207222}
    208223
    209224/*!
    210    Test if two intervals overlap
     225  \brief Test if two intervals overlap
     226
     227  \param other Interval
     228  \return True, when the intervals are intersecting
    211229*/
    212230bool QwtInterval::intersects( const QwtInterval &other ) const
     
    244262
    245263/*!
    246    Adjust the limit that is closer to value, so that value becomes
    247    the center of the interval.
    248 
    249    \param value Center
    250    \return Interval with value as center
     264  Adjust the limit that is closer to value, so that value becomes
     265  the center of the interval.
     266
     267  \param value Center
     268  \return Interval with value as center
    251269*/
    252270QwtInterval QwtInterval::symmetrize( double value ) const
     
    262280
    263281/*!
    264    Limit the interval, keeping the border modes
    265 
    266    \param lowerBound Lower limit
    267    \param upperBound Upper limit
    268 
    269    \return Limited interval
     282  Limit the interval, keeping the border modes
     283
     284  \param lowerBound Lower limit
     285  \param upperBound Upper limit
     286
     287  \return Limited interval
    270288*/
    271289QwtInterval QwtInterval::limited( double lowerBound, double upperBound ) const
     
    284302
    285303/*!
    286    Extend the interval
    287 
    288    If value is below minValue, value becomes the lower limit.
    289    If value is above maxValue, value becomes the upper limit.
    290 
    291    extend has no effect for invalid intervals
    292 
    293    \param value Value
    294    \sa isValid()
     304  \brief Extend the interval
     305
     306  If value is below minValue(), value becomes the lower limit.
     307  If value is above maxValue(), value becomes the upper limit.
     308
     309  extend() has no effect for invalid intervals
     310
     311  \param value Value
     312  \return extended interval
     313
     314  \sa isValid()
    295315*/
    296316QwtInterval QwtInterval::extend( double value ) const
     
    304324
    305325/*!
    306    Extend an interval
    307 
    308    \param value Value
    309    \return Reference of the extended interval
    310 
    311    \sa extend()
     326  Extend an interval
     327
     328  \param value Value
     329  \return Reference of the extended interval
     330
     331  \sa extend()
    312332*/
    313333QwtInterval& QwtInterval::operator|=( double value )
  • trunk/BNC/qwt/qwt_interval.h

    r4271 r8127  
    1212
    1313#include "qwt_global.h"
     14#include <qmetatype.h>
     15
    1416#ifndef QT_NO_DEBUG_STREAM
    1517#include <qdebug.h>
     
    200202
    201203/*!
    202    Return the width of an interval
    203    The width of invalid intervals is 0.0, otherwise the result is
    204    maxValue() - minValue().
    205 
    206    \sa isValid()
    207 */
    208 inline double QwtInterval::width() const
    209 {
    210     return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
    211 }
    212 
    213 /*!
    214    Intersection of two intervals
    215    \sa intersect()
    216 */
    217 inline QwtInterval QwtInterval::operator&(
    218     const QwtInterval &interval ) const
    219 {
    220     return intersect( interval );
    221 }
    222 
    223 /*!
    224    Union of two intervals
    225    \sa unite()
    226 */
    227 inline QwtInterval QwtInterval::operator|(
    228     const QwtInterval &interval ) const
    229 {
    230     return unite( interval );
    231 }
    232 
    233 //! Compare two intervals
    234 inline bool QwtInterval::operator==( const QwtInterval &other ) const
    235 {
    236     return ( d_minValue == other.d_minValue ) &&
    237            ( d_maxValue == other.d_maxValue ) &&
    238            ( d_borderFlags == other.d_borderFlags );
    239 }
    240 
    241 //! Compare two intervals
    242 inline bool QwtInterval::operator!=( const QwtInterval &other ) const
    243 {
    244     return ( !( *this == other ) );
    245 }
    246 
    247 /*!
    248    Extend an interval
    249 
    250    \param value Value
    251    \return Extended interval
    252    \sa extend()
    253 */
    254 inline QwtInterval QwtInterval::operator|( double value ) const
    255 {
    256     return extend( value );
    257 }
    258 
    259 //! \return true, if isValid() && (minValue() >= maxValue())
    260 inline bool QwtInterval::isNull() const
    261 {
    262     return isValid() && d_minValue >= d_maxValue;
    263 }
    264 
    265 /*!
    266204   A interval is valid when minValue() <= maxValue().
    267205   In case of QwtInterval::ExcludeBorders it is true
    268206   when minValue() < maxValue()
     207
     208   \return True, when the interval is valid
    269209*/
    270210inline bool QwtInterval::isValid() const
     
    277217
    278218/*!
     219   \brief Return the width of an interval
     220
     221   The width of invalid intervals is 0.0, otherwise the result is
     222   maxValue() - minValue().
     223
     224   \return Interval width
     225   \sa isValid()
     226*/
     227inline double QwtInterval::width() const
     228{
     229    return isValid() ? ( d_maxValue - d_minValue ) : 0.0;
     230}
     231
     232/*!
     233   \brief Intersection of two intervals
     234 
     235   \param other Interval to intersect with
     236   \return Intersection of this and other
     237
     238   \sa intersect()
     239*/
     240inline QwtInterval QwtInterval::operator&(
     241    const QwtInterval &other ) const
     242{
     243    return intersect( other );
     244}
     245
     246/*!
     247   Union of two intervals
     248
     249   \param other Interval to unite with
     250   \return Union of this and other
     251
     252   \sa unite()
     253*/
     254inline QwtInterval QwtInterval::operator|(
     255    const QwtInterval &other ) const
     256{
     257    return unite( other );
     258}
     259
     260/*!
     261   \brief Compare two intervals
     262
     263   \param other Interval to compare with
     264   \return True, when this and other are equal
     265*/
     266inline bool QwtInterval::operator==( const QwtInterval &other ) const
     267{
     268    return ( d_minValue == other.d_minValue ) &&
     269           ( d_maxValue == other.d_maxValue ) &&
     270           ( d_borderFlags == other.d_borderFlags );
     271}
     272/*!
     273   \brief Compare two intervals
     274
     275   \param other Interval to compare with
     276   \return True, when this and other are not equal
     277*/
     278inline bool QwtInterval::operator!=( const QwtInterval &other ) const
     279{
     280    return ( !( *this == other ) );
     281}
     282
     283/*!
     284   Extend an interval
     285
     286   \param value Value
     287   \return Extended interval
     288   \sa extend()
     289*/
     290inline QwtInterval QwtInterval::operator|( double value ) const
     291{
     292    return extend( value );
     293}
     294
     295//! \return true, if isValid() && (minValue() >= maxValue())
     296inline bool QwtInterval::isNull() const
     297{
     298    return isValid() && d_minValue >= d_maxValue;
     299}
     300
     301/*!
    279302  Invalidate the interval
    280303
     
    289312
    290313Q_DECLARE_OPERATORS_FOR_FLAGS( QwtInterval::BorderFlags )
     314Q_DECLARE_METATYPE( QwtInterval )
    291315
    292316#ifndef QT_NO_DEBUG_STREAM
  • trunk/BNC/qwt/qwt_interval_symbol.cpp

    r4271 r8127  
    1515#if QT_VERSION < 0x040601
    1616#define qAtan2(y, x) ::atan2(y, x)
     17#define qFastSin(x) qSin(x)
     18#define qFastCos(x) qCos(x)
    1719#endif
    1820
     
    149151{
    150152    return d_data->brush;
     153}
     154
     155/*!
     156  Build and assign a pen
     157   
     158  In Qt5 the default pen width is 1.0 ( 0.0 in Qt4 ) what makes it
     159  non cosmetic ( see QPen::isCosmetic() ). This method has been introduced
     160  to hide this incompatibility.
     161
     162  \param color Pen color
     163  \param width Pen width
     164  \param style Pen style
     165   
     166  \sa pen(), brush()
     167 */
     168void QwtIntervalSymbol::setPen( const QColor &color,
     169    qreal width, Qt::PenStyle style )
     170{   
     171    setPen( QPen( color, width, style ) );
    151172}
    152173
     
    232253                    double dw2 = sw / 2.0;
    233254
    234                     const double cx = qCos( angle ) * dw2;
    235                     const double sy = qSin( angle ) * dw2;
     255                    const double cx = qFastCos( angle ) * dw2;
     256                    const double sy = qFastSin( angle ) * dw2;
    236257
    237258                    QwtPainter::drawLine( painter,
     
    280301                    double dw2 = sw / 2.0;
    281302
    282                     const int cx = qCos( angle ) * dw2;
    283                     const int sy = qSin( angle ) * dw2;
     303                    const double cx = qFastCos( angle ) * dw2;
     304                    const double sy = qFastSin( angle ) * dw2;
    284305
    285306                    QPolygonF polygon;
  • trunk/BNC/qwt/qwt_interval_symbol.h

    r4271 r8127  
    6969    const QBrush& brush() const;
    7070
     71    void setPen( const QColor &, qreal width = 0.0, Qt::PenStyle = Qt::SolidLine );
    7172    void setPen( const QPen & );
    7273    const QPen& pen() const;
  • trunk/BNC/qwt/qwt_legend.cpp

    r4271 r8127  
    99
    1010#include "qwt_legend.h"
    11 #include "qwt_legend_itemmanager.h"
    12 #include "qwt_legend_item.h"
     11#include "qwt_legend_label.h"
    1312#include "qwt_dyngrid_layout.h"
    1413#include "qwt_math.h"
     14#include "qwt_plot_item.h"
     15#include "qwt_painter.h"
    1516#include <qapplication.h>
    16 #include <qmap.h>
    1717#include <qscrollbar.h>
    1818#include <qscrollarea.h>
     19#include <qpainter.h>
     20#include <qstyle.h>
     21#include <qstyleoption.h>
     22
     23class QwtLegendMap
     24{
     25public:
     26    inline bool isEmpty() const { return d_entries.isEmpty(); }
     27
     28    void insert( const QVariant &, const QList<QWidget *> & );
     29    void remove( const QVariant & );
     30
     31    void removeWidget( const QWidget * );
     32
     33    QList<QWidget *> legendWidgets( const QVariant & ) const;
     34    QVariant itemInfo( const QWidget * ) const;
     35
     36private:
     37    // we don't know anything about itemInfo and therefore don't have
     38    // any key that can be used for a map or hashtab.
     39    // But a simple linear list is o.k. here, as we will never have
     40    // more than a few entries.
     41
     42    class Entry
     43    {
     44    public:
     45        QVariant itemInfo;
     46        QList<QWidget *> widgets;
     47    };
     48
     49    QList< Entry > d_entries;
     50};
     51
     52void QwtLegendMap::insert( const QVariant &itemInfo,
     53    const QList<QWidget *> &widgets )
     54{
     55    for ( int i = 0; i < d_entries.size(); i++ )
     56    {
     57        Entry &entry = d_entries[i];
     58        if ( entry.itemInfo == itemInfo )
     59        {
     60            entry.widgets = widgets;
     61            return;
     62        }
     63    }
     64
     65    Entry newEntry;
     66    newEntry.itemInfo = itemInfo;
     67    newEntry.widgets = widgets;
     68
     69    d_entries += newEntry;
     70}
     71
     72void QwtLegendMap::remove( const QVariant &itemInfo )
     73{
     74    for ( int i = 0; i < d_entries.size(); i++ )
     75    {
     76        Entry &entry = d_entries[i];
     77        if ( entry.itemInfo == itemInfo )
     78        {
     79            d_entries.removeAt( i );
     80            return;
     81        }
     82    }
     83}
     84
     85void QwtLegendMap::removeWidget( const QWidget *widget )
     86{
     87    QWidget *w = const_cast<QWidget *>( widget );
     88
     89    for ( int i = 0; i < d_entries.size(); i++ )
     90        d_entries[ i ].widgets.removeAll( w );
     91}
     92
     93QVariant QwtLegendMap::itemInfo( const QWidget *widget ) const
     94{
     95    if ( widget != NULL )
     96    {
     97        QWidget *w = const_cast<QWidget *>( widget );
     98
     99        for ( int i = 0; i < d_entries.size(); i++ )
     100        {
     101            const Entry &entry = d_entries[i];
     102            if ( entry.widgets.indexOf( w ) >= 0 )
     103                return entry.itemInfo;
     104        }
     105    }
     106
     107    return QVariant();
     108}
     109
     110QList<QWidget *> QwtLegendMap::legendWidgets( const QVariant &itemInfo ) const
     111{
     112    if ( itemInfo.isValid() )
     113    {
     114        for ( int i = 0; i < d_entries.size(); i++ )
     115        {
     116            const Entry &entry = d_entries[i];
     117            if ( entry.itemInfo == itemInfo )
     118                return entry.widgets;
     119        }
     120    }
     121
     122    return QList<QWidget *>();
     123}
    19124
    20125class QwtLegend::PrivateData
    21126{
    22127public:
    23     class LegendMap
    24     {
    25     public:
    26         void insert( const QwtLegendItemManager *, QWidget * );
    27 
    28         void remove( const QwtLegendItemManager * );
    29         void remove( QWidget * );
    30 
    31         void clear();
    32 
    33         uint count() const;
    34 
    35         inline const QWidget *find( const QwtLegendItemManager * ) const;
    36         inline QWidget *find( const QwtLegendItemManager * );
    37 
    38         inline const QwtLegendItemManager *find( const QWidget * ) const;
    39         inline QwtLegendItemManager *find( const QWidget * );
    40 
    41         const QMap<QWidget *, const QwtLegendItemManager *> &widgetMap() const;
    42         QMap<QWidget *, const QwtLegendItemManager *> &widgetMap();
    43 
    44     private:
    45         QMap<QWidget *, const QwtLegendItemManager *> d_widgetMap;
    46         QMap<const QwtLegendItemManager *, QWidget *> d_itemMap;
    47     };
    48 
    49     QwtLegend::LegendItemMode itemMode;
    50 
    51     LegendMap map;
     128    PrivateData():
     129        itemMode( QwtLegendData::ReadOnly ),
     130        view( NULL )
     131    {
     132    }
     133
     134    QwtLegendData::Mode itemMode;
     135    QwtLegendMap itemMap;
    52136
    53137    class LegendView;
     
    61145        QScrollArea( parent )
    62146    {
    63         setFocusPolicy( Qt::NoFocus );
    64 
    65147        contentsWidget = new QWidget( this );
    66148        contentsWidget->setObjectName( "QwtLegendViewContents" );
     
    77159    }
    78160
    79     virtual bool viewportEvent( QEvent *e )
    80     {
    81         bool ok = QScrollArea::viewportEvent( e );
    82 
    83         if ( e->type() == QEvent::Resize )
    84         {
    85             QEvent event( QEvent::LayoutRequest );
    86             QApplication::sendEvent( contentsWidget, &event );
     161    virtual bool event( QEvent *event )
     162    {
     163        if ( event->type() == QEvent::PolishRequest )
     164        {
     165            setFocusPolicy( Qt::NoFocus );
     166        }
     167
     168        if ( event->type() == QEvent::Resize )
     169        {
     170            // adjust the size to en/disable the scrollbars
     171            // before QScrollArea adjusts the viewport size
     172
     173            const QRect cr = contentsRect();
     174
     175            int w = cr.width();
     176            int h = contentsWidget->heightForWidth( cr.width() );
     177            if ( h > w )
     178            {
     179                w -= verticalScrollBar()->sizeHint().width();
     180                h = contentsWidget->heightForWidth( w );
     181            }
     182
     183            contentsWidget->resize( w, h );
     184        }
     185
     186        return QScrollArea::event( event );
     187    }
     188
     189    virtual bool viewportEvent( QEvent *event )
     190    {
     191        bool ok = QScrollArea::viewportEvent( event );
     192
     193        if ( event->type() == QEvent::Resize )
     194        {
     195            layoutContents();
    87196        }
    88197        return ok;
     
    112221    }
    113222
     223    void layoutContents()
     224    {
     225        const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
     226            contentsWidget->layout() );
     227        if ( tl == NULL )
     228            return;
     229
     230        const QSize visibleSize = viewport()->contentsRect().size();
     231
     232        const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin();
     233
     234        int w = qMax( visibleSize.width(), minW );
     235        int h = qMax( tl->heightForWidth( w ), visibleSize.height() );
     236
     237        const int vpWidth = viewportSize( w, h ).width();
     238        if ( w > vpWidth )
     239        {
     240            w = qMax( vpWidth, minW );
     241            h = qMax( tl->heightForWidth( w ), visibleSize.height() );
     242        }
     243
     244        contentsWidget->resize( w, h );
     245    }
     246
    114247    QWidget *contentsWidget;
    115248};
    116249
    117 void QwtLegend::PrivateData::LegendMap::insert(
    118     const QwtLegendItemManager *item, QWidget *widget )
    119 {
    120     d_itemMap.insert( item, widget );
    121     d_widgetMap.insert( widget, item );
    122 }
    123 
    124 void QwtLegend::PrivateData::LegendMap::remove( const QwtLegendItemManager *item )
    125 {
    126     QWidget *widget = d_itemMap[item];
    127     d_itemMap.remove( item );
    128     d_widgetMap.remove( widget );
    129 }
    130 
    131 void QwtLegend::PrivateData::LegendMap::remove( QWidget *widget )
    132 {
    133     const QwtLegendItemManager *item = d_widgetMap[widget];
    134     d_itemMap.remove( item );
    135     d_widgetMap.remove( widget );
    136 }
    137 
    138 void QwtLegend::PrivateData::LegendMap::clear()
    139 {
    140 
    141     /*
    142        We can't delete the widgets in the following loop, because
    143        we would get ChildRemoved events, changing d_itemMap, while
    144        we are iterating.
    145      */
    146 
    147     QList<const QWidget *> widgets;
    148 
    149     QMap<const QwtLegendItemManager *, QWidget *>::const_iterator it;
    150     for ( it = d_itemMap.begin(); it != d_itemMap.end(); ++it )
    151         widgets.append( it.value() );
    152 
    153     d_itemMap.clear();
    154     d_widgetMap.clear();
    155 
    156     for ( int i = 0; i < widgets.size(); i++ )
    157         delete widgets[i];
    158 }
    159 
    160 uint QwtLegend::PrivateData::LegendMap::count() const
    161 {
    162     return d_itemMap.count();
    163 }
    164 
    165 inline const QWidget *QwtLegend::PrivateData::LegendMap::find(
    166     const QwtLegendItemManager *item ) const
    167 {
    168     if ( !d_itemMap.contains( item ) )
    169         return NULL;
    170 
    171     return d_itemMap[item];
    172 }
    173 
    174 inline QWidget *QwtLegend::PrivateData::LegendMap::find(
    175     const QwtLegendItemManager *item )
    176 {
    177     if ( !d_itemMap.contains( item ) )
    178         return NULL;
    179 
    180     return d_itemMap[item];
    181 }
    182 
    183 inline const QwtLegendItemManager *QwtLegend::PrivateData::LegendMap::find(
    184     const QWidget *widget ) const
    185 {
    186     QWidget *w = const_cast<QWidget *>( widget );
    187     if ( !d_widgetMap.contains( w ) )
    188         return NULL;
    189 
    190     return d_widgetMap[w];
    191 }
    192 
    193 inline QwtLegendItemManager *QwtLegend::PrivateData::LegendMap::find(
    194     const QWidget *widget )
    195 {
    196     QWidget *w = const_cast<QWidget *>( widget );
    197     if ( !d_widgetMap.contains( w ) )
    198         return NULL;
    199 
    200     return const_cast<QwtLegendItemManager *>( d_widgetMap[w] );
    201 }
    202 
    203 inline const QMap<QWidget *, const QwtLegendItemManager *> &
    204 QwtLegend::PrivateData::LegendMap::widgetMap() const
    205 {
    206     return d_widgetMap;
    207 }
    208 
    209 inline QMap<QWidget *, const QwtLegendItemManager *> &
    210 QwtLegend::PrivateData::LegendMap::widgetMap()
    211 {
    212     return d_widgetMap;
    213 }
    214 
    215250/*!
    216251  Constructor
    217 
    218252  \param parent Parent widget
    219253*/
    220254QwtLegend::QwtLegend( QWidget *parent ):
    221     QFrame( parent )
     255    QwtAbstractLegend( parent )
    222256{
    223257    setFrameStyle( NoFrame );
    224258
    225259    d_data = new QwtLegend::PrivateData;
    226     d_data->itemMode = QwtLegend::ReadOnlyItem;
    227260
    228261    d_data->view = new QwtLegend::PrivateData::LegendView( this );
     
    247280}
    248281
    249 //! \sa LegendItemMode
    250 void QwtLegend::setItemMode( LegendItemMode mode )
     282/*!
     283  \brief Set the maximum number of entries in a row
     284
     285  F.e when the maximum is set to 1 all items are aligned
     286  vertically. 0 means unlimited
     287
     288  \param numColums Maximum number of entries in a row
     289
     290  \sa maxColumns(), QwtDynGridLayout::setMaxColumns()
     291 */
     292void QwtLegend::setMaxColumns( uint numColums )
     293{
     294    QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
     295        d_data->view->contentsWidget->layout() );
     296    if ( tl )
     297        tl->setMaxColumns( numColums );
     298}
     299
     300/*!
     301  \return Maximum number of entries in a row
     302  \sa setMaxColumns(), QwtDynGridLayout::maxColumns()
     303 */
     304uint QwtLegend::maxColumns() const
     305{
     306    uint maxCols = 0;
     307
     308    const QwtDynGridLayout *tl = qobject_cast<const QwtDynGridLayout *>(
     309        d_data->view->contentsWidget->layout() );
     310    if ( tl )
     311        maxCols = tl->maxColumns();
     312
     313    return maxCols;
     314}
     315
     316/*!
     317  \brief Set the default mode for legend labels
     318
     319  Legend labels will be constructed according to the
     320  attributes in a QwtLegendData object. When it doesn't
     321  contain a value for the QwtLegendData::ModeRole the
     322  label will be initialized with the default mode of the legend.
     323
     324  \param mode Default item mode
     325
     326  \sa itemMode(), QwtLegendData::value(), QwtPlotItem::legendData()
     327  \note Changing the mode doesn't have any effect on existing labels.
     328 */
     329void QwtLegend::setDefaultItemMode( QwtLegendData::Mode mode )
    251330{
    252331    d_data->itemMode = mode;
    253332}
    254333
    255 //! \sa LegendItemMode
    256 QwtLegend::LegendItemMode QwtLegend::itemMode() const
     334/*!
     335  \return Default item mode
     336  \sa setDefaultItemMode()
     337*/
     338QwtLegendData::Mode QwtLegend::defaultItemMode() const
    257339{
    258340    return d_data->itemMode;
     
    261343/*!
    262344  The contents widget is the only child of the viewport of
    263   the internal QScrollArea  and the parent widget of all legend items.
     345  the internal QScrollArea and the parent widget of all legend items.
    264346
    265347  \return Container widget of the legend items
     
    290372/*!
    291373  The contents widget is the only child of the viewport of
    292   the internal QScrollArea  and the parent widget of all legend items.
     374  the internal QScrollArea and the parent widget of all legend items.
    293375
    294376  \return Container widget of the legend items
     
    301383
    302384/*!
    303   Insert a new item for a plot item
    304   \param plotItem Plot item
    305   \param legendItem New legend item
    306   \note The parent of item will be changed to contentsWidget()
    307 */
    308 void QwtLegend::insert( const QwtLegendItemManager *plotItem, QWidget *legendItem )
    309 {
    310     if ( legendItem == NULL || plotItem == NULL )
    311         return;
    312 
    313     QWidget *contentsWidget = d_data->view->contentsWidget;
    314 
    315     if ( legendItem->parent() != contentsWidget )
    316         legendItem->setParent( contentsWidget );
    317 
    318     legendItem->show();
    319 
    320     d_data->map.insert( plotItem, legendItem );
    321 
    322     layoutContents();
    323 
    324     if ( contentsWidget->layout() )
    325     {
    326         contentsWidget->layout()->addWidget( legendItem );
    327 
     385  \brief Update the entries for an item
     386
     387  \param itemInfo Info for an item
     388  \param data List of legend entry attributes for the item
     389 */
     390void QwtLegend::updateLegend( const QVariant &itemInfo,
     391    const QList<QwtLegendData> &data )
     392{
     393    QList<QWidget *> widgetList = legendWidgets( itemInfo );
     394
     395    if ( widgetList.size() != data.size() )
     396    {
     397        QLayout *contentsLayout = d_data->view->contentsWidget->layout();
     398
     399        while ( widgetList.size() > data.size() )
     400        {
     401            QWidget *w = widgetList.takeLast();
     402
     403            contentsLayout->removeWidget( w );
     404
     405            // updates might be triggered by signals from the legend widget
     406            // itself. So we better don't delete it here.
     407
     408            w->hide();
     409            w->deleteLater();
     410        }
     411
     412        for ( int i = widgetList.size(); i < data.size(); i++ )
     413        {
     414            QWidget *widget = createWidget( data[i] );
     415
     416            if ( contentsLayout )
     417                contentsLayout->addWidget( widget );
     418
     419            if ( isVisible() )
     420            {
     421                // QLayout does a delayed show, with the effect, that
     422                // the size hint will be wrong, when applications
     423                // call replot() right after changing the list
     424                // of plot items. So we better do the show now.
     425
     426                widget->setVisible( true );
     427            }
     428
     429            widgetList += widget;
     430        }
     431
     432        if ( widgetList.isEmpty() )
     433        {
     434            d_data->itemMap.remove( itemInfo );
     435        }
     436        else
     437        {
     438            d_data->itemMap.insert( itemInfo, widgetList );
     439        }
     440
     441        updateTabOrder();
     442    }
     443   
     444    for ( int i = 0; i < data.size(); i++ )
     445        updateWidget( widgetList[i], data[i] );
     446}
     447
     448/*!
     449  \brief Create a widget to be inserted into the legend
     450
     451  The default implementation returns a QwtLegendLabel.
     452
     453  \param data Attributes of the legend entry
     454  \return Widget representing data on the legend
     455 
     456  \note updateWidget() will called soon after createWidget()
     457        with the same attributes.
     458 */
     459QWidget *QwtLegend::createWidget( const QwtLegendData &data ) const
     460{
     461    Q_UNUSED( data );
     462
     463    QwtLegendLabel *label = new QwtLegendLabel();
     464    label->setItemMode( defaultItemMode() );
     465
     466    connect( label, SIGNAL( clicked() ), SLOT( itemClicked() ) );
     467    connect( label, SIGNAL( checked( bool ) ), SLOT( itemChecked( bool ) ) );
     468
     469    return label;
     470}
     471
     472/*!
     473  \brief Update the widget
     474
     475  \param widget Usually a QwtLegendLabel
     476  \param data Attributes to be displayed
     477
     478  \sa createWidget()
     479  \note When widget is no QwtLegendLabel updateWidget() does nothing.
     480 */
     481void QwtLegend::updateWidget( QWidget *widget, const QwtLegendData &data )
     482{
     483    QwtLegendLabel *label = qobject_cast<QwtLegendLabel *>( widget );
     484    if ( label )
     485    {
     486        label->setData( data );
     487        if ( !data.value( QwtLegendData::ModeRole ).isValid() )
     488        {
     489            // use the default mode, when there is no specific
     490            // hint from the legend data
     491
     492            label->setItemMode( defaultItemMode() );
     493        }
     494    }
     495}
     496
     497void QwtLegend::updateTabOrder()
     498{
     499    QLayout *contentsLayout = d_data->view->contentsWidget->layout();
     500    if ( contentsLayout )
     501    {
    328502        // set tab focus chain
    329503
    330504        QWidget *w = NULL;
    331505
    332         for ( int i = 0; i < contentsWidget->layout()->count(); i++ )
    333         {
    334             QLayoutItem *item = contentsWidget->layout()->itemAt( i );
     506        for ( int i = 0; i < contentsLayout->count(); i++ )
     507        {
     508            QLayoutItem *item = contentsLayout->itemAt( i );
    335509            if ( w && item->widget() )
    336510                QWidget::setTabOrder( w, item->widget() );
     
    339513        }
    340514    }
    341     if ( parentWidget() && parentWidget()->layout() == NULL )
    342     {
    343         /*
    344            updateGeometry() doesn't post LayoutRequest in certain
    345            situations, like when we are hidden. But we want the
    346            parent widget notified, so it can show/hide the legend
    347            depending on its items.
    348          */
    349         QApplication::postEvent( parentWidget(),
    350             new QEvent( QEvent::LayoutRequest ) );
    351     }
    352 }
    353 
    354 /*!
    355   Find the widget that represents a plot item
    356 
    357   \param plotItem Plot item
    358   \return Widget on the legend, or NULL
    359 */
    360 QWidget *QwtLegend::find( const QwtLegendItemManager *plotItem ) const
    361 {
    362     return d_data->map.find( plotItem );
    363 }
    364 
    365 /*!
    366   Find the widget that represents a plot item
    367 
    368   \param legendItem Legend item
    369   \return Widget on the legend, or NULL
    370 */
    371 QwtLegendItemManager *QwtLegend::find( const QWidget *legendItem ) const
    372 {
    373     return d_data->map.find( legendItem );
    374 }
    375 
    376 /*!
    377    Find the corresponding item for a plotItem and remove it
    378    from the item list.
    379 
    380    \param plotItem Plot item
    381 */
    382 void QwtLegend::remove( const QwtLegendItemManager *plotItem )
    383 {
    384     QWidget *legendItem = d_data->map.find( plotItem );
    385     d_data->map.remove( legendItem );
    386     delete legendItem;
    387 }
    388 
    389 //! Remove all items.
    390 void QwtLegend::clear()
    391 {
    392     bool doUpdate = updatesEnabled();
    393     if ( doUpdate )
    394         setUpdatesEnabled( false );
    395 
    396     d_data->map.clear();
    397 
    398     if ( doUpdate )
    399         setUpdatesEnabled( true );
    400 
    401     update();
    402515}
    403516
     
    412525
    413526/*!
    414   \return The preferred height, for the width w.
     527  \return The preferred height, for a width.
    415528  \param width Width
    416529*/
     
    426539}
    427540
    428 /*!
    429   Adjust contents widget and item layout to the size of the viewport().
    430 */
    431 void QwtLegend::layoutContents()
    432 {
    433     const QSize visibleSize =
    434         d_data->view->viewport()->contentsRect().size();
    435 
    436     const QwtDynGridLayout *tl = qobject_cast<QwtDynGridLayout *>(
    437         d_data->view->contentsWidget->layout() );
    438     if ( tl )
    439     {
    440         const int minW = int( tl->maxItemWidth() ) + 2 * tl->margin();
    441 
    442         int w = qMax( visibleSize.width(), minW );
    443         int h = qMax( tl->heightForWidth( w ), visibleSize.height() );
    444 
    445         const int vpWidth = d_data->view->viewportSize( w, h ).width();
    446         if ( w > vpWidth )
    447         {
    448             w = qMax( vpWidth, minW );
    449             h = qMax( tl->heightForWidth( w ), visibleSize.height() );
    450         }
    451 
    452         d_data->view->contentsWidget->resize( w, h );
    453     }
    454 }
    455541
    456542/*!
     
    460546  \param object Object to be filtered
    461547  \param event Event
     548
     549  \return Forwarded to QwtAbstractLegend::eventFilter()
    462550*/
    463551bool QwtLegend::eventFilter( QObject *object, QEvent *event )
     
    474562                {
    475563                    QWidget *w = static_cast< QWidget * >( ce->child() );
    476                     d_data->map.remove( w );
     564                    d_data->itemMap.removeWidget( w );
    477565                }
    478566                break;
     
    480568            case QEvent::LayoutRequest:
    481569            {
    482                 layoutContents();
     570                d_data->view->layoutContents();
     571
     572                if ( parentWidget() && parentWidget()->layout() == NULL )
     573                {
     574                    /*
     575                       We want the parent widget ( usually QwtPlot ) to recalculate
     576                       its layout, when the contentsWidget has changed. But
     577                       because of the scroll view we have to forward the LayoutRequest
     578                       event manually.
     579
     580                       We don't use updateGeometry() because it doesn't post LayoutRequest
     581                       events when the legend is hidden. But we want the
     582                       parent widget notified, so it can show/hide the legend
     583                       depending on its items.
     584                     */
     585                    QApplication::postEvent( parentWidget(),
     586                        new QEvent( QEvent::LayoutRequest ) );
     587                }               
    483588                break;
    484589            }
     
    488593    }
    489594
    490     return QFrame::eventFilter( object, event );
    491 }
    492 
    493 
    494 //! Return true, if there are no legend items.
     595    return QwtAbstractLegend::eventFilter( object, event );
     596}
     597
     598/*!
     599  Called internally when the legend has been clicked on.
     600  Emits a clicked() signal.
     601*/
     602void QwtLegend::itemClicked()
     603{
     604    QWidget *w = qobject_cast<QWidget *>( sender() );
     605    if ( w )
     606    {
     607        const QVariant itemInfo = d_data->itemMap.itemInfo( w );
     608        if ( itemInfo.isValid() )
     609        {
     610            const QList<QWidget *> widgetList =
     611                d_data->itemMap.legendWidgets( itemInfo );
     612
     613            const int index = widgetList.indexOf( w );
     614            if ( index >= 0 )
     615                Q_EMIT clicked( itemInfo, index );
     616        }
     617    }
     618}
     619
     620/*!
     621  Called internally when the legend has been checked
     622  Emits a checked() signal.
     623*/
     624void QwtLegend::itemChecked( bool on )
     625{
     626    QWidget *w = qobject_cast<QWidget *>( sender() );
     627    if ( w )
     628    {
     629        const QVariant itemInfo = d_data->itemMap.itemInfo( w );
     630        if ( itemInfo.isValid() )
     631        {
     632            const QList<QWidget *> widgetList =
     633                d_data->itemMap.legendWidgets( itemInfo );
     634
     635            const int index = widgetList.indexOf( w );
     636            if ( index >= 0 )
     637                Q_EMIT checked( itemInfo, on, index );
     638        }
     639    }
     640}
     641
     642/*!
     643  Render the legend into a given rectangle.
     644
     645  \param painter Painter
     646  \param rect Bounding rectangle
     647  \param fillBackground When true, fill rect with the widget background
     648
     649  \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
     650*/
     651void QwtLegend::renderLegend( QPainter *painter,
     652    const QRectF &rect, bool fillBackground ) const
     653{
     654    if ( d_data->itemMap.isEmpty() )
     655        return;
     656
     657    if ( fillBackground )
     658    {
     659        if ( autoFillBackground() ||
     660            testAttribute( Qt::WA_StyledBackground ) )
     661        {
     662            QwtPainter::drawBackgound( painter, rect, this );
     663        }
     664    }
     665
     666    const QwtDynGridLayout *legendLayout =
     667        qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
     668    if ( legendLayout == NULL )
     669        return;
     670
     671    int left, right, top, bottom;
     672    getContentsMargins( &left, &top, &right, &bottom );
     673
     674    QRect layoutRect;
     675    layoutRect.setLeft( qCeil( rect.left() ) + left );
     676    layoutRect.setTop( qCeil( rect.top() ) + top );
     677    layoutRect.setRight( qFloor( rect.right() ) - right );
     678    layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );
     679
     680    uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
     681    QList<QRect> itemRects =
     682        legendLayout->layoutItems( layoutRect, numCols );
     683
     684    int index = 0;
     685
     686    for ( int i = 0; i < legendLayout->count(); i++ )
     687    {
     688        QLayoutItem *item = legendLayout->itemAt( i );
     689        QWidget *w = item->widget();
     690        if ( w )
     691        {
     692            painter->save();
     693
     694            painter->setClipRect( itemRects[index], Qt::IntersectClip );
     695            renderItem( painter, w, itemRects[index], fillBackground );
     696
     697            index++;
     698            painter->restore();
     699        }
     700    }
     701}
     702
     703/*!
     704  Render a legend entry into a given rectangle.
     705
     706  \param painter Painter
     707  \param widget Widget representing a legend entry
     708  \param rect Bounding rectangle
     709  \param fillBackground When true, fill rect with the widget background
     710
     711  \note When widget is not derived from QwtLegendLabel renderItem
     712        does nothing beside the background
     713*/
     714void QwtLegend::renderItem( QPainter *painter,
     715    const QWidget *widget, const QRectF &rect, bool fillBackground ) const
     716{
     717    if ( fillBackground )
     718    {
     719        if ( widget->autoFillBackground() ||
     720            widget->testAttribute( Qt::WA_StyledBackground ) )
     721        {
     722            QwtPainter::drawBackgound( painter, rect, widget );
     723        }
     724    }
     725
     726    const QwtLegendLabel *label = qobject_cast<const QwtLegendLabel *>( widget );
     727    if ( label )
     728    {
     729        // icon
     730
     731        const QwtGraphic &icon = label->data().icon();
     732        const QSizeF sz = icon.defaultSize();
     733
     734        const QRectF iconRect( rect.x() + label->margin(),
     735            rect.center().y() - 0.5 * sz.height(),
     736            sz.width(), sz.height() );
     737
     738        icon.render( painter, iconRect, Qt::KeepAspectRatio );
     739
     740        // title
     741
     742        QRectF titleRect = rect;
     743        titleRect.setX( iconRect.right() + 2 * label->spacing() );
     744
     745        painter->setFont( label->font() );
     746        painter->setPen( label->palette().color( QPalette::Text ) );
     747        const_cast< QwtLegendLabel *>( label )->drawText( painter, titleRect );
     748    }
     749}
     750
     751/*!
     752  \return List of widgets associated to a item
     753  \param itemInfo Info about an item
     754  \sa legendWidget(), itemInfo(), QwtPlot::itemToInfo()
     755 */
     756QList<QWidget *> QwtLegend::legendWidgets( const QVariant &itemInfo ) const
     757{
     758    return d_data->itemMap.legendWidgets( itemInfo );
     759}
     760
     761/*!
     762  \return First widget in the list of widgets associated to an item
     763  \param itemInfo Info about an item
     764  \sa itemInfo(), QwtPlot::itemToInfo()
     765  \note Almost all types of items have only one widget
     766*/
     767QWidget *QwtLegend::legendWidget( const QVariant &itemInfo ) const
     768{
     769    const QList<QWidget *> list = d_data->itemMap.legendWidgets( itemInfo );
     770    if ( list.isEmpty() )
     771        return NULL;
     772
     773    return list[0];
     774}
     775
     776/*!
     777  Find the item that is associated to a widget
     778
     779  \param widget Widget on the legend
     780  \return Associated item info
     781  \sa legendWidget()
     782 */
     783QVariant QwtLegend::itemInfo( const QWidget *widget ) const
     784{
     785    return d_data->itemMap.itemInfo( widget );
     786}
     787
     788//! \return True, when no item is inserted
    495789bool QwtLegend::isEmpty() const
    496790{
    497     return d_data->map.count() == 0;
    498 }
    499 
    500 //! Return the number of legend items.
    501 uint QwtLegend::itemCount() const
    502 {
    503     return d_data->map.count();
    504 }
    505 
    506 //! Return a list of all legend items
    507 QList<QWidget *> QwtLegend::legendItems() const
    508 {
    509     const QMap<QWidget *, const QwtLegendItemManager *> &map =
    510         d_data->map.widgetMap();
    511 
    512     QList<QWidget *> list;
    513 
    514     QMap<QWidget *, const QwtLegendItemManager *>::const_iterator it;
    515     for ( it = map.begin(); it != map.end(); ++it )
    516         list += it.key();
    517 
    518     return list;
    519 }
     791    return d_data->itemMap.isEmpty();
     792}
     793
     794/*!
     795    Return the extent, that is needed for the scrollbars
     796
     797    \param orientation Orientation (
     798    \return The width of the vertical scrollbar for Qt::Horizontal and v.v.
     799 */
     800int QwtLegend::scrollExtent( Qt::Orientation orientation ) const
     801{
     802    int extent = 0;
     803
     804    if ( orientation == Qt::Horizontal )
     805        extent = verticalScrollBar()->sizeHint().width();
     806    else
     807        extent = horizontalScrollBar()->sizeHint().height();
     808
     809    return extent;
     810}
     811
  • trunk/BNC/qwt/qwt_legend.h

    r4271 r8127  
    1212
    1313#include "qwt_global.h"
    14 #include <qframe.h>
    15 #include <qlist.h>
     14#include "qwt_abstract_legend.h"
     15#include <qvariant.h>
    1616
    1717class QScrollBar;
    18 class QwtLegendItemManager;
    1918
    2019/*!
     
    2322  The QwtLegend widget is a tabular arrangement of legend items. Legend
    2423  items might be any type of widget, but in general they will be
    25   a QwtLegendItem.
     24  a QwtLegendLabel.
    2625
    27   \sa QwtLegendItem, QwtLegendItemManager QwtPlot
     26  \sa QwtLegendLabel, QwtPlotItem, QwtPlot
    2827*/
    2928
    30 class QWT_EXPORT QwtLegend : public QFrame
     29class QWT_EXPORT QwtLegend : public QwtAbstractLegend
    3130{
    3231    Q_OBJECT
    3332
    3433public:
    35     /*!
    36       \brief Interaction mode for the legend items
    37 
    38        The default is QwtLegend::ReadOnlyItem.
    39 
    40        \sa setItemMode(), itemMode(), QwtLegendItem::IdentifierMode
    41            QwtLegendItem::clicked(), QwtLegendItem::checked(),
    42            QwtPlot::legendClicked(), QwtPlot::legendChecked()
    43      */
    44 
    45     enum LegendItemMode
    46     {
    47         //! The legend item is not interactive, like a label
    48         ReadOnlyItem,
    49 
    50         //! The legend item is clickable, like a push button
    51         ClickableItem,
    52 
    53         //! The legend item is checkable, like a checkable button
    54         CheckableItem
    55     };
    56 
    5734    explicit QwtLegend( QWidget *parent = NULL );
    5835    virtual ~QwtLegend();
    5936
    60     void setItemMode( LegendItemMode );
    61     LegendItemMode itemMode() const;
     37    void setMaxColumns( uint numColums );
     38    uint maxColumns() const;
     39
     40    void setDefaultItemMode( QwtLegendData::Mode );
     41    QwtLegendData::Mode defaultItemMode() const;
    6242
    6343    QWidget *contentsWidget();
    6444    const QWidget *contentsWidget() const;
    6545
    66     void insert( const QwtLegendItemManager *, QWidget * );
    67     void remove( const QwtLegendItemManager * );
     46    QWidget *legendWidget( const QVariant &  ) const;
     47    QList<QWidget *> legendWidgets( const QVariant & ) const;
    6848
    69     QWidget *find( const QwtLegendItemManager * ) const;
    70     QwtLegendItemManager *find( const QWidget * ) const;
    71 
    72     virtual QList<QWidget *> legendItems() const;
    73 
    74     void clear();
    75 
    76     bool isEmpty() const;
    77     uint itemCount() const;
     49    QVariant itemInfo( const QWidget * ) const;
    7850
    7951    virtual bool eventFilter( QObject *, QEvent * );
     
    8557    QScrollBar *verticalScrollBar() const;
    8658
     59    virtual void renderLegend( QPainter *,
     60        const QRectF &, bool fillBackground ) const;
     61
     62    virtual void renderItem( QPainter *,
     63        const QWidget *, const QRectF &, bool fillBackground ) const;
     64
     65    virtual bool isEmpty() const;
     66    virtual int scrollExtent( Qt::Orientation ) const;
     67
     68Q_SIGNALS:
     69    /*!
     70      A signal which is emitted when the user has clicked on
     71      a legend label, which is in QwtLegendData::Clickable mode.
     72
     73      \param itemInfo Info for the item item of the
     74                      selected legend item
     75      \param index Index of the legend label in the list of widgets
     76                   that are associated with the plot item
     77
     78      \note clicks are disabled as default
     79      \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
     80     */
     81    void clicked( const QVariant &itemInfo, int index );
     82
     83    /*!
     84      A signal which is emitted when the user has clicked on
     85      a legend label, which is in QwtLegendData::Checkable mode
     86
     87      \param itemInfo Info for the item of the
     88                      selected legend label
     89      \param index Index of the legend label in the list of widgets
     90                   that are associated with the plot item
     91      \param on True when the legend label is checked
     92
     93      \note clicks are disabled as default
     94      \sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
     95     */
     96    void checked( const QVariant &itemInfo, bool on, int index );
     97
     98public Q_SLOTS:
     99    virtual void updateLegend( const QVariant &,
     100        const QList<QwtLegendData> & );
     101
     102protected Q_SLOTS:
     103    void itemClicked();
     104    void itemChecked( bool );
     105
    87106protected:
    88     virtual void layoutContents();
     107    virtual QWidget *createWidget( const QwtLegendData & ) const;
     108    virtual void updateWidget( QWidget *widget, const QwtLegendData &data );
    89109
    90110private:
     111    void updateTabOrder();
     112
    91113    class PrivateData;
    92114    PrivateData *d_data;
  • trunk/BNC/qwt/qwt_magnifier.cpp

    r4271 r8127  
    1919        isEnabled( false ),
    2020        wheelFactor( 0.9 ),
    21         wheelButtonState( Qt::NoButton ),
     21        wheelModifiers( Qt::NoModifier ),
    2222        mouseFactor( 0.95 ),
    2323        mouseButton( Qt::RightButton ),
    24         mouseButtonState( Qt::NoButton ),
     24        mouseButtonModifiers( Qt::NoModifier ),
    2525        keyFactor( 0.9 ),
    2626        zoomInKey( Qt::Key_Plus ),
     27        zoomInKeyModifiers( Qt::NoModifier ),
    2728        zoomOutKey( Qt::Key_Minus ),
    28         zoomInKeyModifiers( Qt::NoModifier ),
    2929        zoomOutKeyModifiers( Qt::NoModifier ),
    3030        mousePressed( false )
     
    3535
    3636    double wheelFactor;
    37     int wheelButtonState;
     37    Qt::KeyboardModifiers wheelModifiers;
    3838
    3939    double mouseFactor;
    40     int mouseButton;
    41     int mouseButtonState;
     40
     41    Qt::MouseButton mouseButton;
     42    Qt::KeyboardModifiers mouseButtonModifiers;
    4243
    4344    double keyFactor;
     45
    4446    int zoomInKey;
     47    Qt::KeyboardModifiers zoomInKeyModifiers;
     48
    4549    int zoomOutKey;
    46     int zoomInKeyModifiers;
    47     int zoomOutKeyModifiers;
     50    Qt::KeyboardModifiers  zoomOutKeyModifiers;
    4851
    4952    bool mousePressed;
     
    109112   The wheel factor defines the ratio between the current range
    110113   on the parent widget and the zoomed range for each step of the wheel.
     114
     115   Use values > 1 for magnification (i.e. 2.0) and values < 1 for
     116   scaling down (i.e. 1/2.0 = 0.5). You can use this feature for
     117   inverting the direction of the wheel.
     118
    111119   The default value is 0.9.
    112120
     
    130138
    131139/*!
    132    Assign a mandatory button state for zooming in/out using the wheel.
    133    The default button state is Qt::NoButton.
    134 
    135    \param buttonState Button state
    136    \sa wheelButtonState()
    137 */
    138 void QwtMagnifier::setWheelButtonState( int buttonState )
    139 {
    140     d_data->wheelButtonState = buttonState;
    141 }
    142 
    143 /*!
    144    \return Wheel button state
    145    \sa setWheelButtonState()
    146 */
    147 int QwtMagnifier::wheelButtonState() const
    148 {
    149     return d_data->wheelButtonState;
     140   Assign keyboard modifiers for zooming in/out using the wheel.
     141   The default modifiers are Qt::NoModifiers.
     142
     143   \param modifiers Keyboard modifiers
     144   \sa wheelModifiers()
     145*/
     146void QwtMagnifier::setWheelModifiers( Qt::KeyboardModifiers modifiers )
     147{
     148    d_data->wheelModifiers = modifiers;
     149}
     150
     151/*!
     152   \return Wheel modifiers
     153   \sa setWheelModifiers()
     154*/
     155Qt::KeyboardModifiers QwtMagnifier::wheelModifiers() const
     156{
     157    return d_data->wheelModifiers;
    150158}
    151159
     
    179187
    180188   \param button Button
    181    \param buttonState Button state
     189   \param modifiers Keyboard modifiers
     190
    182191   \sa getMouseButton()
    183192*/
    184 void QwtMagnifier::setMouseButton( int button, int buttonState )
     193void QwtMagnifier::setMouseButton(
     194    Qt::MouseButton button, Qt::KeyboardModifiers modifiers )
    185195{
    186196    d_data->mouseButton = button;
    187     d_data->mouseButtonState = buttonState;
     197    d_data->mouseButtonModifiers = modifiers;
    188198}
    189199
    190200//! \sa setMouseButton()
    191201void QwtMagnifier::getMouseButton(
    192     int &button, int &buttonState ) const
     202    Qt::MouseButton &button, Qt::KeyboardModifiers &modifiers ) const
    193203{
    194204    button = d_data->mouseButton;
    195     buttonState = d_data->mouseButtonState;
     205    modifiers = d_data->mouseButtonModifiers;
    196206}
    197207
     
    229239   \sa getZoomInKey(), setZoomOutKey()
    230240*/
    231 void QwtMagnifier::setZoomInKey( int key, int modifiers )
     241void QwtMagnifier::setZoomInKey( int key,
     242    Qt::KeyboardModifiers modifiers )
    232243{
    233244    d_data->zoomInKey = key;
     
    235246}
    236247
    237 //! \sa setZoomInKey()
    238 void QwtMagnifier::getZoomInKey( int &key, int &modifiers ) const
     248/*!
     249   \brief Retrieve the settings of the zoom in key
     250
     251   \param key Key code, see Qt::Key
     252   \param modifiers Keyboard modifiers
     253
     254   \sa setZoomInKey()
     255*/
     256void QwtMagnifier::getZoomInKey( int &key,
     257    Qt::KeyboardModifiers &modifiers ) const
    239258{
    240259    key = d_data->zoomInKey;
     
    250269   \sa getZoomOutKey(), setZoomOutKey()
    251270*/
    252 void QwtMagnifier::setZoomOutKey( int key, int modifiers )
     271void QwtMagnifier::setZoomOutKey( int key,
     272    Qt::KeyboardModifiers modifiers )
    253273{
    254274    d_data->zoomOutKey = key;
     
    256276}
    257277
    258 //! \sa setZoomOutKey()
    259 void QwtMagnifier::getZoomOutKey( int &key, int &modifiers ) const
     278/*!
     279   \brief Retrieve the settings of the zoom out key
     280
     281   \param key Key code, see Qt::Key
     282   \param modifiers Keyboard modifiers
     283
     284   \sa setZoomOutKey()
     285*/
     286void QwtMagnifier::getZoomOutKey( int &key,
     287    Qt::KeyboardModifiers &modifiers ) const
    260288{
    261289    key = d_data->zoomOutKey;
     
    266294  \brief Event filter
    267295
    268   When isEnabled() the mouse events of the observed widget are filtered.
     296  When isEnabled() is true, the mouse events of the
     297  observed widget are filtered.
    269298
    270299  \param object Object to be filtered
    271300  \param event Event
     301
     302  \return Forwarded to QObject::eventFilter()
    272303
    273304  \sa widgetMousePressEvent(), widgetMouseReleaseEvent(),
     
    283314            case QEvent::MouseButtonPress:
    284315            {
    285                 widgetMousePressEvent( ( QMouseEvent * )event );
     316                widgetMousePressEvent( static_cast<QMouseEvent *>( event ) );
    286317                break;
    287318            }
    288319            case QEvent::MouseMove:
    289320            {
    290                 widgetMouseMoveEvent( ( QMouseEvent * )event );
     321                widgetMouseMoveEvent( static_cast<QMouseEvent *>( event ) );
    291322                break;
    292323            }
    293324            case QEvent::MouseButtonRelease:
    294325            {
    295                 widgetMouseReleaseEvent( ( QMouseEvent * )event );
     326                widgetMouseReleaseEvent( static_cast<QMouseEvent *>( event ) );
    296327                break;
    297328            }
    298329            case QEvent::Wheel:
    299330            {
    300                 widgetWheelEvent( ( QWheelEvent * )event );
     331                widgetWheelEvent( static_cast<QWheelEvent *>( event ) );
    301332                break;
    302333            }
    303334            case QEvent::KeyPress:
    304335            {
    305                 widgetKeyPressEvent( ( QKeyEvent * )event );
     336                widgetKeyPressEvent( static_cast<QKeyEvent *>( event ) );
    306337                break;
    307338            }
    308339            case QEvent::KeyRelease:
    309340            {
    310                 widgetKeyReleaseEvent( ( QKeyEvent * )event );
     341                widgetKeyReleaseEvent( static_cast<QKeyEvent *>( event ) );
    311342                break;
    312343            }
     
    325356void QwtMagnifier::widgetMousePressEvent( QMouseEvent *mouseEvent )
    326357{
    327     if ( ( mouseEvent->button() != d_data->mouseButton)
    328         || parentWidget() == NULL )
    329     {
     358    if ( parentWidget() == NULL )
    330359        return;
    331     }
    332 
    333     if ( ( mouseEvent->modifiers() & Qt::KeyboardModifierMask ) !=
    334         ( int )( d_data->mouseButtonState & Qt::KeyboardModifierMask ) )
     360
     361    if ( ( mouseEvent->button() != d_data->mouseButton ) ||
     362        ( mouseEvent->modifiers() != d_data->mouseButtonModifiers ) )
    335363    {
    336364        return;
     
    338366
    339367    d_data->hasMouseTracking = parentWidget()->hasMouseTracking();
     368
    340369    parentWidget()->setMouseTracking( true );
    341370    d_data->mousePos = mouseEvent->pos();
     
    393422void QwtMagnifier::widgetWheelEvent( QWheelEvent *wheelEvent )
    394423{
    395     if ( ( wheelEvent->modifiers() & Qt::KeyboardModifierMask ) !=
    396         ( int )( d_data->wheelButtonState & Qt::KeyboardModifierMask ) )
     424    if ( wheelEvent->modifiers() != d_data->wheelModifiers )
    397425    {
    398426        return;
     
    411439         */
    412440        double f = qPow( d_data->wheelFactor,
    413             qAbs( wheelEvent->delta() / 120 ) );
     441            qAbs( wheelEvent->delta() / 120.0 ) );
    414442
    415443        if ( wheelEvent->delta() > 0 )
     
    428456void QwtMagnifier::widgetKeyPressEvent( QKeyEvent *keyEvent )
    429457{
    430     const int key = keyEvent->key();
    431     const int state = keyEvent->modifiers();
    432 
    433     if ( key == d_data->zoomInKey &&
    434         state == d_data->zoomInKeyModifiers )
     458    if ( keyEvent->key() == d_data->zoomInKey &&
     459        keyEvent->modifiers() == d_data->zoomInKeyModifiers )
    435460    {
    436461        rescale( d_data->keyFactor );
    437462    }
    438     else if ( key == d_data->zoomOutKey &&
    439         state == d_data->zoomOutKeyModifiers )
     463    else if ( keyEvent->key() == d_data->zoomOutKey &&
     464        keyEvent->modifiers() == d_data->zoomOutKeyModifiers )
    440465    {
    441466        rescale( 1.0 / d_data->keyFactor );
     
    457482QWidget *QwtMagnifier::parentWidget()
    458483{
    459     if ( parent()->inherits( "QWidget" ) )
    460         return ( QWidget * )parent();
    461 
    462     return NULL;
     484    return qobject_cast<QWidget *>( parent() );
    463485}
    464486
     
    466488const QWidget *QwtMagnifier::parentWidget() const
    467489{
    468     if ( parent()->inherits( "QWidget" ) )
    469         return ( const QWidget * )parent();
    470 
    471     return NULL;
    472 }
    473 
     490    return qobject_cast<const QWidget *>( parent() );
     491}
     492
  • trunk/BNC/qwt/qwt_magnifier.h

    r4271 r8127  
    4343    double mouseFactor() const;
    4444
    45     void setMouseButton( int button, int buttonState = Qt::NoButton );
    46     void getMouseButton( int &button, int &buttonState ) const;
     45    void setMouseButton( Qt::MouseButton, Qt::KeyboardModifiers = Qt::NoModifier );
     46    void getMouseButton( Qt::MouseButton &, Qt::KeyboardModifiers & ) const;
    4747
    4848    // mouse wheel
     
    5050    double wheelFactor() const;
    5151
    52     void setWheelButtonState( int buttonState );
    53     int wheelButtonState() const;
     52    void setWheelModifiers( Qt::KeyboardModifiers );
     53    Qt::KeyboardModifiers wheelModifiers() const;
    5454
    5555    // keyboard
     
    5757    double keyFactor() const;
    5858
    59     void setZoomInKey( int key, int modifiers );
    60     void getZoomInKey( int &key, int &modifiers ) const;
     59    void setZoomInKey( int key, Qt::KeyboardModifiers = Qt::NoModifier );
     60    void getZoomInKey( int &key, Qt::KeyboardModifiers & ) const;
    6161
    62     void setZoomOutKey( int key, int modifiers );
    63     void getZoomOutKey( int &key, int &modifiers ) const;
     62    void setZoomOutKey( int key, Qt::KeyboardModifiers = Qt::NoModifier );
     63    void getZoomOutKey( int &key, Qt::KeyboardModifiers & ) const;
    6464
    6565    virtual bool eventFilter( QObject *, QEvent * );
  • trunk/BNC/qwt/qwt_math.cpp

    r4271 r8127  
    4444    return rv;
    4545}
     46
     47/*!
     48  \brief Normalize an angle to be int the range [0.0, 2 * PI[
     49  \param radians Angle in radians
     50  \return Normalized angle in radians
     51*/
     52double qwtNormalizeRadians( double radians )
     53{
     54    double a = ::fmod( radians, 2.0 * M_PI );
     55    if ( a < 0.0 )
     56        a += 2.0 * M_PI;
     57
     58    return a;
     59
     60}
     61
     62/*!
     63  \brief Normalize an angle to be int the range [0.0, 360.0[
     64  \param radians Angle in degrees
     65  \return Normalized angle in degrees
     66*/
     67double qwtNormalizeDegrees( double degrees )
     68{
     69    double a = ::fmod( degrees, 360.0 );
     70    if ( a < 0.0 )
     71        a += 360.0;
     72
     73    return a;
     74}
  • trunk/BNC/qwt/qwt_math.h

    r4271 r8127  
    2424#endif
    2525
    26 #include <qpoint.h>
    2726#include <qmath.h>
    2827#include "qwt_global.h"
    2928
    30 #ifndef LOG10_2
    31 #define LOG10_2     0.30102999566398119802  /* log10(2) */
    32 #endif
    33 
    34 #ifndef LOG10_3
    35 #define LOG10_3     0.47712125471966243540  /* log10(3) */
    36 #endif
    37 
    38 #ifndef LOG10_5
    39 #define LOG10_5     0.69897000433601885749  /* log10(5) */
    40 #endif
    41 
    42 #ifndef M_2PI
    43 #define M_2PI       6.28318530717958623200  /* 2 pi */
     29#ifndef M_PI_2
     30// For Qt <= 4.8.4 M_PI_2 is not known by MinGW-w64
     31// when compiling with -std=c++11
     32#define M_PI_2 (1.57079632679489661923)
    4433#endif
    4534
    4635#ifndef LOG_MIN
    47 //! Mininum value for logarithmic scales
     36//! Minimum value for logarithmic scales
    4837#define LOG_MIN 1.0e-100
    4938#endif
     
    5443#endif
    5544
    56 #ifndef M_E
    57 #define M_E            2.7182818284590452354   /* e */
    58 #endif
    59 
    60 #ifndef M_LOG2E
    61 #define M_LOG2E 1.4426950408889634074   /* log_2 e */
    62 #endif
    63 
    64 #ifndef M_LOG10E
    65 #define M_LOG10E    0.43429448190325182765  /* log_10 e */
    66 #endif
    67 
    68 #ifndef M_LN2
    69 #define M_LN2       0.69314718055994530942  /* log_e 2 */
    70 #endif
    71 
    72 #ifndef M_LN10
    73 #define M_LN10         2.30258509299404568402  /* log_e 10 */
    74 #endif
    75 
    76 #ifndef M_PI
    77 #define M_PI        3.14159265358979323846  /* pi */
    78 #endif
    79 
    80 #ifndef M_PI_2
    81 #define M_PI_2      1.57079632679489661923  /* pi/2 */
    82 #endif
    83 
    84 #ifndef M_PI_4
    85 #define M_PI_4      0.78539816339744830962  /* pi/4 */
    86 #endif
    87 
    88 #ifndef M_1_PI
    89 #define M_1_PI      0.31830988618379067154  /* 1/pi */
    90 #endif
    91 
    92 #ifndef M_2_PI
    93 #define M_2_PI      0.63661977236758134308  /* 2/pi */
    94 #endif
    95 
    96 #ifndef M_2_SQRTPI
    97 #define M_2_SQRTPI  1.12837916709551257390  /* 2/sqrt(pi) */
    98 #endif
    99 
    100 #ifndef M_SQRT2
    101 #define M_SQRT2 1.41421356237309504880  /* sqrt(2) */
    102 #endif
    103 
    104 #ifndef M_SQRT1_2
    105 #define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */
    106 #endif
    107 
    10845QWT_EXPORT double qwtGetMin( const double *array, int size );
    10946QWT_EXPORT double qwtGetMax( const double *array, int size );
     47
     48QWT_EXPORT double qwtNormalizeRadians( double radians );
     49QWT_EXPORT double qwtNormalizeDegrees( double degrees );
    11050
    11151/*!
     
    162102}
    163103
    164 //! Like qRound, but without converting the result to an int
    165 inline double qwtRoundF(double d)
    166 {
    167     return ::floor( d + 0.5 );
     104//! Approximation of arc tangent ( error below 0,005 radians )
     105inline double qwtFastAtan( double x )
     106{
     107    if ( x < -1.0 )
     108        return -M_PI_2 - x / ( x * x + 0.28 );
     109
     110    if ( x > 1.0 )
     111        return M_PI_2 - x / ( x * x + 0.28 );
     112
     113    return x / ( 1.0 + x * x * 0.28 );
    168114}
    169115
    170 //! Like qFloor, but without converting the result to an int
    171 inline double qwtFloorF(double d)
    172 {
    173     return ::floor( d );
     116//! Approximation of arc tangent ( error below 0,005 radians )
     117inline double qwtFastAtan2( double y, double x )
     118{
     119    if ( x > 0 )
     120        return qwtFastAtan( y / x );
     121
     122    if ( x < 0 )
     123    {
     124        const double d = qwtFastAtan( y / x );
     125        return ( y >= 0 ) ? d + M_PI : d - M_PI;
     126    }
     127
     128    if ( y < 0.0 )
     129        return -M_PI_2;
     130
     131    if ( y > 0.0 )
     132        return M_PI_2;
     133
     134    return 0.0;
    174135}
    175136
    176 //! Like qCeil, but without converting the result to an int
    177 inline double qwtCeilF(double d)
    178 {
    179     return ::ceil( d );
     137//! Translate degrees into radians
     138inline double qwtRadians( double degrees )
     139{
     140    return degrees * M_PI / 180.0;
     141}
     142
     143//! Translate radians into degrees
     144inline double qwtDegrees( double degrees )
     145{
     146    return degrees * 180.0 / M_PI;
    180147}
    181148
  • trunk/BNC/qwt/qwt_matrix_raster_data.cpp

    r4271 r8127  
    2121    }
    2222
    23     inline double value(size_t row, size_t col) const
     23    inline double value(int row, int col) const
    2424    {
    2525        return values.data()[ row * numColumns + col ];
     
    2929
    3030    QVector<double> values;
    31     size_t numColumns;
    32     size_t numRows;
     31    int numColumns;
     32    int numRows;
    3333
    3434    double dx;
     
    5555   \sa resampleMode(), value()
    5656*/
    57 void QwtMatrixRasterData::setResampleMode(ResampleMode mode)
     57void QwtMatrixRasterData::setResampleMode( ResampleMode mode )
    5858{
    5959    d_data->resampleMode = mode;
     
    106106*/
    107107void QwtMatrixRasterData::setValueMatrix(
    108     const QVector<double> &values, size_t numColumns )
     108    const QVector<double> &values, int numColumns )
    109109{
    110110    d_data->values = values;
    111     d_data->numColumns = numColumns;
     111    d_data->numColumns = qMax( numColumns, 0 );
    112112    update();
    113113}
     
    123123
    124124/*!
     125  \brief Change a single value in the matrix
     126
     127  \param row Row index
     128  \param col Column index
     129  \param value New value
     130
     131  \sa value(), setValueMatrix()
     132*/
     133void QwtMatrixRasterData::setValue( int row, int col, double value )
     134{
     135    if ( row >= 0 && row < d_data->numRows &&
     136        col >= 0 && col < d_data->numColumns )
     137    {
     138        const int index = row * d_data->numColumns + col;
     139        d_data->values.data()[ index ] = value;
     140    }
     141}
     142
     143/*!
    125144   \return Number of columns of the value matrix
    126145   \sa valueMatrix(), numRows(), setValueMatrix()
    127146*/
    128 size_t QwtMatrixRasterData::numColumns() const
     147int QwtMatrixRasterData::numColumns() const
    129148{
    130149    return d_data->numColumns;
     
    135154   \sa valueMatrix(), numColumns(), setValueMatrix()
    136155*/
    137 size_t QwtMatrixRasterData::numRows() const
     156int QwtMatrixRasterData::numRows() const
    138157{
    139158    return d_data->numRows;
     
    141160
    142161/*!
    143    \brief Pixel hint
     162   \brief Calculate the pixel hint
     163
     164   pixelHint() returns the geometry of a pixel, that can be used
     165   to calculate the resolution and alignment of the plot item, that is
     166   representing the data.
    144167
    145168   - NearestNeighbour\n
     
    151174     to render in target device ( f.e. screen ) resolution.
    152175
     176   \param area Requested area, ignored
     177   \return Calculated hint
     178
    153179   \sa ResampleMode, setMatrix(), setInterval()
    154180*/
    155 QRectF QwtMatrixRasterData::pixelHint( const QRectF & ) const
    156 {
     181QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const
     182{
     183    Q_UNUSED( area )
     184
    157185    QRectF rect;
    158186    if ( d_data->resampleMode == NearestNeighbour )
     
    199227            if ( col1 < 0 )
    200228                col1 = col2;
    201             else if ( col2 >= (int)d_data->numColumns )
     229            else if ( col2 >= static_cast<int>( d_data->numColumns ) )
    202230                col2 = col1;
    203231
    204232            if ( row1 < 0 )
    205233                row1 = row2;
    206             else if ( row2 >= (int)d_data->numRows )
     234            else if ( row2 >= static_cast<int>( d_data->numRows ) )
    207235                row2 = row1;
    208236
     
    230258        default:
    231259        {
    232             uint row = uint( (y - yInterval.minValue() ) / d_data->dy );
    233             uint col = uint( (x - xInterval.minValue() ) / d_data->dx );
     260            int row = int( (y - yInterval.minValue() ) / d_data->dy );
     261            int col = int( (x - xInterval.minValue() ) / d_data->dx );
    234262
    235263            // In case of intervals, where the maximum is included
  • trunk/BNC/qwt/qwt_matrix_raster_data.h

    r4271 r8127  
    5252
    5353    virtual void setInterval( Qt::Axis, const QwtInterval & );
    54     void setValueMatrix( const QVector<double> &values, size_t numColumns );
    55    
     54
     55    void setValueMatrix( const QVector<double> &values, int numColumns );
    5656    const QVector<double> valueMatrix() const;
    57     size_t numColumns() const;
    58     size_t numRows() const;
     57
     58    void setValue( int row, int col, double value );
     59
     60    int numColumns() const;
     61    int numRows() const;
    5962
    6063    virtual QRectF pixelHint( const QRectF & ) const;
  • trunk/BNC/qwt/qwt_null_paintdevice.cpp

    r4271 r8127  
    1616public:
    1717    PrivateData():
    18         size( 0, 0 )
    19     {
    20     }
    21 
    22     QSize size;
     18        mode( QwtNullPaintDevice::NormalMode )
     19    {
     20    }
     21
     22    QwtNullPaintDevice::Mode mode;
    2323};
    2424
     
    2626{
    2727public:
    28     PaintEngine( QPaintEngine::PaintEngineFeatures );
     28    PaintEngine();
    2929
    3030    virtual bool begin( QPaintDevice * );
     
    5555
    5656    virtual void drawTextItem(const QPointF &, const QTextItem &);
     57
    5758    virtual void drawTiledPixmap(const QRectF &,
    5859        const QPixmap &, const QPointF &s);
     60
    5961    virtual void drawImage(const QRectF &,
    6062        const QImage &, const QRectF &, Qt::ImageConversionFlags );
    6163
    6264private:
    63     QwtNullPaintDevice *d_device;
     65    QwtNullPaintDevice *nullDevice();
    6466};
    6567   
    66 QwtNullPaintDevice::PaintEngine::PaintEngine(
    67         QPaintEngine::PaintEngineFeatures features ):
    68     QPaintEngine( features ),
    69     d_device(NULL)
    70 {
    71 }
    72 
    73 bool QwtNullPaintDevice::PaintEngine::begin(
    74     QPaintDevice *device )
    75 {
    76     d_device = static_cast<QwtNullPaintDevice *>( device );
     68QwtNullPaintDevice::PaintEngine::PaintEngine():
     69    QPaintEngine( QPaintEngine::AllFeatures )
     70{
     71}
     72
     73bool QwtNullPaintDevice::PaintEngine::begin( QPaintDevice * )
     74{
     75    setActive( true );
    7776    return true;
    7877}
     
    8079bool QwtNullPaintDevice::PaintEngine::end()
    8180{
    82     d_device = NULL;
     81    setActive( false );
    8382    return true;
    8483}
    8584
    86 QPaintEngine::Type
    87 QwtNullPaintDevice::PaintEngine::type () const
     85QPaintEngine::Type QwtNullPaintDevice::PaintEngine::type() const
    8886{
    8987    return QPaintEngine::User;
     
    9391    const QRect *rects, int rectCount)
    9492{
    95     if ( d_device )
    96         d_device->drawRects( rects, rectCount );
     93    QwtNullPaintDevice *device = nullDevice();
     94    if ( device == NULL )
     95        return;
     96
     97    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     98    {
     99        QPaintEngine::drawRects( rects, rectCount );
     100        return;
     101    }
     102
     103    device->drawRects( rects, rectCount );
    97104}
    98105
     
    100107    const QRectF *rects, int rectCount)
    101108{
    102     if ( d_device )
    103         d_device->drawRects( rects, rectCount );
     109    QwtNullPaintDevice *device = nullDevice();
     110    if ( device == NULL )
     111        return;
     112
     113    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     114    {
     115        QPaintEngine::drawRects( rects, rectCount );
     116        return;
     117    }
     118
     119    device->drawRects( rects, rectCount );
    104120}
    105121
     
    107123    const QLine *lines, int lineCount)
    108124{
    109     if ( d_device )
    110         d_device->drawLines( lines, lineCount );
     125    QwtNullPaintDevice *device = nullDevice();
     126    if ( device == NULL )
     127        return;
     128
     129    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     130    {
     131        QPaintEngine::drawLines( lines, lineCount );
     132        return;
     133    }
     134
     135    device->drawLines( lines, lineCount );
    111136}
    112137
     
    114139    const QLineF *lines, int lineCount)
    115140{
    116     if ( d_device )
    117         d_device->drawLines( lines, lineCount );
     141    QwtNullPaintDevice *device = nullDevice();
     142    if ( device == NULL )
     143        return;
     144
     145    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     146    {
     147        QPaintEngine::drawLines( lines, lineCount );
     148        return;
     149    }
     150
     151    device->drawLines( lines, lineCount );
    118152}
    119153
     
    121155    const QRectF &rect)
    122156{
    123     if ( d_device )
    124         d_device->drawEllipse( rect );
     157    QwtNullPaintDevice *device = nullDevice();
     158    if ( device == NULL )
     159        return;
     160
     161    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     162    {
     163        QPaintEngine::drawEllipse( rect );
     164        return;
     165    }
     166
     167    device->drawEllipse( rect );
    125168}
    126169
     
    128171    const QRect &rect)
    129172{
    130     if ( d_device )
    131         d_device->drawEllipse( rect );
     173    QwtNullPaintDevice *device = nullDevice();
     174    if ( device == NULL )
     175        return;
     176
     177    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     178    {
     179        QPaintEngine::drawEllipse( rect );
     180        return;
     181    }
     182
     183    device->drawEllipse( rect );
    132184}
    133185
     
    136188    const QPainterPath &path)
    137189{
    138     if ( d_device )
    139         d_device->drawPath( path );
     190    QwtNullPaintDevice *device = nullDevice();
     191    if ( device == NULL )
     192        return;
     193
     194    device->drawPath( path );
    140195}
    141196
     
    143198    const QPointF *points, int pointCount)
    144199{
    145     if ( d_device )
    146         d_device->drawPoints( points, pointCount );
     200    QwtNullPaintDevice *device = nullDevice();
     201    if ( device == NULL )
     202        return;
     203
     204    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     205    {
     206        QPaintEngine::drawPoints( points, pointCount );
     207        return;
     208    }
     209
     210    device->drawPoints( points, pointCount );
    147211}
    148212
     
    150214    const QPoint *points, int pointCount)
    151215{
    152     if ( d_device )
    153         d_device->drawPoints( points, pointCount );
     216    QwtNullPaintDevice *device = nullDevice();
     217    if ( device == NULL )
     218        return;
     219
     220    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     221    {
     222        QPaintEngine::drawPoints( points, pointCount );
     223        return;
     224    }
     225
     226    device->drawPoints( points, pointCount );
    154227}
    155228
     
    157230    const QPointF *points, int pointCount, PolygonDrawMode mode)
    158231{
    159     if ( d_device )
    160         d_device->drawPolygon( points, pointCount, mode );
     232    QwtNullPaintDevice *device = nullDevice();
     233    if ( device == NULL )
     234        return;
     235
     236    if ( device->mode() == QwtNullPaintDevice::PathMode )
     237    {
     238        QPainterPath path;
     239
     240        if ( pointCount > 0 )
     241        {
     242            path.moveTo( points[0] );
     243            for ( int i = 1; i < pointCount; i++ )
     244                path.lineTo( points[i] );
     245
     246            if ( mode != PolylineMode )
     247                path.closeSubpath();
     248        }
     249
     250        device->drawPath( path );
     251        return;
     252    }
     253
     254    device->drawPolygon( points, pointCount, mode );
    161255}
    162256
     
    164258    const QPoint *points, int pointCount, PolygonDrawMode mode)
    165259{
    166     if ( d_device )
    167         d_device->drawPolygon( points, pointCount, mode );
     260    QwtNullPaintDevice *device = nullDevice();
     261    if ( device == NULL )
     262        return;
     263
     264    if ( device->mode() == QwtNullPaintDevice::PathMode )
     265    {
     266        QPainterPath path;
     267
     268        if ( pointCount > 0 )
     269        {
     270            path.moveTo( points[0] );
     271            for ( int i = 1; i < pointCount; i++ )
     272                path.lineTo( points[i] );
     273
     274            if ( mode != PolylineMode )
     275                path.closeSubpath();
     276        }
     277
     278        device->drawPath( path );
     279        return;
     280    }
     281
     282    device->drawPolygon( points, pointCount, mode );
    168283}
    169284
     
    171286    const QRectF &rect, const QPixmap &pm, const QRectF &subRect )
    172287{
    173     if ( d_device )
    174         d_device->drawPixmap( rect, pm, subRect );
     288    QwtNullPaintDevice *device = nullDevice();
     289    if ( device == NULL )
     290        return;
     291
     292    device->drawPixmap( rect, pm, subRect );
    175293}
    176294
     
    178296    const QPointF &pos, const QTextItem &textItem)
    179297{
    180     if ( d_device )
    181         d_device->drawTextItem( pos, textItem );
     298    QwtNullPaintDevice *device = nullDevice();
     299    if ( device == NULL )
     300        return;
     301
     302    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     303    {
     304        QPaintEngine::drawTextItem( pos, textItem );
     305        return;
     306    }
     307
     308    device->drawTextItem( pos, textItem );
    182309}
    183310
     
    186313    const QPointF &subRect)
    187314{
    188     if ( d_device )
    189         d_device->drawTiledPixmap( rect, pixmap, subRect );
     315    QwtNullPaintDevice *device = nullDevice();
     316    if ( device == NULL )
     317        return;
     318
     319    if ( device->mode() != QwtNullPaintDevice::NormalMode )
     320    {
     321        QPaintEngine::drawTiledPixmap( rect, pixmap, subRect );
     322        return;
     323    }   
     324
     325    device->drawTiledPixmap( rect, pixmap, subRect );
    190326}
    191327
     
    194330    const QRectF &subRect, Qt::ImageConversionFlags flags)
    195331{
    196     if ( d_device )
    197         d_device->drawImage( rect, image, subRect, flags );
     332    QwtNullPaintDevice *device = nullDevice();
     333    if ( device == NULL )
     334        return;
     335
     336    device->drawImage( rect, image, subRect, flags );
    198337}
    199338
     
    201340    const QPaintEngineState &state)
    202341{
    203     if ( d_device )
    204         d_device->updateState( state );
     342    QwtNullPaintDevice *device = nullDevice();
     343    if ( device == NULL )
     344        return;
     345
     346    device->updateState( state );
     347}
     348
     349inline QwtNullPaintDevice *QwtNullPaintDevice::PaintEngine::nullDevice()
     350{
     351    if ( !isActive() )
     352        return NULL;
     353
     354    return static_cast<QwtNullPaintDevice *>( paintDevice() );
    205355}
    206356
    207357//! Constructor
    208 QwtNullPaintDevice::QwtNullPaintDevice(
    209     QPaintEngine::PaintEngineFeatures features )
    210 {
    211     init( features );
    212 }
    213 
    214 //! Constructor
    215 QwtNullPaintDevice::QwtNullPaintDevice( const QSize &size,
    216     QPaintEngine::PaintEngineFeatures features )
    217 {
    218     init( features );
    219     d_data->size = size;
    220 }
    221 
    222 void QwtNullPaintDevice::init(
    223     QPaintEngine::PaintEngineFeatures features )
    224 {
    225     d_engine = new PaintEngine( features );
     358QwtNullPaintDevice::QwtNullPaintDevice():
     359    d_engine( NULL )
     360{
    226361    d_data = new PrivateData;
    227362}
     
    235370
    236371/*!
    237    Set the size of the paint device
    238 
    239    \param size Size
    240    \sa size()
     372    Set the render mode
     373
     374    \param mode New mode
     375    \sa mode()
     376 */
     377void QwtNullPaintDevice::setMode( Mode mode )
     378{
     379    d_data->mode = mode;
     380}
     381
     382/*!
     383    \return Render mode
     384    \sa setMode()
    241385*/
    242 void QwtNullPaintDevice::setSize( const QSize & size )
    243 {
    244     d_data->size = size;
    245 }
    246 
    247 /*!
    248     \return Size of the paint device
    249     \sa setSize()
    250 */
    251 QSize QwtNullPaintDevice::size() const
    252 {
    253     return d_data->size;
     386QwtNullPaintDevice::Mode QwtNullPaintDevice::mode() const
     387{
     388    return d_data->mode;
    254389}
    255390
     
    257392QPaintEngine *QwtNullPaintDevice::paintEngine() const
    258393{
     394    if ( d_engine == NULL )
     395    {
     396        QwtNullPaintDevice *that =
     397            const_cast< QwtNullPaintDevice * >( this );
     398
     399        that->d_engine = new PaintEngine();
     400    }
     401
    259402    return d_engine;
    260403}
     
    262405/*!
    263406    See QPaintDevice::metric()
    264     \sa setSize()
     407
     408    \param deviceMetric Type of metric
     409    \return Metric information for the given paint device metric.
     410
     411    \sa sizeMetrics()
    265412*/
    266 int QwtNullPaintDevice::metric( PaintDeviceMetric metric ) const
    267 {
    268     static QPixmap pm;
    269 
     413int QwtNullPaintDevice::metric( PaintDeviceMetric deviceMetric ) const
     414{
    270415    int value;
    271416
    272     switch ( metric )
     417    switch ( deviceMetric )
    273418    {
    274419        case PdmWidth:
    275             value = qMax( d_data->size.width(), 0 );
    276             break;
     420        {
     421            value = sizeMetrics().width();
     422            break;
     423        }
    277424        case PdmHeight:
    278             value = qMax( d_data->size.height(), 0 );
    279             break;
     425        {
     426            value = sizeMetrics().height();
     427            break;
     428        }
    280429        case PdmNumColors:
    281             value = 16777216;
    282             break;
     430        {
     431            value = 0xffffffff;
     432            break;
     433        }
    283434        case PdmDepth:
    284             value = 24;
    285             break;
     435        {
     436            value = 32;
     437            break;
     438        }
    286439        case PdmPhysicalDpiX:
     440        case PdmPhysicalDpiY:
    287441        case PdmDpiY:
    288         case PdmPhysicalDpiY:
     442        case PdmDpiX:
     443        {
     444            value = 72;
     445            break;
     446        }
    289447        case PdmWidthMM:
     448        {
     449            value = qRound( metric( PdmWidth ) * 25.4 / metric( PdmDpiX ) );
     450            break;
     451        }
    290452        case PdmHeightMM:
    291         case PdmDpiX:
     453        {
     454            value = qRound( metric( PdmHeight ) * 25.4 / metric( PdmDpiY ) );
     455            break;
     456        }
    292457        default:
    293458            value = 0;
  • trunk/BNC/qwt/qwt_null_paintdevice.h

    r4271 r8127  
    1919
    2020  Sometimes important layout/rendering geometries are not
    21   available or changable from the public Qt class interface.
     21  available or changeable from the public Qt class interface.
    2222  ( f.e hidden in the style implementation ).
    2323
    2424  QwtNullPaintDevice can be used to manipulate or filter out
    25   these informations by analyzing the stream of paint primitives.
     25  this information by analyzing the stream of paint primitives.
    2626
    2727  F.e. QwtNullPaintDevice is used by QwtPlotCanvas to identify
     
    3232{
    3333public:
    34     QwtNullPaintDevice( QPaintEngine::PaintEngineFeatures );
    35     QwtNullPaintDevice( const QSize &size,
    36         QPaintEngine::PaintEngineFeatures );
     34    /*!
     35      \brief Render mode
    3736
     37      \sa setMode(), mode()
     38     */
     39    enum Mode
     40    {
     41        /*!
     42           All vector graphic primitives are painted by
     43           the corresponding draw methods
     44         */
     45        NormalMode,
     46
     47        /*!
     48           Vector graphic primitives ( beside polygons ) are mapped to a QPainterPath
     49           and are painted by drawPath. In PathMode mode
     50           only a few draw methods are called:
     51
     52           - drawPath()
     53           - drawPixmap()
     54           - drawImage()
     55           - drawPolygon()
     56         */
     57        PolygonPathMode,
     58
     59        /*!
     60           Vector graphic primitives are mapped to a QPainterPath
     61           and are painted by drawPath. In PathMode mode
     62           only a few draw methods are called:
     63
     64           - drawPath()
     65           - drawPixmap()
     66           - drawImage()
     67         */
     68        PathMode
     69    };
     70
     71    QwtNullPaintDevice();
    3872    virtual ~QwtNullPaintDevice();
    3973
    40     void setSize( const QSize &);
    41     QSize size() const;
     74    void setMode( Mode );
     75    Mode mode() const;
    4276
    4377    virtual QPaintEngine *paintEngine() const;
     78
    4479    virtual int metric( PaintDeviceMetric metric ) const;
    4580
     
    77112    virtual void updateState( const QPaintEngineState &state );
    78113
     114protected:
     115    //! \return Size needed to implement metric()
     116    virtual QSize sizeMetrics() const = 0;
     117
    79118private:
    80     void init( QPaintEngine::PaintEngineFeatures );
    81 
    82119    class PaintEngine;
    83120    PaintEngine *d_engine;
  • trunk/BNC/qwt/qwt_painter.cpp

    r4271 r8127  
    2929#include <qdesktopwidget.h>
    3030
     31#if QT_VERSION >= 0x050000
     32#include <qwindow.h>
     33#endif
     34
     35#if QT_VERSION < 0x050000
     36
     37#ifdef Q_WS_X11
     38#include <qx11info_x11.h>
     39#endif
     40
     41#endif
     42
    3143bool QwtPainter::d_polylineSplitting = true;
    3244bool QwtPainter::d_roundingAlignment = true;
    3345
    34 static inline bool isClippingNeeded( const QPainter *painter, QRectF &clipRect )
     46static inline bool qwtIsClippingNeeded(
     47    const QPainter *painter, QRectF &clipRect )
    3548{
    3649    bool doClipping = false;
     
    5063}
    5164
    52 static inline void drawPolyline( QPainter *painter,
    53     const QPointF *points, int pointCount, bool polylineSplitting )
     65template <class T>
     66static inline void qwtDrawPolyline( QPainter *painter,
     67    const T *points, int pointCount, bool polylineSplitting )
    5468{
    5569    bool doSplit = false;
     
    7185    if ( doSplit )
    7286    {
    73         const int splitSize = 20;
     87        const int splitSize = 6;
     88
    7489        for ( int i = 0; i < pointCount; i += splitSize )
    7590        {
     
    7994    }
    8095    else
     96    {
    8197        painter->drawPolyline( points, pointCount );
    82 }
    83 
    84 static inline void unscaleFont( QPainter *painter )
     98    }
     99}
     100
     101static inline QSize qwtScreenResolution()
     102{
     103    static QSize screenResolution;
     104    if ( !screenResolution.isValid() )
     105    {
     106        QDesktopWidget *desktop = QApplication::desktop();
     107        if ( desktop )
     108        {
     109            screenResolution.setWidth( desktop->logicalDpiX() );
     110            screenResolution.setHeight( desktop->logicalDpiY() );
     111        }
     112    }
     113
     114    return screenResolution;
     115}
     116
     117static inline void qwtUnscaleFont( QPainter *painter )
    85118{
    86119    if ( painter->font().pixelSize() >= 0 )
    87120        return;
    88121
    89     static QSize screenResolution;
    90     if ( !screenResolution.isValid() )
    91     {
    92         QDesktopWidget *desktop = QApplication::desktop();
    93         if ( desktop )
    94         {
    95             screenResolution.setWidth( desktop->logicalDpiX() );
    96             screenResolution.setHeight( desktop->logicalDpiY() );
    97         }
    98     }
     122    const QSize screenResolution = qwtScreenResolution();
    99123
    100124    const QPaintDevice *pd = painter->device();
     
    107131        painter->setFont( pixelFont );
    108132    }
     133}
     134
     135/*!
     136  Check is the application is running with the X11 graphics system
     137  that has some special capabilities that can be used for incremental
     138  painting to a widget.
     139
     140  \return True, when the graphics system is X11
     141*/
     142bool QwtPainter::isX11GraphicsSystem()
     143{
     144    static int onX11 = -1;
     145    if ( onX11 < 0 )
     146    {
     147        QPixmap pm( 1, 1 );
     148        QPainter painter( &pm );
     149
     150        onX11 = ( painter.paintEngine()->type() == QPaintEngine::X11 ) ? 1 : 0;
     151    }
     152
     153    return onX11 == 1;
    109154}
    110155
     
    114159  beside QPaintEngine::Pdf and QPaintEngine::SVG.
    115160
     161  If we have an integer based paint engine it is also
     162  checked if the painter has a transformation matrix,
     163  that rotates or scales.
     164
    116165  \param  painter Painter
    117   \return true, when the paint engine is aligning
     166  \return true, when the painter is aligning
    118167
    119168  \sa setRoundingAlignment()
     
    131180            default:;
    132181        }
     182
     183        const QTransform tr = painter->transform();
     184        if ( tr.isRotating() || tr.isScaling() )
     185        {
     186            // we might have to check translations too
     187            return false;
     188        }
    133189    }
    134190
     
    139195  Enable whether coordinates should be rounded, before they are painted
    140196  to a paint engine that floors to integer values. For other paint engines
    141   this ( Pdf, SVG ), this flag has no effect.
    142   QwtPainter stores this flag only, the rounding itsself is done in
     197  ( PDF, SVG ) this flag has no effect.
     198  QwtPainter stores this flag only, the rounding itself is done in
    143199  the painting code ( f.e the plot items ).
    144200
     
    155211  \brief En/Disable line splitting for the raster paint engine
    156212
    157   The raster paint engine paints polylines of many points
    158   much faster when they are splitted in smaller chunks.
     213  In some Qt versions the raster paint engine paints polylines of many points
     214  much faster when they are split in smaller chunks: f.e all supported Qt versions
     215  >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2.
     216
     217  The default setting is true.
    159218
    160219  \sa polylineSplitting()
     
    183242
    184243    QRectF clipRect;
    185     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     244    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    186245
    187246    if ( deviceClipping )
     
    214273
    215274    QRectF clipRect;
    216     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     275    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    217276
    218277    /*
    219       Performance of Qt4 is horrible for non trivial brushs. Without
    220       clipping expect minutes or hours for repainting large rects
     278      Performance of Qt4 is horrible for a non trivial brush. Without
     279      clipping expect minutes or hours for repainting large rectangles
    221280      (might result from zooming)
    222281    */
     
    232291    QRectF r = rect;
    233292    if ( deviceClipping )
    234         r = r.intersect( clipRect );
     293        r = r.intersected( clipRect );
    235294
    236295    if ( r.isValid() )
     
    243302{
    244303    QRectF clipRect;
    245     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     304    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    246305    if ( deviceClipping && !clipRect.contains( rect ) )
    247306        return;
     
    254313{
    255314    QRectF clipRect;
    256     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     315    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    257316
    258317    if ( deviceClipping && !clipRect.contains( rect ) )
     
    274333{
    275334    QRectF clipRect;
    276     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     335    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    277336
    278337    if ( deviceClipping && !clipRect.contains( pos ) )
     
    281340
    282341    painter->save();
    283     unscaleFont( painter );
     342    qwtUnscaleFont( painter );
    284343    painter->drawText( pos, text );
    285344    painter->restore();
     
    299358{
    300359    painter->save();
    301     unscaleFont( painter );
     360    qwtUnscaleFont( painter );
    302361    painter->drawText( rect, flags, text );
    303362    painter->restore();
     
    321380    painter->save();
    322381
    323     painter->setFont( txt->defaultFont() );
    324     unscaleFont( painter );
     382    QRectF unscaledRect = rect;
     383
     384    if ( painter->font().pixelSize() < 0 )
     385    {
     386        const QSize res = qwtScreenResolution();
     387
     388        const QPaintDevice *pd = painter->device();
     389        if ( pd->logicalDpiX() != res.width() ||
     390            pd->logicalDpiY() != res.height() )
     391        {
     392            QTransform transform;
     393            transform.scale( res.width() / double( pd->logicalDpiX() ),
     394                res.height() / double( pd->logicalDpiY() ));
     395
     396            painter->setWorldTransform( transform, true );
     397            unscaledRect = transform.inverted().mapRect(rect);
     398        }
     399    } 
    325400
    326401    txt->setDefaultFont( painter->font() );
    327     txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
     402    txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) );
    328403
    329404    QAbstractTextDocumentLayout* layout = txt->documentLayout();
    330405
    331406    const double height = layout->documentSize().height();
    332     double y = rect.y();
     407    double y = unscaledRect.y();
    333408    if ( flags & Qt::AlignBottom )
    334         y += ( rect.height() - height );
     409        y += ( unscaledRect.height() - height );
    335410    else if ( flags & Qt::AlignVCenter )
    336         y += ( rect.height() - height ) / 2;
     411        y += ( unscaledRect.height() - height ) / 2;
    337412
    338413    QAbstractTextDocumentLayout::PaintContext context;
    339414    context.palette.setColor( QPalette::Text, painter->pen().color() );
    340415
    341     painter->translate( rect.x(), y );
     416    painter->translate( unscaledRect.x(), y );
    342417    layout->draw( painter, context );
    343418
     
    354429{
    355430    QRectF clipRect;
    356     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     431    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    357432
    358433    if ( deviceClipping &&
     
    373448{
    374449    QRectF clipRect;
    375     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     450    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    376451
    377452    QPolygonF cpa = polygon;
     
    386461{
    387462    QRectF clipRect;
    388     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     463    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    389464
    390465    QPolygonF cpa = polygon;
     
    392467        cpa = QwtClipper::clipPolygonF( clipRect, cpa );
    393468
    394     ::drawPolyline( painter,
     469    qwtDrawPolyline<QPointF>( painter,
    395470        cpa.constData(), cpa.size(), d_polylineSplitting );
    396471}
     
    401476{
    402477    QRectF clipRect;
    403     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     478    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    404479
    405480    if ( deviceClipping )
    406481    {
    407482        QPolygonF polygon( pointCount );
    408         qMemCopy( polygon.data(), points, pointCount * sizeof( QPointF ) );
     483        ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) );
    409484
    410485        polygon = QwtClipper::clipPolygonF( clipRect, polygon );
    411         ::drawPolyline( painter,
     486        qwtDrawPolyline<QPointF>( painter,
    412487            polygon.constData(), polygon.size(), d_polylineSplitting );
    413488    }
    414489    else
    415         ::drawPolyline( painter, points, pointCount, d_polylineSplitting );
     490    {
     491        qwtDrawPolyline<QPointF>( painter, points, pointCount, d_polylineSplitting );
     492    }
     493}
     494
     495//! Wrapper for QPainter::drawPolygon()
     496void QwtPainter::drawPolygon( QPainter *painter, const QPolygon &polygon )
     497{
     498    QRectF clipRect;
     499    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
     500
     501    QPolygon cpa = polygon;
     502    if ( deviceClipping )
     503        cpa = QwtClipper::clipPolygon( clipRect, polygon );
     504
     505    painter->drawPolygon( cpa );
     506}
     507
     508//! Wrapper for QPainter::drawPolyline()
     509void QwtPainter::drawPolyline( QPainter *painter, const QPolygon &polygon )
     510{
     511    QRectF clipRect;
     512    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
     513
     514    QPolygon cpa = polygon;
     515    if ( deviceClipping )
     516        cpa = QwtClipper::clipPolygon( clipRect, cpa );
     517
     518    qwtDrawPolyline<QPoint>( painter,
     519        cpa.constData(), cpa.size(), d_polylineSplitting );
     520}
     521
     522//! Wrapper for QPainter::drawPolyline()
     523void QwtPainter::drawPolyline( QPainter *painter,
     524    const QPoint *points, int pointCount )
     525{
     526    QRectF clipRect;
     527    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
     528
     529    if ( deviceClipping )
     530    {
     531        QPolygon polygon( pointCount );
     532        ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) );
     533
     534        polygon = QwtClipper::clipPolygon( clipRect, polygon );
     535        qwtDrawPolyline<QPoint>( painter,
     536            polygon.constData(), polygon.size(), d_polylineSplitting );
     537    }
     538    else
     539        qwtDrawPolyline<QPoint>( painter, points, pointCount, d_polylineSplitting );
    416540}
    417541
     
    420544{
    421545    QRectF clipRect;
    422     const bool deviceClipping = isClippingNeeded( painter, clipRect );
     546    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
    423547
    424548    if ( deviceClipping && !clipRect.contains( pos ) )
     
    426550
    427551    painter->drawPoint( pos );
     552}
     553
     554//! Wrapper for QPainter::drawPoint()
     555void QwtPainter::drawPoint( QPainter *painter, const QPoint &pos )
     556{
     557    QRectF clipRect;
     558    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
     559
     560    if ( deviceClipping )
     561    {
     562        const int minX = qCeil( clipRect.left() );
     563        const int maxX = qFloor( clipRect.right() );
     564        const int minY = qCeil( clipRect.top() );
     565        const int maxY = qFloor( clipRect.bottom() );
     566
     567        if ( pos.x() < minX || pos.x() > maxX
     568            || pos.y() < minY || pos.y() > maxY )
     569        {
     570            return;
     571        }
     572    }
     573
     574    painter->drawPoint( pos );
     575}
     576
     577//! Wrapper for QPainter::drawPoints()
     578void QwtPainter::drawPoints( QPainter *painter,
     579    const QPoint *points, int pointCount )
     580{
     581    QRectF clipRect;
     582    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
     583
     584    if ( deviceClipping )
     585    {
     586        const int minX = qCeil( clipRect.left() );
     587        const int maxX = qFloor( clipRect.right() );
     588        const int minY = qCeil( clipRect.top() );
     589        const int maxY = qFloor( clipRect.bottom() );
     590
     591        const QRect r( minX, minY, maxX - minX, maxY - minY );
     592
     593        QPolygon clippedPolygon( pointCount );
     594        QPoint *clippedData = clippedPolygon.data();
     595
     596        int numClippedPoints = 0;
     597        for ( int i = 0; i < pointCount; i++ )
     598        {
     599            if ( r.contains( points[i] ) )
     600                clippedData[ numClippedPoints++ ] = points[i];
     601        }
     602        painter->drawPoints( clippedData, numClippedPoints );
     603    }
     604    else
     605    {
     606        painter->drawPoints( points, pointCount );
     607    }
     608}
     609
     610//! Wrapper for QPainter::drawPoints()
     611void QwtPainter::drawPoints( QPainter *painter,
     612    const QPointF *points, int pointCount )
     613{
     614    QRectF clipRect;
     615    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );
     616
     617    if ( deviceClipping )
     618    {
     619        QPolygonF clippedPolygon( pointCount );
     620        QPointF *clippedData = clippedPolygon.data();
     621
     622        int numClippedPoints = 0;
     623        for ( int i = 0; i < pointCount; i++ )
     624        {
     625            if ( clipRect.contains( points[i] ) )
     626                clippedData[ numClippedPoints++ ] = points[i];
     627        }
     628        painter->drawPoints( clippedData, numClippedPoints );
     629    }
     630    else
     631    {
     632        painter->drawPoints( points, pointCount );
     633    }
    428634}
    429635
     
    471677
    472678//! Draw a focus rectangle on a widget using its style.
    473 void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget )
     679void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget )
    474680{
    475681    drawFocusRect( painter, widget, widget->rect() );
     
    477683
    478684//! Draw a focus rectangle on a widget using its style.
    479 void QwtPainter::drawFocusRect( QPainter *painter, QWidget *widget,
     685void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget,
    480686    const QRect &rect )
    481687{
     
    484690    opt.rect = rect;
    485691    opt.state |= QStyle::State_HasFocus;
    486 
    487     widget->style()->drawPrimitive( QStyle::PE_FrameFocusRect,
    488         &opt, painter, widget );
     692    opt.backgroundColor = widget->palette().color( widget->backgroundRole() );
     693
     694    widget->style()->drawPrimitive(
     695        QStyle::PE_FrameFocusRect, &opt, painter, widget );
    489696}
    490697
    491698/*!
    492   Draw a frame with rounded borders
     699  Draw a round frame
     700
     701  \param painter Painter
     702  \param rect Frame rectangle
     703  \param palette QPalette::WindowText is used for plain borders
     704                 QPalette::Dark and QPalette::Light for raised
     705                 or sunken borders
     706  \param lineWidth Line width
     707  \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow
     708*/
     709void QwtPainter::drawRoundFrame( QPainter *painter,
     710    const QRectF &rect, const QPalette &palette,
     711    int lineWidth, int frameStyle )
     712{
     713    enum Style
     714    {
     715        Plain,
     716        Sunken,
     717        Raised
     718    };
     719
     720    Style style = Plain;
     721    if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )
     722        style = Sunken;
     723    else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )
     724        style = Raised;
     725
     726    const double lw2 = 0.5 * lineWidth;
     727    QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 );
     728
     729    QBrush brush;
     730
     731    if ( style != Plain )
     732    {
     733        QColor c1 = palette.color( QPalette::Light );
     734        QColor c2 = palette.color( QPalette::Dark );
     735
     736        if ( style == Sunken )
     737            qSwap( c1, c2 );
     738
     739        QLinearGradient gradient( r.topLeft(), r.bottomRight() );
     740        gradient.setColorAt( 0.0, c1 );
     741#if 0
     742        gradient.setColorAt( 0.3, c1 );
     743        gradient.setColorAt( 0.7, c2 );
     744#endif
     745        gradient.setColorAt( 1.0, c2 );
     746
     747        brush = QBrush( gradient );
     748    }
     749    else // Plain
     750    {
     751        brush = palette.brush( QPalette::WindowText );
     752    }
     753
     754    painter->save();
     755