qpieseries.cpp
640 lines
| 16.9 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r142 | #include "qpieseries.h" | ||
Jani Honkonen
|
r669 | #include "qpiesliceprivate_p.h" | ||
#include "qpieseriesprivate_p.h" | ||||
Jani Honkonen
|
r142 | #include <QDebug> | ||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Jani Honkonen
|
r669 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | ||
:QObject(parent), | ||||
q_ptr(parent), | ||||
m_pieRelativeHorPos(0.5), | ||||
m_pieRelativeVerPos(0.5), | ||||
m_pieRelativeSize(0.7), | ||||
m_pieStartAngle(0), | ||||
m_pieEndAngle(360), | ||||
m_total(0) | ||||
{ | ||||
} | ||||
QPieSeriesPrivate::~QPieSeriesPrivate() | ||||
{ | ||||
} | ||||
void QPieSeriesPrivate::updateDerivativeData() | ||||
{ | ||||
m_total = 0; | ||||
// nothing to do? | ||||
if (m_slices.count() == 0) | ||||
return; | ||||
// calculate total | ||||
foreach (QPieSlice* s, m_slices) | ||||
m_total += s->value(); | ||||
// nothing to show.. | ||||
if (m_total == 0) | ||||
return; | ||||
// update slice attributes | ||||
qreal sliceAngle = m_pieStartAngle; | ||||
qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | ||||
QVector<QPieSlice*> changed; | ||||
foreach (QPieSlice* s, m_slices) { | ||||
bool isChanged = false; | ||||
qreal percentage = s->value() / m_total; | ||||
Jani Honkonen
|
r676 | if (s->data_ptr()->m_data.m_percentage != percentage) { | ||
s->data_ptr()->m_data.m_percentage = percentage; | ||||
Jani Honkonen
|
r669 | isChanged = true; | ||
} | ||||
qreal sliceSpan = pieSpan * percentage; | ||||
Jani Honkonen
|
r676 | if (s->data_ptr()->m_data.m_angleSpan != sliceSpan) { | ||
s->data_ptr()->m_data.m_angleSpan = sliceSpan; | ||||
Jani Honkonen
|
r669 | isChanged = true; | ||
} | ||||
Jani Honkonen
|
r676 | if (s->data_ptr()->m_data.m_startAngle != sliceAngle) { | ||
s->data_ptr()->m_data.m_startAngle = sliceAngle; | ||||
Jani Honkonen
|
r669 | isChanged = true; | ||
} | ||||
sliceAngle += sliceSpan; | ||||
if (isChanged) | ||||
changed << s; | ||||
} | ||||
// emit signals | ||||
foreach (QPieSlice* s, changed) | ||||
Jani Honkonen
|
r676 | emit s->data_ptr()->changed(); | ||
Jani Honkonen
|
r669 | } | ||
void QPieSeriesPrivate::sliceChanged() | ||||
{ | ||||
Michal Klocek
|
r689 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | ||
Jani Honkonen
|
r669 | updateDerivativeData(); | ||
} | ||||
Jani Honkonen
|
r707 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | ||
Jani Honkonen
|
r669 | { | ||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
Jani Honkonen
|
r707 | emit q->clicked(slice, buttons); | ||
Jani Honkonen
|
r669 | } | ||
void QPieSeriesPrivate::sliceHoverEnter() | ||||
{ | ||||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
emit q->hoverEnter(slice); | ||||
} | ||||
void QPieSeriesPrivate::sliceHoverLeave() | ||||
{ | ||||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
emit q->hoverLeave(slice); | ||||
} | ||||
void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | ||||
{ | ||||
Q_UNUSED(bottomRight) | ||||
Q_Q(QPieSeries); | ||||
if (m_mapOrientation == Qt::Vertical) | ||||
{ | ||||
// slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); | ||||
if (topLeft.column() == m_mapValues) | ||||
if (m_mapValues == m_mapLabels) | ||||
{ | ||||
m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | ||||
m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | ||||
} | ||||
else | ||||
{ | ||||
m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | ||||
} | ||||
else if (topLeft.column() == m_mapLabels) | ||||
m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | ||||
} | ||||
else | ||||
{ | ||||
// slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble()); | ||||
if (topLeft.row() == m_mapValues) | ||||
if (m_mapValues == m_mapLabels) | ||||
{ | ||||
m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | ||||
m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | ||||
} | ||||
else | ||||
{ | ||||
m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble()); | ||||
} | ||||
else if (topLeft.row() == m_mapLabels) | ||||
m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString()); | ||||
} | ||||
} | ||||
void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | ||||
{ | ||||
Q_UNUSED(parent) | ||||
Q_UNUSED(end) | ||||
Q_Q(QPieSeries); | ||||
QPieSlice* newSlice = new QPieSlice; | ||||
newSlice->setLabelVisible(true); | ||||
if (m_mapOrientation == Qt::Vertical) | ||||
{ | ||||
newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | ||||
newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | ||||
} | ||||
else | ||||
{ | ||||
newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | ||||
newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | ||||
} | ||||
q->insert(start, newSlice); | ||||
} | ||||
void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | ||||
{ | ||||
Q_UNUSED(parent) | ||||
Q_UNUSED(end) | ||||
Q_Q(QPieSeries); | ||||
q->remove(m_slices.at(start)); | ||||
} | ||||
Jani Honkonen
|
r320 | /*! | ||
\class QPieSeries | ||||
\brief Pie series API for QtCommercial Charts | ||||
The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | ||||
The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | ||||
Jani Honkonen
|
r386 | The actual slice size is determined by that relative value. | ||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
r386 | By default the pie is defined as a full pie but it can be a partial pie. | ||
Jani Honkonen
|
r320 | This can be done by setting a starting angle and angle span to the series. | ||
*/ | ||||
Jani Honkonen
|
r314 | /*! | ||
Constructs a series object which is a child of \a parent. | ||||
*/ | ||||
Jani Honkonen
|
r203 | QPieSeries::QPieSeries(QObject *parent) : | ||
Michal Klocek
|
r360 | QSeries(parent), | ||
Jani Honkonen
|
r669 | d_ptr(new QPieSeriesPrivate(this)) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r157 | |||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r314 | /*! | ||
Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | ||||
*/ | ||||
Jani Honkonen
|
r203 | QPieSeries::~QPieSeries() | ||
{ | ||||
Jani Honkonen
|
r669 | // NOTE: d_prt destroyed by QObject | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r320 | Returns QChartSeries::SeriesTypePie. | ||
Jani Honkonen
|
r314 | */ | ||
Michal Klocek
|
r360 | QSeries::QSeriesType QPieSeries::type() const | ||
Jani Honkonen
|
r314 | { | ||
Michal Klocek
|
r360 | return QSeries::SeriesTypePie; | ||
Jani Honkonen
|
r314 | } | ||
/*! | ||||
Jani Honkonen
|
r354 | Sets an array of \a slices to the series replacing the existing slices. | ||
Jani Honkonen
|
r314 | Slice ownership is passed to the series. | ||
*/ | ||||
Jani Honkonen
|
r354 | void QPieSeries::replace(QList<QPieSlice*> slices) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r203 | clear(); | ||
add(slices); | ||||
} | ||||
Jani Honkonen
|
r163 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r345 | Adds an array of \a slices to the series. | ||
Jani Honkonen
|
r314 | Slice ownership is passed to the series. | ||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::add(QList<QPieSlice*> slices) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r203 | foreach (QPieSlice* s, slices) { | ||
s->setParent(this); | ||||
Jani Honkonen
|
r669 | d->m_slices << s; | ||
Jani Honkonen
|
r174 | } | ||
Jani Honkonen
|
r157 | |||
Jani Honkonen
|
r669 | d->updateDerivativeData(); | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r203 | foreach (QPieSlice* s, slices) { | ||
Jani Honkonen
|
r669 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | ||
Jani Honkonen
|
r707 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | ||
Jani Honkonen
|
r669 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | ||
connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r621 | emit added(slices); | ||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Adds a single \a slice to the series. | ||||
Slice ownership is passed to the series. | ||||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::add(QPieSlice* slice) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r203 | add(QList<QPieSlice*>() << slice); | ||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r415 | /*! | ||
Adds a single \a slice to the series and returns a reference to the series. | ||||
Slice ownership is passed to the series. | ||||
*/ | ||||
Jani Honkonen
|
r406 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | ||
{ | ||||
add(slice); | ||||
return *this; | ||||
} | ||||
Jani Honkonen
|
r314 | |||
/*! | ||||
Adds a single slice to the series with give \a value and \a name. | ||||
Slice ownership is passed to the series. | ||||
*/ | ||||
Jani Honkonen
|
r203 | QPieSlice* QPieSeries::add(qreal value, QString name) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r203 | QPieSlice* slice = new QPieSlice(value, name); | ||
add(slice); | ||||
return slice; | ||||
} | ||||
Jani Honkonen
|
r174 | |||
Marek Rosa
|
r604 | void QPieSeries::insert(int i, QPieSlice* slice) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Q_ASSERT(i <= d->m_slices.count()); | ||||
Marek Rosa
|
r604 | slice->setParent(this); | ||
Jani Honkonen
|
r669 | d->m_slices.insert(i, slice); | ||
Marek Rosa
|
r604 | |||
Jani Honkonen
|
r669 | d->updateDerivativeData(); | ||
Marek Rosa
|
r604 | |||
Jani Honkonen
|
r669 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | ||
connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | ||||
connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | ||||
connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | ||||
Marek Rosa
|
r604 | |||
Jani Honkonen
|
r621 | emit added(QList<QPieSlice*>() << slice); | ||
Marek Rosa
|
r604 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Removes a single \a slice from the series and deletes the slice. | ||||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
r314 | Do not reference this pointer after this call. | ||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::remove(QPieSlice* slice) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
if (!d->m_slices.removeOne(slice)) { | ||||
Jani Honkonen
|
r289 | Q_ASSERT(0); // TODO: how should this be reported? | ||
Jani Honkonen
|
r203 | return; | ||
} | ||||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r669 | d->updateDerivativeData(); | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r621 | emit removed(QList<QPieSlice*>() << slice); | ||
Jani Honkonen
|
r203 | delete slice; | ||
slice = NULL; | ||||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Clears all slices from the series. | ||||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::clear() | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
if (d->m_slices.count() == 0) | ||||
Jani Honkonen
|
r203 | return; | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r669 | QList<QPieSlice*> slices = d->m_slices; | ||
foreach (QPieSlice* s, d->m_slices) { | ||||
d->m_slices.removeOne(s); | ||||
Jani Honkonen
|
r203 | delete s; | ||
} | ||||
Jani Honkonen
|
r566 | |||
Jani Honkonen
|
r669 | d->updateDerivativeData(); | ||
Jani Honkonen
|
r621 | |||
emit removed(slices); | ||||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Counts the number of the slices in this series. | ||||
*/ | ||||
int QPieSeries::count() const | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_slices.count(); | ||||
Jani Honkonen
|
r314 | } | ||
Jani Honkonen
|
r621 | /*! | ||
Returns true is the series is empty. | ||||
*/ | ||||
bool QPieSeries::isEmpty() const | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_slices.isEmpty(); | ||||
Jani Honkonen
|
r621 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns a list of slices that belong to this series. | ||||
*/ | ||||
QList<QPieSlice*> QPieSeries::slices() const | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_slices; | ||||
Jani Honkonen
|
r314 | } | ||
/*! | ||||
Jani Honkonen
|
r498 | Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition. | ||
Jani Honkonen
|
r454 | |||
The factors are relative to the chart rectangle where: | ||||
Jani Honkonen
|
r498 | \a relativeHorizontalPosition 0.0 means the absolute left. | ||
\a relativeHorizontalPosition 1.0 means the absolute right. | ||||
\a relativeVerticalPosition 0.0 means the absolute top. | ||||
\a relativeVerticalPosition 1.0 means the absolute bottom. | ||||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | By default both values are 0.5 which puts the pie in the middle of the chart rectangle. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r498 | void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r498 | if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || | ||
Marek Rosa
|
r597 | relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) | ||
Jani Honkonen
|
r163 | return; | ||
Jani Honkonen
|
r669 | if (d->m_pieRelativeHorPos != relativeHorizontalPosition || d->m_pieRelativeVerPos != relativeVerticalPosition) { | ||
d->m_pieRelativeHorPos = relativeHorizontalPosition; | ||||
d->m_pieRelativeVerPos = relativeVerticalPosition; | ||||
Jani Honkonen
|
r621 | emit piePositionChanged(); | ||
Jani Honkonen
|
r163 | } | ||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r498 | Gets the horizontal position of the pie. | ||
Jani Honkonen
|
r314 | |||
Jani Honkonen
|
r498 | The returned value is relative to the chart rectangle where: | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | 0.0 means the absolute left. | ||
1.0 means the absolute right. | ||||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | \sa setPiePosition(), pieVerticalPosition(), setPieSize() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieHorizontalPosition() const | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeHorPos; | ||||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r498 | Gets the vertical position position of the pie. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | The returned value is relative to the chart rectangle where: | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | 0.0 means the absolute top. | ||
1.0 means the absolute bottom. | ||||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | \sa setPiePosition(), pieHorizontalPosition(), setPieSize() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieVerticalPosition() const | ||
Jani Honkonen
|
r314 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeVerPos; | ||||
Jani Honkonen
|
r314 | } | ||
/*! | ||||
Jani Honkonen
|
r498 | Sets the relative size of the pie. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | ||
Jani Honkonen
|
r454 | |||
Default value is 0.7. | ||||
Jani Honkonen
|
r498 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | ||
Jani Honkonen
|
r437 | */ | ||
Jani Honkonen
|
r498 | void QPieSeries::setPieSize(qreal relativeSize) | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r498 | if (relativeSize < 0.0 || relativeSize > 1.0) | ||
Jani Honkonen
|
r454 | return; | ||
Jani Honkonen
|
r669 | if (d->m_pieRelativeSize != relativeSize) { | ||
d->m_pieRelativeSize = relativeSize; | ||||
Jani Honkonen
|
r621 | emit pieSizeChanged(); | ||
Jani Honkonen
|
r437 | } | ||
} | ||||
Jani Honkonen
|
r314 | |||
Jani Honkonen
|
r437 | /*! | ||
Jani Honkonen
|
r498 | Gets the relative size of the pie. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | ||
Jani Honkonen
|
r454 | |||
Default value is 0.7. | ||||
Jani Honkonen
|
r498 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieSize() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeSize; | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r454 | /*! | ||
Sets the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r498 | \a angle must be less than pie end angle. Default value is 0. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() | ||
Jani Honkonen
|
r454 | */ | ||
Jani Honkonen
|
r498 | void QPieSeries::setPieStartAngle(qreal angle) | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
if (angle >= 0 && angle <= 360 && angle != d->m_pieStartAngle && angle <= d->m_pieEndAngle) { | ||||
d->m_pieStartAngle = angle; | ||||
d->updateDerivativeData(); | ||||
Jani Honkonen
|
r203 | } | ||
} | ||||
Jani Honkonen
|
r454 | /*! | ||
Gets the start angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. | ||||
Jani Honkonen
|
r498 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() | ||
Jani Honkonen
|
r454 | */ | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieStartAngle() const | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieStartAngle; | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r454 | /*! | ||
Sets the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r498 | \a angle must be greater than start angle. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | ||
Jani Honkonen
|
r454 | */ | ||
Jani Honkonen
|
r498 | void QPieSeries::setPieEndAngle(qreal angle) | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
if (angle >= 0 && angle <= 360 && angle != d->m_pieEndAngle && angle >= d->m_pieStartAngle) { | ||||
d->m_pieEndAngle = angle; | ||||
d->updateDerivativeData(); | ||||
Jani Honkonen
|
r437 | } | ||
} | ||||
Jani Honkonen
|
r454 | /*! | ||
Returns the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r498 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | ||
Jani Honkonen
|
r454 | */ | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieEndAngle() const | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieEndAngle; | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Sets the all the slice labels \a visible or invisible. | ||||
\sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | ||||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::setLabelsVisible(bool visible) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
foreach (QPieSlice* s, d->m_slices) | ||||
Jani Honkonen
|
r203 | s->setLabelVisible(visible); | ||
} | ||||
Jani Honkonen
|
r406 | /*! | ||
Returns the sum of all slice values in this series. | ||||
\sa QPieSlice::value(), QPieSlice::setValue() | ||||
*/ | ||||
qreal QPieSeries::total() const | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_total; | ||||
Jani Honkonen
|
r406 | } | ||
Jani Honkonen
|
r314 | /*! | ||
\fn void QPieSeries::clicked(QPieSlice* slice) | ||||
This signal is emitted when a \a slice has been clicked. | ||||
\sa QPieSlice::clicked() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::hoverEnter(QPieSlice* slice) | ||||
This signal is emitted when user has hovered over a \a slice. | ||||
\sa QPieSlice::hoverEnter() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::hoverLeave(QPieSlice* slice) | ||||
This signal is emitted when user has hovered away from a \a slice. | ||||
\sa QPieSlice::hoverLeave() | ||||
*/ | ||||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r174 | |||
Marek Rosa
|
r597 | bool QPieSeries::setModel(QAbstractItemModel* model) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Marek Rosa
|
r597 | // disconnect signals from old model | ||
if(m_model) | ||||
{ | ||||
Marek Rosa
|
r630 | disconnect(m_model, 0, this, 0); | ||
Jani Honkonen
|
r669 | d->m_mapValues = -1; | ||
d->m_mapLabels = -1; | ||||
d->m_mapOrientation = Qt::Vertical; | ||||
Marek Rosa
|
r597 | } | ||
Marek Rosa
|
r630 | // set new model | ||
Marek Rosa
|
r597 | if(model) | ||
{ | ||||
m_model = model; | ||||
Marek Rosa
|
r630 | return true; | ||
} | ||||
else | ||||
{ | ||||
m_model = NULL; | ||||
return false; | ||||
Marek Rosa
|
r597 | } | ||
} | ||||
void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Marek Rosa
|
r630 | if (m_model == NULL) | ||
return; | ||||
Jani Honkonen
|
r669 | |||
d->m_mapValues = modelValuesLine; | ||||
d->m_mapLabels = modelLabelsLine; | ||||
d->m_mapOrientation = orientation; | ||||
Marek Rosa
|
r597 | |||
Marek Rosa
|
r630 | // connect the signals | ||
Jani Honkonen
|
r669 | if (d->m_mapOrientation == Qt::Vertical) { | ||
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | ||||
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | ||||
connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | ||||
} else { | ||||
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | ||||
connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | ||||
connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | ||||
Marek Rosa
|
r630 | } | ||
Marek Rosa
|
r597 | |||
Marek Rosa
|
r630 | // create the initial slices set | ||
Jani Honkonen
|
r669 | if (d->m_mapOrientation == Qt::Vertical) { | ||
Marek Rosa
|
r597 | for (int i = 0; i < m_model->rowCount(); i++) | ||
Jani Honkonen
|
r669 | add(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | ||
} else { | ||||
Marek Rosa
|
r597 | for (int i = 0; i < m_model->columnCount(); i++) | ||
Jani Honkonen
|
r669 | add(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | ||
Marek Rosa
|
r604 | } | ||
Marek Rosa
|
r597 | } | ||
Jani Honkonen
|
r142 | #include "moc_qpieseries.cpp" | ||
Jani Honkonen
|
r669 | #include "moc_qpieseriesprivate_p.cpp" | ||
Jani Honkonen
|
r142 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||