##// END OF EJS Templates
framework for legend
framework for legend

File last commit:

r498:597882065a5e
r524:280ce33a2f47
Show More
piepresenter.cpp
158 lines | 4.4 KiB | text/x-c | CppLexer
Jani Honkonen
Add _p to pie internal headers
r353 #include "piepresenter_p.h"
#include "pieslice_p.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
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 #include "qpieseries.h"
Tero Ahola
Z order for pie
r490 #include "chartpresenter_p.h"
Jani Honkonen
Pie chart refactoring
r142 #include <QDebug>
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 #include <QPainter>
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289
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
Renamed the "factor" stuff from pie series API.
r498 connect(series, SIGNAL(piePositionChanged()), this, SLOT(updateGeometry()));
connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateGeometry()));
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289
if (m_series->count()) {
QPieSeries::ChangeSet changeSet;
changeSet.appendAdded(m_series->m_slices);
handleSeriesChanged(changeSet);
}
Tero Ahola
Z order for pie
r490
// Note: the following does not affect as long as the item does not have anything to paint
setZValue(ChartPresenter::PieSeriesZValue);
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
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 void PiePresenter::paint(QPainter *painter, 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?
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 //painter->setBrush(QBrush(Qt::red));
//painter->drawRect(m_debugRect);
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
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
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 foreach (QPieSlice* s, changeSet.added())
addSlice(s);
foreach (QPieSlice* s, changeSet.changed())
updateSlice(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.removed())
deleteSlice(s);
Jani Honkonen
Pie chart refactoring
r142
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 // every change possibly changes the actual pie size
updateGeometry();
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
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;
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 prepareGeometryChange();
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 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
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 if (!m_rect.isValid() || m_rect.isEmpty())
return;
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 // find pie center coordinates
QPointF center;
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 center.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition()));
center.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition()));
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 // find maximum radius for pie
qreal radius = m_rect.height() / 2;
if (m_rect.width() < m_rect.height())
radius = m_rect.width() / 2;
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 // apply size factor
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 radius *= m_series->pieSize();
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 // update slices
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 if (m_pieCenter != center || m_pieRadius != radius) {
m_pieCenter = center;
m_pieRadius = radius;
//qDebug() << "PiePresenter::updateGeometry()" << m_rect << m_pieCenter << m_pieRadius;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 foreach (PieSlice* s, m_slices.values()) {
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 s->setPieCenterAndRadius(center, radius);
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 s->updateGeometry();
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 s->update();
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
update();
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)) {
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 Q_ASSERT(0); // TODO: how to handle this nicely?
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);
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 slice->setPieCenterAndRadius(m_pieCenter, m_pieRadius);
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 slice->updateData(sliceData);
Jani Honkonen
Fix issue with pie label not drawn correctly when first created
r209 slice->updateGeometry();
slice->update();
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_slices.insert(sliceData, slice);
// connect signals
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
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 void PiePresenter::updateSlice(QPieSlice* sliceData)
{
//qDebug() << "PiePresenter::updateSlice()" << sliceData;
if (!m_slices.contains(sliceData)) {
Q_ASSERT(0); // TODO: how to handle this nicely?
return;
}
m_slices[sliceData]->updateData(sliceData);
}
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
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 if (!m_slices.contains(sliceData)) {
Q_ASSERT(0); // TODO: how to handle this nicely?
return;
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289
delete m_slices.take(sliceData);
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Add _p to pie internal headers
r353 #include "moc_piepresenter_p.cpp"
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_END_NAMESPACE