File: plot.cpp

package info (click to toggle)
qwt 6.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 23,808 kB
  • sloc: cpp: 57,687; xml: 182; makefile: 32
file content (70 lines) | stat: -rw-r--r-- 2,097 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "plot.h"
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <qwt_plot_picker.h>
#include <qwt_scale_engine.h>

Plot::Plot( QWidget *parent ):
    QwtPlot( parent )
{
    setCanvasBackground( Qt::white );

    setAxisScale(QwtPlot::yLeft, 0.0, 10.0 );
    setTransformation( new QwtNullTransform() );

    populate();

    QwtPlotPicker *picker = new QwtPlotPicker( canvas() );
    picker->setTrackerMode( QwtPlotPicker::AlwaysOn );
}

void Plot::populate()
{
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->setMinorPen( Qt::black, 0, Qt::DashLine );
    grid->enableXMin( true );
    grid->attach( this );

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle("Some Points");
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
        QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol );

    QPolygonF points;
    points << QPointF( 10.0, 4.4 )
        << QPointF( 100.0, 3.0 ) << QPointF( 200.0, 4.5 )
        << QPointF( 300.0, 6.8 ) << QPointF( 400.0, 7.9 )
        << QPointF( 500.0, 7.1 ) << QPointF( 600.0, 7.9 )
        << QPointF( 700.0, 7.1 ) << QPointF( 800.0, 5.4 )
        << QPointF( 900.0, 2.8 ) << QPointF( 1000.0, 3.6 );
    curve->setSamples( points );
    curve->attach( this );
}

void Plot::setTransformation( QwtTransform *transform )
{
    QwtLinearScaleEngine *scaleEngine = new QwtLinearScaleEngine();
    scaleEngine->setTransformation( transform );

    setAxisScaleEngine( QwtPlot::xBottom, scaleEngine );

    // we have to reassign the axis settinge, because they are
    // invalidated, when the scale engine has changed

    QwtScaleDiv scaleDiv =
        axisScaleEngine( QwtPlot::xBottom )->divideScale( 10.0, 1000.0, 8, 10 );

    QList<double> ticks;
    ticks += 10.0;
    ticks += scaleDiv.ticks( QwtScaleDiv::MajorTick );
    scaleDiv.setTicks( QwtScaleDiv::MajorTick, ticks );

    setAxisScaleDiv( QwtPlot::xBottom, scaleDiv );

    replot();
}