diff --git a/demos/qmlchart/qml/qmlchart/View2.qml b/demos/qmlchart/qml/qmlchart/View2.qml index 057027a..22a0056 100644 --- a/demos/qmlchart/qml/qmlchart/View2.qml +++ b/demos/qmlchart/qml/qmlchart/View2.qml @@ -39,6 +39,10 @@ Rectangle { XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } } + + Component.onCompleted: { + createDefaultAxes(); + } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index 4ef40b5..68590f0 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -39,6 +39,10 @@ Rectangle { XYPoint { x: 3.4; y: 2.3 } XYPoint { x: 4.1; y: 3.1 } } + + Component.onCompleted: { + createDefaultAxes(); + } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View4.qml b/demos/qmlchart/qml/qmlchart/View4.qml index 8b2dc85..e34c899 100644 --- a/demos/qmlchart/qml/qmlchart/View4.qml +++ b/demos/qmlchart/qml/qmlchart/View4.qml @@ -30,11 +30,12 @@ Rectangle { anchors.fill: parent AreaSeries { - axisX: CategoriesAxis { - id: categoriesAxis - categories: ["2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", - "2008", "2009", "2010", "2011" ] - } + //TODO: obsolate + //axisX: CategoriesAxis { + // id: categoriesAxis + // categories: ["2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", + // "2008", "2009", "2010", "2011" ] + //} name: "Russian" upperSeries: LineSeries { @@ -141,5 +142,8 @@ Rectangle { borderColor = "blue"; } } + Component.onCompleted: { + createDefaultAxes(); + } } } diff --git a/demos/qmlchart/qml/qmlchart/View5.qml b/demos/qmlchart/qml/qmlchart/View5.qml index c496910..ee438f8 100644 --- a/demos/qmlchart/qml/qmlchart/View5.qml +++ b/demos/qmlchart/qml/qmlchart/View5.qml @@ -53,6 +53,11 @@ Rectangle { XYPoint { x: 2.67; y: 2.65 } //![2] } + + Component.onCompleted: { + createDefaultAxes(); + } + } //![2] } diff --git a/demos/qmlchart/qml/qmlchart/View6.qml b/demos/qmlchart/qml/qmlchart/View6.qml index 2bbec15..77c64f5 100644 --- a/demos/qmlchart/qml/qmlchart/View6.qml +++ b/demos/qmlchart/qml/qmlchart/View6.qml @@ -29,13 +29,20 @@ Rectangle { title: "Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - + CategoriesAxis { + id:myAxis + categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] + } BarSeries { - axisX: CategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + id: mySeries BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } + Component.onCompleted: { + createDefaultAxes(); + setAxisX(myAxis,mySeries); + } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View7.qml b/demos/qmlchart/qml/qmlchart/View7.qml index a0ab5bf..90a65c2 100644 --- a/demos/qmlchart/qml/qmlchart/View7.qml +++ b/demos/qmlchart/qml/qmlchart/View7.qml @@ -26,16 +26,23 @@ Rectangle { //![1] ChartView { - title: "Grouped Bar series" + title: "Stacked Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - - GroupedBarSeries { - axisX: CategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + CategoriesAxis { + id: myAxis; + categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] + } + StackedBarSeries { + id: mySeries; BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } + Component.onCompleted: { + createDefaultAxes(); + setAxisX(myAxis,mySeries); + } } //![1] } diff --git a/demos/qmlchart/qml/qmlchart/View8.qml b/demos/qmlchart/qml/qmlchart/View8.qml index 00b86ae..da97012 100644 --- a/demos/qmlchart/qml/qmlchart/View8.qml +++ b/demos/qmlchart/qml/qmlchart/View8.qml @@ -26,16 +26,24 @@ Rectangle { //![1] ChartView { - title: "Stacked Bar series" + title: "Percent Bar series" anchors.fill: parent legend.alignment: Qt.AlignBottom - - StackedBarSeries { - axisX: CategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + CategoriesAxis { + id: myAxis + categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] + } + PercentBarSeries { + id: mySeries BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } } + Component.onCompleted: { + createDefaultAxes(); + setAxisX(myAxis,mySeries); + } } //![1] } + diff --git a/demos/qmlchart/qml/qmlchart/View9.qml b/demos/qmlchart/qml/qmlchart/View9.qml deleted file mode 100644 index e5a57d8..0000000 --- a/demos/qmlchart/qml/qmlchart/View9.qml +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -import QtQuick 1.0 -import QtCommercial.Chart 1.0 - -Rectangle { - anchors.fill: parent - - //![1] - ChartView { - title: "Percent Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - - PercentBarSeries { - axisX: CategoriesAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} diff --git a/demos/qmlchart/qml/qmlchart/main.qml b/demos/qmlchart/qml/qmlchart/main.qml index e530786..4017db2 100644 --- a/demos/qmlchart/qml/qmlchart/main.qml +++ b/demos/qmlchart/qml/qmlchart/main.qml @@ -74,7 +74,7 @@ Rectangle { function nextView() { var i = viewNumber + 1; - if (i > 9) + if (i > 8) viewNumber = 1; else viewNumber = i; @@ -83,7 +83,7 @@ Rectangle { function previousView() { var i = viewNumber - 1; if (i <= 0) - viewNumber = 9; + viewNumber = 8; else viewNumber = i; } diff --git a/demos/qmlchart/resources.qrc b/demos/qmlchart/resources.qrc index c9f45da..bf03f1b 100644 --- a/demos/qmlchart/resources.qrc +++ b/demos/qmlchart/resources.qrc @@ -10,6 +10,5 @@ qml/qmlchart/View6.qml qml/qmlchart/View7.qml qml/qmlchart/View8.qml - qml/qmlchart/View9.qml diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index fbcadd3..a3a65c6 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -60,106 +60,6 @@ void DeclarativeBarSet::setValues(QVariantList values) } } -DeclarativeAbstractBarSeries::DeclarativeAbstractBarSeries(QDeclarativeItem *parent) : - QAbstractBarSeries(parent) -{ - connect(this, SIGNAL(barsetsAdded(QList)), this, SLOT(handleAdded(QList))); - connect(this, SIGNAL(barsetsRemoved(QList)), this, SLOT(handleRemoved(QList))); -} - -void DeclarativeAbstractBarSeries::handleAdded(QList barsets) -{ - foreach(QBarSet *b, barsets) { - DeclarativeBarSet *barset = qobject_cast(b); - emit added(barset); - } -} - -void DeclarativeAbstractBarSeries::handleRemoved(QList barsets) -{ - foreach(QBarSet *b, barsets) { - DeclarativeBarSet *barset = qobject_cast(b); - emit removed(barset); - } -} - -void DeclarativeAbstractBarSeries::classBegin() -{ -} - -void DeclarativeAbstractBarSeries::componentComplete() -{ - foreach(QObject *child, children()) { - if (qobject_cast(child)) { - QAbstractBarSeries::append(qobject_cast(child)); - } else if (qobject_cast(child)) { - QVBarModelMapper *mapper = qobject_cast(child); - mapper->setSeries(this); - } else if (qobject_cast(child)) { - QHBarModelMapper *mapper = qobject_cast(child); - mapper->setSeries(this); - } - } -} - -void DeclarativeAbstractBarSeries::setAxisX(QAbstractAxis *axis) -{ - chart()->setAxisX(axis, this); -} - -QAbstractAxis *DeclarativeAbstractBarSeries::axisX() -{ - return chart()->axisX(this); -} - -void DeclarativeAbstractBarSeries::setAxisY(QAbstractAxis *axis) -{ - chart()->setAxisY(axis, this); -} - -QAbstractAxis *DeclarativeAbstractBarSeries::axisY() -{ - return chart()->axisY(this); -} - -QDeclarativeListProperty DeclarativeAbstractBarSeries::seriesChildren() -{ - return QDeclarativeListProperty(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); -} - -void DeclarativeAbstractBarSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) -{ - // Empty implementation; the children are parsed in componentComplete instead - Q_UNUSED(list); - Q_UNUSED(element); -} - -DeclarativeBarSet *DeclarativeAbstractBarSeries::at(int index) -{ - QList setList = barSets(); - if (index >= 0 && index < setList.count()) - return qobject_cast(setList[index]); - - return 0; -} - -DeclarativeBarSet *DeclarativeAbstractBarSeries::insert(int index, QString label, QVariantList values) -{ - int insertIndex = index; - if (insertIndex < 0) - insertIndex = 0; - else if (insertIndex > count()) - insertIndex = count(); - - DeclarativeBarSet *barset = new DeclarativeBarSet(this); - barset->setLabel(label); - barset->setValues(values); - if (QAbstractBarSeries::insert(insertIndex, barset)) - return barset; - delete barset; - return 0; -} - DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : QBarSeries(parent) { @@ -184,29 +84,9 @@ void DeclarativeBarSeries::componentComplete() } } -void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis) -{ - chart()->setAxisX(axis, this); -} - -QAbstractAxis *DeclarativeBarSeries::axisX() -{ - return chart()->axisX(this); -} - -void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis) -{ - chart()->setAxisY(axis, this); -} - -QAbstractAxis *DeclarativeBarSeries::axisY() -{ - return chart()->axisY(this); -} - QDeclarativeListProperty DeclarativeBarSeries::seriesChildren() { - return QDeclarativeListProperty(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); + return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendSeriesChildren); } void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) @@ -260,29 +140,10 @@ void DeclarativeStackedBarSeries::componentComplete() } } -void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis) -{ - chart()->setAxisX(axis, this); -} - -QAbstractAxis *DeclarativeStackedBarSeries::axisX() -{ - return chart()->axisX(this); -} - -void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis) -{ - chart()->setAxisY(axis, this); -} - -QAbstractAxis *DeclarativeStackedBarSeries::axisY() -{ - return chart()->axisY(this); -} QDeclarativeListProperty DeclarativeStackedBarSeries::seriesChildren() { - return QDeclarativeListProperty(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); + return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendSeriesChildren); } void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) @@ -336,29 +197,9 @@ void DeclarativePercentBarSeries::componentComplete() } } -void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis) -{ - chart()->setAxisX(axis, this); -} - -QAbstractAxis *DeclarativePercentBarSeries::axisX() -{ - return chart()->axisX(this); -} - -void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis) -{ - chart()->setAxisY(axis, this); -} - -QAbstractAxis *DeclarativePercentBarSeries::axisY() -{ - return chart()->axisY(this); -} - QDeclarativeListProperty DeclarativePercentBarSeries::seriesChildren() { - return QDeclarativeListProperty(this, 0, &DeclarativeAbstractBarSeries::appendSeriesChildren); + return QDeclarativeListProperty(this, 0, &DeclarativeBarSeries::appendSeriesChildren); } void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty * list, QObject *element) diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index f16e60d..b4caf14 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -59,48 +59,10 @@ private Q_SLOTS: void handleCountChanged(int index, int count); }; -class DeclarativeAbstractBarSeries : public QAbstractBarSeries, public QDeclarativeParserStatus -{ - Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) - Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) - Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) - Q_CLASSINFO("DefaultProperty", "seriesChildren") - -public: - explicit DeclarativeAbstractBarSeries(QDeclarativeItem *parent = 0); - void setAxisX(QAbstractAxis *axis); - QAbstractAxis *axisX(); - void setAxisY(QAbstractAxis *axis); - QAbstractAxis *axisY(); - QDeclarativeListProperty seriesChildren(); - Q_INVOKABLE DeclarativeBarSet *at(int index); - Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } - Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); - Q_INVOKABLE bool remove(QBarSet *barset) { return QAbstractBarSeries::remove(barset); } - Q_INVOKABLE void clear() { return QAbstractBarSeries::clear(); } - -public: // from QDeclarativeParserStatus - void classBegin(); - void componentComplete(); - -Q_SIGNALS: - void added(DeclarativeBarSet *barset); - void removed(DeclarativeBarSet *barset); - -public Q_SLOTS: - static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); - void handleAdded(QList barsets); - void handleRemoved(QList barsets); -}; - class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) - Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") @@ -123,23 +85,21 @@ public: // from QDeclarativeParserStatus public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + +private: + QAbstractAxis* m_axisX; + QAbstractAxis* m_axisY; }; class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) - Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); - void setAxisX(QAbstractAxis *axis); - QAbstractAxis *axisX(); - void setAxisY(QAbstractAxis *axis); - QAbstractAxis *axisY(); QDeclarativeListProperty seriesChildren(); Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } @@ -153,23 +113,18 @@ public: // from QDeclarativeParserStatus public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); + }; class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) - Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX) - Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); - void setAxisX(QAbstractAxis *axis); - QAbstractAxis *axisX(); - void setAxisY(QAbstractAxis *axis); - QAbstractAxis *axisY(); QDeclarativeListProperty seriesChildren(); Q_INVOKABLE DeclarativeBarSet *at(int index); Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index f5f7290..454ecca 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -250,19 +250,15 @@ void DeclarativeChart::childEvent(QChildEvent *event) void DeclarativeChart::componentComplete() { - bool createAxis = true; foreach(QObject *child, children()) { if (qobject_cast(child)) { // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; // TODO: how about optional y-axis? m_chart->addSeries(qobject_cast(child)); }else if(qobject_cast(child)){ - createAxis = false; + } } - - if(createAxis) m_chart->createDefaultAxes(); - QDeclarativeItem::componentComplete(); } @@ -499,6 +495,21 @@ QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ return series; } +void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series) +{ + m_chart->setAxisX(axis,series); +} + +void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series) +{ + m_chart->setAxisY(axis,series); +} + +void DeclarativeChart::createDefaultAxes() +{ + m_chart->createDefaultAxes(); +} + #include "moc_declarativechart.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index b077da3..7ae0a1a 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -114,12 +114,17 @@ public: qreal leftMargin(); qreal rightMargin(); + QAbstractAxis *axisX(QAbstractSeries *series = 0); + QAbstractAxis *axisY(QAbstractSeries *series = 0); + public: Q_INVOKABLE QAbstractSeries *series(int index); Q_INVOKABLE QAbstractSeries *series(QString seriesName); Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); - Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); - Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); + Q_INVOKABLE void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); + Q_INVOKABLE void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); + Q_INVOKABLE void createDefaultAxes(); + Q_INVOKABLE void zoom(qreal factor); Q_INVOKABLE void scrollLeft(qreal pixels); Q_INVOKABLE void scrollRight(qreal pixels); diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index b7a5b7f..0b486b8 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -74,12 +74,6 @@ public: QLatin1String("Trying to create uncreatable: Legend.")); qmlRegisterUncreatableType(uri, 1, 0, "XYSeries", QLatin1String("Trying to create uncreatable: XYSeries.")); - qmlRegisterUncreatableType(uri, 1, 0, "QScatterSeries", - QLatin1String("Trying to create uncreatable: QScatterSeries.")); - qmlRegisterUncreatableType(uri, 1, 0, "QPieSeries", - QLatin1String("Trying to create uncreatable: QPieSeries.")); - qmlRegisterUncreatableType(uri, 1, 0, "QBarSet", - QLatin1String("Trying to create uncreatable: QBarSet.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractItemModel", QLatin1String("Trying to create uncreatable: AbstractItemModel.")); qmlRegisterUncreatableType(uri, 1, 0, "XYModelMapper", @@ -90,6 +84,8 @@ public: QLatin1String("Trying to create uncreatable: BarModelMapper.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractSeries", QLatin1String("Trying to create uncreatable: AbstractSeries.")); + qmlRegisterUncreatableType(uri, 1, 0, "AbstractBarSeries", + QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); qmlRegisterUncreatableType(uri, 1, 0, "AbstractAxis", QLatin1String("Trying to create uncreatable: AbstractAxis.")); qmlRegisterUncreatableType(uri, 1, 0, "PieModelMapper",