##// END OF EJS Templates
remove unnecessary stuff from pie series
remove unnecessary stuff from pie series

File last commit:

r618:249071e508d1
r620:51f99c2be375
Show More
piechartitem.cpp
185 lines | 5.1 KiB | text/x-c | CppLexer
Jani Honkonen
Rename piepresenter -> piechartitem
r568 #include "piechartitem_p.h"
Jani Honkonen
Add _p to pie internal headers
r353 #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
Add animations to pie. Works but has some visual issues when adding slices.
r618 #include "chartanimator_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
Rename piepresenter -> piechartitem
r568 PieChartItem::PieChartItem(QGraphicsItem *parent, QPieSeries *series)
Jani Honkonen
Refactoring piechart API (and internals)
r174 :ChartItem(parent),
m_series(series)
Jani Honkonen
Pie chart refactoring
r142 {
Q_ASSERT(series);
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 connect(series, SIGNAL(changed()), this, SLOT(handleSeriesChanged()));
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
Rename piepresenter -> piechartitem
r568 PieChartItem::~PieChartItem()
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
Rename piepresenter -> piechartitem
r568 void PieChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
Jani Honkonen
Pie chart refactoring
r142 {
Tero Ahola
Squashed bunch of warnings
r611 Q_UNUSED(painter)
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 }
Jani Honkonen
Rename piepresenter -> piechartitem
r568 void PieChartItem::handleSeriesChanged()
Jani Honkonen
Refactoring piechart API (and internals)
r174 {
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 QVector<PieSliceLayout> layout = calculateLayout();
applyLayout(layout);
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 update();
}
Jani Honkonen
Pie chart refactoring
r142
Jani Honkonen
Rename piepresenter -> piechartitem
r568 void PieChartItem::handleSliceChanged()
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 {
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
Q_ASSERT(m_slices.contains(slice));
//qDebug() << "PieChartItem::handleSliceChanged" << slice->label();
// TODO: Optimize. No need to calculate everything.
QVector<PieSliceLayout> layout = calculateLayout();
foreach (PieSliceLayout sl, layout) {
if (sl.m_data == slice)
updateLayout(sl);
}
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 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
Rename piepresenter -> piechartitem
r568 void PieChartItem::handleDomainChanged(qreal, qreal, qreal, qreal)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
// TODO
}
Jani Honkonen
Rename piepresenter -> piechartitem
r568 void PieChartItem::handleGeometryChanged(const QRectF& rect)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 prepareGeometryChange();
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 m_rect = rect;
QVector<PieSliceLayout> sliceLayout = calculateLayout();
applyLayout(sliceLayout);
update();
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Rename piepresenter -> piechartitem
r568 QVector<PieSliceLayout> PieChartItem::calculateLayout()
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 {
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
Refactoring the pie for animations (no actual animations yet)
r566 QVector<PieSliceLayout> layout;
foreach (QPieSlice* s, m_series->slices()) {
PieSliceLayout sliceLayout;
sliceLayout.m_data = s;
sliceLayout.m_center = PieSlice::sliceCenter(center, radius, s);
sliceLayout.m_radius = radius;
sliceLayout.m_startAngle = s->startAngle();
sliceLayout.m_angleSpan = s->m_angleSpan;
layout << sliceLayout;
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 return layout;
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 void PieChartItem::applyLayout(QVector<PieSliceLayout> &layout)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 if (m_animator)
m_animator->applyLayout(this, layout);
else
setLayout(layout);
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 void PieChartItem::updateLayout(PieSliceLayout &layout)
{
if (m_animator)
m_animator->updateLayout(this, layout);
else
setLayout(layout);
}
void PieChartItem::setLayout(QVector<PieSliceLayout> &layout)
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 {
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 foreach (PieSliceLayout l, layout) {
// find slice
PieSlice *slice = m_slices.value(l.m_data);
if (!slice) {
// add a new slice
slice = new PieSlice(this);
m_slices.insert(l.m_data, slice);
// connect signals
connect(l.m_data, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
connect(slice, SIGNAL(clicked()), l.m_data, SIGNAL(clicked()));
connect(slice, SIGNAL(hoverEnter()), l.m_data, SIGNAL(hoverEnter()));
connect(slice, SIGNAL(hoverLeave()), l.m_data, SIGNAL(hoverLeave()));
}
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 // update
slice->setLayout(l);
slice->updateGeometry();
slice->update();
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 }
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 // delete slices
foreach (QPieSlice *s, m_slices.keys()) {
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 bool found = false;
foreach (PieSliceLayout l, layout) {
if (l.m_data == s)
found = true;
}
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 if (!found)
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 destroySlice(s);
}
}
void PieChartItem::setLayout(PieSliceLayout &layout)
{
// find slice
PieSlice *slice = m_slices.value(layout.m_data);
if (!slice) {
slice = new PieSlice(this);
m_slices.insert(layout.m_data, slice);
connect(layout.m_data, SIGNAL(changed()), this, SLOT(handleSliceChanged()));
connect(slice, SIGNAL(clicked()), layout.m_data, SIGNAL(clicked()));
connect(slice, SIGNAL(hoverEnter()), layout.m_data, SIGNAL(hoverEnter()));
connect(slice, SIGNAL(hoverLeave()), layout.m_data, SIGNAL(hoverLeave()));
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 slice->setLayout(layout);
if (m_series->m_slices.contains(layout.m_data)) // Slice has been deleted if not found. Animations ongoing...
slice->updateData(layout.m_data);
slice->updateGeometry();
slice->update();
}
void PieChartItem::destroySlice(QPieSlice *slice)
{
delete m_slices.take(slice);
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Rename piepresenter -> piechartitem
r568 #include "moc_piechartitem_p.cpp"
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_END_NAMESPACE