From 6bd1dc9d15e0c9109240d54afda81698c132fbad 2012-11-27 08:18:38 From: Tero Ahola Date: 2012-11-27 08:18:38 Subject: [PATCH] Added axisXTop and axisYRight properties to QML series APIs --- diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index 1b3eeb6..7c7af05 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -37,14 +37,14 @@ Rectangle { categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] min: "2007" max: "2014" - title: "Year" + titleText: "Year" } ValueAxis { id: valueAxis min: 0 max: 60 - title: "Sales count [ku]" + titleText: "Sales count [ku]" } // ... //![1] diff --git a/demos/qmlweather/qml/qmlweather/main.qml b/demos/qmlweather/qml/qmlweather/main.qml index bb4e220..db7b5f8 100644 --- a/demos/qmlweather/qml/qmlweather/main.qml +++ b/demos/qmlweather/qml/qmlweather/main.qml @@ -19,7 +19,7 @@ ****************************************************************************/ import QtQuick 1.1 -import QtCommercial.Chart 1.1 +import QtCommercial.Chart 1.2 Rectangle { width: 360 @@ -43,21 +43,20 @@ Rectangle { //![2] BarCategoriesAxis { id: barCategoriesAxis - title: "Date" + titleText: "Date" } ValueAxis{ id: valueAxisY2 min: 0 max: 10 - title: "Rainfall [mm]" - alignment: Qt.AlignRight + titleText: "Rainfall [mm]" } BarSeries { id: myBarSeries axisX: barCategoriesAxis - axisY: valueAxisY2 + axisYRight: valueAxisY2 BarSet { id: rainfallSet label: "Rainfall" @@ -76,7 +75,7 @@ Rectangle { id: valueAxisY min: 0 max: 15 - title: "Temperature [\u00B0C]" + titleText: "Temperature [\u00B0C]" } LineSeries { diff --git a/plugins/declarative/declarative.pro b/plugins/declarative/declarative.pro index 68fd278..7641b2b 100644 --- a/plugins/declarative/declarative.pro +++ b/plugins/declarative/declarative.pro @@ -24,7 +24,8 @@ SOURCES += \ declarativepieseries.cpp \ declarativebarseries.cpp \ declarativecategoryaxis.cpp \ - declarativemargins.cpp + declarativemargins.cpp \ + declarativeaxes.cpp HEADERS += \ declarativechart.h \ @@ -37,7 +38,8 @@ HEADERS += \ declarativepieseries.h \ declarativebarseries.h \ declarativecategoryaxis.h \ - declarativemargins.h + declarativemargins.h \ + declarativeaxes.h TARGETPATH = QtCommercial/Chart target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH diff --git a/plugins/declarative/declarativeareaseries.cpp b/plugins/declarative/declarativeareaseries.cpp index 1ffdb61..d583191 100644 --- a/plugins/declarative/declarativeareaseries.cpp +++ b/plugins/declarative/declarativeareaseries.cpp @@ -25,9 +25,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : QAreaSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(new DeclarativeAxes(this)) { + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries *series) diff --git a/plugins/declarative/declarativeareaseries.h b/plugins/declarative/declarativeareaseries.h index 79fc755..f75ae04 100644 --- a/plugins/declarative/declarativeareaseries.h +++ b/plugins/declarative/declarativeareaseries.h @@ -22,6 +22,7 @@ #define DECLARATIVEAREASERIES_H #include "qareaseries.h" +#include "declarativeaxes.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeLineSeries; @@ -33,6 +34,8 @@ class DeclarativeAreaSeries : public QAreaSeries Q_PROPERTY(DeclarativeLineSeries *lowerSeries READ lowerSeries WRITE setLowerSeries) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1) public: @@ -41,10 +44,14 @@ public: DeclarativeLineSeries *upperSeries() const; void setLowerSeries(DeclarativeLineSeries *series); DeclarativeLineSeries *lowerSeries() const; - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } qreal borderWidth() const; void setBorderWidth(qreal borderWidth); @@ -52,10 +59,11 @@ Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); Q_REVISION(1) void borderWidthChanged(qreal width); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativeaxes.cpp b/plugins/declarative/declarativeaxes.cpp new file mode 100644 index 0000000..dd2b47a --- /dev/null +++ b/plugins/declarative/declarativeaxes.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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 "declarativeaxes.h" +#include "qabstractaxis.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +DeclarativeAxes::DeclarativeAxes(QObject *parent) : + QObject(parent), + m_axisX(0), + m_axisY(0), + m_axisXTop(0), + m_axisYRight(0) +{ +} + +void DeclarativeAxes::setAxisX(QAbstractAxis *axis) +{ + m_axisX = axis; + emit axisXChanged(axis); +} + +void DeclarativeAxes::setAxisY(QAbstractAxis *axis) +{ + m_axisY = axis; + emit axisYChanged(axis); +} + +void DeclarativeAxes::setAxisXTop(QAbstractAxis *axis) +{ + m_axisXTop = axis; + emit axisXTopChanged(axis); +} + +void DeclarativeAxes::setAxisYRight(QAbstractAxis *axis) +{ + m_axisYRight = axis; + emit axisYRightChanged(axis); +} + +#include "moc_declarativeaxes.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativeaxes.h b/plugins/declarative/declarativeaxes.h new file mode 100644 index 0000000..f3fc558 --- /dev/null +++ b/plugins/declarative/declarativeaxes.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 DECLARATIVEAXES_H +#define DECLARATIVEAXES_H + +#include "qchartglobal.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QAbstractAxis; + +class DeclarativeAxes : public QObject +{ + Q_OBJECT + Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) + Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged) + +public: + explicit DeclarativeAxes(QObject *parent = 0); + + QAbstractAxis *axisX() { return m_axisX; } + void setAxisX(QAbstractAxis *axis); + QAbstractAxis *axisY() { return m_axisY; } + void setAxisY(QAbstractAxis *axis); + QAbstractAxis *axisXTop() { return m_axisXTop; } + void setAxisXTop(QAbstractAxis *axis); + QAbstractAxis *axisYRight() { return m_axisYRight; } + void setAxisYRight(QAbstractAxis *axis); + +public: + void emitAxisXChanged() { emit axisXChanged(m_axisX); } + void emitAxisYChanged() { emit axisYChanged(m_axisY); } + void emitAxisXTopChanged() { emit axisXTopChanged(m_axisXTop); } + void emitAxisYRightChanged() { emit axisYRightChanged(m_axisYRight); } + +signals: + void axisXChanged(QAbstractAxis *axis); + void axisYChanged(QAbstractAxis *axis); + void axisXTopChanged(QAbstractAxis *axis); + void axisYRightChanged(QAbstractAxis *axis); + +private: + QAbstractAxis *m_axisX; + QAbstractAxis *m_axisY; + QAbstractAxis *m_axisXTop; + QAbstractAxis *m_axisYRight; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // DECLARATIVEAXES_H diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index e307279..ef4e67f 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -76,9 +76,12 @@ void DeclarativeBarSet::setValues(QVariantList values) // Declarative bar series ====================================================================================== DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : QBarSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(new DeclarativeAxes(this)) { + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativeBarSeries::classBegin() @@ -135,9 +138,13 @@ DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVaria // Declarative stacked bar series ============================================================================== DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : QStackedBarSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(0) { + m_axes = new DeclarativeAxes(this); + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativeStackedBarSeries::classBegin() @@ -195,9 +202,13 @@ DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, // Declarative percent bar series ============================================================================== DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : QPercentBarSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(0) { + m_axes = new DeclarativeAxes(this); + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativePercentBarSeries::classBegin() @@ -254,9 +265,13 @@ DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, // Declarative horizontal bar series =========================================================================== DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QDeclarativeItem *parent) : QHorizontalBarSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(0) { + m_axes = new DeclarativeAxes(this); + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativeHorizontalBarSeries::classBegin() @@ -313,9 +328,13 @@ DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString lab // Declarative horizontal stacked bar series =================================================================== DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QDeclarativeItem *parent) : QHorizontalStackedBarSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(0) { + m_axes = new DeclarativeAxes(this); + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativeHorizontalStackedBarSeries::classBegin() @@ -372,9 +391,13 @@ DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QStr // Declarative horizontal percent bar series =================================================================== DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QDeclarativeItem *parent) : QHorizontalPercentBarSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(0) { + m_axes = new DeclarativeAxes(this); + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); } void DeclarativeHorizontalPercentBarSeries::classBegin() diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 5274233..4fdac8e 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -28,6 +28,7 @@ #include "qhorizontalstackedbarseries.h" #include "qhorizontalpercentbarseries.h" #include "qbarset.h" +#include "declarativeaxes.h" #include #include @@ -69,15 +70,21 @@ class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDeclarativeListProperty seriesChildren(); public: @@ -94,13 +101,14 @@ public: // from QDeclarativeParserStatus Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus @@ -109,15 +117,21 @@ class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativ Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0); - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDeclarativeListProperty seriesChildren(); public: @@ -134,13 +148,14 @@ public: // from QDeclarativeParserStatus Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus @@ -149,15 +164,21 @@ class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativ Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0); - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDeclarativeListProperty seriesChildren(); public: @@ -174,13 +195,14 @@ public: // from QDeclarativeParserStatus Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; class DeclarativeHorizontalBarSeries : public QHorizontalBarSeries, public QDeclarativeParserStatus @@ -189,15 +211,21 @@ class DeclarativeHorizontalBarSeries : public QHorizontalBarSeries, public QDecl Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeHorizontalBarSeries(QDeclarativeItem *parent = 0); - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDeclarativeListProperty seriesChildren(); public: @@ -214,13 +242,14 @@ public: // from QDeclarativeParserStatus Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; class DeclarativeHorizontalStackedBarSeries : public QHorizontalStackedBarSeries, public QDeclarativeParserStatus @@ -229,15 +258,21 @@ class DeclarativeHorizontalStackedBarSeries : public QHorizontalStackedBarSeries Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeHorizontalStackedBarSeries(QDeclarativeItem *parent = 0); - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDeclarativeListProperty seriesChildren(); public: @@ -254,13 +289,14 @@ public: // from QDeclarativeParserStatus Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; class DeclarativeHorizontalPercentBarSeries : public QHorizontalPercentBarSeries, public QDeclarativeParserStatus @@ -269,15 +305,21 @@ class DeclarativeHorizontalPercentBarSeries : public QHorizontalPercentBarSeries Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: explicit DeclarativeHorizontalPercentBarSeries(QDeclarativeItem *parent = 0); - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDeclarativeListProperty seriesChildren(); public: @@ -294,13 +336,14 @@ public: // from QDeclarativeParserStatus Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendSeriesChildren(QDeclarativeListProperty *list, QObject *element); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativechart.cpp b/plugins/declarative/declarativechart.cpp index 93d8158..e463538 100644 --- a/plugins/declarative/declarativechart.cpp +++ b/plugins/declarative/declarativechart.cpp @@ -33,6 +33,7 @@ #include "qabstractseries_p.h" #include "declarativemargins.h" #include "chartdataset_p.h" +#include "declarativeaxes.h" #include "qchart_p.h" #ifndef QT_ON_ARM @@ -286,94 +287,71 @@ void DeclarativeChart::componentComplete() QAbstractSeries *series = qobject_cast(child); m_chart->addSeries(series); - // Set optional user defined axes for the series and connect axis related signals - if (qobject_cast(child)) { - DeclarativeLineSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeSplineSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeScatterSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeAreaSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeBarSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeStackedBarSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativePercentBarSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeHorizontalBarSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeHorizontalStackedBarSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); - } else if (qobject_cast(child)) { - DeclarativeHorizontalPercentBarSeries *s = qobject_cast(child); - connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); - connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); - setAxisX(s->axisX(), s); - setAxisY(s->axisY(), s); + // Connect to axis changed signals (unless this is a pie series) + if (!qobject_cast(series)) { + connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); + connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); + connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); + connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); } + + initializeAxes(series); } } - // Create the missing axes for the series that cannot be painted without axes - foreach (QAbstractSeries *chartSeries, m_chart->series()) - createDefaultAxes(chartSeries); - QDeclarativeItem::componentComplete(); } void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) { -// qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; - if (axis && qobject_cast(sender())) - m_chart->setAxisX(axis, qobject_cast(sender())); - else + QAbstractSeries *s = qobject_cast(sender()); + if (axis && s) { + if (!m_chart->axes(Qt::Horizontal).contains(axis)) + m_chart->addAxis(axis, Qt::AlignBottom); + if (!s->attachedAxes().contains(axis)) + s->attachAxis(axis); + } else { qWarning() << "Trying to set axisX to null."; + } +} + +void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) +{ + QAbstractSeries *s = qobject_cast(sender()); + if (axis && s) { + if (!m_chart->axes(Qt::Horizontal).contains(axis)) + m_chart->addAxis(axis, Qt::AlignTop); + if (!s->attachedAxes().contains(axis)) + s->attachAxis(axis); + } else { + qWarning() << "Trying to set axisXTop to null."; + } } void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) { -// qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; - if (axis && qobject_cast(sender())) - m_chart->setAxisY(axis, qobject_cast(sender())); - else + QAbstractSeries *s = qobject_cast(sender()); + if (axis && s) { + if (!m_chart->axes(Qt::Vertical).contains(axis)) + m_chart->addAxis(axis, Qt::AlignLeft); + if (!s->attachedAxes().contains(axis)) + s->attachAxis(axis); + } else { qWarning() << "Trying to set axisY to null."; + } +} + +void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) +{ + QAbstractSeries *s = qobject_cast(sender()); + if (axis && s) { + if (!m_chart->axes(Qt::Vertical).contains(axis)) + m_chart->addAxis(axis, Qt::AlignRight); + if (!s->attachedAxes().contains(axis)) + s->attachAxis(axis); + } else { + qWarning() << "Trying to set axisYRight to null."; + } } void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) @@ -435,12 +413,18 @@ QString DeclarativeChart::title() QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) { - return m_chart->axisX(series); + QList axes = m_chart->axes(Qt::Horizontal, series); + if (axes.count()) + return axes[0]; + return 0; } QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) { - return m_chart->axisY(series); + QList axes = m_chart->axes(Qt::Vertical, series); + if (axes.count()) + return axes[0]; + return 0; } QLegend *DeclarativeChart::legend() @@ -557,6 +541,40 @@ void DeclarativeChart::scrollDown(qreal pixels) m_chart->scroll(0, -pixels); } +QDeclarativeListProperty DeclarativeChart::axes() +{ + return QDeclarativeListProperty(this, 0, + &DeclarativeChart::axesAppendFunc, + &DeclarativeChart::axesCountFunc, + &DeclarativeChart::axesAtFunc); +} + +void DeclarativeChart::axesAppendFunc(QDeclarativeListProperty *list, QAbstractAxis *element) +{ + // Empty implementation + Q_UNUSED(list); + Q_UNUSED(element); +} + +int DeclarativeChart::axesCountFunc(QDeclarativeListProperty *list) +{ + if (qobject_cast(list->object)) { + DeclarativeChart *chart = qobject_cast(list->object); + return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]).count(); + } + return 0; +} + +QAbstractAxis *DeclarativeChart::axesAtFunc(QDeclarativeListProperty *list, int index) +{ + if (qobject_cast(list->object)) { + DeclarativeChart *chart = qobject_cast(list->object); + QList axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); + return axes.at(index); + } + return 0; +} + QAbstractSeries *DeclarativeChart::series(int index) { if (index < m_chart->series().count()) { @@ -625,13 +643,24 @@ QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ } if (series) { + // Connect to axis changed signals (unless this is a pie series) + if (!qobject_cast(series)) { + connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); + connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); + connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); + connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); + } + series->setName(name); m_chart->addSeries(series); - // Set possible user defined axes - setAxisX(axisX, series); - setAxisY(axisY, series); - // Then create the missing axes - createDefaultAxes(series); + + if (axisX) + setAxisX(axisX, series); + if (axisY) + setAxisY(axisY, series); + + if (series->attachedAxes().count() < 2) + initializeAxes(series); } return series; @@ -662,67 +691,77 @@ void DeclarativeChart::createDefaultAxes() qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; } -void DeclarativeChart::createDefaultAxes(QAbstractSeries *series) +QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) { - foreach (QAbstractSeries *s, m_chart->series()) { - // If there is already an x axis of the correct type, re-use it - if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) - && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) - m_chart->setAxisX(m_chart->axisX(s), series); - - // If there is already a y axis of the correct type, re-use it - if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) - && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) - m_chart->setAxisY(m_chart->axisY(s), series); + if (!series) { + qWarning() << "No axis type defined for null series"; + return 0; } - // If no x axis of correct type was found, create a new x axis based of default axis type - if (!m_chart->axisX(series)) { - switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { - case QAbstractAxis::AxisTypeValue: - m_chart->setAxisX(new QValueAxis(this), series); - break; - case QAbstractAxis::AxisTypeBarCategory: - m_chart->setAxisX(new QBarCategoryAxis(this), series); - break; - case QAbstractAxis::AxisTypeCategory: - m_chart->setAxisX(new QCategoryAxis(this), series); - break; -#ifndef QT_ON_ARM - case QAbstractAxis::AxisTypeDateTime: - m_chart->setAxisX(new QDateTimeAxis(this), series); - break; -#endif - default: - // Do nothing, assume AxisTypeNoAxis - break; - } + foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { + if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) + return existingAxis; } - // If no y axis of correct type was found, create a new y axis based of default axis type - if (!m_chart->axisY(series)) { - switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { - case QAbstractAxis::AxisTypeValue: - m_chart->setAxisY(new QValueAxis(this), series); - break; - case QAbstractAxis::AxisTypeBarCategory: - m_chart->setAxisY(new QBarCategoryAxis(this), series); - break; - case QAbstractAxis::AxisTypeCategory: - m_chart->setAxisY(new QCategoryAxis(this), series); - break; + switch (series->d_ptr->defaultAxisType(orientation)) { + case QAbstractAxis::AxisTypeValue: + return new QValueAxis(this); + case QAbstractAxis::AxisTypeBarCategory: + return new QBarCategoryAxis(this); + case QAbstractAxis::AxisTypeCategory: + return new QCategoryAxis(this); #ifndef QT_ON_ARM - case QAbstractAxis::AxisTypeDateTime: - m_chart->setAxisY(new QDateTimeAxis(this), series); - break; + case QAbstractAxis::AxisTypeDateTime: + return new QDateTimeAxis(this); #endif - default: - // Do nothing, assume AxisTypeNoAxis - break; - } + default: + // assume AxisTypeNoAxis + return 0; } +} - //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); +void DeclarativeChart::initializeAxes(QAbstractSeries *series) +{ + if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + else if (qobject_cast(series)) + doInitializeAxes(series, qobject_cast(series)->m_axes); + // else: do nothing +} + +void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) +{ + // Initialize axis X + if (axes->axisX()) + axes->emitAxisXChanged(); + else if (axes->axisXTop()) + axes->emitAxisXTopChanged(); + else + axes->setAxisX(defaultAxis(Qt::Horizontal, series)); + + // Initialize axis Y + if (axes->axisY()) + axes->emitAxisYChanged(); + else if (axes->axisYRight()) + axes->emitAxisYRightChanged(); + else + axes->setAxisY(defaultAxis(Qt::Vertical, series)); } #include "moc_declarativechart.cpp" diff --git a/plugins/declarative/declarativechart.h b/plugins/declarative/declarativechart.h index 8c2aa30..52ba2ef 100644 --- a/plugins/declarative/declarativechart.h +++ b/plugins/declarative/declarativechart.h @@ -29,7 +29,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class DeclarativeMargins; -class AbstractDomain; +class Domain; +class DeclarativeAxes; class DeclarativeChart : public QDeclarativeItem { @@ -50,6 +51,7 @@ class DeclarativeChart : public QDeclarativeItem Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) + Q_PROPERTY(QDeclarativeListProperty axes READ axes REVISION 2) Q_ENUMS(Animation) Q_ENUMS(Theme) Q_ENUMS(SeriesType) @@ -117,13 +119,21 @@ public: qreal bottomMargin(); qreal leftMargin(); qreal rightMargin(); - void createDefaultAxes(QAbstractSeries *series); + QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); + void initializeAxes(QAbstractSeries *series); + void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); //TODO this is deprecated: DeclarativeMargins *minimumMargins() { return m_margins; } Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } QRectF plotArea() { return m_chart->plotArea(); } + // Axis list property methods + QDeclarativeListProperty axes(); + static void axesAppendFunc(QDeclarativeListProperty *list, QAbstractAxis *element); + static int axesCountFunc(QDeclarativeListProperty *list); + static QAbstractAxis *axesAtFunc(QDeclarativeListProperty *list, int index); + public: Q_INVOKABLE QAbstractSeries *series(int index); Q_INVOKABLE QAbstractSeries *series(QString seriesName); @@ -153,10 +163,12 @@ Q_SIGNALS: void seriesAdded(QAbstractSeries *series); void seriesRemoved(QAbstractSeries *series); -public Q_SLOTS: +private Q_SLOTS: void changeMinimumMargins(int top, int bottom, int left, int right); void handleAxisXSet(QAbstractAxis *axis); void handleAxisYSet(QAbstractAxis *axis); + void handleAxisXTopSet(QAbstractAxis *axis); + void handleAxisYRightSet(QAbstractAxis *axis); void handleSeriesAdded(QAbstractSeries *series); private: diff --git a/plugins/declarative/declarativelineseries.cpp b/plugins/declarative/declarativelineseries.cpp index 30f4ce1..95bedb9 100644 --- a/plugins/declarative/declarativelineseries.cpp +++ b/plugins/declarative/declarativelineseries.cpp @@ -24,9 +24,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : QLineSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(new DeclarativeAxes(this)) { + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); } diff --git a/plugins/declarative/declarativelineseries.h b/plugins/declarative/declarativelineseries.h index 655d89d..cefa6b8 100644 --- a/plugins/declarative/declarativelineseries.h +++ b/plugins/declarative/declarativelineseries.h @@ -23,6 +23,7 @@ #include "qlineseries.h" #include "declarativexyseries.h" +#include "declarativeaxes.h" #include #include @@ -35,6 +36,8 @@ class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, pu Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged REVISION 1) Q_PROPERTY(Qt::PenStyle style READ style WRITE setStyle NOTIFY styleChanged REVISION 1) Q_PROPERTY(Qt::PenCapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged REVISION 1) @@ -44,10 +47,14 @@ class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, pu public: explicit DeclarativeLineSeries(QObject *parent = 0); QXYSeries *xySeries() { return this; } - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } qreal width() const; void setWidth(qreal width); Qt::PenStyle style() const; @@ -72,6 +79,8 @@ Q_SIGNALS: void countChanged(int count); Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); Q_REVISION(1) void widthChanged(qreal width); Q_REVISION(1) void styleChanged(Qt::PenStyle style); Q_REVISION(1) void capStyleChanged(Qt::PenCapStyle capStyle); @@ -80,9 +89,8 @@ public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); void handleCountChanged(int index); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativescatterseries.cpp b/plugins/declarative/declarativescatterseries.cpp index 254f165..443f2c0 100644 --- a/plugins/declarative/declarativescatterseries.cpp +++ b/plugins/declarative/declarativescatterseries.cpp @@ -24,9 +24,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : QScatterSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(new DeclarativeAxes(this)) { + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); } diff --git a/plugins/declarative/declarativescatterseries.h b/plugins/declarative/declarativescatterseries.h index 0159ed4..5d00d71 100644 --- a/plugins/declarative/declarativescatterseries.h +++ b/plugins/declarative/declarativescatterseries.h @@ -23,6 +23,7 @@ #include "qscatterseries.h" #include "declarativexyseries.h" +#include "declarativeaxes.h" #include #include @@ -35,6 +36,8 @@ class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeri Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1) Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) Q_CLASSINFO("DefaultProperty", "declarativeChildren") @@ -42,10 +45,14 @@ class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeri public: explicit DeclarativeScatterSeries(QObject *parent = 0); QXYSeries *xySeries() { return this; } - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } qreal borderWidth() const; void setBorderWidth(qreal borderWidth); QDeclarativeListProperty declarativeChildren(); @@ -67,14 +74,15 @@ Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); Q_REVISION(1) void borderWidthChanged(qreal width); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); public Q_SLOTS: static void appendDeclarativeChildren(QDeclarativeListProperty *list, QObject *element); void handleCountChanged(int index); -private: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; +public: + DeclarativeAxes *m_axes; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativesplineseries.cpp b/plugins/declarative/declarativesplineseries.cpp index b910c0d..f8104b3 100644 --- a/plugins/declarative/declarativesplineseries.cpp +++ b/plugins/declarative/declarativesplineseries.cpp @@ -24,9 +24,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : QSplineSeries(parent), - m_axisX(0), - m_axisY(0) + m_axes(new DeclarativeAxes(this)) { + connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*))); + connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); } diff --git a/plugins/declarative/declarativesplineseries.h b/plugins/declarative/declarativesplineseries.h index 4beb90b..dd0d042 100644 --- a/plugins/declarative/declarativesplineseries.h +++ b/plugins/declarative/declarativesplineseries.h @@ -23,6 +23,7 @@ #include "qsplineseries.h" #include "declarativexyseries.h" +#include "declarativeaxes.h" #include #include @@ -35,6 +36,8 @@ class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1) Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1) + Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2) + Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2) Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged REVISION 1) Q_PROPERTY(Qt::PenStyle style READ style WRITE setStyle NOTIFY styleChanged REVISION 1) Q_PROPERTY(Qt::PenCapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged REVISION 1) @@ -44,10 +47,14 @@ class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries public: explicit DeclarativeSplineSeries(QObject *parent = 0); QXYSeries *xySeries() { return this; } - QAbstractAxis *axisX() { return m_axisX; } - void setAxisX(QAbstractAxis *axis) { m_axisX = axis; emit axisXChanged(axis); } - QAbstractAxis *axisY() { return m_axisY; } - void setAxisY(QAbstractAxis *axis) { m_axisY = axis; emit axisYChanged(axis); } + QAbstractAxis *axisX() { return m_axes->axisX(); } + void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); } + QAbstractAxis *axisY() { return m_axes->axisY(); } + void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); } + Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); } + Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); } + Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } + Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } qreal width() const; void setWidth(qreal width); Qt::PenStyle style() const; @@ -72,6 +79,8 @@ Q_SIGNALS: void countChanged(int count); Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); Q_REVISION(1) void axisYChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis); + Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); Q_REVISION(1) void widthChanged(qreal width); Q_REVISION(1) void styleChanged(Qt::PenStyle style); Q_REVISION(1) void capStyleChanged(Qt::PenCapStyle capStyle); @@ -81,8 +90,7 @@ public Q_SLOTS: void handleCountChanged(int index); public: - QAbstractAxis *m_axisX; - QAbstractAxis *m_axisY; + DeclarativeAxes *m_axes; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index e8581ea..750b1a8 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -31,6 +31,7 @@ #include "declarativescatterseries.h" #include "declarativebarseries.h" #include "declarativepieseries.h" +#include "declarativeaxes.h" #include "qvxymodelmapper.h" #include "qhxymodelmapper.h" #include "qhpiemodelmapper.h" @@ -53,6 +54,7 @@ QTCOMMERCIALCHART_USE_NAMESPACE Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) @@ -127,6 +129,7 @@ public: qRegisterMetaType >(); qRegisterMetaType >(); + qRegisterMetaType >(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) qRegisterMetaType(); #endif @@ -174,6 +177,8 @@ public: QLatin1String("Trying to create uncreatable: BarsetBase.")); qmlRegisterUncreatableType(uri, 1, 0, "QPieSeries", QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); + qmlRegisterUncreatableType(uri, 1, 0, "DeclarativeAxes", + QLatin1String("Trying to create uncreatable: DeclarativeAxes.")); // QtCommercial.Chart 1.1 qmlRegisterType(uri, 1, 1, "ChartView"); @@ -201,6 +206,16 @@ public: // QtCommercial.Chart 1.2 qmlRegisterType(uri, 1, 2, "ChartView"); + qmlRegisterType(uri, 1, 2, "ScatterSeries"); + qmlRegisterType(uri, 1, 2, "LineSeries"); + qmlRegisterType(uri, 1, 2, "SplineSeries"); + qmlRegisterType(uri, 1, 2, "AreaSeries"); + qmlRegisterType(uri, 1, 2, "BarSeries"); + qmlRegisterType(uri, 1, 2, "StackedBarSeries"); + qmlRegisterType(uri, 1, 2, "PercentBarSeries"); + qmlRegisterType(uri, 1, 2, "HorizontalBarSeries"); + qmlRegisterType(uri, 1, 2, "HorizontalStackedBarSeries"); + qmlRegisterType(uri, 1, 2, "HorizontalPercentBarSeries"); } }; diff --git a/src/qchart.cpp b/src/qchart.cpp index 41860aa..ad33607 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -358,14 +358,22 @@ QAbstractAxis *QChart::axisY(QAbstractSeries *series) const return left?left:right; } - QList QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const { QList result ; - foreach(QAbstractAxis* axis,series->attachedAxes()){ - if(orientation.testFlag(axis->orientation())) - result << axis; + if (series) { + foreach (QAbstractAxis *axis, series->attachedAxes()){ + if (orientation.testFlag(axis->orientation())) + result << axis; + } + } else { + foreach (QAbstractSeries *s, QChart::series()) { + foreach (QAbstractAxis *axis, s->attachedAxes()){ + if (orientation.testFlag(axis->orientation())) + result << axis; + } + } } return result; diff --git a/src/themes/chartthemesystem_p.h b/src/themes/chartthemesystem_p.h index c373e8f..468e48f 100644 --- a/src/themes/chartthemesystem_p.h +++ b/src/themes/chartthemesystem_p.h @@ -80,7 +80,7 @@ public: m_seriesColors.append(ChartThemeManager::colorAt(g, 0.5)); // Generate gradients from the base colors - ChartThemeManager::generateSeriesGradients(m_seriesColors); + m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); // Background fill color from COLOR_WINDOW QLinearGradient backgroundGradient; @@ -129,7 +129,7 @@ public: m_seriesColors << QRgb(0x92ca66); m_seriesColors << QRgb(0xeba85f); m_seriesColors << QRgb(0xfc5751); - generateSeriesGradients(); + m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); // Background QLinearGradient backgroundGradient; diff --git a/tests/auto/qml-qtquicktest/tst_barseries.qml b/tests/auto/qml-qtquicktest/tst_barseries.qml index 61156bb..d31ea32 100644 --- a/tests/auto/qml-qtquicktest/tst_barseries.qml +++ b/tests/auto/qml-qtquicktest/tst_barseries.qml @@ -36,6 +36,18 @@ Rectangle { compare(barSeries.labelsVisible, false); } + function test_axes() { + compare(chartView.axes.length, 2); + verify(chartView.axes[0] == barSeries.axisX || chartView.axes[1] == barSeries.axisX); + verify(chartView.axes[0] == barSeries.axisY || chartView.axes[1] == barSeries.axisY); + + compare(barSeries.axisX, stackedBarSeries.axisX); + compare(barSeries.axisY, stackedBarSeries.axisY); + + compare(barSeries.axisX, percentBarSeries.axisX); + compare(barSeries.axisY, percentBarSeries.axisY); + } + function test_append() { var setCount = 5; var valueCount = 50; @@ -105,10 +117,10 @@ Rectangle { anchors.fill: parent BarSeries { - axisX: BarCategoriesAxis {} - axisY: ValuesAxis { min: 0; max: 10 } id: barSeries name: "bar" + axisX: BarCategoryAxis {} + axisY: ValueAxis { min: 0; max: 10 } SignalSpy { id: addedSpy @@ -121,5 +133,15 @@ Rectangle { signalName: "barsetsRemoved" } } + + StackedBarSeries { + id: stackedBarSeries + name: "stackedBar" + } + + PercentBarSeries { + id: percentBarSeries + name: "percentBar" + } } } diff --git a/tests/auto/qml-qtquicktest/tst_xyseries.qml b/tests/auto/qml-qtquicktest/tst_xyseries.qml index eba5006..eddf788 100644 --- a/tests/auto/qml-qtquicktest/tst_xyseries.qml +++ b/tests/auto/qml-qtquicktest/tst_xyseries.qml @@ -34,26 +34,17 @@ Rectangle { function test_properties() { verify(lineSeries.color != undefined); compare(lineSeries.pointsVisible, false); - // TODO: Should the properties be set or not? -// verify(lineSeries.axisX != null); -// verify(lineSeries.axisY != null); compare(lineSeries.capStyle, Qt.SquareCap); compare(lineSeries.style, Qt.SolidLine); compare(lineSeries.width, 2.0); verify(splineSeries.color != undefined); compare(splineSeries.pointsVisible, false); - // TODO: Should the properties be set or not? -// verify(splineSeries.axisX != null); -// verify(splineSeries.axisY != null); compare(splineSeries.capStyle, Qt.SquareCap); compare(splineSeries.style, Qt.SolidLine); compare(splineSeries.width, 2.0); verify(scatterSeries.color != undefined); - // TODO: Should the properties be set or not? -// verify(scatterSeries.axisX != null); -// verify(scatterSeries.axisY != null); verify(scatterSeries.borderColor != undefined); compare(scatterSeries.borderWidth, 2.0); compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle); @@ -64,6 +55,20 @@ Rectangle { compare(areaSeries.borderWidth, 2.0); } + function test_axes() { + compare(chartView.axes.length, 2); + console.log("chart.axes[0] " + chartView.axes[0]); + console.log("chart.axes[1] " + chartView.axes[1]); + console.log("lineSeries.axisX " + lineSeries.axisX); + console.log("lineSeries.axisY " + lineSeries.axisY); + verify(chartView.axes[0] == lineSeries.axisX || chartView.axes[1] == lineSeries.axisX); + verify(chartView.axes[0] == lineSeries.axisY || chartView.axes[1] == lineSeries.axisY); + verify(lineSeries.axisX == splineSeries.axisX); + verify(lineSeries.axisY == splineSeries.axisY); + verify(lineSeries.axisX == areaSeries.axisX); + verify(lineSeries.axisY == areaSeries.axisY); + } + function test_append() { lineSeriesPointAddedSpy.clear(); splineSeriesPointAddedSpy.clear(); diff --git a/tests/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml b/tests/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml index f13a814..5fd0803 100644 --- a/tests/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml +++ b/tests/qmlchartaxis/qml/qmlchartaxis/ConfiguringDynamically.qml @@ -33,12 +33,12 @@ ChartView { onTriggered: { switch (index) { case 0: - chartView.axisX(lineSeries).max = 6; - chartView.axisY(lineSeries).max = 6; + lineSeries.axisX.max = 6; + lineSeries.axisY.max = 6; break; case 1: - chartView.axisX(scatterSeries).max = 10; - chartView.axisY(scatterSeries).max = 10; + scatterSeries.axisX.max = 10; + scatterSeries.axisY.max = 10; break; default: chartView.axisX().max = 4;