~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.0.1/examples/cpuplot/cpupiemarker.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <qpainter.h>
2
 
#include <qwt_scale_map.h>
3
 
#include <qwt_plot_curve.h>
4
 
#include "cpuplot.h"
5
 
#include "cpupiemarker.h"
6
 
 
7
 
CpuPieMarker::CpuPieMarker()
8
 
{
9
 
    setZ(1000);
10
 
#if QT_VERSION >= 0x040000
11
 
    setRenderHint(QwtPlotItem::RenderAntialiased, true);
12
 
#endif
13
 
}
14
 
 
15
 
int CpuPieMarker::rtti() const
16
 
{
17
 
    return QwtPlotItem::Rtti_PlotUserItem;
18
 
}
19
 
 
20
 
void CpuPieMarker::draw(QPainter *p, 
21
 
    const QwtScaleMap &, const QwtScaleMap &,
22
 
    const QRect &rect) const
23
 
{
24
 
    const CpuPlot *cpuPlot = (CpuPlot *)plot();
25
 
 
26
 
    const QwtScaleMap yMap = cpuPlot->canvasMap(QwtPlot::yLeft);
27
 
 
28
 
    const int margin = 5;
29
 
    
30
 
    QRect pieRect;
31
 
    pieRect.setX(rect.x() + margin);
32
 
    pieRect.setY(rect.y() + margin);
33
 
    pieRect.setHeight(yMap.transform(80.0));
34
 
    pieRect.setWidth(pieRect.height());
35
 
    
36
 
    const int dataType[] = { CpuPlot::User, CpuPlot::System, CpuPlot::Idle };
37
 
 
38
 
    int angle = (int)(5760 * 0.75);
39
 
    for ( unsigned int i = 0; 
40
 
        i < sizeof(dataType) / sizeof(dataType[0]); i++ )
41
 
    {
42
 
        const QwtPlotCurve *curve = cpuPlot->cpuCurve(dataType[i]);
43
 
        if ( curve->dataSize() > 0 )
44
 
        {
45
 
            const int value = (int)(5760 * curve->y(0) / 100.0);
46
 
 
47
 
            p->save();
48
 
            p->setBrush(QBrush(curve->pen().color(), Qt::SolidPattern));
49
 
            if ( value != 0 )
50
 
                p->drawPie(pieRect, -angle, -value);
51
 
            p->restore();
52
 
 
53
 
            angle += value;
54
 
        }
55
 
    }
56
 
}
57