declarativebarseries.cpp
232 lines
| 7.0 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
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$ | ||||
** | ||||
****************************************************************************/ | ||||
Tero Ahola
|
r646 | #include "declarativebarseries.h" | ||
Tero Ahola
|
r1162 | #include <QBarSet> | ||
Tero Ahola
|
r1313 | #include <QVBarModelMapper> | ||
#include <QHBarModelMapper> | ||||
Tero Ahola
|
r646 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Tero Ahola
|
r1162 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | ||
QBarSet("", parent) | ||||
Tero Ahola
|
r646 | { | ||
Tero Ahola
|
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()); | ||||
Tero Ahola
|
r646 | } | ||
Tero Ahola
|
r1162 | QVariantList DeclarativeBarSet::values() | ||
Tero Ahola
|
r646 | { | ||
Tero Ahola
|
r1162 | QVariantList values; | ||
for (int i(0); i < count(); i++) | ||||
Tero Ahola
|
r1513 | values.append(QVariant(QBarSet::at(i))); | ||
Tero Ahola
|
r1162 | return values; | ||
Tero Ahola
|
r1004 | } | ||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1162 | void DeclarativeBarSet::setValues(QVariantList values) | ||
Tero Ahola
|
r1004 | { | ||
Tero Ahola
|
r1162 | while (count()) | ||
remove(count() - 1); | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1162 | for (int i(0); i < values.count(); i++) { | ||
if (values.at(i).canConvert(QVariant::Double)) | ||||
Tero Ahola
|
r1513 | QBarSet::append(values[i].toDouble()); | ||
Tero Ahola
|
r1004 | } | ||
Tero Ahola
|
r1162 | } | ||
Tero Ahola
|
r646 | |||
sauimone
|
r1594 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | ||
QBarSeries(parent) | ||||
Tero Ahola
|
r1211 | { | ||
} | ||||
sauimone
|
r1594 | void DeclarativeBarSeries::classBegin() | ||
Tero Ahola
|
r1211 | { | ||
} | ||||
sauimone
|
r1594 | void DeclarativeBarSeries::componentComplete() | ||
Tero Ahola
|
r1211 | { | ||
foreach(QObject *child, children()) { | ||||
Tero Ahola
|
r1302 | if (qobject_cast<DeclarativeBarSet *>(child)) { | ||
sauimone
|
r1584 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | ||
Tero Ahola
|
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); | ||||
Tero Ahola
|
r1211 | } | ||
} | ||||
} | ||||
sauimone
|
r1594 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | ||
Tero Ahola
|
r1313 | { | ||
Michal Klocek
|
r1604 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||
Tero Ahola
|
r1313 | } | ||
sauimone
|
r1594 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | ||
Tero Ahola
|
r1211 | { | ||
Tero Ahola
|
r1313 | // Empty implementation; the children are parsed in componentComplete instead | ||
Q_UNUSED(list); | ||||
Q_UNUSED(element); | ||||
Tero Ahola
|
r1211 | } | ||
sauimone
|
r1594 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) | ||
Tero Ahola
|
r1302 | { | ||
QList<QBarSet*> setList = barSets(); | ||||
Tero Ahola
|
r1511 | if (index >= 0 && index < setList.count()) | ||
Tero Ahola
|
r1302 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||
return 0; | ||||
} | ||||
sauimone
|
r1594 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) | ||
Tero Ahola
|
r1511 | { | ||
DeclarativeBarSet *barset = new DeclarativeBarSet(this); | ||||
barset->setLabel(label); | ||||
barset->setValues(values); | ||||
sauimone
|
r1594 | if (QBarSeries::insert(index, barset)) | ||
Tero Ahola
|
r1511 | return barset; | ||
delete barset; | ||||
return 0; | ||||
} | ||||
Tero Ahola
|
r1318 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : | ||
QStackedBarSeries(parent) | ||||
{ | ||||
} | ||||
void DeclarativeStackedBarSeries::classBegin() | ||||
{ | ||||
} | ||||
void DeclarativeStackedBarSeries::componentComplete() | ||||
{ | ||||
foreach(QObject *child, children()) { | ||||
if (qobject_cast<DeclarativeBarSet *>(child)) { | ||||
sauimone
|
r1584 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | ||
Tero Ahola
|
r1318 | } 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); | ||||
} | ||||
} | ||||
} | ||||
Tero Ahola
|
r1550 | |||
Tero Ahola
|
r1318 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() | ||
{ | ||||
Michal Klocek
|
r1604 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||
Tero Ahola
|
r1318 | } | ||
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(); | ||||
Tero Ahola
|
r1511 | if (index >= 0 && index < setList.count()) | ||
Tero Ahola
|
r1318 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||
return 0; | ||||
} | ||||
Tero Ahola
|
r1511 | 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; | ||||
} | ||||
Tero Ahola
|
r1318 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : | ||
QPercentBarSeries(parent) | ||||
{ | ||||
} | ||||
void DeclarativePercentBarSeries::classBegin() | ||||
{ | ||||
} | ||||
void DeclarativePercentBarSeries::componentComplete() | ||||
{ | ||||
foreach(QObject *child, children()) { | ||||
if (qobject_cast<DeclarativeBarSet *>(child)) { | ||||
sauimone
|
r1584 | QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); | ||
Tero Ahola
|
r1318 | } 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() | ||||
{ | ||||
Michal Klocek
|
r1604 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | ||
Tero Ahola
|
r1318 | } | ||
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(); | ||||
Tero Ahola
|
r1511 | if (index >= 0 && index < setList.count()) | ||
Tero Ahola
|
r1318 | return qobject_cast<DeclarativeBarSet *>(setList[index]); | ||
return 0; | ||||
} | ||||
Tero Ahola
|
r1511 | 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; | ||||
} | ||||
sauimone
|
r1592 | #include "moc_declarativebarseries.cpp" | ||
Tero Ahola
|
r646 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||