##// END OF EJS Templates
Fix compilation issue with scatterpresenter.cpp
Fix compilation issue with scatterpresenter.cpp

File last commit:

r174:0d781305aa75
r202:384e4e17c6c1
Show More
piepresenter.cpp
170 lines | 4.9 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>
Jani Honkonen
Make pie work better with chartwidgettest
r163 #include <QTime>
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
Refactoring piechart API (and internals)
r174 PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series)
:ChartItem(parent),
m_series(series)
Jani Honkonen
Pie chart refactoring
r142 {
Q_ASSERT(series);
Jani Honkonen
Refactoring piechart API (and internals)
r174 connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&)));
Jani Honkonen
Make pie work better with chartwidgettest
r163 connect(series, SIGNAL(sizeFactorChanged()), this, SLOT(updateGeometry()));
connect(series, SIGNAL(positionChanged()), this, SLOT(updateGeometry()));
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Moved pie stuff to own .pri file and rename stuff
r146 PiePresenter::~PiePresenter()
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Refactoring piechart API (and internals)
r174 // slices deleted automatically through QGraphicsItem
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Refactoring piechart API (and internals)
r174 void PiePresenter::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Refactoring piechart API (and internals)
r174 // TODO: paint shadows for all components
// - get paths from items & merge & offset and draw with shadow color?
}
void PiePresenter::handleSeriesChanged(const QPieSeries::ChangeSet& changeSet)
{
qDebug() << "PiePresenter::handleSeriesChanged()";
qDebug() << " added : " << changeSet.m_added;
qDebug() << " changed: " << changeSet.m_changed;
qDebug() << " removed: " << changeSet.m_removed;
// ignore changeset when there are no visual slices
// changeset might not be valid about the added slices
if (m_slices.count() == 0) {
foreach (QPieSliceId id, m_series->m_slices.keys())
addSlice(id);
return;
Jani Honkonen
Make pie work better with chartwidgettest
r163 }
Jani Honkonen
Pie chart refactoring
r142
Jani Honkonen
Refactoring piechart API (and internals)
r174 foreach (QPieSliceId id, changeSet.m_removed)
deleteSlice(id);
Jani Honkonen
Pie chart refactoring
r142
Jani Honkonen
Refactoring piechart API (and internals)
r174 foreach (QPieSliceId id, changeSet.m_changed)
updateSlice(id);
foreach (QPieSliceId id, changeSet.m_added)
addSlice(id);
Jani Honkonen
Pie chart refactoring
r142 }
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
Refactoring piechart API (and internals)
r174 m_pieRect.setWidth(m_pieRect.width() * m_series->sizeFactor());
Jani Honkonen
Pie chart refactoring
r142 m_pieRect.setHeight(m_pieRect.width());
m_pieRect.moveCenter(m_rect.center());
} else {
Jani Honkonen
Refactoring piechart API (and internals)
r174 m_pieRect.setHeight(m_pieRect.height() * m_series->sizeFactor());
Jani Honkonen
Pie chart refactoring
r142 m_pieRect.setWidth(m_pieRect.height());
m_pieRect.moveCenter(m_rect.center());
}
Jani Honkonen
Refactoring piechart API (and internals)
r174 switch (m_series->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;
}
Jani Honkonen
Refactoring piechart API (and internals)
r174 // update slice geometry
const qreal fullPie = 360;
qreal angle = 0;
foreach (QPieSliceId id, m_slices.keys()) {
qreal span = fullPie * m_series->slice(id).percentage();
m_slices[id]->updateGeometry(m_pieRect, angle, span);
angle += span;
}
//qDebug() << "PiePresenter::updateGeometry" << m_rect << m_pieRect;
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
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Refactoring piechart API (and internals)
r174 void PiePresenter::addSlice(QPieSliceId id)
{
qDebug() << "PiePresenter::addSlice()" << id;
if (m_slices.contains(id)) {
qWarning() << "PiePresenter::addSlice(): slice already exists!" << id;
updateSlice(id);
return;
}
// create slice
PieSlice *slice = new PieSlice(id, m_series, this);
m_slices.insert(id, slice);
updateGeometry();
}
void PiePresenter::updateSlice(QPieSliceId id)
{
qDebug() << "PiePresenter::updateSlice()" << id;
// TODO: animation
if (m_slices.contains(id))
m_slices.value(id)->updateData();
else {
qWarning() << "PiePresenter::updateSlice(): slice does not exist!" << id;
addSlice(id);
}
updateGeometry();
}
void PiePresenter::deleteSlice(QPieSliceId id)
{
qDebug() << "PiePresenter::deleteSlice()" << id;
// TODO: animation
if (m_slices.contains(id))
delete m_slices.take(id);
else
qWarning() << "PiePresenter::deleteSlice(): slice does not exist!" << id;
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