From 50493b5d7ed91619d27c327e128ed60921f290d7 2012-04-03 12:43:41 From: Tero Ahola Date: 2012-04-03 12:43:41 Subject: [PATCH] Added area series to QML api --- diff --git a/qmlplugin/declarativeareaseries.cpp b/qmlplugin/declarativeareaseries.cpp new file mode 100644 index 0000000..2144b48 --- /dev/null +++ b/qmlplugin/declarativeareaseries.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "declarativeareaseries.h" +#include "declarativechart.h" +#include "qchart.h" +#include "qlineseries.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : + QAreaSeries(new QLineSeries(parent), new QLineSeries(parent)) +{ +} + +QSeries *DeclarativeAreaSeries::series() +{ + return this; +} + +QDeclarativeListProperty DeclarativeAreaSeries::points() +{ + return QDeclarativeListProperty(this, 0, &DeclarativeAreaSeries::appendPoints); +} + +QDeclarativeListProperty DeclarativeAreaSeries::lowerPoints() +{ + return QDeclarativeListProperty(this, 0, &DeclarativeAreaSeries::appendLowerPoints); +} + +void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty *list, + DeclarativeXyPoint *element) +{ + QAreaSeries *series = qobject_cast(list->object); + if (series) { + QLineSeries *upper = series->upperSeries(); + upper->append(element->x(), element->y()); + } +} + +void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty *list, + DeclarativeXyPoint *element) +{ + QAreaSeries *series = qobject_cast(list->object); + if (series) { + QLineSeries *lower = series->lowerSeries(); + lower->append(element->x(), element->y()); + } +} + +#include "moc_declarativeareaseries.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/qmlplugin/declarativeareaseries.h b/qmlplugin/declarativeareaseries.h new file mode 100644 index 0000000..440a252 --- /dev/null +++ b/qmlplugin/declarativeareaseries.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef DECLARATIVEAREASERIES_H +#define DECLARATIVEAREASERIES_H + +#include "qchartglobal.h" +#include "qareaseries.h" +#include "declarativexyseries.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty points READ points) + Q_PROPERTY(QDeclarativeListProperty lowerPoints READ lowerPoints) + +public: + explicit DeclarativeAreaSeries(QObject *parent = 0); + +public: + QSeries *series(); + QDeclarativeListProperty points(); + QDeclarativeListProperty lowerPoints(); + +public Q_SLOTS: + static void appendPoints(QDeclarativeListProperty *list, + DeclarativeXyPoint *element); + static void appendLowerPoints(QDeclarativeListProperty *list, + DeclarativeXyPoint *element); +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // DECLARATIVEAREASERIES_H diff --git a/qmlplugin/declarativechart.cpp b/qmlplugin/declarativechart.cpp index eb6f2ff..f0da8c9 100644 --- a/qmlplugin/declarativechart.cpp +++ b/qmlplugin/declarativechart.cpp @@ -27,7 +27,7 @@ DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) : QDeclarativeItem(parent), m_chart(new QChart(this)) { - m_chart->setAnimationOptions(QChart::SeriesAnimations); +// m_chart->setAnimationOptions(QChart::SeriesAnimations); setFlag(QGraphicsItem::ItemHasNoContents, false); } diff --git a/qmlplugin/declarativexyseries.cpp b/qmlplugin/declarativexyseries.cpp index 42b7369..55c16b2 100644 --- a/qmlplugin/declarativexyseries.cpp +++ b/qmlplugin/declarativexyseries.cpp @@ -22,7 +22,6 @@ #include "declarativexyseries.h" #include "qxyseries.h" #include "declarativechart.h" -#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -41,8 +40,6 @@ void DeclarativeXySeries::classBegin() void DeclarativeXySeries::componentComplete() { QSeries *thisObj = reinterpret_cast(series()); -// QSeries *thisObj = qobject_cast(this); -// Q_ASSERT(thisObj); DeclarativeChart *declarativeChart = qobject_cast(thisObj->parent()); if (declarativeChart) { diff --git a/qmlplugin/plugin.cpp b/qmlplugin/plugin.cpp index 0ab5c72..b5cc853 100644 --- a/qmlplugin/plugin.cpp +++ b/qmlplugin/plugin.cpp @@ -25,6 +25,7 @@ #include "declarativexypoint.h" #include "declarativelineseries.h" #include "declarativesplineseries.h" +#include "declarativeareaseries.h" #include "declarativescatterseries.h" #include "declarativebarseries.h" #include "declarativepieseries.h" @@ -44,6 +45,7 @@ public: 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, "PieSeries"); qmlRegisterType(uri, 1, 0, "PieSlice"); diff --git a/qmlplugin/qmlplugin.pro b/qmlplugin/qmlplugin.pro index 51f4927..938f8a1 100644 --- a/qmlplugin/qmlplugin.pro +++ b/qmlplugin/qmlplugin.pro @@ -28,6 +28,7 @@ SOURCES += \ declarativexypoint.cpp \ declarativelineseries.cpp \ declarativesplineseries.cpp \ + declarativeareaseries.cpp \ declarativescatterseries.cpp \ declarativepieseries.cpp \ declarativebarseries.cpp @@ -37,6 +38,7 @@ HEADERS += \ declarativexypoint.h \ declarativelineseries.h \ declarativesplineseries.h \ + declarativeareaseries.h \ declarativescatterseries.h \ declarativepieseries.h \ declarativebarseries.h diff --git a/src/linechart/linechartitem.cpp b/src/linechart/linechartitem.cpp index 1f669f5..a059329 100644 --- a/src/linechart/linechartitem.cpp +++ b/src/linechart/linechartitem.cpp @@ -49,8 +49,6 @@ QPainterPath LineChartItem::shape() const void LineChartItem::setLayout(QVector& points) { -// qDebug() << "line: " << points.count(); - if(points.size()==0) { XYChartItem::setLayout(points); @@ -70,6 +68,7 @@ void LineChartItem::setLayout(QVector& points) m_rect = linePath.boundingRect(); XYChartItem::setLayout(points); + } void LineChartItem::handleUpdated() diff --git a/src/scatterseries/scatterchartitem.cpp b/src/scatterseries/scatterchartitem.cpp index e5cc99c..7351f80 100644 --- a/src/scatterseries/scatterchartitem.cpp +++ b/src/scatterseries/scatterchartitem.cpp @@ -102,7 +102,6 @@ void ScatterChartItem::markerSelected(Marker *marker) void ScatterChartItem::setLayout(QVector& points) { -// qDebug() << "scatter: " << points.count(); if(points.size()==0) { XYChartItem::setLayout(points); @@ -121,10 +120,8 @@ void ScatterChartItem::setLayout(QVector& points) if(diff!=0) handleUpdated(); QList items = m_items.childItems(); -// qDebug() << "items count" << items.count(); - for (int i = 0; i < points.size() && i < items.count(); i++) { - Q_ASSERT(i < items.count()); + for (int i = 0; i < points.size(); i++) { Marker* item = static_cast(items.at(i)); const QPointF& point = points.at(i); const QRectF& rect = item->boundingRect(); diff --git a/test/qmlchart/qml/qmlchart/main.qml b/test/qmlchart/qml/qmlchart/main.qml index 42426ea..c475fa2 100644 --- a/test/qmlchart/qml/qmlchart/main.qml +++ b/test/qmlchart/qml/qmlchart/main.qml @@ -54,7 +54,7 @@ Rectangle { anchors.left: parent.left anchors.right: parent.right height: parent.height / 2 - theme: Chart.ChartThemeBlueCerulean + theme: Chart.ChartThemeDark BarSeries { barCategories: [ "2008", "2009", "2010", "2011", "2012" ] @@ -79,7 +79,7 @@ Rectangle { anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right - theme: Chart.ChartThemeHighContrast + theme: Chart.ChartThemeBrownSand LineSeries { points: [ @@ -90,13 +90,26 @@ Rectangle { ] } -// SplineSeries { -// points: [ -// XyPoint { x: 0.0; y: 0.3 }, -// XyPoint { x: 1.1; y: 3.2 }, -// XyPoint { x: 4.17; y: 3.15 } -// ] -// } + SplineSeries { + points: [ + XyPoint { x: 0.0; y: 0.3 }, + XyPoint { x: 1.1; y: 3.2 }, + XyPoint { x: 4.17; y: 3.15 } + ] + } + + AreaSeries { + points: [ + XyPoint { x: 0.0; y: 1.1 }, + XyPoint { x: 2.5; y: 3.6 }, + XyPoint { x: 3.57; y: 2.55 } + ] + lowerPoints: [ + XyPoint { x: 0.0; y: 0.0 }, + XyPoint { x: 2.5; y: 0.0 }, + XyPoint { x: 3.57; y: 0.0 } + ] + } ScatterSeries { points: [ @@ -105,19 +118,19 @@ Rectangle { XyPoint { x: 1.57; y: 1.55 } ] } -// ScatterSeries { -// points: [ -// XyPoint { x: 2.0; y: 2.0 }, -// XyPoint { x: 2.0; y: 2.1 }, -// XyPoint { x: 2.07; y: 2.05 } -// ] -// } -// ScatterSeries { -// points: [ -// XyPoint { x: 2.6; y: 2.6 }, -// XyPoint { x: 2.6; y: 2.7 }, -// XyPoint { x: 2.67; y: 2.65 } -// ] -// } + ScatterSeries { + points: [ + XyPoint { x: 2.0; y: 2.0 }, + XyPoint { x: 2.0; y: 2.1 }, + XyPoint { x: 2.07; y: 2.05 } + ] + } + ScatterSeries { + points: [ + XyPoint { x: 2.6; y: 2.6 }, + XyPoint { x: 2.6; y: 2.7 }, + XyPoint { x: 2.67; y: 2.65 } + ] + } } }