6 class TaskSummaryPieChart
: public QGraphicsItem
9 TaskSummaryPieChart(QGraphicsItem
* parent
= NULL
) : QGraphicsItem(parent
)
11 setAcceptsHoverEvents(true);
13 QRectF
boundingRect() const { return QRectF(-0.61,-0.6,1.2,1.2);}
14 void setHits(const QList
<HitElement
>& hits
)
16 qDeleteAll(m_subItems
);
19 // compute total values per task
21 QMap
<Task
*, double> totals
;
22 for(QList
<HitElement
>::const_iterator itr
= hits
.begin(); itr
!= hits
.end(); itr
++) {
23 const HitElement
& element
= (*itr
);
24 total
+= element
.duration
;
25 totals
[element
.task
] = totals
.value(element
.task
, 0) + element
.duration
;
28 QMap
<double, Task
*> sortedTotals
;
29 for(QMap
<Task
*, double>::const_iterator titr
= totals
.begin(); titr
!=totals
.end(); titr
++) {
30 sortedTotals
.insertMulti(titr
.value(), titr
.key());
32 double startAngle
= 90;
33 for(QMap
<double, Task
*>::const_iterator itr
= sortedTotals
.begin(); itr
!= sortedTotals
.end(); itr
++) {
35 double spanAngle
= itr
.key() / (total
) * 360;
36 QGraphicsPathItem
* pathItem
= new QGraphicsPathItem(this);
37 scene()->addItem(pathItem
);
38 pathItem
->setToolTip(task
->title
);
42 p
.arcTo(boundingRect(), startAngle
, spanAngle
);
45 pathItem
->setBrush(task
->bgColor
);
46 pathItem
->setPen(QPen(QBrush(task
->fgColor
),0));
47 startAngle
+= spanAngle
;
48 m_subItems
.insert(task
, pathItem
);
51 virtual void paint ( QPainter
* painter
, const QStyleOptionGraphicsItem
* /* option */, QWidget
* /* widget */ )
54 // void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
57 QMap
<Task
*, QGraphicsPathItem
*> m_subItems
;