##// END OF EJS Templates
added _p to private class headers
added _p to private class headers

File last commit:

r355:b889b21eeadf
r381:8ab9ba5c10bd
Show More
pieslice.cpp
135 lines | 3.3 KiB | text/x-c | CppLexer
Jani Honkonen
Add _p to pie internal headers
r353 #include "pieslice_p.h"
#include "pieslicelabel_p.h"
#include "piepresenter_p.h"
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 #include "qpieseries.h"
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 #include "qpieslice.h"
Tero Ahola
Integrated draft version of pie series
r51 #include <QPainter>
#include <QDebug>
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 #include <qmath.h>
Jani Honkonen
Make pie work better with chartwidgettest
r163 #include <QGraphicsSceneEvent>
Jani Honkonen
Refactoring piechart API (and internals)
r174 #include <QTime>
Tero Ahola
Integrated draft version of pie series
r51
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 QPointF offset(qreal angle, qreal length)
{
qreal dx = qSin(angle*(PI/180)) * length;
qreal dy = qCos(angle*(PI/180)) * length;
return QPointF(dx, -dy);
}
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 PieSlice::PieSlice(QGraphicsItem* parent)
Jani Honkonen
Refactoring piechart API (and internals)
r174 :QGraphicsObject(parent),
m_slicelabel(new PieSliceLabel(this)),
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 m_startAngle(0),
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 m_angleSpan(0),
m_isExploded(false),
m_explodeDistance(0)
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()
{
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203
Tero Ahola
Integrated draft version of pie series
r51 }
QRectF PieSlice::boundingRect() const
{
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 return m_path.boundingRect();
Tero Ahola
Integrated draft version of pie series
r51 }
QPainterPath PieSlice::shape() const
{
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 return m_path;
Tero Ahola
Integrated draft version of pie series
r51 }
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 {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 painter->setPen(m_pen);
painter->setBrush(m_brush);
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 painter->drawPath(m_path);
Tero Ahola
Integrated draft version of pie series
r51 }
Jani Honkonen
Refactoring piechart API (and internals)
r174 void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/)
Tero Ahola
Integrated draft version of pie series
r51 {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit hoverEnter();
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 }
Jani Honkonen
Make pie work better with chartwidgettest
r163 void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit hoverLeave();
Tero Ahola
Integrated draft version of pie series
r51 }
Jani Honkonen
Make pie work better with chartwidgettest
r163 void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit clicked();
}
void PieSlice::setPieRect(QRectF rect)
{
m_pieRect = rect;
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 }
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void PieSlice::updateGeometry()
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 {
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 if (!m_pieRect.isValid() || m_pieRect.isEmpty())
return;
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 prepareGeometryChange();
Jani Honkonen
Refactoring piechart API (and internals)
r174 // calculate center angle
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 qreal centerAngle = m_startAngle + (m_angleSpan/2);
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Refactoring piechart API (and internals)
r174 // adjust rect for exploding
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QRectF rect = m_pieRect;
if (m_isExploded) {
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 qreal dx = qSin(centerAngle*(PI/180)) * m_explodeDistance;
qreal dy = -qCos(centerAngle*(PI/180)) * m_explodeDistance;
rect.translate(dx, dy);
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 }
Jani Honkonen
Refactoring piechart API (and internals)
r174 // update slice path
// TODO: draw the shape so that it might have a hole in the center
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 QPainterPath path;
path.moveTo(rect.center());
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 path.arcTo(rect, -m_startAngle + 90, -m_angleSpan);
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 path.closeSubpath();
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 m_path = path;
Jani Honkonen
Refactoring piechart API (and internals)
r174 // update label position
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 qreal radius = rect.height() / 2;
Jani Honkonen
Refactoring piechart API (and internals)
r174 QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5);
Jani Honkonen
Implementing slice label
r181 m_slicelabel->setArmStartPoint(edgeCenter);
m_slicelabel->setArmAngle(centerAngle);
m_slicelabel->updateGeometry();
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 m_slicelabel->update();
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 //qDebug() << "PieSlice::updateGeometry" << m_slicelabel->text() << boundingRect() << m_angle << m_span;
}
void PieSlice::updateData(const QPieSlice* sliceData)
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 // TODO: compare what has changes to avoid unneccesary geometry updates
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 m_startAngle = sliceData->startAngle();
m_angleSpan = sliceData->m_angleSpan;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_isExploded = sliceData->isExploded();
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 m_explodeDistance = sliceData->explodeDistance(); // TODO: expose to public API
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_pen = sliceData->pen();
m_brush = sliceData->brush();
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_slicelabel->setVisible(sliceData->isLabelVisible());
m_slicelabel->setText(sliceData->label());
m_slicelabel->setPen(sliceData->labelPen());
m_slicelabel->setFont(sliceData->labelFont());
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 m_slicelabel->setArmLength(sliceData->labelArmLength());
Jani Honkonen
Fix issue with pie label not drawn correctly when first created
r209
updateGeometry();
update();
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 }
Jani Honkonen
Add _p to pie internal headers
r353 #include "moc_pieslice_p.cpp"
Jani Honkonen
Refactoring piechart API (and internals)
r174
Tero Ahola
Integrated draft version of pie series
r51 QTCOMMERCIALCHART_END_NAMESPACE