qpieseries.cpp
109 lines
| 2.1 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r142 | #include "qpieseries.h" | ||
Jani Honkonen
|
r146 | #include "piepresenter.h" | ||
Jani Honkonen
|
r142 | #include "pieslice.h" | ||
#include <QDebug> | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
QPieSeries::QPieSeries(QObject *parent) : | ||||
QChartSeries(parent), | ||||
m_sizeFactor(1.0), | ||||
m_position(PiePositionMaximized) | ||||
{ | ||||
} | ||||
QPieSeries::~QPieSeries() | ||||
{ | ||||
} | ||||
Jani Honkonen
|
r163 | bool QPieSeries::setData(QList<qreal> data) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r163 | QList<QPieSlice> slices; | ||
foreach (int value, data) | ||||
slices << QPieSlice(value, QString::number(value)); | ||||
return set(slices); | ||||
} | ||||
bool QPieSeries::set(QList<QPieSlice> slices) | ||||
{ | ||||
if (!slices.count()) | ||||
return false; | ||||
Jani Honkonen
|
r157 | PieChangeSet changeSet; | ||
for (int i=slices.count(); i<m_slices.count(); i++) | ||||
changeSet.m_removed << i; | ||||
for (int i=0; i<slices.count(); i++) { | ||||
if (i < m_slices.count()) | ||||
changeSet.m_changed << i; | ||||
else | ||||
changeSet.m_added << i; | ||||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r157 | |||
m_slices = slices; | ||||
emit changed(changeSet); | ||||
Jani Honkonen
|
r163 | return true; | ||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r163 | bool QPieSeries::add(QList<QPieSlice> slices) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r163 | if (!slices.count()) | ||
return false; | ||||
Jani Honkonen
|
r157 | PieChangeSet changeSet; | ||
for (int i=0; i<slices.count(); i++) | ||||
changeSet.m_added << m_slices.count() + i; | ||||
Jani Honkonen
|
r142 | m_slices += slices; | ||
Jani Honkonen
|
r157 | emit changed(changeSet); | ||
Jani Honkonen
|
r163 | return true; | ||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r163 | bool QPieSeries::add(QPieSlice slice) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r163 | return add(QList<QPieSlice>() << slice); | ||
Jani Honkonen
|
r142 | } | ||
QPieSlice QPieSeries::slice(int index) const | ||||
{ | ||||
if ((index >= 0) && (index < m_slices.count())) | ||||
return m_slices.at(index); | ||||
return QPieSlice(); | ||||
} | ||||
bool QPieSeries::update(int index, QPieSlice slice) | ||||
{ | ||||
if ((index >= 0) && (index < m_slices.count())) { | ||||
m_slices[index] = slice; | ||||
Jani Honkonen
|
r157 | PieChangeSet changeSet; | ||
changeSet.m_changed << index; | ||||
emit changed(changeSet); | ||||
Jani Honkonen
|
r142 | return true; | ||
} | ||||
return false; | ||||
} | ||||
void QPieSeries::setSizeFactor(qreal factor) | ||||
{ | ||||
Jani Honkonen
|
r163 | if (factor < 0.0) | ||
return; | ||||
if (m_sizeFactor != factor) { | ||||
Jani Honkonen
|
r142 | m_sizeFactor = factor; | ||
Jani Honkonen
|
r163 | emit sizeFactorChanged(); | ||
} | ||||
Jani Honkonen
|
r142 | } | ||
void QPieSeries::setPosition(PiePosition position) | ||||
{ | ||||
Jani Honkonen
|
r163 | if (m_position != position) { | ||
m_position = position; | ||||
emit positionChanged(); | ||||
} | ||||
Jani Honkonen
|
r142 | } | ||
#include "moc_qpieseries.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||