From 8344a0102a72f2fbdafe472bd88082866a495b51 2014-05-02 10:18:44 From: Titta Heikkala Date: 2014-05-02 10:18:44 Subject: [PATCH] Add possibility to set brush image via QML API User can set a brush image for AreaSeries, BarSet, BoxPlotSeries, BoxSet, PieSlice and ScatterSeries by specifying 'brushFilename'. Task-number: QTRD-2603 Change-Id: Ie4b75cec1f64da513b1b85749c28984cb7f88e38 Reviewed-by: Miikka Heikkinen --- diff --git a/plugins/declarative/declarativeareaseries.cpp b/plugins/declarative/declarativeareaseries.cpp index 94fbb13..87c223d 100644 --- a/plugins/declarative/declarativeareaseries.cpp +++ b/plugins/declarative/declarativeareaseries.cpp @@ -33,6 +33,7 @@ DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisAngularChanged(QAbstractAxis*))); connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*))); + connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); } void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries *series) @@ -70,6 +71,45 @@ void DeclarativeAreaSeries::setBorderWidth(qreal width) } } +QString DeclarativeAreaSeries::brushFilename() const +{ + return m_brushFilename; +} + +void DeclarativeAreaSeries::setBrushFilename(const QString &brushFilename) +{ + QImage brushImage(brushFilename); + if (QAreaSeries::brush().textureImage() != brushImage) { + QBrush brush = QAreaSeries::brush(); + brush.setTextureImage(brushImage); + QAreaSeries::setBrush(brush); + m_brushFilename = brushFilename; + m_brushImage = brushImage; + emit brushFilenameChanged(brushFilename); + } +} + +void DeclarativeAreaSeries::handleBrushChanged() +{ + // If the texture image of the brush has changed along the brush + // the brush file name needs to be cleared. + if (!m_brushFilename.isEmpty() && QAreaSeries::brush().textureImage() != m_brushImage) { + m_brushFilename.clear(); + emit brushFilenameChanged(QString("")); + } +} + +void DeclarativeAreaSeries::setBrush(const QBrush &brush) +{ + QAreaSeries::setBrush(brush); + emit brushChanged(); +} + +QBrush DeclarativeAreaSeries::brush() const +{ + return QAreaSeries::brush(); +} + #include "moc_declarativeareaseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativeareaseries.h b/plugins/declarative/declarativeareaseries.h index af1be0e..3f37e7b 100644 --- a/plugins/declarative/declarativeareaseries.h +++ b/plugins/declarative/declarativeareaseries.h @@ -39,6 +39,8 @@ class DeclarativeAreaSeries : public QAreaSeries Q_PROPERTY(QAbstractAxis *axisAngular READ axisAngular WRITE setAxisAngular NOTIFY axisAngularChanged REVISION 3) Q_PROPERTY(QAbstractAxis *axisRadial READ axisRadial WRITE setAxisRadial NOTIFY axisRadialChanged REVISION 3) Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1) + Q_PROPERTY(QString brushFilename READ brushFilename WRITE setBrushFilename NOTIFY brushFilenameChanged REVISION 4) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged REVISION 4) public: explicit DeclarativeAreaSeries(QObject *parent = 0); @@ -60,6 +62,10 @@ public: Q_REVISION(3) void setAxisRadial(QAbstractAxis *axis) { m_axes->setAxisY(axis); } qreal borderWidth() const; void setBorderWidth(qreal borderWidth); + QString brushFilename() const; + void setBrushFilename(const QString &brushFilename); + void setBrush(const QBrush &brush); + QBrush brush() const; Q_SIGNALS: Q_REVISION(1) void axisXChanged(QAbstractAxis *axis); @@ -69,9 +75,18 @@ Q_SIGNALS: Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); Q_REVISION(3) void axisAngularChanged(QAbstractAxis *axis); Q_REVISION(3) void axisRadialChanged(QAbstractAxis *axis); + Q_REVISION(4) void brushChanged(); + Q_REVISION(4) void brushFilenameChanged(const QString &brushFilename); + +private Q_SLOTS: + void handleBrushChanged(); public: DeclarativeAxes *m_axes; + +private: + QString m_brushFilename; + QImage m_brushImage; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativebarseries.cpp b/plugins/declarative/declarativebarseries.cpp index 29cd26c..45008ea 100644 --- a/plugins/declarative/declarativebarseries.cpp +++ b/plugins/declarative/declarativebarseries.cpp @@ -30,6 +30,7 @@ DeclarativeBarSet::DeclarativeBarSet(QObject *parent) { connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int))); connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int))); + connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); } void DeclarativeBarSet::handleCountChanged(int index, int count) @@ -97,6 +98,34 @@ void DeclarativeBarSet::setValues(QVariantList values) } } +QString DeclarativeBarSet::brushFilename() const +{ + return m_brushFilename; +} + +void DeclarativeBarSet::setBrushFilename(const QString &brushFilename) +{ + QImage brushImage(brushFilename); + if (QBarSet::brush().textureImage() != brushImage) { + QBrush brush = QBarSet::brush(); + brush.setTextureImage(brushImage); + QBarSet::setBrush(brush); + m_brushFilename = brushFilename; + m_brushImage = brushImage; + emit brushFilenameChanged(brushFilename); + } +} + +void DeclarativeBarSet::handleBrushChanged() +{ + // If the texture image of the brush has changed along the brush + // the brush file name needs to be cleared. + if (!m_brushFilename.isEmpty() && QBarSet::brush().textureImage() != m_brushImage) { + m_brushFilename.clear(); + emit brushFilenameChanged(QString("")); + } +} + // Declarative bar series ====================================================================================== DeclarativeBarSeries::DeclarativeBarSeries(QDECLARATIVE_ITEM *parent) : QBarSeries(parent), diff --git a/plugins/declarative/declarativebarseries.h b/plugins/declarative/declarativebarseries.h index 7c5856c..b224e24 100644 --- a/plugins/declarative/declarativebarseries.h +++ b/plugins/declarative/declarativebarseries.h @@ -49,6 +49,7 @@ class DeclarativeBarSet : public QBarSet Q_PROPERTY(QVariantList values READ values WRITE setValues) Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QString brushFilename READ brushFilename WRITE setBrushFilename NOTIFY brushFilenameChanged REVISION 2) public: explicit DeclarativeBarSet(QObject *parent = 0); @@ -56,6 +57,8 @@ public: void setValues(QVariantList values); qreal borderWidth() const; void setBorderWidth(qreal borderWidth); + QString brushFilename() const; + void setBrushFilename(const QString &brushFilename); public: // From QBarSet Q_INVOKABLE void append(qreal value) { QBarSet::append(value); } @@ -66,9 +69,15 @@ public: // From QBarSet Q_SIGNALS: void countChanged(int count); Q_REVISION(1) void borderWidthChanged(qreal width); + Q_REVISION(2) void brushFilenameChanged(const QString &brushFilename); private Q_SLOTS: void handleCountChanged(int index, int count); + void handleBrushChanged(); + +private: + QString m_brushFilename; + QImage m_brushImage; }; class DeclarativeBarSeries : public QBarSeries, public QDECLARATIVE_PARSER_STATUS diff --git a/plugins/declarative/declarativeboxplotseries.cpp b/plugins/declarative/declarativeboxplotseries.cpp index 9ff3af7..7cdcde6 100644 --- a/plugins/declarative/declarativeboxplotseries.cpp +++ b/plugins/declarative/declarativeboxplotseries.cpp @@ -245,6 +245,7 @@ DeclarativeBoxSet::DeclarativeBoxSet(const QString label, QObject *parent) { connect(this, SIGNAL(valuesChanged()), this, SIGNAL(changedValues())); connect(this, SIGNAL(valueChanged(int)), this, SIGNAL(changedValue(int))); + connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); } QVariantList DeclarativeBoxSet::values() @@ -263,6 +264,34 @@ void DeclarativeBoxSet::setValues(QVariantList values) } } +QString DeclarativeBoxSet::brushFilename() const +{ + return m_brushFilename; +} + +void DeclarativeBoxSet::setBrushFilename(const QString &brushFilename) +{ + QImage brushImage(brushFilename); + if (QBoxSet::brush().textureImage() != brushImage) { + QBrush brush = QBoxSet::brush(); + brush.setTextureImage(brushImage); + QBoxSet::setBrush(brush); + m_brushFilename = brushFilename; + m_brushImage = brushImage; + emit brushFilenameChanged(brushFilename); + } +} + +void DeclarativeBoxSet::handleBrushChanged() +{ + // If the texture image of the brush has changed along the brush + // the brush file name needs to be cleared. + if (!m_brushFilename.isEmpty() && QBoxSet::brush().textureImage() != m_brushImage) { + m_brushFilename.clear(); + emit brushFilenameChanged(QString("")); + } +} + // ===================================================== DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDECLARATIVE_ITEM *parent) : @@ -275,6 +304,7 @@ DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDECLARATIVE_ITEM *parent) : connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*))); connect(this, SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(onHovered(bool, QBoxSet*))); connect(this, SIGNAL(clicked(QBoxSet*)), this, SLOT(onClicked(QBoxSet*))); + connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); } void DeclarativeBoxPlotSeries::classBegin() @@ -334,6 +364,34 @@ void DeclarativeBoxPlotSeries::onClicked(QBoxSet *boxset) emit clicked(qobject_cast(boxset)); } +QString DeclarativeBoxPlotSeries::brushFilename() const +{ + return m_brushFilename; +} + +void DeclarativeBoxPlotSeries::setBrushFilename(const QString &brushFilename) +{ + QImage brushImage(brushFilename); + if (QBoxPlotSeries::brush().textureImage() != brushImage) { + QBrush brush = QBoxPlotSeries::brush(); + brush.setTextureImage(brushImage); + QBoxPlotSeries::setBrush(brush); + m_brushFilename = brushFilename; + m_brushImage = brushImage; + emit brushFilenameChanged(brushFilename); + } +} + +void DeclarativeBoxPlotSeries::handleBrushChanged() +{ + // If the texture image of the brush has changed along the brush + // the brush file name needs to be cleared. + if (!m_brushFilename.isEmpty() && QBoxPlotSeries::brush().textureImage() != m_brushImage) { + m_brushFilename.clear(); + emit brushFilenameChanged(QString("")); + } +} + #include "moc_declarativeboxplotseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativeboxplotseries.h b/plugins/declarative/declarativeboxplotseries.h index 3c6b4fd..a8a7000 100644 --- a/plugins/declarative/declarativeboxplotseries.h +++ b/plugins/declarative/declarativeboxplotseries.h @@ -40,6 +40,7 @@ class DeclarativeBoxSet : public QBoxSet Q_PROPERTY(QVariantList values READ values WRITE setValues) Q_PROPERTY(QString label READ label WRITE setLabel) Q_PROPERTY(int count READ count) + Q_PROPERTY(QString brushFilename READ brushFilename WRITE setBrushFilename NOTIFY brushFilenameChanged REVISION 1) Q_ENUMS(ValuePositions) public: // duplicate from QBoxSet @@ -55,6 +56,8 @@ public: explicit DeclarativeBoxSet(const QString label = "", QObject *parent = 0); QVariantList values(); void setValues(QVariantList values); + QString brushFilename() const; + void setBrushFilename(const QString &brushFilename); public: // From QBoxSet Q_INVOKABLE void append(qreal value) { QBoxSet::append(value); } @@ -65,6 +68,14 @@ public: // From QBoxSet Q_SIGNALS: void changedValues(); void changedValue(int index); + Q_REVISION(1) void brushFilenameChanged(const QString &brushFilename); + +private Q_SLOTS: + void handleBrushChanged(); + +private: + QString m_brushFilename; + QImage m_brushImage; }; class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDECLARATIVE_PARSER_STATUS @@ -84,6 +95,7 @@ class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDECLARATIVE_PARS #else Q_PROPERTY(QDeclarativeListProperty seriesChildren READ seriesChildren) #endif + Q_PROPERTY(QString brushFilename READ brushFilename WRITE setBrushFilename NOTIFY brushFilenameChanged REVISION 1) Q_CLASSINFO("DefaultProperty", "seriesChildren") public: @@ -97,6 +109,8 @@ public: QAbstractAxis *axisYRight() { return m_axes->axisYRight(); } void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); } QDECLARATIVE_LIST_PROPERTY seriesChildren(); + QString brushFilename() const; + void setBrushFilename(const QString &brushFilename); public: Q_INVOKABLE DeclarativeBoxSet *at(int index); @@ -117,14 +131,22 @@ Q_SIGNALS: void axisYRightChanged(QAbstractAxis *axis); void clicked(DeclarativeBoxSet *boxset); void hovered(bool status, DeclarativeBoxSet *boxset); + Q_REVISION(1) void brushFilenameChanged(const QString &brushFilename); public Q_SLOTS: static void appendSeriesChildren(QDECLARATIVE_LIST_PROPERTY *list, QObject *element); void onHovered(bool status, QBoxSet *boxset); void onClicked(QBoxSet *boxset); +private Q_SLOTS: + void handleBrushChanged(); + public: DeclarativeAxes *m_axes; + +private: + QString m_brushFilename; + QImage m_brushImage; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index acceca8..3ecfe34 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -25,6 +25,41 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +DeclarativePieSlice::DeclarativePieSlice(QObject *parent) + : QPieSlice(parent) +{ + connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); +} + +QString DeclarativePieSlice::brushFilename() const +{ + return m_brushFilename; +} + +void DeclarativePieSlice::setBrushFilename(const QString &brushFilename) +{ + QImage brushImage(brushFilename); + if (QPieSlice::brush().textureImage() != brushImage) { + QBrush brush = QPieSlice::brush(); + brush.setTextureImage(brushImage); + QPieSlice::setBrush(brush); + m_brushFilename = brushFilename; + m_brushImage = brushImage; + emit brushFilenameChanged(brushFilename); + } +} + +void DeclarativePieSlice::handleBrushChanged() +{ + // If the texture image of the brush has changed along the brush + // the brush file name needs to be cleared. + if (!m_brushFilename.isEmpty() && QPieSlice::brush().textureImage() != m_brushImage) { + m_brushFilename.clear(); + emit brushFilenameChanged(QString("")); + } +} + +// Declarative pie series ========================================================================= DeclarativePieSeries::DeclarativePieSeries(QDECLARATIVE_ITEM *parent) : QPieSeries(parent) { @@ -81,13 +116,15 @@ QPieSlice *DeclarativePieSeries::find(QString label) return 0; } -QPieSlice *DeclarativePieSeries::append(QString label, qreal value) +DeclarativePieSlice *DeclarativePieSeries::append(QString label, qreal value) { - QPieSlice *slice = new QPieSlice(this); + DeclarativePieSlice *slice = new DeclarativePieSlice(this); slice->setLabel(label); slice->setValue(value); - QPieSeries::append(slice); - return slice; + if (QPieSeries::append(slice)) + return slice; + delete slice; + return 0; } bool DeclarativePieSeries::remove(QPieSlice *slice) diff --git a/plugins/declarative/declarativepieseries.h b/plugins/declarative/declarativepieseries.h index 5f4ec0e..12cb181 100644 --- a/plugins/declarative/declarativepieseries.h +++ b/plugins/declarative/declarativepieseries.h @@ -22,6 +22,7 @@ #define DECLARATIVEPIESERIES_H #include "qpieseries.h" +#include "qpieslice.h" #include "shared_defines.h" #ifdef CHARTS_FOR_QUICK2 @@ -33,7 +34,27 @@ #endif QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QPieSlice; + +class DeclarativePieSlice : public QPieSlice +{ + Q_OBJECT + Q_PROPERTY(QString brushFilename READ brushFilename WRITE setBrushFilename NOTIFY brushFilenameChanged) + +public: + explicit DeclarativePieSlice(QObject *parent = 0); + QString brushFilename() const; + void setBrushFilename(const QString &brushFilename); + +Q_SIGNALS: + void brushFilenameChanged(const QString &brushFilename); + +private Q_SLOTS: + void handleBrushChanged(); + +private: + QString m_brushFilename; + QImage m_brushImage; +}; class DeclarativePieSeries : public QPieSeries, public QDECLARATIVE_PARSER_STATUS { @@ -52,7 +73,7 @@ public: QDECLARATIVE_LIST_PROPERTY seriesChildren(); Q_INVOKABLE QPieSlice *at(int index); Q_INVOKABLE QPieSlice *find(QString label); - Q_INVOKABLE QPieSlice *append(QString label, qreal value); + Q_INVOKABLE DeclarativePieSlice *append(QString label, qreal value); Q_INVOKABLE bool remove(QPieSlice *slice); Q_INVOKABLE void clear(); diff --git a/plugins/declarative/declarativescatterseries.cpp b/plugins/declarative/declarativescatterseries.cpp index 8422556..89e3c36 100644 --- a/plugins/declarative/declarativescatterseries.cpp +++ b/plugins/declarative/declarativescatterseries.cpp @@ -34,6 +34,7 @@ DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*))); connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int))); connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int))); + connect(this, SIGNAL(brushChanged()), this, SLOT(handleBrushChanged())); } void DeclarativeScatterSeries::handleCountChanged(int index) @@ -69,6 +70,45 @@ void DeclarativeScatterSeries::appendDeclarativeChildren(QDECLARATIVE_LIST_PROPE // Empty implementation, children are parsed in componentComplete } +QString DeclarativeScatterSeries::brushFilename() const +{ + return m_brushFilename; +} + +void DeclarativeScatterSeries::setBrushFilename(const QString &brushFilename) +{ + QImage brushImage(brushFilename); + if (QScatterSeries::brush().textureImage() != brushImage) { + QBrush brush = QScatterSeries::brush(); + brush.setTextureImage(brushImage); + QScatterSeries::setBrush(brush); + m_brushFilename = brushFilename; + m_brushImage = brushImage; + emit brushFilenameChanged(brushFilename); + } +} + +void DeclarativeScatterSeries::setBrush(const QBrush &brush) +{ + QScatterSeries::setBrush(brush); + emit brushChanged(); +} + +QBrush DeclarativeScatterSeries::brush() const +{ + return QScatterSeries::brush(); +} + +void DeclarativeScatterSeries::handleBrushChanged() +{ + // If the texture image of the brush has changed along the brush + // the brush file name needs to be cleared. + if (!m_brushFilename.isEmpty() && QScatterSeries::brush().textureImage() != m_brushImage) { + m_brushFilename.clear(); + emit brushFilenameChanged(QString("")); + } +} + #include "moc_declarativescatterseries.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/declarativescatterseries.h b/plugins/declarative/declarativescatterseries.h index c59e0e9..17e95e4 100644 --- a/plugins/declarative/declarativescatterseries.h +++ b/plugins/declarative/declarativescatterseries.h @@ -57,6 +57,8 @@ class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeri #else Q_PROPERTY(QDeclarativeListProperty declarativeChildren READ declarativeChildren) #endif + Q_PROPERTY(QString brushFilename READ brushFilename WRITE setBrushFilename NOTIFY brushFilenameChanged REVISION 4) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged REVISION 4) Q_CLASSINFO("DefaultProperty", "declarativeChildren") public: @@ -77,6 +79,10 @@ public: qreal borderWidth() const; void setBorderWidth(qreal borderWidth); QDECLARATIVE_LIST_PROPERTY declarativeChildren(); + QString brushFilename() const; + void setBrushFilename(const QString &brushFilename); + void setBrush(const QBrush &brush); + QBrush brush() const; public: // from QDeclarativeParserStatus void classBegin() { DeclarativeXySeries::classBegin(); } @@ -101,13 +107,22 @@ Q_SIGNALS: Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis); Q_REVISION(3) void axisAngularChanged(QAbstractAxis *axis); Q_REVISION(3) void axisRadialChanged(QAbstractAxis *axis); + Q_REVISION(4) void brushFilenameChanged(const QString &brushFilename); + Q_REVISION(4) void brushChanged(); public Q_SLOTS: static void appendDeclarativeChildren(QDECLARATIVE_LIST_PROPERTY *list, QObject *element); void handleCountChanged(int index); +private Q_SLOTS: + void handleBrushChanged(); + public: DeclarativeAxes *m_axes; + +private: + QString m_brushFilename; + QImage m_brushImage; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index 01de104..ad4aca7 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -76,6 +76,7 @@ Q_DECLARE_METATYPE(DeclarativeBoxPlotSeries *) Q_DECLARE_METATYPE(DeclarativeBoxSet *) Q_DECLARE_METATYPE(DeclarativeLineSeries *) Q_DECLARE_METATYPE(DeclarativePieSeries *) +Q_DECLARE_METATYPE(DeclarativePieSlice *) Q_DECLARE_METATYPE(DeclarativeScatterSeries *) Q_DECLARE_METATYPE(DeclarativeSplineSeries *) @@ -238,6 +239,14 @@ public: qmlRegisterType(uri, 1, 3, "LogValueAxis"); qmlRegisterType(uri, 1, 3, "BoxPlotSeries"); qmlRegisterType(uri, 1, 3, "BoxSet"); + + // QtCommercial.Chart 1.4 + qmlRegisterType(uri, 1, 4, "AreaSeries"); + qmlRegisterType(uri, 1, 4, "BarSet"); + qmlRegisterType(uri, 1, 4, "BoxPlotSeries"); + qmlRegisterType(uri, 1, 4, "BoxSet"); + qmlRegisterType(uri, 1, 4, "PieSlice"); + qmlRegisterType(uri, 1, 4, "ScatterSeries"); } }; diff --git a/plugins/quick2/plugins.qmltypes b/plugins/quick2/plugins.qmltypes index 8f715cb..d0a9bd6 100644 --- a/plugins/quick2/plugins.qmltypes +++ b/plugins/quick2/plugins.qmltypes @@ -2,6 +2,9 @@ import QtQuick.tooling 1.1 // This file describes the plugin-supplied types contained in the library. // It is used for QML tooling purposes only. +// +// This file was auto-generated by: +// 'qmlplugindump -nonrelocatable QtCommercial.Chart 1.4' Module { Component { @@ -55,9 +58,10 @@ Module { "QtCommercial.Chart/AreaSeries 1.0", "QtCommercial.Chart/AreaSeries 1.1", "QtCommercial.Chart/AreaSeries 1.2", - "QtCommercial.Chart/AreaSeries 1.3" + "QtCommercial.Chart/AreaSeries 1.3", + "QtCommercial.Chart/AreaSeries 1.4" ] - exportMetaObjectRevisions: [0, 1, 2, 3] + exportMetaObjectRevisions: [0, 1, 2, 3, 4] Property { name: "upperSeries"; type: "DeclarativeLineSeries"; isPointer: true } Property { name: "lowerSeries"; type: "DeclarativeLineSeries"; isPointer: true } Property { name: "axisX"; revision: 1; type: "QAbstractAxis"; isPointer: true } @@ -67,6 +71,8 @@ Module { Property { name: "axisAngular"; revision: 3; type: "QAbstractAxis"; isPointer: true } Property { name: "axisRadial"; revision: 3; type: "QAbstractAxis"; isPointer: true } Property { name: "borderWidth"; revision: 1; type: "double" } + Property { name: "brushFilename"; revision: 4; type: "string" } + Property { name: "brush"; revision: 4; type: "QBrush" } Signal { name: "axisXChanged" revision: 1 @@ -102,12 +108,17 @@ Module { revision: 3 Parameter { name: "axis"; type: "QAbstractAxis"; isPointer: true } } + Signal { name: "brushChanged"; revision: 4 } + Signal { + name: "brushFilenameChanged" + revision: 4 + Parameter { name: "brushFilename"; type: "string" } + } } Component { name: "QtCommercialChart::DeclarativeAxes" prototype: "QObject" exports: ["QtCommercial.Chart/DeclarativeAxes 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "axisX"; type: "QAbstractAxis"; isPointer: true } Property { name: "axisY"; type: "QAbstractAxis"; isPointer: true } @@ -200,12 +211,14 @@ Module { prototype: "QtCommercialChart::QBarSet" exports: [ "QtCommercial.Chart/BarSet 1.0", - "QtCommercial.Chart/BarSet 1.1" + "QtCommercial.Chart/BarSet 1.1", + "QtCommercial.Chart/BarSet 1.4" ] - exportMetaObjectRevisions: [0, 0] + exportMetaObjectRevisions: [0, 0, 2] Property { name: "values"; type: "QVariantList" } Property { name: "borderWidth"; revision: 1; type: "double" } Property { name: "count"; type: "int"; isReadonly: true } + Property { name: "brushFilename"; revision: 2; type: "string" } Signal { name: "countChanged" Parameter { name: "count"; type: "int" } @@ -215,6 +228,11 @@ Module { revision: 1 Parameter { name: "width"; type: "double" } } + Signal { + name: "brushFilenameChanged" + revision: 2 + Parameter { name: "brushFilename"; type: "string" } + } Method { name: "append" Parameter { name: "value"; type: "double" } @@ -243,13 +261,17 @@ Module { name: "QtCommercialChart::DeclarativeBoxPlotSeries" defaultProperty: "seriesChildren" prototype: "QtCommercialChart::QBoxPlotSeries" - exports: ["QtCommercial.Chart/BoxPlotSeries 1.3"] - exportMetaObjectRevisions: [0] + exports: [ + "QtCommercial.Chart/BoxPlotSeries 1.3", + "QtCommercial.Chart/BoxPlotSeries 1.4" + ] + exportMetaObjectRevisions: [0, 1] Property { name: "axisX"; type: "QAbstractAxis"; isPointer: true } Property { name: "axisY"; type: "QAbstractAxis"; isPointer: true } Property { name: "axisXTop"; type: "QAbstractAxis"; isPointer: true } Property { name: "axisYRight"; type: "QAbstractAxis"; isPointer: true } Property { name: "seriesChildren"; type: "QObject"; isList: true; isReadonly: true } + Property { name: "brushFilename"; revision: 1; type: "string" } Signal { name: "axisXChanged" Parameter { name: "axis"; type: "QAbstractAxis"; isPointer: true } @@ -275,6 +297,11 @@ Module { Parameter { name: "status"; type: "bool" } Parameter { name: "boxset"; type: "DeclarativeBoxSet"; isPointer: true } } + Signal { + name: "brushFilenameChanged" + revision: 1 + Parameter { name: "brushFilename"; type: "string" } + } Method { name: "appendSeriesChildren" Parameter { name: "list"; type: "QDECLARATIVE_LIST_PROPERTY"; isPointer: true } @@ -321,8 +348,11 @@ Module { Component { name: "QtCommercialChart::DeclarativeBoxSet" prototype: "QtCommercialChart::QBoxSet" - exports: ["QtCommercial.Chart/BoxSet 1.3"] - exportMetaObjectRevisions: [0] + exports: [ + "QtCommercial.Chart/BoxSet 1.3", + "QtCommercial.Chart/BoxSet 1.4" + ] + exportMetaObjectRevisions: [0, 1] Enum { name: "ValuePositions" values: { @@ -336,11 +366,17 @@ Module { Property { name: "values"; type: "QVariantList" } Property { name: "label"; type: "string" } Property { name: "count"; type: "int"; isReadonly: true } + Property { name: "brushFilename"; revision: 1; type: "string" } Signal { name: "changedValues" } Signal { name: "changedValue" Parameter { name: "index"; type: "int" } } + Signal { + name: "brushFilenameChanged" + revision: 1 + Parameter { name: "brushFilename"; type: "string" } + } Method { name: "append" Parameter { name: "value"; type: "double" } @@ -912,7 +948,6 @@ Module { name: "QtCommercialChart::DeclarativeMargins" prototype: "QObject" exports: ["QtCommercial.Chart/Margins 1.1"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "top"; type: "int" } Property { name: "bottom"; type: "int" } @@ -1055,7 +1090,7 @@ Module { } Method { name: "append" - type: "QPieSlice*" + type: "DeclarativePieSlice*" Parameter { name: "label"; type: "string" } Parameter { name: "value"; type: "double" } } @@ -1067,6 +1102,17 @@ Module { Method { name: "clear" } } Component { + name: "QtCommercialChart::DeclarativePieSlice" + prototype: "QtCommercialChart::QPieSlice" + exports: ["QtCommercial.Chart/PieSlice 1.4"] + exportMetaObjectRevisions: [0] + Property { name: "brushFilename"; type: "string" } + Signal { + name: "brushFilenameChanged" + Parameter { name: "brushFilename"; type: "string" } + } + } + Component { name: "QtCommercialChart::DeclarativePolarChart" defaultProperty: "data" prototype: "QtCommercialChart::DeclarativeChart" @@ -1081,9 +1127,10 @@ Module { "QtCommercial.Chart/ScatterSeries 1.0", "QtCommercial.Chart/ScatterSeries 1.1", "QtCommercial.Chart/ScatterSeries 1.2", - "QtCommercial.Chart/ScatterSeries 1.3" + "QtCommercial.Chart/ScatterSeries 1.3", + "QtCommercial.Chart/ScatterSeries 1.4" ] - exportMetaObjectRevisions: [0, 1, 2, 3] + exportMetaObjectRevisions: [0, 1, 2, 3, 4] Property { name: "count"; type: "int"; isReadonly: true } Property { name: "axisX"; revision: 1; type: "QAbstractAxis"; isPointer: true } Property { name: "axisY"; revision: 1; type: "QAbstractAxis"; isPointer: true } @@ -1093,6 +1140,8 @@ Module { Property { name: "axisRadial"; revision: 3; type: "QAbstractAxis"; isPointer: true } Property { name: "borderWidth"; revision: 1; type: "double" } Property { name: "declarativeChildren"; type: "QObject"; isList: true; isReadonly: true } + Property { name: "brushFilename"; revision: 4; type: "string" } + Property { name: "brush"; revision: 4; type: "QBrush" } Signal { name: "countChanged" Parameter { name: "count"; type: "int" } @@ -1132,6 +1181,12 @@ Module { revision: 3 Parameter { name: "axis"; type: "QAbstractAxis"; isPointer: true } } + Signal { + name: "brushFilenameChanged" + revision: 4 + Parameter { name: "brushFilename"; type: "string" } + } + Signal { name: "brushChanged"; revision: 4 } Method { name: "appendDeclarativeChildren" Parameter { name: "list"; type: "QObject"; isList: true; isPointer: true } @@ -1387,7 +1442,6 @@ Module { name: "QtCommercialChart::QAbstractAxis" prototype: "QObject" exports: ["QtCommercial.Chart/AbstractAxis 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "visible"; type: "bool" } Property { name: "lineVisible"; type: "bool" } @@ -1506,7 +1560,6 @@ Module { name: "QtCommercialChart::QAbstractBarSeries" prototype: "QtCommercialChart::QAbstractSeries" exports: ["QtCommercial.Chart/AbstractBarSeries 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "barWidth"; type: "double" } Property { name: "count"; type: "int"; isReadonly: true } @@ -1540,7 +1593,6 @@ Module { name: "QtCommercialChart::QAbstractSeries" prototype: "QObject" exports: ["QtCommercial.Chart/AbstractSeries 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Enum { name: "SeriesType" @@ -1620,7 +1672,6 @@ Module { name: "QtCommercialChart::QBarModelMapper" prototype: "QObject" exports: ["QtCommercial.Chart/BarModelMapper 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] } Component { @@ -1631,7 +1682,6 @@ Module { name: "QtCommercialChart::QBarSet" prototype: "QObject" exports: ["QtCommercial.Chart/BarSetBase 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "label"; type: "string" } Property { name: "pen"; type: "QPen" } @@ -1823,7 +1873,6 @@ Module { defaultProperty: "children" prototype: "QGraphicsWidget" exports: ["QtCommercial.Chart/Legend 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "alignment"; type: "Qt::Alignment" } Property { name: "backgroundVisible"; type: "bool" } @@ -1897,14 +1946,12 @@ Module { name: "QtCommercialChart::QPieModelMapper" prototype: "QObject" exports: ["QtCommercial.Chart/PieModelMapper 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] } Component { name: "QtCommercialChart::QPieSeries" prototype: "QtCommercialChart::QAbstractSeries" exports: ["QtCommercial.Chart/QPieSeries 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "horizontalPosition"; type: "double" } Property { name: "verticalPosition"; type: "double" } @@ -1984,6 +2031,7 @@ Module { Property { name: "borderColor"; type: "QColor" } Property { name: "markerShape"; type: "MarkerShape" } Property { name: "markerSize"; type: "double" } + Property { name: "brush"; type: "QBrush" } Signal { name: "colorChanged" Parameter { name: "color"; type: "QColor" } @@ -2083,14 +2131,12 @@ Module { name: "QtCommercialChart::QXYModelMapper" prototype: "QObject" exports: ["QtCommercial.Chart/XYModelMapper 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] } Component { name: "QtCommercialChart::QXYSeries" prototype: "QtCommercialChart::QAbstractSeries" exports: ["QtCommercial.Chart/XYSeries 1.0"] - isCreatable: false exportMetaObjectRevisions: [0] Property { name: "pointsVisible"; type: "bool" } Property { name: "color"; type: "QColor" } diff --git a/src/areachart/qareaseries.cpp b/src/areachart/qareaseries.cpp index ffcf697..961ef81 100644 --- a/src/areachart/qareaseries.cpp +++ b/src/areachart/qareaseries.cpp @@ -121,6 +121,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \qmlproperty QString AreaSeries::brushFilename + The name of the file used as a brush image for the series. +*/ + +/*! \fn void QAreaSeries::colorChanged(QColor color) \brief Signal is emitted when the fill (brush) color has changed to \a color. */ diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index 1767177..0d81820 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -75,6 +75,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \qmlproperty QString BarSet::brushFilename + The name of the file used as a brush for the set. +*/ + +/*! \property QBarSet::labelBrush \brief Defines the brush used by the bar set's label. */ diff --git a/src/boxplotchart/qboxplotseries.cpp b/src/boxplotchart/qboxplotseries.cpp index 0ae3065..5dc6be1 100644 --- a/src/boxplotchart/qboxplotseries.cpp +++ b/src/boxplotchart/qboxplotseries.cpp @@ -87,6 +87,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \property QBoxPlotSeries::brush \brief This property configures the brush of the box-and-whiskers items. */ + +/*! + \qmlproperty QString BoxPlotSeries::brushFilename + The name of the file used as a brush for the series. +*/ + /*! \fn void QBoxPlotSeries::boxOutlineVisibilityChanged() Signal is emitted when the middle box outline visibility is changed. diff --git a/src/boxplotchart/qboxset.cpp b/src/boxplotchart/qboxset.cpp index 45af714..a385c29 100644 --- a/src/boxplotchart/qboxset.cpp +++ b/src/boxplotchart/qboxset.cpp @@ -56,6 +56,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \property QBoxSet::brush \brief Defines the brush used by the box-and-whiskers set. */ + +/*! + \qmlproperty QString BoxSet::brushFilename + The name of the file used as a brush for the box-and-whiskers set. +*/ + /*! \fn void QBoxSet::clicked() The signal is emitted if the user clicks with a mouse on top of box-and-whisker item. diff --git a/src/piechart/qpieslice.cpp b/src/piechart/qpieslice.cpp index a40658d..3ae5d89 100644 --- a/src/piechart/qpieslice.cpp +++ b/src/piechart/qpieslice.cpp @@ -211,6 +211,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \qmlproperty QString PieSlice::brushFilename + The name of the file used as a brush for the slice. +*/ + +/*! \property QPieSlice::color Fill (brush) color of the slice. This is a convenience property for modifying the slice brush. diff --git a/src/scatterchart/qscatterseries.cpp b/src/scatterchart/qscatterseries.cpp index 62fa1a6..844aa91 100644 --- a/src/scatterchart/qscatterseries.cpp +++ b/src/scatterchart/qscatterseries.cpp @@ -73,6 +73,11 @@ */ /*! + \property QScatterSeries::brush + Brush used to draw the series. +*/ + +/*! \property QScatterSeries::color Fill (brush) color of the series. This is a convenience property for modifying the color of brush. \sa QScatterSeries::brush() @@ -114,6 +119,11 @@ */ /*! + \qmlproperty QString ScatterSeries::brushFilename + The name of the file used as a brush for the series. +*/ + +/*! \fn void QScatterSeries::colorChanged(QColor color) Signal is emitted when the fill (brush) color has changed to \a color. */ @@ -192,6 +202,15 @@ void QScatterSeries::setBrush(const QBrush &brush) } } +QBrush QScatterSeries::brush() const +{ + Q_D(const QScatterSeries); + if (d->m_brush == QChartPrivate::defaultBrush()) + return QBrush(); + else + return d->m_brush; +} + void QScatterSeries::setColor(const QColor &color) { QBrush b = brush(); diff --git a/src/scatterchart/qscatterseries.h b/src/scatterchart/qscatterseries.h index 83c3fac..1a0ce31 100644 --- a/src/scatterchart/qscatterseries.h +++ b/src/scatterchart/qscatterseries.h @@ -35,6 +35,7 @@ class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape) Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush) Q_ENUMS(MarkerShape) public: @@ -49,6 +50,7 @@ public: QAbstractSeries::SeriesType type() const; void setPen(const QPen &pen); void setBrush(const QBrush &brush); + QBrush brush() const; void setColor(const QColor &color); QColor color() const; void setBorderColor(const QColor &color); diff --git a/tests/auto/qml-qtquicktest/tst_barcategoryaxis.qml b/tests/auto/qml-qtquicktest/tst_barcategoryaxis.qml index bb3dcc0..8ce990f 100644 --- a/tests/auto/qml-qtquicktest/tst_barcategoryaxis.qml +++ b/tests/auto/qml-qtquicktest/tst_barcategoryaxis.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 diff --git a/tests/auto/qml-qtquicktest/tst_barcategoryaxis_1_3.qml b/tests/auto/qml-qtquicktest/tst_barcategoryaxis_1_3.qml new file mode 100644 index 0000000..a584532 --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_barcategoryaxis_1_3.qml @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest BarCategoryAxis 1.3" + when: windowShown + + function test_minMax() { + compare(barSeries1.axisX.min, "Jan", "AxisX min"); + compare(barSeries1.axisX.max, "Jun", "AxisX max"); + compare(barSeries1.axisY.min, 0, "AxisY min"); + compare(barSeries1.axisY.max, 10, "AxisY max"); + } + + function test_categories() { + compare(barSeries1.axisX.count, 6, "AxisX count"); + categoriesCountChangedSpy.clear(); + categoriesChangedSpy.clear(); + + // Replace categories + barSeries1.axisX.categories = ["Tam", "Hel", "Maa", "Huh"]; + compare(barSeries1.axisX.count, 4, "AxisX count"); + compare(categoriesCountChangedSpy.count, 1, "onCountChanged"); + compare(categoriesChangedSpy.count, 1, "onCategoriesChanged"); + + // Reset the original categories + barSeries1.axisX.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] + compare(barSeries1.axisX.count, 6, "AxisX count"); + compare(categoriesCountChangedSpy.count, 2, "onCountChanged"); + compare(categoriesChangedSpy.count, 2, "onCategoriesChanged"); + } + + function test_minMaxChanged() { + axisY.min = -1; + compare(minChangedSpy.count, 1, "onMinChanged"); + compare(maxChangedSpy.count, 0, "onMaxChanged"); + axisY.max = 12; + compare(minChangedSpy.count, 1, "onMinChanged"); + compare(maxChangedSpy.count, 1, "onMaxChanged"); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + BarSeries { + id: barSeries1 + axisX: BarCategoryAxis { + id: axisX + categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] + } + axisY: ValuesAxis { + id: axisY + min: 0 + max: 10 + } + } + + SignalSpy { + id: categoriesCountChangedSpy + target: axisX + signalName: "countChanged" + } + SignalSpy { + id: categoriesChangedSpy + target: axisX + signalName: "categoriesChanged" + } + SignalSpy { + id: minChangedSpy + target: axisY + signalName: "minChanged" + } + SignalSpy { + id: maxChangedSpy + target: axisY + signalName: "maxChanged" + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_barseries.qml b/tests/auto/qml-qtquicktest/tst_barseries.qml index b092399..9d7335a 100644 --- a/tests/auto/qml-qtquicktest/tst_barseries.qml +++ b/tests/auto/qml-qtquicktest/tst_barseries.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 @@ -36,6 +36,11 @@ Rectangle { compare(barSeries.labelsVisible, false); } + function test_setproperties() { + var set = barSeries.append("property", [1, 2, 3]) + compare(set.brushFilename, ""); + } + function test_axes() { verify(chartView.axisX() == barSeries.axisX); verify(chartView.axisY() == barSeries.axisY); diff --git a/tests/auto/qml-qtquicktest/tst_barseries_1_3.qml b/tests/auto/qml-qtquicktest/tst_barseries_1_3.qml new file mode 100644 index 0000000..3e6a97a --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_barseries_1_3.qml @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest BarSeries 1.3" + when: windowShown + + function test_properties() { + compare(barSeries.barWidth, 0.5); + compare(barSeries.labelsVisible, false); + } + + function test_axes() { + verify(chartView.axisX() == barSeries.axisX); + verify(chartView.axisY() == 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; + addedSpy.clear(); + append(setCount, valueCount); + + compare(barSeries.count, setCount); + for (var k = 0; k < setCount; k++) { + compare(barSeries.at(k).count, valueCount); + compare(barSeries.at(k).label, "barset" + k); + } + compare(addedSpy.count, setCount); + + barSeries.clear(); + compare(barSeries.count, 0); + } + + function test_insert() { + var setCount = 5; + var valueCount = 50; + addedSpy.clear(); + append(setCount, valueCount); + + for (var i = 0; i < setCount; i++) { + var values = []; + for (var j = 0; j < valueCount; j++) + values[j] = Math.random() * 10; + var set = barSeries.insert(i, "barset" + i, values); + compare(set.label, "barset" + i); + } + + compare(barSeries.count, setCount * 2); + for (var k = 0; k < setCount * 2; k++) + compare(barSeries.at(k).count, valueCount); + compare(addedSpy.count, 2 * setCount); + + barSeries.clear(); + compare(barSeries.count, 0); + } + + function test_remove() { + var setCount = 5; + var valueCount = 50; + removedSpy.clear(); + append(setCount, valueCount); + + for (var k = 0; k < setCount; k++) + barSeries.remove(barSeries.at(0)); + + compare(barSeries.count, 0); + compare(removedSpy.count, setCount); + } + + // Not a test function, used by one or more test functions + function append(setCount, valueCount) { + for (var i = 0; i < setCount; i++) { + var values = []; + for (var j = 0; j < valueCount; j++) + values[j] = Math.random() * 10; + barSeries.append("barset" + i, values); + } + } + } + + ChartView { + id: chartView + anchors.fill: parent + + BarSeries { + id: barSeries + name: "bar" + axisX: BarCategoryAxis {} + axisY: ValueAxis { min: 0; max: 10 } + + SignalSpy { + id: addedSpy + target: barSeries + signalName: "barsetsAdded" + } + SignalSpy { + id: removedSpy + target: barSeries + signalName: "barsetsRemoved" + } + } + + StackedBarSeries { + id: stackedBarSeries + name: "stackedBar" + } + + PercentBarSeries { + id: percentBarSeries + name: "percentBar" + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_boxplotseries.qml b/tests/auto/qml-qtquicktest/tst_boxplotseries.qml index 56eba68..7a991a6 100644 --- a/tests/auto/qml-qtquicktest/tst_boxplotseries.qml +++ b/tests/auto/qml-qtquicktest/tst_boxplotseries.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 @@ -33,12 +33,14 @@ Rectangle { function test_properties() { compare(boxPlotSeries.boxWidth, 0.5); + compare(boxPlotSeries.brushFilename, ""); } function test_setproperties() { var set = boxPlotSeries.append("boxplot", [1, 2, 5, 6, 8]); compare(set.label, "boxplot"); compare(set.count, 5); + compare(set.brushFilename, ""); } function test_append() { diff --git a/tests/auto/qml-qtquicktest/tst_boxplotseries_1_3.qml b/tests/auto/qml-qtquicktest/tst_boxplotseries_1_3.qml new file mode 100644 index 0000000..28ae66f --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_boxplotseries_1_3.qml @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest BoxPlotSeries 1.3" + when: windowShown + + function test_properties() { + compare(boxPlotSeries.boxWidth, 0.5); + } + + function test_setproperties() { + var set = boxPlotSeries.append("boxplot", [1, 2, 5, 6, 8]); + compare(set.label, "boxplot"); + compare(set.count, 5); + } + + function test_append() { + addedSpy.clear(); + countChangedSpy.clear(); + var count = 50; + for (var i = 0; i < count; i++) + boxPlotSeries.append("boxplot" + i, Math.random()); + compare(addedSpy.count, count); + compare(countChangedSpy.count, count); + console.log("Check the series count once QTRD-2504 is implemented"); + boxPlotSeries.clear(); + } + + function test_remove() { + removedSpy.clear(); + countChangedSpy.clear(); + var count = 50; + for (var i = 0; i < count; i++) + boxPlotSeries.append("boxplot" + i, Math.random()); + for (var j = 0; j < count; j++) + boxPlotSeries.remove(boxPlotSeries.at(0)); + compare(removedSpy.count, count); + compare(countChangedSpy.count, 2 * count); + console.log("Check the series count once QTRD-2504 is implemented"); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + BoxPlotSeries { + id: boxPlotSeries + name: "boxplot" + BoxSet { label: "Jan"; values: [3, 4, 5.1, 6.2, 8.5] } + + SignalSpy { + id: addedSpy + target: boxPlotSeries + signalName: "boxsetsAdded" + } + SignalSpy { + id: removedSpy + target: boxPlotSeries + signalName: "boxsetsRemoved" + } + SignalSpy { + id: countChangedSpy + target: boxPlotSeries + signalName: "countChanged" + } + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_categoryaxis.qml b/tests/auto/qml-qtquicktest/tst_categoryaxis.qml index a5b2f96..15da082 100644 --- a/tests/auto/qml-qtquicktest/tst_categoryaxis.qml +++ b/tests/auto/qml-qtquicktest/tst_categoryaxis.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 diff --git a/tests/auto/qml-qtquicktest/tst_categoryaxis_1_3.qml b/tests/auto/qml-qtquicktest/tst_categoryaxis_1_3.qml new file mode 100644 index 0000000..febf63f --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_categoryaxis_1_3.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest CategoryAxis 1.3" + when: windowShown + + function test_minMax() { + compare(lineSeries1.axisX.min, 0, "AxisX min"); + compare(lineSeries1.axisX.max, 10, "AxisX max"); + compare(lineSeries1.axisY.min, 0, "AxisY min"); + compare(lineSeries1.axisY.max, 10, "AxisY max"); + } + + function test_categories() { + compare(lineSeries1.axisY.startValue, 0, "AxisY start value"); + compare(lineSeries1.axisY.count, 3, "AxisY count"); + compare(lineSeries1.axisY.categoriesLabels[0], "label0", "AxisY categories labels"); + compare(lineSeries1.axisY.categoriesLabels[1], "label1", "AxisY categories labels"); + compare(lineSeries1.axisY.categoriesLabels[2], "label2", "AxisY categories labels"); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + LineSeries { + id: lineSeries1 + axisX: ValuesAxis { + id: axisX + min: 0 + max: 10 + } + axisY: CategoryAxis { + id: axisY + min: 0 + max: 10 + startValue: 0 + CategoryRange { + label: "label0" + endValue: 1 + } + CategoryRange { + label: "label1" + endValue: 3 + } + CategoryRange { + label: "label2" + endValue: 10 + } + } + XYPoint { x: -1; y: -1 } + XYPoint { x: 0; y: 0 } + XYPoint { x: 5; y: 5 } + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_chartview.qml b/tests/auto/qml-qtquicktest/tst_chartview.qml index bcfb605..2e3a8b3 100644 --- a/tests/auto/qml-qtquicktest/tst_chartview.qml +++ b/tests/auto/qml-qtquicktest/tst_chartview.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 diff --git a/tests/auto/qml-qtquicktest/tst_chartview_1_3.qml b/tests/auto/qml-qtquicktest/tst_chartview_1_3.qml new file mode 100644 index 0000000..ca38b3e --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_chartview_1_3.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest ChartView Properties 1.3" + when: windowShown + + function test_chartViewProperties() { + compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions"); + verify(chartView.backgroundColor != undefined); + verify(chartView.margins.bottom > 0, "ChartView.margins.bottom"); + verify(chartView.margins.top > 0, "ChartView.margins.top"); + verify(chartView.margins.left > 0, "ChartView.margins.left"); + verify(chartView.margins.right > 0, "ChartView.margins.right"); + compare(chartView.count, 0, "ChartView.count"); + compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled"); + verify(chartView.plotArea.height > 0, "ChartView.plotArea.height"); + verify(chartView.plotArea.width > 0, "ChartView.plotArea.width"); + verify(chartView.plotArea.x > 0, "ChartView.plotArea.x"); + verify(chartView.plotArea.y > 0, "ChartView.plotArea.y"); + compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme"); + compare(chartView.title, "", "ChartView.title"); + compare(chartView.title, "", "ChartView.title"); + verify(chartView.titleColor != undefined, "ChartView.titleColor"); + compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold"); + // Legend + compare(chartView.legend.visible, true, "ChartView.legend.visible"); + compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment"); + compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible"); + verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor"); + verify(chartView.legend.color != undefined, "ChartView.legend.color"); + compare(chartView.legend.reverseMarkers, false, "ChartView.legend.reverseMarkers"); + // Legend font + compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold"); + compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization"); + verify(chartView.legend.font.family != "", "ChartView.legend.font.family"); + compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic"); + compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing"); + verify(chartView.legend.font.pixelSize > 0 + && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize"); + verify(chartView.legend.font.pointSize > 0 + && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize"); + compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout"); + compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline"); + compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight"); + compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing"); + } + } + + ChartView { + id: chartView + anchors.fill: parent + } +} diff --git a/tests/auto/qml-qtquicktest/tst_chartviewfunctions.qml b/tests/auto/qml-qtquicktest/tst_chartviewfunctions.qml index 2f20211..8c829e1 100644 --- a/tests/auto/qml-qtquicktest/tst_chartviewfunctions.qml +++ b/tests/auto/qml-qtquicktest/tst_chartviewfunctions.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 diff --git a/tests/auto/qml-qtquicktest/tst_chartviewfunctions_1_3.qml b/tests/auto/qml-qtquicktest/tst_chartviewfunctions_1_3.qml new file mode 100644 index 0000000..16e60cd --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_chartviewfunctions_1_3.qml @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest ChartView Functions 1.3" + when: windowShown + + function test_chartViewSeriesAndAxes() { + // Create XY series + var line = chartView.createSeries(ChartView.SeriesTypeLine, "line"); + verify(line != null && line != undefined); + var spline = chartView.createSeries(ChartView.SeriesTypeSpline, "spline"); + verify(spline != null && spline != undefined); + var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter"); + verify(scatter != null && scatter != undefined); + + // Create a series with specific axes + var line2 = chartView.createSeries(ChartView.SeriesTypeLine, "line2", chartView.axisX(line), chartView.axisY(line)); + + // Check that all the XY series use the same axes + verify(chartView.axisX(line) != null); + verify(chartView.axisY(line) != null); + compare(chartView.axisX(line), chartView.axisX(line2)); + compare(chartView.axisY(line), chartView.axisY(line2)); + compare(chartView.axisX(line), chartView.axisX(spline)); + compare(chartView.axisY(line), chartView.axisY(spline)); + compare(chartView.axisX(line), chartView.axisX(scatter)); + compare(chartView.axisY(line), chartView.axisY(scatter)); + + var bar = chartView.createSeries(ChartView.SeriesTypeBar, "bar"); + verify(bar != null && bar != undefined); + var stackedbar = chartView.createSeries(ChartView.SeriesTypeStackedBar, "stackedbar"); + verify(stackedbar != null && stackedbar != undefined); + var percentbar = chartView.createSeries(ChartView.SeriesTypePercentBar, "percentbar"); + verify(percentbar != null && percentbar != undefined); + var horizontalbar = chartView.createSeries(ChartView.SeriesTypeHorizontalBar, "horizontalbar"); + verify(horizontalbar != null && horizontalbar != undefined); + var horizontalstackedbar = chartView.createSeries(ChartView.SeriesTypeHorizontalStackedBar, "horizontalstackedbar"); + verify(horizontalstackedbar != null && horizontalstackedbar != undefined); + var horizontalpercentbar = chartView.createSeries(ChartView.SeriesTypeHorizontalPercentBar, "horizontalpercentbar"); + verify(horizontalpercentbar != null && horizontalpercentbar != undefined); + var area = chartView.createSeries(ChartView.SeriesTypeArea, "area"); + verify(area != null && area != undefined); + + // Remove all series + chartView.removeAllSeries(); + compare(chartView.count, 0); + } + + function test_chartViewRange() { + // Set initial values + chartView.createSeries(ChartView.SeriesTypeLine, "line"); + verify(chartView.axisX() != null); + verify(chartView.axisY() != null); + chartView.axisX().min = 1.0; + chartView.axisX().max = 2.0; + chartView.axisY().min = 1.0; + chartView.axisY().max = 2.0; + + var xMax = chartView.axisX().max; + var xMin = chartView.axisX().min; + var yMax = chartView.axisY().max; + var yMin = chartView.axisY().min; + + // zoom x 2.5 + chartView.zoom(1.5); + verify(chartView.axisX().max < xMax); + verify(chartView.axisX().min > xMin); + verify(chartView.axisY().max < yMax); + verify(chartView.axisY().min > yMin); + xMax = chartView.axisX().max; + xMin = chartView.axisX().min; + yMax = chartView.axisY().max; + yMin = chartView.axisY().min; + + // zoom x 0.5 + chartView.zoom(0.5); + verify(chartView.axisX().max > xMax); + verify(chartView.axisX().min < xMin); + verify(chartView.axisY().max > yMax); + verify(chartView.axisY().min < yMin); + xMax = chartView.axisX().max; + xMin = chartView.axisX().min; + yMax = chartView.axisY().max; + yMin = chartView.axisY().min; + + // Scroll up + chartView.scrollUp(10); + compare(chartView.axisX().max, xMax); + compare(chartView.axisX().min, xMin); + verify(chartView.axisY().max > yMax); + verify(chartView.axisY().min > yMin); + xMax = chartView.axisX().max; + xMin = chartView.axisX().min; + yMax = chartView.axisY().max; + yMin = chartView.axisY().min; + + // Scroll down + chartView.scrollDown(10); + compare(chartView.axisX().max, xMax); + compare(chartView.axisX().min, xMin); + verify(chartView.axisY().max < yMax); + verify(chartView.axisY().min < yMin); + xMax = chartView.axisX().max; + xMin = chartView.axisX().min; + yMax = chartView.axisY().max; + yMin = chartView.axisY().min; + + // Scroll left + chartView.scrollLeft(10); + verify(chartView.axisX().max < xMax); + verify(chartView.axisX().min < xMin); + compare(chartView.axisY().max, yMax); + compare(chartView.axisY().min, yMin); + xMax = chartView.axisX().max; + xMin = chartView.axisX().min; + yMax = chartView.axisY().max; + yMin = chartView.axisY().min; + + // Scroll right + chartView.scrollRight(10); + verify(chartView.axisX().max > xMax); + verify(chartView.axisX().min > xMin); + compare(chartView.axisY().max, yMax); + compare(chartView.axisY().min, yMin); + } + } + + ChartView { + id: chartView + anchors.fill: parent + title: "Chart" + } +} diff --git a/tests/auto/qml-qtquicktest/tst_chartviewsignals.qml b/tests/auto/qml-qtquicktest/tst_chartviewsignals.qml index f4f3156..5fd1ce9 100644 --- a/tests/auto/qml-qtquicktest/tst_chartviewsignals.qml +++ b/tests/auto/qml-qtquicktest/tst_chartviewsignals.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 diff --git a/tests/auto/qml-qtquicktest/tst_chartviewsignals_1_3.qml b/tests/auto/qml-qtquicktest/tst_chartviewsignals_1_3.qml new file mode 100644 index 0000000..ba1532f --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_chartviewsignals_1_3.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest ChartView Signals 1.3" + when: windowShown + + // Verify onSeriesAdded and onSeriesRemoved signals + function test_chartView() { + var series = chartView.createSeries(ChartView.SeriesTypeLine, "line"); + seriesAddedSpy.wait(); + compare(seriesAddedSpy.count, 1, "ChartView.onSeriesAdded"); + + // Modifying layout triggers more than one plotAreaChanged signal + chartView.titleFont.pixelSize = 50; + verify(plotAreaChangedSpy.count > 0, "ChartView.onPlotAreaChanged"); + + chartView.removeSeries(series); + seriesRemovedSpy.wait(); + compare(seriesRemovedSpy.count, 1, "ChartView.onSeriesAdded"); + } + } + + ChartView { + id: chartView + anchors.fill: parent + title: "Chart" + + SignalSpy { + id: plotAreaChangedSpy + target: chartView + signalName: "plotAreaChanged" + } + + SignalSpy { + id: seriesAddedSpy + target: chartView + signalName: "seriesAdded" + } + + SignalSpy { + id: seriesRemovedSpy + target: chartView + signalName: "seriesRemoved" + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_pieseries.qml b/tests/auto/qml-qtquicktest/tst_pieseries.qml index e6dc6de..1471349 100644 --- a/tests/auto/qml-qtquicktest/tst_pieseries.qml +++ b/tests/auto/qml-qtquicktest/tst_pieseries.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 @@ -58,6 +58,7 @@ Rectangle { compare(slice.percentage, 1.0); compare(slice.startAngle, 0.0); compare(slice.value, 10.0); + compare(slice.brushFilename, ""); } function test_append() { @@ -88,12 +89,15 @@ Rectangle { compare(pieSeries.count, 0); } - function test_find() { + function test_find_and_at() { var count = 50; for (var i = 0; i < count; i++) pieSeries.append("slice" + i, Math.random()); - for (var j = 0; j < count; j++) + for (var j = 0; j < count; j++) { compare(pieSeries.find("slice" + j).label, "slice" + j); + compare(pieSeries.find("slice" + j).brushFilename, ""); + } + compare(pieSeries.at(3).brushFilename,""); pieSeries.clear(); } } diff --git a/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml b/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml new file mode 100644 index 0000000..a44a83a --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_pieseries_1_3.qml @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest PieSeries 1.3" + when: windowShown + + function test_properties() { + compare(pieSeries.endAngle, 360); + compare(pieSeries.holeSize, 0); + compare(pieSeries.horizontalPosition, 0.5); + compare(pieSeries.size, 0.7); + compare(pieSeries.startAngle, 0); + compare(pieSeries.sum, 0); + compare(pieSeries.verticalPosition, 0.5); + } + + function test_sliceproperties() { + var slice = pieSeries.append("slice", 10); + compare(slice.angleSpan, 360.0); + verify(slice.borderColor != undefined); + compare(slice.borderWidth, 1); + verify(slice.color != undefined); + compare(slice.explodeDistanceFactor, 0.15); + compare(slice.exploded, false); + compare(slice.label, "slice"); + compare(slice.labelArmLengthFactor, 0.15); + verify(slice.labelColor != undefined); + compare(slice.labelFont.bold, false); + compare(slice.labelPosition, PieSlice.LabelOutside); + compare(slice.labelVisible, false); + compare(slice.percentage, 1.0); + compare(slice.startAngle, 0.0); + compare(slice.value, 10.0); + } + + function test_append() { + addedSpy.clear(); + countChangedSpy.clear(); + sumChangedSpy.clear(); + var count = 50; + for (var i = 0; i < count; i++) + pieSeries.append("slice" + i, Math.random()); + compare(addedSpy.count, count); + compare(countChangedSpy.count, count); + compare(sumChangedSpy.count, count); + pieSeries.clear(); + } + + function test_remove() { + removedSpy.clear(); + countChangedSpy.clear(); + sumChangedSpy.clear(); + var count = 50; + for (var i = 0; i < count; i++) + pieSeries.append("slice" + i, Math.random()); + for (var j = 0; j < count; j++) + pieSeries.remove(pieSeries.at(0)); + compare(removedSpy.count, count); + compare(countChangedSpy.count, 2 * count); + compare(sumChangedSpy.count, 2 * count); + compare(pieSeries.count, 0); + } + + function test_find() { + var count = 50; + for (var i = 0; i < count; i++) + pieSeries.append("slice" + i, Math.random()); + for (var j = 0; j < count; j++) + compare(pieSeries.find("slice" + j).label, "slice" + j); + pieSeries.clear(); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + PieSeries { + id: pieSeries + name: "pie" + + SignalSpy { + id: addedSpy + target: pieSeries + signalName: "added" + } + SignalSpy { + id: removedSpy + target: pieSeries + signalName: "removed" + } + SignalSpy { + id: sumChangedSpy + target: pieSeries + signalName: "sumChanged" + } + SignalSpy { + id: countChangedSpy + target: pieSeries + signalName: "countChanged" + } + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_valueaxis.qml b/tests/auto/qml-qtquicktest/tst_valueaxis.qml index 747c243..56b8183 100644 --- a/tests/auto/qml-qtquicktest/tst_valueaxis.qml +++ b/tests/auto/qml-qtquicktest/tst_valueaxis.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 diff --git a/tests/auto/qml-qtquicktest/tst_valueaxis_1_3.qml b/tests/auto/qml-qtquicktest/tst_valueaxis_1_3.qml new file mode 100644 index 0000000..24bffeb --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_valueaxis_1_3.qml @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest ValueAxis 1.3" + when: windowShown + + // test functions are run in alphabetical order, the name has 'a' so that it + // will be the first function to execute. + function test_a_properties() { + // Default properties + verify(axisX.min < 0, "AxisX min"); + verify(axisX.max > 0, "AxisX max"); + verify(axisY.min < 0, "AxisY min"); + verify(axisY.max > 0, "AxisY max"); + verify(axisX.tickCount == 5, "AxisX tick count"); + verify(axisY.tickCount == 5, "AxisY tick count"); + verify(axisX.labelFormat == "", "label format"); + + // Modify properties + axisX.tickCount = 3; + verify(axisX.tickCount == 3, "set tick count"); + } + + function test_functions() { + // Set the axis ranges to not "nice" ones... + var min = 0.032456456; + var max = 10.67845634; + axisX.min = min; + axisX.max = max; + axisY.min = min; + axisY.max = max; + + // ...And then apply nice numbers and verify the range was changed + axisX.applyNiceNumbers(); + axisY.applyNiceNumbers(); + verify(axisX.min != min); + verify(axisX.max != max); + verify(axisY.min != min); + verify(axisY.max != max); + } + + function test_signals() { + minChangedSpy.clear(); + maxChangedSpy.clear(); + axisX.min = 2; + compare(minChangedSpy.count, 1, "onMinChanged"); + compare(maxChangedSpy.count, 0, "onMaxChanged"); + + axisX.max = 8; + compare(minChangedSpy.count, 1, "onMinChanged"); + compare(maxChangedSpy.count, 1, "onMaxChanged"); + + // restore original values + axisX.min = 0; + axisX.max = 10; + compare(minChangedSpy.count, 2, "onMinChanged"); + compare(maxChangedSpy.count, 2, "onMaxChanged"); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + LineSeries { + id: lineSeries1 + axisX: ValueAxis { + id: axisX + } + axisY: ValueAxis { + id: axisY + } + XYPoint { x: -1; y: -1 } + XYPoint { x: 0; y: 0 } + XYPoint { x: 5; y: 5 } + } + + SignalSpy { + id: minChangedSpy + target: axisX + signalName: "minChanged" + } + SignalSpy { + id: maxChangedSpy + target: axisX + signalName: "maxChanged" + } + } +} diff --git a/tests/auto/qml-qtquicktest/tst_xyseries.qml b/tests/auto/qml-qtquicktest/tst_xyseries.qml index 4b57f31..4fef265 100644 --- a/tests/auto/qml-qtquicktest/tst_xyseries.qml +++ b/tests/auto/qml-qtquicktest/tst_xyseries.qml @@ -20,7 +20,7 @@ import QtQuick 2.0 import QtTest 1.0 -import QtCommercial.Chart 1.3 +import QtCommercial.Chart 1.4 Rectangle { width: 400 @@ -49,10 +49,12 @@ Rectangle { compare(scatterSeries.borderWidth, 2.0); compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle); compare(scatterSeries.markerSize, 15.0); + compare(scatterSeries.brushFilename, ""); verify(areaSeries.color != undefined); verify(areaSeries.borderColor != undefined); compare(areaSeries.borderWidth, 2.0); + compare(areaSeries.brushFilename, ""); } function test_axes() { diff --git a/tests/auto/qml-qtquicktest/tst_xyseries_1_3.qml b/tests/auto/qml-qtquicktest/tst_xyseries_1_3.qml new file mode 100644 index 0000000..144978c --- /dev/null +++ b/tests/auto/qml-qtquicktest/tst_xyseries_1_3.qml @@ -0,0 +1,260 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 Enterprise Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise 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 2.0 +import QtTest 1.0 +import QtCommercial.Chart 1.3 + +Rectangle { + width: 400 + height: 300 + + TestCase { + id: tc1 + name: "tst_qml-qtquicktest XY Series 1.3" + when: windowShown + + function test_properties() { + verify(lineSeries.color != undefined); + compare(lineSeries.pointsVisible, false); + compare(lineSeries.capStyle, Qt.SquareCap); + compare(lineSeries.style, Qt.SolidLine); + compare(lineSeries.width, 2.0); + + verify(splineSeries.color != undefined); + compare(splineSeries.pointsVisible, false); + compare(splineSeries.capStyle, Qt.SquareCap); + compare(splineSeries.style, Qt.SolidLine); + compare(splineSeries.width, 2.0); + + verify(scatterSeries.color != undefined); + verify(scatterSeries.borderColor != undefined); + compare(scatterSeries.borderWidth, 2.0); + compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle); + compare(scatterSeries.markerSize, 15.0); + + verify(areaSeries.color != undefined); + verify(areaSeries.borderColor != undefined); + compare(areaSeries.borderWidth, 2.0); + } + + function test_axes() { + // Axis initialization + compare(chartView.axisX(), lineSeries.axisX); + compare(chartView.axisY(), lineSeries.axisY); + compare(lineSeries.axisX, splineSeries.axisX); + compare(lineSeries.axisY, splineSeries.axisY); + compare(lineSeries.axisX, areaSeries.axisX); + compare(lineSeries.axisY, areaSeries.axisY); + } + + function test_append() { + lineSeriesPointAddedSpy.clear(); + splineSeriesPointAddedSpy.clear(); + scatterSeriesPointAddedSpy.clear(); + var count = append(); + compare(lineSeries.count, count); + compare(splineSeries.count, count); + compare(scatterSeries.count, count); + compare(lineSeriesPointAddedSpy.count, count); + compare(splineSeriesPointAddedSpy.count, count); + compare(scatterSeriesPointAddedSpy.count, count); + clear(); + compare(lineSeries.count, 0); + compare(splineSeries.count, 0); + compare(scatterSeries.count, 0); + } + + function test_replace() { + var count = append(); + for (var i = 0; i < count; i++) { + lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random()); + splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random()); + scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random()); + } + compare(lineSeries.count, count); + compare(splineSeries.count, count); + compare(scatterSeries.count, count); + compare(lineSeriesPointReplacedSpy.count, count); + compare(splineSeriesPointReplacedSpy.count, count); + compare(scatterSeriesPointReplacedSpy.count, count); + clear(); + } + + function test_insert() { + var count = append(); + lineSeriesPointAddedSpy.clear(); + splineSeriesPointAddedSpy.clear(); + scatterSeriesPointAddedSpy.clear(); + for (var i = 0; i < count; i++) { + lineSeries.insert(i * 2, i, Math.random()); + splineSeries.insert(i * 2, i, Math.random()); + scatterSeries.insert(i * 2, i, Math.random()); + } + compare(lineSeries.count, count * 2); + compare(splineSeries.count, count * 2); + compare(scatterSeries.count, count * 2); + compare(lineSeriesPointAddedSpy.count, count); + compare(splineSeriesPointAddedSpy.count, count); + compare(scatterSeriesPointAddedSpy.count, count); + clear(); + } + + function test_remove() { + lineSeriesPointRemovedSpy.clear(); + splineSeriesPointRemovedSpy.clear(); + scatterSeriesPointRemovedSpy.clear(); + var count = append(); + for (var i = 0; i < count; i++) { + lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y); + splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y); + scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y); + } + compare(lineSeries.count, 0); + compare(splineSeries.count, 0); + compare(scatterSeries.count, 0); + compare(lineSeriesPointRemovedSpy.count, count); + compare(splineSeriesPointRemovedSpy.count, count); + compare(scatterSeriesPointRemovedSpy.count, count); + } + + // Not a test function, called from test functions + function append() { + var count = 100; + chartView.axisX().min = 0; + chartView.axisX().max = 100; + chartView.axisY().min = 0; + chartView.axisY().max = 1; + + for (var i = 0; i < count; i++) { + lineSeries.append(i, Math.random()); + splineSeries.append(i, Math.random()); + scatterSeries.append(i, Math.random()); + } + + return count; + } + + // Not a test function, called from test functions + function clear() { + lineSeries.clear(); + splineSeries.clear(); + scatterSeries.clear(); + } + } + + ChartView { + id: chartView + anchors.fill: parent + + LineSeries { + id: lineSeries + name: "line" + + SignalSpy { + id: lineSeriesPointAddedSpy + target: lineSeries + signalName: "pointAdded" + } + + SignalSpy { + id: lineSeriesPointReplacedSpy + target: lineSeries + signalName: "pointReplaced" + } + + SignalSpy { + id: lineSeriesPointsReplacedSpy + target: lineSeries + signalName: "pointsReplaced" + } + + SignalSpy { + id: lineSeriesPointRemovedSpy + target: lineSeries + signalName: "pointRemoved" + } + } + + AreaSeries { + id: areaSeries + name: "area" + upperSeries: lineSeries + } + + SplineSeries { + id: splineSeries + name: "spline" + + SignalSpy { + id: splineSeriesPointAddedSpy + target: splineSeries + signalName: "pointAdded" + } + + SignalSpy { + id: splineSeriesPointReplacedSpy + target: splineSeries + signalName: "pointReplaced" + } + + SignalSpy { + id: splineSeriesPointsReplacedSpy + target: splineSeries + signalName: "pointsReplaced" + } + + SignalSpy { + id: splineSeriesPointRemovedSpy + target: splineSeries + signalName: "pointRemoved" + } + } + + ScatterSeries { + id: scatterSeries + name: "scatter" + + SignalSpy { + id: scatterSeriesPointAddedSpy + target: scatterSeries + signalName: "pointAdded" + } + + SignalSpy { + id: scatterSeriesPointReplacedSpy + target: scatterSeries + signalName: "pointReplaced" + } + + SignalSpy { + id: scatterSeriesPointsReplacedSpy + target: scatterSeries + signalName: "pointsReplaced" + } + + SignalSpy { + id: scatterSeriesPointRemovedSpy + target: scatterSeries + signalName: "pointRemoved" + } + } + } +}