##// END OF EJS Templates
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.

File last commit:

r203:7350e0387b3f
r203:7350e0387b3f
Show More
piepresenter.cpp
155 lines | 4.7 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"
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 #include "qpieslice.h"
Jani Honkonen
Pie chart refactoring
r142 #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)
{
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 //qDebug() << "PiePresenter::handleSeriesChanged()";
//qDebug() << " added : " << changeSet.added();
//qDebug() << " changed: " << changeSet.changed();
//qDebug() << " removed: " << changeSet.removed();
Jani Honkonen
Refactoring piechart API (and internals)
r174
// ignore changeset when there are no visual slices
// changeset might not be valid about the added slices
if (m_slices.count() == 0) {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 foreach (QPieSlice* s, m_series->m_slices)
addSlice(s);
Jani Honkonen
Refactoring piechart API (and internals)
r174 return;
Jani Honkonen
Make pie work better with chartwidgettest
r163 }
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 foreach (QPieSlice* s, changeSet.removed())
deleteSlice(s);
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 foreach (QPieSlice* s, changeSet.added())
addSlice(s);
}
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 void PiePresenter::handleDomainChanged(const Domain& domain)
{
// TODO
}
void PiePresenter::handleGeometryChanged(const QRectF& rect)
{
m_rect = rect;
updateGeometry();
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
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QRectF pieRect = m_rect;
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 if (pieRect.width() < pieRect.height()) {
pieRect.setWidth(pieRect.width() * m_series->sizeFactor());
pieRect.setHeight(pieRect.width());
pieRect.moveCenter(m_rect.center());
Jani Honkonen
Pie chart refactoring
r142 } else {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 pieRect.setHeight(pieRect.height() * m_series->sizeFactor());
pieRect.setWidth(pieRect.height());
pieRect.moveCenter(m_rect.center());
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Refactoring piechart API (and internals)
r174 switch (m_series->position()) {
Jani Honkonen
Pie chart refactoring
r142 case QPieSeries::PiePositionTopLeft: {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 pieRect.setHeight(pieRect.height() / 2);
pieRect.setWidth(pieRect.height());
pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2));
Jani Honkonen
Pie chart refactoring
r142 break;
}
case QPieSeries::PiePositionTopRight: {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 pieRect.setHeight(pieRect.height() / 2);
pieRect.setWidth(pieRect.height());
pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2));
Jani Honkonen
Pie chart refactoring
r142 break;
}
case QPieSeries::PiePositionBottomLeft: {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 pieRect.setHeight(pieRect.height() / 2);
pieRect.setWidth(pieRect.height());
pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3));
Jani Honkonen
Pie chart refactoring
r142 break;
}
case QPieSeries::PiePositionBottomRight: {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 pieRect.setHeight(pieRect.height() / 2);
pieRect.setWidth(pieRect.height());
pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3));
Jani Honkonen
Pie chart refactoring
r142 break;
}
default:
break;
}
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 if (m_pieRect != pieRect) {
m_pieRect = pieRect;
//qDebug() << "PiePresenter::updateGeometry()" << m_pieRect;
foreach (PieSlice* s, m_slices.values()) {
s->setPieRect(m_pieRect);
s->updateGeometry();
}
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
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 void PiePresenter::addSlice(QPieSlice* sliceData)
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 //qDebug() << "PiePresenter::addSlice()" << sliceData;
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 if (m_slices.keys().contains(sliceData)) {
//qWarning() << "PiePresenter::addSlice(): slice already exists!" << sliceData;
Q_ASSERT(0);
Jani Honkonen
Refactoring piechart API (and internals)
r174 return;
}
// create slice
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 PieSlice *slice = new PieSlice(this);
slice->updateData(sliceData);
m_slices.insert(sliceData, slice);
// connect signals
connect(sliceData, SIGNAL(changed()), slice, SLOT(handleSliceDataChanged()));
connect(slice, SIGNAL(clicked()), sliceData, SIGNAL(clicked()));
connect(slice, SIGNAL(hoverEnter()), sliceData, SIGNAL(hoverEnter()));
connect(slice, SIGNAL(hoverLeave()), sliceData, SIGNAL(hoverLeave()));
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 void PiePresenter::deleteSlice(QPieSlice* sliceData)
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() << "PiePresenter::deleteSlice()" << sliceData;
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 if (m_slices.contains(sliceData))
delete m_slices.take(sliceData);
Jani Honkonen
Refactoring piechart API (and internals)
r174 else {
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 // nothing to remove
Q_ASSERT(0); // TODO: remove before release
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
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