##// END OF EJS Templates
Model example for the RnD offsite
Model example for the RnD offsite

File last commit:

r1097:431f68143802
r1097:431f68143802
Show More
qpieseries.cpp
792 lines | 23.7 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
Pie chart refactoring
r142 #include "qpieseries.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qpieseries_p.h"
Jani Honkonen
Refactoring QPieSlice private implementation. Removes the useless QPieSlicePrivate layer and uses PieSliceData directly.
r818 #include "qpieslice.h"
#include "pieslicedata_p.h"
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943 #include "chartdataset_p.h"
#include "charttheme_p.h"
#include "chartanimator_p.h"
Michal Klocek
Adds qlegend pimpl...
r950 #include "legendmarker_p.h"
Marek Rosa
Fixed: QAbstractItemModel could be forward declaration
r862 #include <QAbstractItemModel>
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
More documentation for pie
r320 /*!
\class QPieSeries
\brief Pie series API for QtCommercial Charts
Jani Honkonen
Pie doc updates
r952 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
Jani Honkonen
More documentation for pie
r320 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
Jani Honkonen
Review corrections for pie
r386 The actual slice size is determined by that relative value.
Jani Honkonen
More documentation for pie
r320
Jani Honkonen
Pie doc updates
r952 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
These relate to the actual chart rectangle.
By default the pie is defined as a full pie but it can also be a partial pie.
Jani Honkonen
More documentation for pie
r320 This can be done by setting a starting angle and angle span to the series.
Jani Honkonen
Pie doc updates
r952 Full pie is 360 degrees where 0 is at 12 a'clock.
Tero Ahola
Documentation fixes....
r995
See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
\image examples_piechart.png
Jani Honkonen
More documentation for pie
r320 */
Marek Rosa
Some more doc fixes and additions
r924 /*!
Jani Honkonen
fix QPieSeries property docs
r928 \property QPieSeries::horizontalPosition
Jani Honkonen
Update pie docs
r932 \brief Defines the horizontal position of the pie.
Marek Rosa
Some more doc fixes and additions
r924
Jani Honkonen
Update pie docs
r932 The value is a relative value to the chart rectangle where:
\list
\o 0.0 is the absolute left.
\o 1.0 is the absolute right.
\endlist
Default value is 0.5 (center).
Marek Rosa
Some more doc fixes and additions
r924 */
Jani Honkonen
fix QPieSeries property docs
r928 /*!
\property QPieSeries::verticalPosition
Jani Honkonen
Update pie docs
r932 \brief Defines the vertical position of the pie.
The value is a relative value to the chart rectangle where:
\list
\o 0.0 is the absolute top.
\o 1.0 is the absolute bottom.
\endlist
Jani Honkonen
fix QPieSeries property docs
r928
Jani Honkonen
Update pie docs
r932 Default value is 0.5 (center).
Jani Honkonen
fix QPieSeries property docs
r928 */
/*!
\property QPieSeries::size
Jani Honkonen
Update pie docs
r932 \brief Defines the pie size.
Jani Honkonen
fix QPieSeries property docs
r928
Jani Honkonen
Update pie docs
r932 The value is a relative value to the chart rectangle where:
\list
Michal Klocek
Krazy reported errors...
r974 \o 0.0 is the minimum size (pie not drawn).
Jani Honkonen
Update pie docs
r932 \o 1.0 is the maximum size that can fit the chart.
\endlist
Default value is 0.7.
Jani Honkonen
fix QPieSeries property docs
r928 */
/*!
\property QPieSeries::startAngle
Jani Honkonen
Update pie docs
r932 \brief Defines the starting angle of the pie.
Jani Honkonen
fix QPieSeries property docs
r928
Jani Honkonen
Update pie docs
r932 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
Jani Honkonen
fix QPieSeries property docs
r928
Jani Honkonen
Update pie docs
r932 Default is value is 0.
*/
Jani Honkonen
fix QPieSeries property docs
r928
/*!
\property QPieSeries::endAngle
Jani Honkonen
Update pie docs
r932 \brief Defines the ending angle of the pie.
Jani Honkonen
fix QPieSeries property docs
r928
Jani Honkonen
Update pie docs
r932 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
Jani Honkonen
fix QPieSeries property docs
r928
Jani Honkonen
Update pie docs
r932 Default is value is 360.
*/
Jani Honkonen
fix QPieSeries property docs
r928
Marek Rosa
Some more doc fixes and additions
r924
Jani Honkonen
Add documentation to pie
r314 /*!
Constructs a series object which is a child of \a parent.
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QPieSeries::QPieSeries(QObject *parent) :
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
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
Add documentation to pie
r314 /*!
Jani Honkonen
Minor qpieseries doc updates.
r933 Destroys the series and its slices.
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QPieSeries::~QPieSeries()
{
Jani Honkonen
Adding PIMPL to pie
r669 // NOTE: d_prt destroyed by QObject
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
More documentation for pie
r320 Returns QChartSeries::SeriesTypePie.
Jani Honkonen
Add documentation to pie
r314 */
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 QAbstractSeries::QSeriesType QPieSeries::type() const
Jani Honkonen
Add documentation to pie
r314 {
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 return QAbstractSeries::SeriesTypePie;
Jani Honkonen
Add documentation to pie
r314 }
/*!
Jani Honkonen
Minor qpieseries doc updates.
r933 Appends an array of \a slices to the series.
Jani Honkonen
Add documentation to pie
r314 Slice ownership is passed to the series.
*/
Jani Honkonen
rename functions add() -> append()
r796 void QPieSeries::append(QList<QPieSlice*> slices)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 foreach (QPieSlice* s, slices) {
Jani Honkonen
Prevent double adding slice pointer to series with Q_ASSERT
r1092 Q_ASSERT(!d->m_slices.contains(s)); // cannot add same slice twice
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 s->setParent(this);
Jani Honkonen
Adding PIMPL to pie
r669 d->m_slices << s;
Jani Honkonen
Refactoring piechart API (and internals)
r174 }
Jani Honkonen
Use signals from pieseries, visible hover and exploding slices
r157
Jani Honkonen
Adding PIMPL to pie
r669 d->updateDerivativeData();
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 foreach (QPieSlice* s, slices) {
Jani Honkonen
Adding PIMPL to pie
r669 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
Jani Honkonen
API review changes for pie
r1009 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
API review changes for pie
r1009 emit d->added(slices);
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Minor qpieseries doc updates.
r933 Appends a single \a slice to the series.
Jani Honkonen
Add documentation to pie
r314 Slice ownership is passed to the series.
*/
Jani Honkonen
rename functions add() -> append()
r796 void QPieSeries::append(QPieSlice* slice)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
rename functions add() -> append()
r796 append(QList<QPieSlice*>() << slice);
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Update pie series doc
r415 /*!
Jani Honkonen
Minor qpieseries doc updates.
r933 Appends a single \a slice to the series and returns a reference to the series.
Jani Honkonen
Update pie series doc
r415 Slice ownership is passed to the series.
*/
Jani Honkonen
Add drilldown example for piechart
r406 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
{
Jani Honkonen
rename functions add() -> append()
r796 append(slice);
Jani Honkonen
Add drilldown example for piechart
r406 return *this;
}
Jani Honkonen
Add documentation to pie
r314
/*!
Jani Honkonen
Doc fixes for pie
r809 Appends a single slice to the series with give \a value and \a name.
Jani Honkonen
Add documentation to pie
r314 Slice ownership is passed to the series.
*/
Jani Honkonen
rename functions add() -> append()
r796 QPieSlice* QPieSeries::append(qreal value, QString name)
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 QPieSlice* slice = new QPieSlice(value, name);
Jani Honkonen
rename functions add() -> append()
r796 append(slice);
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 return slice;
}
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
Doc fixes for pie
r809 /*!
Inserts a single \a slice to the series before the slice at \a index position.
Slice ownership is passed to the series.
*/
void QPieSeries::insert(int index, QPieSlice* slice)
Marek Rosa
Added insert pie slice function to QPieSeries
r604 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Jani Honkonen
Doc fixes for pie
r809 Q_ASSERT(index <= d->m_slices.count());
Jani Honkonen
Prevent double adding slice pointer to series with Q_ASSERT
r1092 Q_ASSERT(!d->m_slices.contains(slice)); // cannot add same slice twice
Marek Rosa
Added insert pie slice function to QPieSeries
r604 slice->setParent(this);
Jani Honkonen
Doc fixes for pie
r809 d->m_slices.insert(index, slice);
Marek Rosa
Added insert pie slice function to QPieSeries
r604
Jani Honkonen
Adding PIMPL to pie
r669 d->updateDerivativeData();
Marek Rosa
Added insert pie slice function to QPieSeries
r604
Jani Honkonen
Adding PIMPL to pie
r669 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
Jani Honkonen
API review changes for pie
r1009 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
Marek Rosa
Added insert pie slice function to QPieSeries
r604
Jani Honkonen
API review changes for pie
r1009 emit d->added(QList<QPieSlice*>() << slice);
Marek Rosa
Added insert pie slice function to QPieSeries
r604 }
Jani Honkonen
Add documentation to pie
r314 /*!
Removes a single \a slice from the series and deletes the slice.
Jani Honkonen
More documentation for pie
r320
Jani Honkonen
Pie doc updates
r952 Do not reference the pointer after this call.
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSeries::remove(QPieSlice* slice)
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
if (!d->m_slices.removeOne(slice)) {
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 should this be reported?
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 return;
}
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
Adding PIMPL to pie
r669 d->updateDerivativeData();
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
API review changes for pie
r1009 emit d->removed(QList<QPieSlice*>() << slice);
Jani Honkonen
Refactoring pie series and animations.
r621
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 delete slice;
Jani Honkonen
NULL -> 0
r823 slice = 0;
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Add documentation to pie
r314 /*!
Clears all slices from the series.
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSeries::clear()
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
if (d->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 return;
Jani Honkonen
Refactoring piechart API (and internals)
r174
Jani Honkonen
Adding PIMPL to pie
r669 QList<QPieSlice*> slices = d->m_slices;
foreach (QPieSlice* s, d->m_slices) {
d->m_slices.removeOne(s);
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 delete s;
}
Jani Honkonen
Refactoring the pie for animations (no actual animations yet)
r566
Jani Honkonen
Adding PIMPL to pie
r669 d->updateDerivativeData();
Jani Honkonen
Refactoring pie series and animations.
r621
Jani Honkonen
API review changes for pie
r1009 emit d->removed(slices);
Jani Honkonen
Pie chart refactoring
r142 }
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Minor qpieseries doc updates.
r933 returns the number of the slices in this series.
Jani Honkonen
Add documentation to pie
r314 */
int QPieSeries::count() const
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_slices.count();
Jani Honkonen
Add documentation to pie
r314 }
Jani Honkonen
Refactoring pie series and animations.
r621 /*!
Returns true is the series is empty.
*/
bool QPieSeries::isEmpty() const
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_slices.isEmpty();
Jani Honkonen
Refactoring pie series and animations.
r621 }
Jani Honkonen
Add documentation to pie
r314 /*!
Returns a list of slices that belong to this series.
*/
QList<QPieSlice*> QPieSeries::slices() const
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_slices;
Jani Honkonen
Add documentation to pie
r314 }
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 void QPieSeries::setHorizontalPosition(qreal relativePosition)
{
Q_D(QPieSeries);
if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0))
Jani Honkonen
API review changes for pie
r1009 emit d->piePositionChanged();
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 }
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 void QPieSeries::setVerticalPosition(qreal relativePosition)
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0))
Jani Honkonen
API review changes for pie
r1009 emit d->piePositionChanged();
Jani Honkonen
Pie chart refactoring
r142 }
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 qreal QPieSeries::horizontalPosition() const
Jani Honkonen
Pie chart refactoring
r142 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_pieRelativeHorPos;
Jani Honkonen
Pie chart refactoring
r142 }
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 qreal QPieSeries::verticalPosition() const
Jani Honkonen
Add documentation to pie
r314 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_pieRelativeVerPos;
Jani Honkonen
Add documentation to pie
r314 }
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 void QPieSeries::setPieSize(qreal relativeSize)
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0))
Jani Honkonen
API review changes for pie
r1009 emit d->pieSizeChanged();
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 }
Jani Honkonen
Add documentation to pie
r314
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 qreal QPieSeries::pieSize() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_pieRelativeSize;
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 }
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 void QPieSeries::setPieStartAngle(qreal angle)
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle))
Jani Honkonen
Adding PIMPL to pie
r669 d->updateDerivativeData();
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 qreal QPieSeries::pieStartAngle() const
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_pieStartAngle;
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 /*!
Sets the end angle of the pie.
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 \a angle must be greater than start angle.
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 */
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 void QPieSeries::setPieEndAngle(qreal angle)
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Jani Honkonen
Fix issues with comparing equality of floating values in pie
r765
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle))
Jani Honkonen
Adding PIMPL to pie
r669 d->updateDerivativeData();
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 /*!
Returns the end angle of the pie.
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 */
Jani Honkonen
Renamed the "factor" stuff from pie series API.
r498 qreal QPieSeries::pieEndAngle() const
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
return d->m_pieEndAngle;
Jani Honkonen
Added a pie chart customization example and refactoring the pie interface.
r437 }
Jani Honkonen
Add documentation to pie
r314 /*!
Sets the all the slice labels \a visible or invisible.
\sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSeries::setLabelsVisible(bool visible)
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
foreach (QPieSlice* s, d->m_slices)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 s->setLabelVisible(visible);
}
Jani Honkonen
Add drilldown example for piechart
r406 /*!
Returns the sum of all slice values in this series.
Jani Honkonen
Pie doc updates
r952 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
Jani Honkonen
Add drilldown example for piechart
r406 */
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 qreal QPieSeries::sum() const
Jani Honkonen
Add drilldown example for piechart
r406 {
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(const QPieSeries);
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 return d->m_sum;
Jani Honkonen
Add drilldown example for piechart
r406 }
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
API review changes for pie
r1009 \fn void QPieSeries::clicked(QPieSlice* slice)
Jani Honkonen
Add documentation to pie
r314
Jani Honkonen
API review changes for pie
r1009 This signal is emitted when a \a slice has been clicked.
Jani Honkonen
Add documentation to pie
r314
\sa QPieSlice::clicked()
*/
/*!
Jani Honkonen
API review changes for pie
r1009 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
Jani Honkonen
Add documentation to pie
r314
Jani Honkonen
API review changes for pie
r1009 This signal is emitted when user has hovered over or away from the \a slice.
Jani Honkonen
Add documentation to pie
r314
Jani Honkonen
API review changes for pie
r1009 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
Jani Honkonen
Doc fixes for pie
r809
Jani Honkonen
API review changes for pie
r1009 \sa QPieSlice::hovered()
Jani Honkonen
Doc fixes for pie
r809 */
Jani Honkonen
Refactoring piechart API (and internals)
r174
Marek Rosa
Removed few commeneted out lines and documented few funtions
r879 /*!
\fn bool QPieSeries::setModel(QAbstractItemModel *model)
Sets the \a model to be used as a data source
*/
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 bool QPieSeries::setModel(QAbstractItemModel* model)
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 // disconnect signals from old model
Michal Klocek
Adds big fat pimpl to series classes...
r938 if(d->m_model)
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 disconnect(d->m_model, 0, this, 0);
Jani Honkonen
Adding PIMPL to pie
r669 d->m_mapValues = -1;
d->m_mapLabels = -1;
d->m_mapOrientation = Qt::Vertical;
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 }
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 // set new model
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 if(model)
{
Michal Klocek
Adds big fat pimpl to series classes...
r938 d->m_model = model;
Marek Rosa
PieSeries model support - further refactoring
r1081 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
connect(d->m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 return true;
}
else
{
Michal Klocek
Adds big fat pimpl to series classes...
r938 d->m_model = 0;
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 return false;
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 }
}
Marek Rosa
Added documentation for model related funtions
r900 /*!
\fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie.
Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model.
Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model.
Michal Klocek
Krazy reported errors...
r974 The \a orientation parameter specifies whether the data is in columns or in rows.
Marek Rosa
Added documentation for model related funtions
r900 */
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
{
Jani Honkonen
Adding PIMPL to pie
r669 Q_D(QPieSeries);
Michal Klocek
Adds big fat pimpl to series classes...
r938 if (d->m_model == 0)
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 return;
Jani Honkonen
Adding PIMPL to pie
r669
d->m_mapValues = modelValuesLine;
d->m_mapLabels = modelLabelsLine;
d->m_mapOrientation = orientation;
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 d->initializePieFromModel();
// // connect the signals
// connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
Marek Rosa
Removed unfinished model related methods from PieSeries
r1018
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 // // create the initial slices set
// if (d->m_mapOrientation == Qt::Vertical) {
// for (int i = 0; i < d->m_model->rowCount(); i++)
// append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString());
// } else {
// for (int i = 0; i < d->m_model->columnCount(); i++)
// append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString());
// }
}
void QPieSeries::setModelMappingRange(int first, int count)
{
Q_D(QPieSeries);
d->m_mapFirst = first;
d->m_mapCount = count;
Marek Rosa
Model example for the RnD offsite
r1097 d->initializePieFromModel();
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 }
Michal Klocek
Adds big fat pimpl to series classes...
r938 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Tero Ahola
Renamed QSeries to QAbstractSeries
r988 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
QAbstractSeriesPrivate(parent),
Michal Klocek
Adds big fat pimpl to series classes...
r938 m_pieRelativeHorPos(0.5),
m_pieRelativeVerPos(0.5),
m_pieRelativeSize(0.7),
m_pieStartAngle(0),
m_pieEndAngle(360),
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 m_sum(0),
Michal Klocek
Adds big fat pimpl to series classes...
r938 m_mapValues(0),
Marek Rosa
QXYSeries: support for removing data from model when using custom mapping
r1055 m_mapLabels(0)
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
}
QPieSeriesPrivate::~QPieSeriesPrivate()
{
}
void QPieSeriesPrivate::updateDerivativeData()
{
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 m_sum = 0;
Michal Klocek
Adds big fat pimpl to series classes...
r938
// nothing to do?
if (m_slices.count() == 0)
return;
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 // calculate sum of all slices
Michal Klocek
Adds big fat pimpl to series classes...
r938 foreach (QPieSlice* s, m_slices)
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 m_sum += s->value();
Michal Klocek
Adds big fat pimpl to series classes...
r938
// nothing to show..
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 if (qFuzzyIsNull(m_sum))
Michal Klocek
Adds big fat pimpl to series classes...
r938 return;
// update slice attributes
qreal sliceAngle = m_pieStartAngle;
qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
QVector<QPieSlice*> changed;
foreach (QPieSlice* s, m_slices) {
PieSliceData data = PieSliceData::data(s);
Jani Honkonen
Rename pie series total() -> sum() to be consistent with bar series.
r939 data.m_percentage = s->value() / m_sum;
Michal Klocek
Adds big fat pimpl to series classes...
r938 data.m_angleSpan = pieSpan * data.m_percentage;
data.m_startAngle = sliceAngle;
sliceAngle += data.m_angleSpan;
if (PieSliceData::data(s) != data) {
PieSliceData::data(s) = data;
changed << s;
}
}
// emit signals
foreach (QPieSlice* s, changed)
PieSliceData::data(s).emitChangedSignal(s);
}
Jani Honkonen
API review changes for pie
r1009 QPieSeriesPrivate* QPieSeriesPrivate::seriesData(QPieSeries &series)
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
Jani Honkonen
API review changes for pie
r1009 return series.d_func();
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Jani Honkonen
API review changes for pie
r1009 void QPieSeriesPrivate::sliceChanged()
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
Jani Honkonen
API review changes for pie
r1009 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
updateDerivativeData();
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Jani Honkonen
API review changes for pie
r1009 void QPieSeriesPrivate::sliceClicked()
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
Q_ASSERT(m_slices.contains(slice));
Q_Q(QPieSeries);
Jani Honkonen
API review changes for pie
r1009 emit q->clicked(slice);
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Jani Honkonen
API review changes for pie
r1009 void QPieSeriesPrivate::sliceHovered(bool state)
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
Q_ASSERT(m_slices.contains(slice));
Q_Q(QPieSeries);
Jani Honkonen
API review changes for pie
r1009 emit q->hovered(slice, state);
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
{
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
if (m_mapOrientation == Qt::Vertical)
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 if ( topLeft.row() >= m_mapFirst && (m_mapCount == - 1 || topLeft.row() < m_mapFirst + m_mapCount)) {
if (topLeft.column() == m_mapValues)
m_slices.at(topLeft.row() - m_mapFirst)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
if (topLeft.column() == m_mapLabels)
m_slices.at(topLeft.row() - m_mapFirst)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
}
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
else
{
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 if (topLeft.column() >= m_mapFirst && (m_mapCount == - 1 || topLeft.column() < m_mapFirst + m_mapCount)) {
if (topLeft.row() == m_mapValues)
m_slices.at(topLeft.column() - m_mapFirst)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
if (topLeft.row() == m_mapLabels)
m_slices.at(topLeft.column() - m_mapFirst)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
}
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 }
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 }
Marek Rosa
PieSeries model support - further refactoring
r1081 void QPieSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 {
Q_UNUSED(parent);
Marek Rosa
PieSeries model support - further refactoring
r1081 if (m_mapOrientation == Qt::Vertical)
insertData(start, end);
else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie
initializePieFromModel();
}
void QPieSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
if (m_mapOrientation == Qt::Vertical)
removeData(start, end);
else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie
initializePieFromModel();
}
void QPieSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
if (m_mapOrientation == Qt::Horizontal)
insertData(start, end);
else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie
initializePieFromModel();
}
void QPieSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
{
Q_UNUSED(parent);
if (m_mapOrientation == Qt::Horizontal)
removeData(start, end);
else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie
initializePieFromModel();
}
void QPieSeriesPrivate::insertData(int start, int end)
{
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 Q_Q(QPieSeries);
if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) {
return;
} else {
Marek Rosa
Fixes to model support
r1060 int addedCount = end - start + 1;
if (m_mapCount != -1 && addedCount > m_mapCount)
addedCount = m_mapCount;
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 int first = qMax(start, m_mapFirst);
Marek Rosa
Fixes to model support
r1060 int last = qMin(first + addedCount - 1, m_mapOrientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 for (int i = first; i <= last; i++) {
QPieSlice *slice = new QPieSlice;
if (m_mapOrientation == Qt::Vertical) {
slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble());
slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
} else {
slice->setValue(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble());
slice->setLabel(m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString());
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 slice->setLabelVisible();
q->insert(i - m_mapFirst, slice);
}
if (m_mapCount != -1 && m_slices.size() > m_mapCount)
for (int i = m_slices.size() - 1; i >= m_mapCount; i--)
q->remove(q->slices().at(i));
}
}
Marek Rosa
PieSeries model support - further refactoring
r1081 void QPieSeriesPrivate::removeData(int start, int end)
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 {
Q_Q(QPieSeries);
int removedCount = end - start + 1;
if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) {
return;
Marek Rosa
Refactored model related methods in PieSeries
r1063 } else {
int toRemove = qMin(m_slices.size(), removedCount); // first find how many items can actually be removed
int first = qMax(start, m_mapFirst); // get the index of the first item that will be removed.
int last = qMin(first + toRemove - 1, m_slices.size() + m_mapFirst - 1); // get the index of the last item that will be removed.
for (int i = last; i >= first; i--)
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 q->remove(q->slices().at(i - m_mapFirst));
Marek Rosa
Refactored model related methods in PieSeries
r1063 if (m_mapCount != -1) {
int itemsAvailable; // check how many are available to be added
if (m_mapOrientation == Qt::Vertical)
itemsAvailable = m_model->rowCount() - m_mapFirst - m_slices.size();
else
itemsAvailable = m_model->columnCount() - m_mapFirst - m_slices.size();
int toBeAdded = qMin(itemsAvailable, m_mapCount - m_slices.size()); // add not more items than there is space left to be filled.
int currentSize = m_slices.size();
if (toBeAdded > 0)
for (int i = m_slices.size(); i < currentSize + toBeAdded; i++) {
QPieSlice *slice = new QPieSlice;
if (m_mapOrientation == Qt::Vertical) {
slice->setValue(m_model->data(m_model->index(i + m_mapFirst, m_mapValues), Qt::DisplayRole).toDouble());
slice->setLabel(m_model->data(m_model->index(i + m_mapFirst, m_mapLabels), Qt::DisplayRole).toString());
} else {
slice->setValue(m_model->data(m_model->index(m_mapValues, i + m_mapFirst), Qt::DisplayRole).toDouble());
slice->setLabel(m_model->data(m_model->index(m_mapLabels, i + m_mapFirst), Qt::DisplayRole).toString());
}
slice->setLabelVisible();
q->insert(i, slice);
}
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 }
}
}
void QPieSeriesPrivate::initializePieFromModel()
{
Q_Q(QPieSeries);
// clear current content
q->clear();
// create the initial slices set
Marek Rosa
PieSeries won't crash anymore if mapped columns/rows are not existing
r1086 if (m_mapOrientation == Qt::Vertical) {
if (m_mapValues >= m_model->columnCount() || m_mapLabels >= m_model->columnCount())
return; // mapped columns are not existing
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 int sliceCount = 0;
if(m_mapCount == -1)
sliceCount = m_model->rowCount() - m_mapFirst;
else
sliceCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst);
for (int i = m_mapFirst; i < m_mapFirst + sliceCount; i++)
q->append(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
} else {
Marek Rosa
PieSeries won't crash anymore if mapped columns/rows are not existing
r1086 if (m_mapValues >= m_model->rowCount() || m_mapLabels >= m_model->rowCount())
return; // mapped columns are not existing
Marek Rosa
PieSeries: model now supports custom mapping.
r1056 int sliceCount = 0;
if(m_mapCount == -1)
sliceCount = m_model->columnCount() - m_mapFirst;
else
sliceCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst);
for (int i = m_mapFirst; i < m_mapFirst + sliceCount; i++)
q->append(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString());
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
Marek Rosa
PieSeries model support - further refactoring
r1081 q->setLabelsVisible(true);
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min)
{
// Remove rounding errors
qreal roundedValue = newValue;
if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue))
roundedValue = 0.0;
else if (qFuzzyCompare(newValue, max))
roundedValue = max;
else if (qFuzzyCompare(newValue, min))
roundedValue = min;
// Check if the position is valid after removing the rounding errors
if (roundedValue < min || roundedValue > max) {
qWarning("QPieSeries: Illegal value");
return false;
}
if (!qFuzzyIsNull(value - roundedValue)) {
value = roundedValue;
return true;
}
// The change was so small it is considered a rounding error
return false;
}
Michal Klocek
Refactor to use qseries private for implmentation interface...
r943 void QPieSeriesPrivate::scaleDomain(Domain& domain)
{
Q_UNUSED(domain);
#ifndef QT_NO_DEBUG
qWarning() << __FILE__<<__FUNCTION__<<"not implemented";
#endif
}
Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
{
Q_Q(QPieSeries);
PieChartItem* pie = new PieChartItem(q,presenter);
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
presenter->animator()->addAnimation(pie);
}
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
return pie;
}
Michal Klocek
Adds big fat pimpl to series classes...
r938
Michal Klocek
Adds qlegend pimpl...
r950 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
{
Q_Q(QPieSeries);
QList<LegendMarker*> markers;
foreach(QPieSlice* slice, q->slices()) {
PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
markers << marker;
}
return markers;
}
Jani Honkonen
Pie chart refactoring
r142 #include "moc_qpieseries.cpp"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "moc_qpieseries_p.cpp"
Jani Honkonen
Pie chart refactoring
r142
QTCOMMERCIALCHART_END_NAMESPACE