##// END OF EJS Templates
One more alternative for changing themes
One more alternative for changing themes

File last commit:

r108:4cbe204cc325
r108:4cbe204cc325
Show More
qpieseries.cpp
186 lines | 4.9 KiB | text/x-c | CppLexer
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 #include "qpieseries_p.h"
Tero Ahola
Integrated draft version of pie series
r51 #include "qpieseries.h"
#include <QGraphicsObject>
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 #include "pieslice.h"
Tero Ahola
Integrated draft version of pie series
r51 #include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Tero Ahola
One more alternative for changing themes
r108 QPieSeriesPrivate::QPieSeriesPrivate(QGraphicsItem *parent) :
ChartItem(parent),
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 m_sizeFactor(1.0),
Tero Ahola
One more alternative for changing themes
r108 m_position(QPieSeries::PiePositionMaximized),
m_chartTheme(0)
Tero Ahola
Integrated draft version of pie series
r51 {
Tero Ahola
Refactored series creation with QChart
r61 }
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 QPieSeriesPrivate::~QPieSeriesPrivate()
Tero Ahola
Refactored series creation with QChart
r61 {
while (m_slices.count())
delete m_slices.takeLast();
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 bool QPieSeriesPrivate::setData(QList<qreal> data)
Tero Ahola
Refactored series creation with QChart
r61 {
m_data = data;
Tero Ahola
One more alternative for changing themes
r108 if (parentItem()) {
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 // Create slices
qreal fullPie = 360;
qreal total = 0;
foreach (qreal value, m_data)
total += value;
Tero Ahola
One more alternative for changing themes
r108 m_chartSize = parentItem()->boundingRect();
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 qreal angle = 0;
// TODO: no need to create new slices in case size changed; we should re-use the existing ones
foreach (qreal value, m_data) {
qreal span = value / total * fullPie;
Tero Ahola
One more alternative for changing themes
r108 PieSlice *slice = new PieSlice(QColor(), angle, span, parentItem()->boundingRect());
slice->setParentItem(parentItem());
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 m_slices.append(slice);
angle += span;
}
Tero Ahola
Integrated draft version of pie series
r51
Tero Ahola
One more alternative for changing themes
r108 themeChanged(m_chartTheme);
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 resizeSlices(m_chartSize);
Tero Ahola
Integrated draft version of pie series
r51 }
Tero Ahola
Added size factor property to pie
r60
Tero Ahola
Refactored series creation with QChart
r61 return true;
Tero Ahola
Removed scale from chart's sizeChanged signals
r54 }
Tero Ahola
Refactoring continued: restored ChartItem class
r104 void QPieSeriesPrivate::setSize(const QSize &size)
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 {
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 // TODO: allow user setting the size?
// TODO: allow user defining the margins?
m_chartSize = QRect(0, 0, size.width(), size.height());
resizeSlices(m_chartSize);
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 }
Tero Ahola
One more alternative for changing themes
r108 void QPieSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain)
{
// TODO
}
void QPieSeriesPrivate::themeChanged(ChartTheme *theme)
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 {
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 if (theme) {
m_chartTheme = theme;
for (int i(0); i < m_slices.count(); i++)
m_slices.at(i)->m_theme = theme->themeForSeries();
}
Tero Ahola
Color themes now enabled for scatter, pie and line series.
r75 }
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 void QPieSeriesPrivate::resizeSlices(QRectF rect)
Tero Ahola
Added size factor property to pie
r60 {
QRectF tempRect = rect;
if (tempRect.width() < tempRect.height()) {
tempRect.setWidth(tempRect.width() * m_sizeFactor);
tempRect.setHeight(tempRect.width());
tempRect.moveCenter(rect.center());
} else {
tempRect.setHeight(tempRect.height() * m_sizeFactor);
tempRect.setWidth(tempRect.height());
tempRect.moveCenter(rect.center());
}
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 switch (m_position) {
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 case QPieSeries::PiePositionTopLeft: {
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 tempRect.setHeight(tempRect.height() / 2);
tempRect.setWidth(tempRect.height());
tempRect.moveCenter(QPointF(rect.center().x() / 2, rect.center().y() / 2));
break;
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 case QPieSeries::PiePositionTopRight: {
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 tempRect.setHeight(tempRect.height() / 2);
tempRect.setWidth(tempRect.height());
tempRect.moveCenter(QPointF((rect.center().x() / 2) * 3, rect.center().y() / 2));
break;
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 case QPieSeries::PiePositionBottomLeft: {
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 tempRect.setHeight(tempRect.height() / 2);
tempRect.setWidth(tempRect.height());
tempRect.moveCenter(QPointF(rect.center().x() / 2, (rect.center().y() / 2) * 3));
break;
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 case QPieSeries::PiePositionBottomRight: {
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 tempRect.setHeight(tempRect.height() / 2);
tempRect.setWidth(tempRect.height());
tempRect.moveCenter(QPointF((rect.center().x() / 2) * 3, (rect.center().y() / 2) * 3));
break;
}
default:
break;
}
Tero Ahola
Added size factor property to pie
r60 foreach (PieSlice *slice, m_slices)
slice->m_rect = tempRect;
}
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 QPieSeries::QPieSeries(QGraphicsObject *parent) :
QChartSeries(parent),
Tero Ahola
One more alternative for changing themes
r108 d(new QPieSeriesPrivate(parent))
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 {
}
QPieSeries::~QPieSeries()
{
delete d;
}
bool QPieSeries::setData(QList<qreal> data)
{
return d->setData(data);
}
void QPieSeries::setSliceColor(int index, QColor color)
{
if (index >= 0 && index < d->m_slices.count())
d->m_slices.at(index)->m_color = color;
}
QColor QPieSeries::sliceColor(int index)
{
if (index >= 0 && index < d->m_slices.count())
return d->m_slices.at(index)->m_color;
else
return QColor();
}
int QPieSeries::sliceCount()
{
return d->m_slices.count();
}
Tero Ahola
Added size factor property to pie
r60 void QPieSeries::setSizeFactor(qreal factor)
{
if (factor > 0.0)
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 d->m_sizeFactor = factor;
d->resizeSlices(d->m_chartSize);
Tero Ahola
Added size factor property to pie
r60
// Initiate update via the parent graphics item
// TODO: potential issue: what if this function is called from the parent context?
Tero Ahola
One more alternative for changing themes
r108 if (d->parentItem())
d->parentItem()->update();
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 }
qreal QPieSeries::sizeFactor()
{
return d->m_sizeFactor;
Tero Ahola
Removed scale from chart's sizeChanged signals
r54 }
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 void QPieSeries::setPosition(PiePosition position)
{
Tero Ahola
Refactored themes; now enabled for line, scatter and pies...
r103 d->m_position = position;
d->resizeSlices(d->m_chartSize);
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77
// Initiate update via the parent graphics item
// TODO: potential issue: what if this function is called from the parent context?
QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
Q_ASSERT(parentItem);
parentItem->update();
}
Tero Ahola
Integrated draft version of pie series
r51 #include "moc_qpieseries.cpp"
QTCOMMERCIALCHART_END_NAMESPACE