##// END OF EJS Templates
Clean up obsolete create metods in series
Clean up obsolete create metods in series

File last commit:

r146:6c3759bde1fd
r156:68a8d6592838
Show More
pieslice.cpp
91 lines | 2.6 KiB | text/x-c | CppLexer
Tero Ahola
Integrated draft version of pie series
r51 #include "pieslice.h"
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 #include "piepresenter.h"
Tero Ahola
Integrated draft version of pie series
r51 #include <QPainter>
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 PieSlice::PieSlice(PiePresenter *piePresentation, int seriesIndex, qreal startAngle, qreal span)
Jani Honkonen
Pie chart refactoring
r142 :QGraphicsItem(piePresentation),
m_seriesIndex(seriesIndex),
Tero Ahola
Integrated draft version of pie series
r51 m_startAngle(startAngle),
Jani Honkonen
Pie chart refactoring
r142 m_span(span)
Tero Ahola
Integrated draft version of pie series
r51 {
Jani Honkonen
Pie chart refactoring
r142 Q_ASSERT(piePresentation);
Tero Ahola
Integrated draft version of pie series
r51 setAcceptHoverEvents(true);
Jani Honkonen
Pie chart refactoring
r142 setAcceptedMouseButtons(Qt::LeftButton);
Tero Ahola
Integrated draft version of pie series
r51 }
PieSlice::~PieSlice()
{
}
QRectF PieSlice::boundingRect() const
{
Jani Honkonen
Pie chart refactoring
r142 return shape().boundingRect();
Tero Ahola
Integrated draft version of pie series
r51 }
QPainterPath PieSlice::shape() const
{
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 QRectF rect = (static_cast<PiePresenter*>(parentItem()))->pieRect();
Tero Ahola
Integrated draft version of pie series
r51 qreal angle = (-m_startAngle) + (90);
qreal span = -m_span;
QPainterPath path;
Jani Honkonen
Pie chart refactoring
r142 path.moveTo(rect.center());
path.arcTo(rect, angle, span);
Tero Ahola
Integrated draft version of pie series
r51
// TODO: draw the shape so that it might have a hole in the center
// - Sin & Cos will be needed to find inner/outer arc endpoints
// dx, dy are offsets from the center
//qreal l = boundingRect().height();
//qreal dx = qSin(angle*(M_PI/180)) * l;
//qreal dy = qCos(angle*(M_PI/180)) * l;
// TODO: exploded slice?
return path;
}
Jani Honkonen
Pie chart refactoring
r142 void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
Tero Ahola
Integrated draft version of pie series
r51 {
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 painter->setRenderHint(QPainter::Antialiasing);
Tero Ahola
One more alternative for changing themes
r108 // TODO: how to map theme settings to a pie slice? Now we
//painter->setPen(m_theme.linePen);
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 // TODO:
Jani Honkonen
Pie chart refactoring
r142
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 QPieSlice data = (static_cast<PiePresenter*>(parentItem()))->m_pieSeries->slice(m_seriesIndex);
Jani Honkonen
Pie chart refactoring
r142 painter->setBrush(data.m_color);
Michal Klocek
Refactor themes...
r143
Jani Honkonen
Pie chart refactoring
r142 //painter->setBrush(m_theme.linePen.color());
Tero Ahola
Integrated draft version of pie series
r51
// From Qt docs:
// The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360).
// Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction.
// Zero degrees is at the 3 o'clock position.
//
// For sake of simplicity convert this so that zero degrees is at 12 o'clock and full circle is 360.
//qreal angle = (-m_startAngle*16) + (90*16);
//qreal span = -m_span*16;
//painter->drawPie(boundingRect(), angle, span);
painter->drawPath(shape());
Jani Honkonen
Pie chart refactoring
r142
// Draw the label
// TODO: do this better
painter->drawText(boundingRect().center(), data.m_label);
Tero Ahola
Integrated draft version of pie series
r51 }
void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
{
QGraphicsItem::hoverEnterEvent(event);
Jani Honkonen
Pie chart refactoring
r142 qDebug() << "hover" << m_seriesIndex << m_startAngle << m_span;
Tero Ahola
Integrated draft version of pie series
r51 }
Jani Honkonen
Pie chart refactoring
r142 void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
}
Tero Ahola
Integrated draft version of pie series
r51 QTCOMMERCIALCHART_END_NAMESPACE