##// END OF EJS Templates
Use signals from pieseries, visible hover and exploding slices
Use signals from pieseries, visible hover and exploding slices

File last commit:

r157:036a0ec8efe0
r157:036a0ec8efe0
Show More
piepresenter.cpp
113 lines | 3.3 KiB | text/x-c | CppLexer
Jani Honkonen
Pie chart refactoring
r142
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 #include "piepresenter.h"
Jani Honkonen
Pie chart refactoring
r142 #include "pieslice.h"
#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) :
Jani Honkonen
Pie chart refactoring
r142 ChartItem(parent),
m_pieSeries(series)
{
Q_ASSERT(parent);
Q_ASSERT(series);
m_rect = parentItem()->boundingRect();
setAcceptHoverEvents(true);
}
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 PiePresenter::~PiePresenter()
Jani Honkonen
Pie chart refactoring
r142 {
while (m_slices.count())
delete m_slices.takeLast();
}
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 void PiePresenter::handleSeriesChanged(const PieChangeSet& changeSet)
Jani Honkonen
Pie chart refactoring
r142 {
const qreal fullPie = 360;
qreal total = 0;
// calculate total
foreach (QPieSlice sliceData, m_pieSeries->slices())
total += sliceData.m_value;
// TODO: no need to create new slices in case size changed; we should re-use the existing ones
while (m_slices.count())
delete m_slices.takeLast();
// create slices
qreal angle = 0;
for (int i=0; i<m_pieSeries->count(); i++) {
QPieSlice sliceData = m_pieSeries->slice(i);
qreal span = sliceData.m_value / total * fullPie;
PieSlice *slice = new PieSlice(this, i, angle, span);
m_slices.append(slice);
angle += span;
}
}
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 void PiePresenter::updateGeometry()
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 prepareGeometryChange();
Jani Honkonen
Pie chart refactoring
r142 m_pieRect = m_rect;
if (m_pieRect.width() < m_pieRect.height()) {
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 m_pieRect.setWidth(m_pieRect.width() * m_pieSeries->sizeFactor());
Jani Honkonen
Pie chart refactoring
r142 m_pieRect.setHeight(m_pieRect.width());
m_pieRect.moveCenter(m_rect.center());
} else {
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 m_pieRect.setHeight(m_pieRect.height() * m_pieSeries->sizeFactor());
Jani Honkonen
Pie chart refactoring
r142 m_pieRect.setWidth(m_pieRect.height());
m_pieRect.moveCenter(m_rect.center());
}
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 switch (m_pieSeries->position()) {
Jani Honkonen
Pie chart refactoring
r142 case QPieSeries::PiePositionTopLeft: {
m_pieRect.setHeight(m_pieRect.height() / 2);
m_pieRect.setWidth(m_pieRect.height());
m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2));
break;
}
case QPieSeries::PiePositionTopRight: {
m_pieRect.setHeight(m_pieRect.height() / 2);
m_pieRect.setWidth(m_pieRect.height());
m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2));
break;
}
case QPieSeries::PiePositionBottomLeft: {
m_pieRect.setHeight(m_pieRect.height() / 2);
m_pieRect.setWidth(m_pieRect.height());
m_pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3));
break;
}
case QPieSeries::PiePositionBottomRight: {
m_pieRect.setHeight(m_pieRect.height() / 2);
m_pieRect.setWidth(m_pieRect.height());
m_pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3));
break;
}
default:
break;
}
qDebug() << "presentation rect:" << m_rect;
qDebug() << "pie rect:" << m_pieRect;
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 foreach (PieSlice *slice, m_slices)
slice->updateGeometry();
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 void PiePresenter::handleDomainChanged(const Domain& domain)
Jani Honkonen
Pie chart refactoring
r142 {
// TODO
}
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 void PiePresenter::handleGeometryChanged(const QRectF& rect)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157 m_rect = rect;
updateGeometry();
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 #include "moc_piepresenter.cpp"
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_END_NAMESPACE