##// END OF EJS Templates
Bugfix missing min max intialization when axis added to domain
Bugfix missing min max intialization when axis added to domain

File last commit:

r437:8d9e377a1065
r442:6c610328d6c5
Show More
pieslice.cpp
201 lines | 5.1 KiB | text/x-c | CppLexer
Jani Honkonen
Add _p to pie internal headers
r353 #include "pieslice_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),
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),
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 m_explodeDistance(0),
m_labelVisible(false)
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
Added a pie chart customization example and refactoring the pie interface.
r437 return m_slicePath.boundingRect();
Tero Ahola
Integrated draft version of pie series
r51 }
QPainterPath PieSlice::shape() const
{
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 return m_slicePath;
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
Added a pie chart customization example and refactoring the pie interface.
r437 painter->save();
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
Added a pie chart customization example and refactoring the pie interface.
r437 painter->drawPath(m_slicePath);
painter->restore();
if (m_labelVisible) {
painter->save();
painter->setPen(m_labelArmPen);
painter->drawPath(m_labelArmPath);
painter->restore();
painter->setFont(m_labelFont);
painter->drawText(m_labelTextRect.bottomLeft(), m_labelText);
}
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
Added a pie chart customization example and refactoring the pie interface.
r437 // update slice path
QPointF center = m_pieRect.center();
qreal radius = m_pieRect.height() / 2;
qreal centerAngle;
QPointF armStart;
m_slicePath = slicePath(center, radius, m_startAngle, m_angleSpan, m_isExploded, m_explodeDistance, &centerAngle, &armStart);
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 // update text rect
m_labelTextRect = labelTextRect(m_labelFont, m_labelText);
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 // update label arm path
QPointF labelTextStart;
m_labelArmPath = labelArmPath(armStart, centerAngle, m_labelArmLength, m_labelTextRect.width(), &labelTextStart);
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 // update text position
m_labelTextRect.moveBottomLeft(labelTextStart);
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
Added a pie chart customization example and refactoring the pie interface.
r437 m_explodeDistance = sliceData->explodeDistance();
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
Added a pie chart customization example and refactoring the pie interface.
r437 m_labelVisible = sliceData->isLabelVisible();
m_labelText = sliceData->label();
m_labelFont = sliceData->labelFont();
m_labelArmLength = sliceData->labelArmLength();
m_labelArmPen = sliceData->labelPen();
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
Added a pie chart customization example and refactoring the pie interface.
r437 QPainterPath PieSlice::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, bool exploded, qreal explodeDistance, qreal* centerAngle, QPointF* armStart)
{
// calculate center angle
*centerAngle = startAngle + (angleSpan/2);
// calculate slice rectangle
QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2);
// adjust rect for exploding
if (exploded) {
qreal dx = qSin(*centerAngle*(PI/180)) * explodeDistance;
qreal dy = -qCos(*centerAngle*(PI/180)) * explodeDistance;
rect.translate(dx, dy);
}
// slice path
// TODO: draw the shape so that it might have a hole in the center
QPainterPath path;
path.moveTo(rect.center());
path.arcTo(rect, -startAngle + 90, -angleSpan);
path.closeSubpath();
// calculate label arm start point
*armStart = center;
if (exploded)
*armStart += offset(*centerAngle, explodeDistance + radius + PIESLICE_LABEL_GAP);
else
*armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP);
return path;
}
QPainterPath PieSlice::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF* textStart)
{
qreal dx = qSin(angle*(PI/180)) * length;
qreal dy = -qCos(angle*(PI/180)) * length;
QPointF parm1 = start + QPointF(dx, dy);
QPointF parm2 = parm1;
if (angle < 180) { // arm swings the other way on the left side
parm2 += QPointF(textWidth, 0);
*textStart = parm1;
}
else {
parm2 += QPointF(-textWidth,0);
*textStart = parm2;
}
// elevate the text position a bit so that it does not hit the line
*textStart += QPointF(0, -5);
QPainterPath path;
path.moveTo(start);
path.lineTo(parm1);
path.lineTo(parm2);
return path;
}
QRectF PieSlice::labelTextRect(QFont font, QString text)
{
QFontMetricsF fm(font);
return fm.boundingRect(text);
}
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