##// END OF EJS Templates
Optimize polar chart radius calculation a bit....
Optimize polar chart radius calculation a bit. Current algorithm still results in an occasional extra unneeded iteration, as it uses only crude approximation for radius reduction. However, any speedup gained by accurately calculating needed reduction would be very minor compared to approximations used, so it doesn't seem worth the effort to figure out the complex math. Change-Id: If670a1b058a85cd0305b93f62e6388b463bafd0d Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>

File last commit:

r2488:5862599d088d
r2542:189023d9a551
Show More
declarativebarseries.cpp
456 lines | 16.5 KiB | text/x-c | CppLexer
/****************************************************************************
**
** Copyright (C) 2013 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$
**
****************************************************************************/
#include "declarativebarseries.h"
#include "qbarset.h"
#include "qvbarmodelmapper.h"
#include "qhbarmodelmapper.h"
QTCOMMERCIALCHART_BEGIN_NAMESPACE
DeclarativeBarSet::DeclarativeBarSet(QObject *parent)
: QBarSet("", parent)
{
connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int)));
connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int)));
}
void DeclarativeBarSet::handleCountChanged(int index, int count)
{
Q_UNUSED(index)
Q_UNUSED(count)
emit countChanged(QBarSet::count());
}
qreal DeclarativeBarSet::borderWidth() const
{
return pen().widthF();
}
void DeclarativeBarSet::setBorderWidth(qreal width)
{
if (width != pen().widthF()) {
QPen p = pen();
p.setWidthF(width);
setPen(p);
emit borderWidthChanged(width);
}
}
QVariantList DeclarativeBarSet::values()
{
QVariantList values;
for (int i(0); i < count(); i++)
values.append(QVariant(QBarSet::at(i)));
return values;
}
void DeclarativeBarSet::setValues(QVariantList values)
{
while (count())
remove(count() - 1);
for (int i(0); i < values.count(); i++) {
if (values.at(i).canConvert(QVariant::Double))
QBarSet::append(values[i].toDouble());
}
}
// Declarative bar series ======================================================================================
DeclarativeBarSeries::DeclarativeBarSeries(QDECLARATIVE_ITEM *parent) :
QBarSeries(parent),
m_axes(new DeclarativeAxes(this))
{
connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
}
void DeclarativeBarSeries::classBegin()
{
}
void DeclarativeBarSeries::componentComplete()
{
foreach (QObject *child, children()) {
if (qobject_cast<DeclarativeBarSet *>(child)) {
QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
} else if (qobject_cast<QVBarModelMapper *>(child)) {
QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
mapper->setSeries(this);
} else if (qobject_cast<QHBarModelMapper *>(child)) {
QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
mapper->setSeries(this);
}
}
}
QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeBarSeries::seriesChildren()
{
return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS);
}
void DeclarativeBarSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> *list, QObject *element)
{
// Empty implementation; the children are parsed in componentComplete instead
Q_UNUSED(list);
Q_UNUSED(element);
}
DeclarativeBarSet *DeclarativeBarSeries::at(int index)
{
QList<QBarSet *> setList = barSets();
if (index >= 0 && index < setList.count())
return qobject_cast<DeclarativeBarSet *>(setList[index]);
return 0;
}
DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
{
DeclarativeBarSet *barset = new DeclarativeBarSet(this);
barset->setLabel(label);
barset->setValues(values);
if (QBarSeries::insert(index, barset))
return barset;
delete barset;
return 0;
}
// Declarative stacked bar series ==============================================================================
DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDECLARATIVE_ITEM *parent) :
QStackedBarSeries(parent),
m_axes(0)
{
m_axes = new DeclarativeAxes(this);
connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
}
void DeclarativeStackedBarSeries::classBegin()
{
}
void DeclarativeStackedBarSeries::componentComplete()
{
foreach (QObject *child, children()) {
if (qobject_cast<DeclarativeBarSet *>(child)) {
QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
} else if (qobject_cast<QVBarModelMapper *>(child)) {
QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
mapper->setSeries(this);
} else if (qobject_cast<QHBarModelMapper *>(child)) {
QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
mapper->setSeries(this);
}
}
}
QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeStackedBarSeries::seriesChildren()
{
return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS);
}
void DeclarativeStackedBarSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> * list, QObject *element)
{
// Empty implementation; the children are parsed in componentComplete instead
Q_UNUSED(list);
Q_UNUSED(element);
}
DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
{
QList<QBarSet *> setList = barSets();
if (index >= 0 && index < setList.count())
return qobject_cast<DeclarativeBarSet *>(setList[index]);
return 0;
}
DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
{
DeclarativeBarSet *barset = new DeclarativeBarSet(this);
barset->setLabel(label);
barset->setValues(values);
if (QStackedBarSeries::insert(index, barset))
return barset;
delete barset;
return 0;
}
// Declarative percent bar series ==============================================================================
DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDECLARATIVE_ITEM *parent) :
QPercentBarSeries(parent),
m_axes(0)
{
m_axes = new DeclarativeAxes(this);
connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
}
void DeclarativePercentBarSeries::classBegin()
{
}
void DeclarativePercentBarSeries::componentComplete()
{
foreach (QObject *child, children()) {
if (qobject_cast<DeclarativeBarSet *>(child)) {
QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
} else if (qobject_cast<QVBarModelMapper *>(child)) {
QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
mapper->setSeries(this);
} else if (qobject_cast<QHBarModelMapper *>(child)) {
QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
mapper->setSeries(this);
}
}
}
QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativePercentBarSeries::seriesChildren()
{
return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS);
}
void DeclarativePercentBarSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> * list, QObject *element)
{
// Empty implementation; the children are parsed in componentComplete instead
Q_UNUSED(list);
Q_UNUSED(element);
}
DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
{
QList<QBarSet *> setList = barSets();
if (index >= 0 && index < setList.count())
return qobject_cast<DeclarativeBarSet *>(setList[index]);
return 0;
}
DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
{
DeclarativeBarSet *barset = new DeclarativeBarSet(this);
barset->setLabel(label);
barset->setValues(values);
if (QPercentBarSeries::insert(index, barset))
return barset;
delete barset;
return 0;
}
// Declarative horizontal bar series ===========================================================================
DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QDECLARATIVE_ITEM *parent) :
QHorizontalBarSeries(parent),
m_axes(0)
{
m_axes = new DeclarativeAxes(this);
connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
}
void DeclarativeHorizontalBarSeries::classBegin()
{
}
void DeclarativeHorizontalBarSeries::componentComplete()
{
foreach (QObject *child, children()) {
if (qobject_cast<DeclarativeBarSet *>(child)) {
QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
} else if (qobject_cast<QVBarModelMapper *>(child)) {
QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
mapper->setSeries(this);
} else if (qobject_cast<QHBarModelMapper *>(child)) {
QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
mapper->setSeries(this);
}
}
}
QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeHorizontalBarSeries::seriesChildren()
{
return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeHorizontalBarSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS);
}
void DeclarativeHorizontalBarSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> * list, QObject *element)
{
// Empty implementation; the children are parsed in componentComplete instead
Q_UNUSED(list);
Q_UNUSED(element);
}
DeclarativeBarSet *DeclarativeHorizontalBarSeries::at(int index)
{
QList<QBarSet *> setList = barSets();
if (index >= 0 && index < setList.count())
return qobject_cast<DeclarativeBarSet *>(setList[index]);
return 0;
}
DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString label, QVariantList values)
{
DeclarativeBarSet *barset = new DeclarativeBarSet(this);
barset->setLabel(label);
barset->setValues(values);
if (QHorizontalBarSeries::insert(index, barset))
return barset;
delete barset;
return 0;
}
// Declarative horizontal stacked bar series ===================================================================
DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QDECLARATIVE_ITEM *parent) :
QHorizontalStackedBarSeries(parent),
m_axes(0)
{
m_axes = new DeclarativeAxes(this);
connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
}
void DeclarativeHorizontalStackedBarSeries::classBegin()
{
}
void DeclarativeHorizontalStackedBarSeries::componentComplete()
{
foreach (QObject *child, children()) {
if (qobject_cast<DeclarativeBarSet *>(child)) {
QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
} else if (qobject_cast<QVBarModelMapper *>(child)) {
QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
mapper->setSeries(this);
} else if (qobject_cast<QHBarModelMapper *>(child)) {
QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
mapper->setSeries(this);
}
}
}
QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeHorizontalStackedBarSeries::seriesChildren()
{
return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeHorizontalStackedBarSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS);
}
void DeclarativeHorizontalStackedBarSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> * list, QObject *element)
{
// Empty implementation; the children are parsed in componentComplete instead
Q_UNUSED(list);
Q_UNUSED(element);
}
DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::at(int index)
{
QList<QBarSet *> setList = barSets();
if (index >= 0 && index < setList.count())
return qobject_cast<DeclarativeBarSet *>(setList[index]);
return 0;
}
DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QString label, QVariantList values)
{
DeclarativeBarSet *barset = new DeclarativeBarSet(this);
barset->setLabel(label);
barset->setValues(values);
if (QHorizontalStackedBarSeries::insert(index, barset))
return barset;
delete barset;
return 0;
}
// Declarative horizontal percent bar series ===================================================================
DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QDECLARATIVE_ITEM *parent) :
QHorizontalPercentBarSeries(parent),
m_axes(0)
{
m_axes = new DeclarativeAxes(this);
connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
}
void DeclarativeHorizontalPercentBarSeries::classBegin()
{
}
void DeclarativeHorizontalPercentBarSeries::componentComplete()
{
foreach (QObject *child, children()) {
if (qobject_cast<DeclarativeBarSet *>(child)) {
QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
} else if (qobject_cast<QVBarModelMapper *>(child)) {
QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
mapper->setSeries(this);
} else if (qobject_cast<QHBarModelMapper *>(child)) {
QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
mapper->setSeries(this);
}
}
}
QDECLARATIVE_LIST_PROPERTY<QObject> DeclarativeHorizontalPercentBarSeries::seriesChildren()
{
return QDECLARATIVE_LIST_PROPERTY<QObject>(this, 0, &DeclarativeHorizontalPercentBarSeries::appendSeriesChildren LIST_PROPERTY_PARAM_DEFAULTS);
}
void DeclarativeHorizontalPercentBarSeries::appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY<QObject> * list, QObject *element)
{
// Empty implementation; the children are parsed in componentComplete instead
Q_UNUSED(list);
Q_UNUSED(element);
}
DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::at(int index)
{
QList<QBarSet *> setList = barSets();
if (index >= 0 && index < setList.count())
return qobject_cast<DeclarativeBarSet *>(setList[index]);
return 0;
}
DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::insert(int index, QString label, QVariantList values)
{
DeclarativeBarSet *barset = new DeclarativeBarSet(this);
barset->setLabel(label);
barset->setValues(values);
if (QHorizontalPercentBarSeries::insert(index, barset))
return barset;
delete barset;
return 0;
}
#include "moc_declarativebarseries.cpp"
QTCOMMERCIALCHART_END_NAMESPACE