##// END OF EJS Templates
Fix the warning in chartviewer
Fix the warning in chartviewer

File last commit:

r2104:f8a933676fbd
r2213:245df962f0c3
Show More
piechartitem.cpp
249 lines | 8.2 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
Jani Honkonen
Rename piepresenter -> piechartitem
r568 #include "piechartitem_p.h"
Jani Honkonen
rename PieSlice -> PieSliceItem
r673 #include "piesliceitem_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
pie: added everything as a property in QPieSlice...
r1274 #include "qpieslice_p.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"
Jani Honkonen
API review changes for pie
r1009 #include "qpieseries_p.h"
Tero Ahola
Z order for pie
r490 #include "chartpresenter_p.h"
Jani Honkonen
Fix add/remove animation for pie and apply colors from theme when adding/removing
r659 #include "chartdataset_p.h"
Michal Klocek
Refactor animator...
r1735 #include "pieanimation_p.h"
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 #include <QPainter>
Jani Honkonen
Refactoring pie series and animations.
r621 #include <QTimer>
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
more coding style fixes for src-folder...
r2104 PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter *presenter)
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 : ChartItem(presenter),
m_series(series),
m_animation(0)
Jani Honkonen
Pie chart refactoring
r142 {
Q_ASSERT(series);
Jani Honkonen
API review changes for pie
r1009
Tero Ahola
Removed a few signals from QPieSeries API
r1482 QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series);
Jani Honkonen
pie: implement hiding the series
r1456 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
Tero Ahola
Added opacity property to QAbstractSeries
r2067 connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged()));
Jani Honkonen
pie: make slice added/removed signals public (again)
r1213 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
Tero Ahola
Removed a few signals from QPieSeries API
r1482 connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
Jani Honkonen
Refactoring pie series and animations.
r621
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: fix bug with qmlchart demo...
r1238
// Note: will not create slice items until we have a proper rectangle to draw on.
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
more coding style fixes for src-folder...
r2104 void PieChartItem::setAnimation(PieAnimation *animation)
Michal Klocek
Refactor animator...
r1735 {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_animation = animation;
Michal Klocek
Refactor animator...
r1735 }
Jani Honkonen
more coding style fixes for src-folder...
r2104 ChartAnimation *PieChartItem::animation() const
Michal Klocek
Refactor animator...
r1735 {
return m_animation;
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void PieChartItem::handleGeometryChanged(const QRectF &rect)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 prepareGeometryChange();
m_rect = rect;
updateLayout();
Jani Honkonen
pie: fix bug with qmlchart demo...
r1238
// This is for delayed initialization of the slice items during startup.
// It ensures that startup animation originates from the correct position.
if (m_sliceItems.isEmpty())
handleSlicesAdded(m_series->slices());
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Remove scaledomain ect. warnings from pie. Not going to be implemented (for now at least).
r1191 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
{
Q_UNUSED(minX);
Q_UNUSED(maxX);
Q_UNUSED(minY);
Q_UNUSED(maxY);
// does not apply to pie
}
Jani Honkonen
pie: get rid of "Slot not implemented" warning...
r1815 void PieChartItem::handleDomainUpdated()
{
// does not apply to pie
}
Jani Honkonen
Remove scaledomain ect. warnings from pie. Not going to be implemented (for now at least).
r1191 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
{
Q_UNUSED(min);
Q_UNUSED(max);
Q_UNUSED(tickXCount);
// does not apply to pie
}
void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
{
Q_UNUSED(min);
Q_UNUSED(max);
Q_UNUSED(tickYCount);
// does not apply to pie
}
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 void PieChartItem::updateLayout()
Jani Honkonen
Refactoring pie series and animations.
r621 {
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 // find pie center coordinates
m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition()));
m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition()));
Jani Honkonen
Nicer animation for adding a pie initially.
r634
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 // find maximum radius for pie
m_pieRadius = m_rect.height() / 2;
if (m_rect.width() < m_rect.height())
m_pieRadius = m_rect.width() / 2;
Marek Rosa
Donut support simplified. Examples updated
r1838 m_holeSize = m_pieRadius;
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 // apply size factor
m_pieRadius *= m_series->pieSize();
Marek Rosa
Donut support simplified. Examples updated
r1838 m_holeSize *= m_series->holeSize();
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074
// set layouts for existing slice items
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QPieSlice *slice, m_series->slices()) {
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 PieSliceItem *sliceItem = m_sliceItems.value(slice);
if (sliceItem) {
PieSliceData sliceData = updateSliceGeometry(slice);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_animation)
Michal Klocek
Refactor animator...
r1735 presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData));
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 else
sliceItem->setLayout(sliceData);
}
}
update();
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void PieChartItem::handleSlicesAdded(QList<QPieSlice *> slices)
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 {
Jani Honkonen
pie: fix bug with qmlchart demo...
r1238 // delay creating slice items until there is a proper rectangle
if (!m_rect.isValid() && m_sliceItems.isEmpty())
return;
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
Jani Honkonen
Fix add/remove animation for pie and apply colors from theme when adding/removing
r659
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 bool startupAnimation = m_sliceItems.isEmpty();
Jani Honkonen
Refactoring pie series and animations.
r621
Jani Honkonen
more coding style fixes for src-folder...
r2104 foreach(QPieSlice * slice, slices) {
PieSliceItem *sliceItem = new PieSliceItem(this);
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 m_sliceItems.insert(slice, sliceItem);
Jani Honkonen
pie: remove changed() signal and replace it with more refined signals...
r1224
Tero Ahola
Removed unnecessary signals from QPieSlice
r1494 // Note: no need to connect to slice valueChanged() etc.
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 // This is handled through calculatedDataChanged signal.
Jani Honkonen
pie: remove changed() signal and replace it with more refined signals...
r1224 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
Tero Ahola
Removed unnecessary signals from QPieSlice
r1494
QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice);
connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged()));
connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
Jani Honkonen
Refactoring pie series and animations.
r621
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 PieSliceData sliceData = updateSliceGeometry(slice);
Michal Klocek
Refactor animator...
r1735 if (m_animation)
presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation));
Jani Honkonen
Refactoring pie series and animations.
r621 else
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 sliceItem->setLayout(sliceData);
Jani Honkonen
Refactoring pie series and animations.
r621 }
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void PieChartItem::handleSlicesRemoved(QList<QPieSlice *> slices)
Jani Honkonen
Refactoring pie series and animations.
r621 {
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
Jani Honkonen
Fix add/remove animation for pie and apply colors from theme when adding/removing
r659
Jani Honkonen
Refactor piechart to avoid using invalid QPieSlice pointers....
r1053 foreach (QPieSlice *slice, slices) {
Jani Honkonen
tst_qpieseries: added XXXanimated tests...
r1301
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 PieSliceItem *sliceItem = m_sliceItems.value(slice);
Jani Honkonen
tst_qpieseries: added XXXanimated tests...
r1301
// this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
if (!sliceItem)
continue;
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 m_sliceItems.remove(slice);
Jani Honkonen
bugfix: pie does not disconnect signals when a slice is taken (not deleted)
r2084 slice->disconnect(this);
QPieSlicePrivate::fromSlice(slice)->disconnect(this);
Jani Honkonen
Refactor piechart to avoid using invalid QPieSlice pointers....
r1053
Michal Klocek
Refactor animator...
r1735 if (m_animation)
presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem
Jani Honkonen
Refactoring pie series and animations.
r621 else
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 delete sliceItem;
Jani Honkonen
Refactoring pie series and animations.
r621 }
}
Jani Honkonen
Rename piepresenter -> piechartitem
r568 void PieChartItem::handleSliceChanged()
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566 {
Jani Honkonen
more coding style fixes for src-folder...
r2104 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
Tero Ahola
Removed unnecessary signals from QPieSlice
r1494 if (!slice) {
Jani Honkonen
more coding style fixes for src-folder...
r2104 QPieSlicePrivate *slicep = qobject_cast<QPieSlicePrivate *>(sender());
Tero Ahola
Removed unnecessary signals from QPieSlice
r1494 slice = slicep->q_ptr;
}
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 Q_ASSERT(m_sliceItems.contains(slice));
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 PieSliceItem *sliceItem = m_sliceItems.value(slice);
PieSliceData sliceData = updateSliceGeometry(slice);
Michal Klocek
Refactor animator...
r1735 if (m_animation)
presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData));
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 else
sliceItem->setLayout(sliceData);
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 update();
Jani Honkonen
Refactoring pie series and animations.
r621 }
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437
Jani Honkonen
pie: implement hiding the series
r1456 void PieChartItem::handleSeriesVisibleChanged()
{
setVisible(m_series->isVisible());
}
Tero Ahola
Added opacity property to QAbstractSeries
r2067 void PieChartItem::handleOpacityChanged()
{
setOpacity(m_series->opacity());
}
Jani Honkonen
Refactor graphical side of pie to simplify the implementation.
r1074 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
Jani Honkonen
Refactoring pie series and animations.
r621 {
Jani Honkonen
pie: added everything as a property in QPieSlice...
r1274 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
Jani Honkonen
rename PieSlice -> PieSliceItem
r673 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
Jani Honkonen
Rename PieSliceLayout -> PieSliceData. A "layout" is a bad name for this.
r668 sliceData.m_radius = m_pieRadius;
Marek Rosa
Donut support simplified. Examples updated
r1838 sliceData.m_holeRadius = m_holeSize;
Jani Honkonen
Rename PieSliceLayout -> PieSliceData. A "layout" is a bad name for this.
r668 return sliceData;
Jani Honkonen
Refactoring pie series and animations.
r621 }
Jani Honkonen
Rename piepresenter -> piechartitem
r568 #include "moc_piechartitem_p.cpp"
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_END_NAMESPACE