diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index a223a73..2065b4a 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -96,7 +96,7 @@ Rectangle { } AreaSeries { - name: "Swedish" + name: "Finnish" upperSeries: LineSeries { XyPoint { x: 0; y: 0 } XyPoint { x: 1; y: 0 } diff --git a/demos/qmlchart/qml/qmlchart/View5.qml b/demos/qmlchart/qml/qmlchart/View5.qml index 24cc799..5b7ba4d 100644 --- a/demos/qmlchart/qml/qmlchart/View5.qml +++ b/demos/qmlchart/qml/qmlchart/View5.qml @@ -30,10 +30,10 @@ Rectangle { theme: ChartView.ChartThemeLight legend: ChartView.LegendBottom // TODO: labels defined by x-axis, not by bar series -// axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] + axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] axisX.max: 10 - BarSeries { + GroupedBarSeries { barCategories: [ "2008", "2009", "2010", "2011", "2012" ] BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] } diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index d9f29d6..e8e9421 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -90,12 +90,54 @@ DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() return qobject_cast(model()); } -void DeclarativeBarSeries::setBarCategories(QStringList categories) +DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : + QGroupedBarSeries(parent) +{ +} + +void DeclarativeGroupedBarSeries::classBegin() +{ +} + +void DeclarativeGroupedBarSeries::componentComplete() +{ + foreach(QObject *child, children()) { + if (qobject_cast(child)) { + QBarSeries::append(qobject_cast(child)); + } + } +} + +QDeclarativeListProperty DeclarativeGroupedBarSeries::initialBarSets() +{ + return QDeclarativeListProperty(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets); +} + +bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *model) +{ + QAbstractItemModel *m = qobject_cast(model); + bool value(false); + if (m) { + setModel(m); + //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); +// setModelMapping(0, 1, 1, Qt::Vertical); + } else { + qWarning("DeclarativeGroupedBarSeries: Illegal model"); + } + return value; +} + +DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel() +{ + return qobject_cast(model()); +} + +void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories) { setCategories(categories); } -QStringList DeclarativeBarSeries::barCategories() +QStringList DeclarativeGroupedBarSeries::barCategories() { return categories(); } diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 5500f51..67f1f6c 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -48,7 +48,6 @@ class DeclarativeBarSeries : public QGroupedBarSeries, public QDeclarativeParser Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) - Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) Q_PROPERTY(QDeclarativeListProperty initialBarSets READ initialBarSets) Q_CLASSINFO("DefaultProperty", "initialBarSets") @@ -63,8 +62,33 @@ public: // from QDeclarativeParserStatus public: bool setDeclarativeModel(DeclarativeTableModel *model); DeclarativeTableModel *declarativeModel(); + +public Q_SLOTS: + static void appendInitialBarSets(QDeclarativeListProperty */*list*/, DeclarativeBarSet */*element*/) {} +}; + +class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_INTERFACES(QDeclarativeParserStatus) + Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel) + Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) + Q_PROPERTY(QDeclarativeListProperty initialBarSets READ initialBarSets) + Q_CLASSINFO("DefaultProperty", "initialBarSets") + +public: + explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); + QDeclarativeListProperty initialBarSets(); + +public: // from QDeclarativeParserStatus + void classBegin(); + void componentComplete(); + +public: void setBarCategories(QStringList categories); QStringList barCategories(); + bool setDeclarativeModel(DeclarativeTableModel *model); + DeclarativeTableModel *declarativeModel(); public Q_SLOTS: static void appendInitialBarSets(QDeclarativeListProperty */*list*/, DeclarativeBarSet */*element*/) {} diff --git a/plugins/declarative/declarativelineseries.cpp b/plugins/declarative/declarativelineseries.cpp index 82a2378..de9b0ad 100644 --- a/plugins/declarative/declarativelineseries.cpp +++ b/plugins/declarative/declarativelineseries.cpp @@ -39,10 +39,8 @@ void DeclarativeLineSeries::appendDeclarativeChildren(QDeclarativeListProperty(list->object); DeclarativeXyPoint *point = qobject_cast(element); - if (series && point) { - qDebug() << "DeclarativeScatterSeries::appendDeclarativeChildren:" << *point; + if (series && point) series->append(*point); - } } #include "moc_declarativelineseries.cpp" diff --git a/plugins/declarative/declarativesplineseries.cpp b/plugins/declarative/declarativesplineseries.cpp index dfa05b6..866f6dd 100644 --- a/plugins/declarative/declarativesplineseries.cpp +++ b/plugins/declarative/declarativesplineseries.cpp @@ -38,11 +38,10 @@ void DeclarativeSplineSeries::appendDeclarativeChildren(QDeclarativeListProperty { QXYSeries *series = qobject_cast(list->object); DeclarativeXyPoint *point = qobject_cast(element); - if (series && point) { - qDebug() << "DeclarativeScatterSeries::appendDeclarativeChildren:" << *point; + if (series && point) series->append(*point); - } } + #include "moc_declarativesplineseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 29e5d29..7a3c9e4 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -47,23 +47,21 @@ public: qmlRegisterType(uri, 1, 0, "ChartView"); qmlRegisterUncreatableType(uri, 1, 0, "Axis", QLatin1String("Trying to create uncreatable: Axis.")); - //qmlRegisterType(uri, 1, 0, "AxisCategory"); qmlRegisterType(uri, 1, 0, "XyPoint"); qmlRegisterType(uri, 1, 0, "ScatterSeries"); qmlRegisterType(uri, 1, 0, "LineSeries"); qmlRegisterType(uri, 1, 0, "SplineSeries"); qmlRegisterType(uri, 1, 0, "AreaSeries"); qmlRegisterType(uri, 1, 0, "BarSeries"); + qmlRegisterType(uri, 1, 0, "GroupedBarSeries"); qmlRegisterType(uri, 1, 0, "PieSeries"); qmlRegisterType(uri, 1, 0, "PieSlice"); qmlRegisterType(uri, 1, 0, "ChartModel"); qmlRegisterType(uri, 1, 0, "ChartModelElement"); - //qmlRegisterType(uri, 1, 0, "PieMapping"); - //qmlRegisterType(uri, 1, 0, "PieModelMapper"); qmlRegisterUncreatableType(uri, 1, 0, "PieModelMapper", QLatin1String("Trying to create uncreatable: PieModelMapper.")); qmlRegisterUncreatableType(uri, 1, 0, "XYModelMapper", - QLatin1String("Trying to create uncreatable: PieModelMapper.")); + QLatin1String("Trying to create uncreatable: XYModelMapper.")); qmlRegisterType(uri, 1, 0, "BarSet"); } }; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index daf50a4..5a13e4b 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -353,9 +353,6 @@ QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) { Q_ASSERT(pos >= 0 && pos <= 1.0); - // another possibility: - // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient - QGradientStops stops = gradient.stops(); int count = stops.count();