declarativebarseries.cpp
244 lines
| 7.3 KiB
| text/x-c
|
CppLexer
|
r830 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r646 | #include "declarativebarseries.h" | ||
#include "declarativechart.h" | ||||
|
r1162 | #include <QBarSet> | ||
|
r1313 | #include <QVBarModelMapper> | ||
#include <QHBarModelMapper> | ||||
|
r646 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r1162 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | ||
QBarSet("", parent) | ||||
|
r646 | { | ||
|
r1465 | 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()); | ||||
|
r646 | } | ||
|
r1162 | QVariantList DeclarativeBarSet::values() | ||
|
r646 | { | ||
|
r1162 | QVariantList values; | ||
for (int i(0); i < count(); i++) | ||||
values.append(QVariant(at(i))); | ||||
return values; | ||||
|
r1004 | } | ||
|
r646 | |||
|
r1162 | void DeclarativeBarSet::setValues(QVariantList values) | ||
|
r1004 | { | ||
|
r1162 | while (count()) | ||
remove(count() - 1); | ||||
|
r646 | |||
|
r1162 | for (int i(0); i < values.count(); i++) { | ||
if (values.at(i).canConvert(QVariant::Double)) | ||||
append(values[i].toDouble()); | ||||
|
r1004 | } | ||
|
r1162 | } | ||
|
r646 | |||
|
r1162 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | ||
|
r1222 | QBarSeries(parent) | ||
|
r1162 | { | ||
} | ||||
|
r646 | |||
|
r1162 | void DeclarativeBarSeries::classBegin() | ||
{ | ||||
} | ||||
|
r646 | |||
|
r1162 | void DeclarativeBarSeries::componentComplete() | ||
{ | ||||
|
r1193 | foreach(QObject *child, children()) { | ||
|
r1302 | if (qobject_cast<DeclarativeBarSet *>(child)) { | ||
QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | ||||
|
r1313 | } 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); | ||||
|
r1193 | } | ||
} | ||||
} | ||||
|
r1313 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | ||
|
r1193 | { | ||
|
r1313 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||
} | ||||
void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | ||||
{ | ||||
// Empty implementation; the children are parsed in componentComplete instead | ||||
Q_UNUSED(list); | ||||
Q_UNUSED(element); | ||||
|
r1162 | } | ||
|
r646 | |||
|
r1302 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) | ||
{ | ||||
QList<QBarSet*> setList = barSets(); | ||||
if (index < setList.count()) | ||||
return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||||
return 0; | ||||
} | ||||
|
r1211 | DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : | ||
QGroupedBarSeries(parent) | ||||
{ | ||||
} | ||||
void DeclarativeGroupedBarSeries::classBegin() | ||||
{ | ||||
} | ||||
void DeclarativeGroupedBarSeries::componentComplete() | ||||
{ | ||||
foreach(QObject *child, children()) { | ||||
|
r1302 | if (qobject_cast<DeclarativeBarSet *>(child)) { | ||
QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | ||||
|
r1313 | } 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); | ||||
|
r1211 | } | ||
} | ||||
} | ||||
|
r1313 | QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren() | ||
{ | ||||
return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||||
} | ||||
void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | ||||
|
r1211 | { | ||
|
r1313 | // Empty implementation; the children are parsed in componentComplete instead | ||
Q_UNUSED(list); | ||||
Q_UNUSED(element); | ||||
|
r1211 | } | ||
|
r1302 | DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index) | ||
{ | ||||
QList<QBarSet*> setList = barSets(); | ||||
if (index < setList.count()) | ||||
return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||||
return 0; | ||||
} | ||||
|
r1318 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : | ||
QStackedBarSeries(parent) | ||||
{ | ||||
} | ||||
void DeclarativeStackedBarSeries::classBegin() | ||||
{ | ||||
} | ||||
void DeclarativeStackedBarSeries::componentComplete() | ||||
{ | ||||
foreach(QObject *child, children()) { | ||||
if (qobject_cast<DeclarativeBarSet *>(child)) { | ||||
QBarSeries::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); | ||||
} | ||||
} | ||||
} | ||||
QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() | ||||
{ | ||||
return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||||
} | ||||
void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<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 < setList.count()) | ||||
return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||||
return 0; | ||||
} | ||||
DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : | ||||
QPercentBarSeries(parent) | ||||
{ | ||||
} | ||||
void DeclarativePercentBarSeries::classBegin() | ||||
{ | ||||
} | ||||
void DeclarativePercentBarSeries::componentComplete() | ||||
{ | ||||
foreach(QObject *child, children()) { | ||||
if (qobject_cast<DeclarativeBarSet *>(child)) { | ||||
QBarSeries::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); | ||||
} | ||||
} | ||||
} | ||||
QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() | ||||
{ | ||||
return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||||
} | ||||
void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<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 < setList.count()) | ||||
return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||||
return 0; | ||||
} | ||||
|
r646 | #include "moc_declarativebarseries.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||