File: cpupiemarker.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 (54 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download | duplicates (3)
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
#include <qpainter.h>
#include <qwt_scale_map.h>
#include <qwt_plot_curve.h>
#include "cpuplot.h"
#include "cpupiemarker.h"

CpuPieMarker::CpuPieMarker()
{
    setZ( 1000 );
    setRenderHint( QwtPlotItem::RenderAntialiased, true );
}

int CpuPieMarker::rtti() const
{
    return QwtPlotItem::Rtti_PlotUserItem;
}

void CpuPieMarker::draw( QPainter *painter,
    const QwtScaleMap &, const QwtScaleMap &,
    const QRectF &rect ) const
{
    const CpuPlot *cpuPlot = static_cast<CpuPlot *> ( plot() );

    const QwtScaleMap yMap = cpuPlot->canvasMap( QwtPlot::yLeft );

    const int margin = 5;

    QRectF pieRect;
    pieRect.setX( rect.x() + margin );
    pieRect.setY( rect.y() + margin );
    pieRect.setHeight( yMap.transform( 80.0 ) );
    pieRect.setWidth( pieRect.height() );

    const int dataType[] = { CpuPlot::User, CpuPlot::System, CpuPlot::Idle };

    int angle = static_cast<int>( 5760 * 0.75 );
    for ( unsigned int i = 0;
        i < sizeof( dataType ) / sizeof( dataType[0] ); i++ )
    {
        const QwtPlotCurve *curve = cpuPlot->cpuCurve( dataType[i] );
        if ( curve->dataSize() > 0 )
        {
            const int value = static_cast<int>( 5760 * curve->sample( 0 ).y() / 100.0 );

            painter->save();
            painter->setBrush( QBrush( curve->brush().color(), Qt::SolidPattern ) );
            if ( value != 0 )
                painter->drawPie( pieRect, -angle, -value );
            painter->restore();

            angle += value;
        }
    }
}