declarativebarseries.cpp
106 lines
| 2.8 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" | ||
#include "declarativechart.h" | ||||
Tero Ahola
|
r1162 | #include <QBarSet> | ||
Tero Ahola
|
r646 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Tero Ahola
|
r1162 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | ||
QBarSet("", parent) | ||||
Tero Ahola
|
r646 | { | ||
} | ||||
Tero Ahola
|
r1162 | QVariantList DeclarativeBarSet::values() | ||
Tero Ahola
|
r646 | { | ||
Tero Ahola
|
r1162 | QVariantList values; | ||
for (int i(0); i < count(); i++) | ||||
values.append(QVariant(at(i))); | ||||
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)) | ||||
append(values[i].toDouble()); | ||||
Tero Ahola
|
r1004 | } | ||
Tero Ahola
|
r1162 | } | ||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1162 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | ||
Tero Ahola
|
r1193 | QGroupedBarSeries(parent) | ||
Tero Ahola
|
r1162 | { | ||
} | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1162 | void DeclarativeBarSeries::classBegin() | ||
{ | ||||
} | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1162 | void DeclarativeBarSeries::componentComplete() | ||
{ | ||||
Tero Ahola
|
r1193 | foreach(QObject *child, children()) { | ||
if (qobject_cast<QBarSet *>(child)) { | ||||
qDebug() << "append bar set:" << child; | ||||
Marek Rosa
|
r1196 | QBarSeries::append(qobject_cast<QBarSet *>(child)); | ||
Tero Ahola
|
r1193 | } | ||
} | ||||
} | ||||
QDeclarativeListProperty<DeclarativeBarSet> DeclarativeBarSeries::initialBarSets() | ||||
{ | ||||
return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeBarSeries::appendInitialBarSets); | ||||
Tero Ahola
|
r1162 | } | ||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1193 | bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model) | ||
Tero Ahola
|
r1162 | { | ||
QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | ||||
bool value(false); | ||||
if (m) { | ||||
Marek Rosa
|
r1165 | setModel(m); | ||
Tero Ahola
|
r1162 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | ||
Marek Rosa
|
r1165 | // setModelMapping(0, 1, 1, Qt::Vertical); | ||
Tero Ahola
|
r1162 | } else { | ||
qWarning("DeclarativeBarSeries: Illegal model"); | ||||
} | ||||
return value; | ||||
} | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1193 | DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() | ||
Tero Ahola
|
r1162 | { | ||
Tero Ahola
|
r1193 | return qobject_cast<DeclarativeTableModel *>(model()); | ||
Tero Ahola
|
r1162 | } | ||
Tero Ahola
|
r1004 | |||
Tero Ahola
|
r1162 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | ||
{ | ||||
setCategories(categories); | ||||
Tero Ahola
|
r726 | } | ||
QStringList DeclarativeBarSeries::barCategories() | ||||
{ | ||||
Tero Ahola
|
r1162 | return categories(); | ||
Tero Ahola
|
r726 | } | ||
Tero Ahola
|
r646 | #include "moc_declarativebarseries.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||