2
#include <qwt_scale_map.h>
3
#include <qwt_plot_curve.h>
5
#include "cpupiemarker.h"
7
CpuPieMarker::CpuPieMarker()
10
#if QT_VERSION >= 0x040000
11
setRenderHint(QwtPlotItem::RenderAntialiased, true);
15
int CpuPieMarker::rtti() const
17
return QwtPlotItem::Rtti_PlotUserItem;
20
void CpuPieMarker::draw(QPainter *p,
21
const QwtScaleMap &, const QwtScaleMap &,
22
const QRect &rect) const
24
const CpuPlot *cpuPlot = (CpuPlot *)plot();
26
const QwtScaleMap yMap = cpuPlot->canvasMap(QwtPlot::yLeft);
31
pieRect.setX(rect.x() + margin);
32
pieRect.setY(rect.y() + margin);
33
pieRect.setHeight(yMap.transform(80.0));
34
pieRect.setWidth(pieRect.height());
36
const int dataType[] = { CpuPlot::User, CpuPlot::System, CpuPlot::Idle };
38
int angle = (int)(5760 * 0.75);
39
for ( unsigned int i = 0;
40
i < sizeof(dataType) / sizeof(dataType[0]); i++ )
42
const QwtPlotCurve *curve = cpuPlot->cpuCurve(dataType[i]);
43
if ( curve->dataSize() > 0 )
45
const int value = (int)(5760 * curve->y(0) / 100.0);
48
p->setBrush(QBrush(curve->pen().color(), Qt::SolidPattern));
50
p->drawPie(pieRect, -angle, -value);