@@ -0,0 +1,87 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtQuickTest 1.0 | |
|
23 | import QtCommercial.Chart 1.2 | |
|
24 | ||
|
25 | Rectangle { | |
|
26 | width: 400 | |
|
27 | height: 300 | |
|
28 | ||
|
29 | TestCase { | |
|
30 | id: tc1 | |
|
31 | name: "tst_qml-qtquicktest BarCategoryAxis" | |
|
32 | when: windowShown | |
|
33 | ||
|
34 | function test_minMax() { | |
|
35 | compare(barSeries1.axisX.min, "Jan", "AxisX min"); | |
|
36 | compare(barSeries1.axisX.max, "Jun", "AxisX max"); | |
|
37 | compare(barSeries1.axisY.min, 0, "AxisY min"); | |
|
38 | compare(barSeries1.axisY.max, 10, "AxisY max"); | |
|
39 | } | |
|
40 | ||
|
41 | function test_categories() { | |
|
42 | compare(barSeries1.axisX.count, 6, "AxisX count"); | |
|
43 | ||
|
44 | // Replace categories | |
|
45 | var cat = barSeries1.axisX.categories; | |
|
46 | barSeries1.axisX.categories = ["Tam", "Hel", "Maa", "Huh"]; | |
|
47 | compare(barSeries1.axisX.count, 4, "AxisX count"); | |
|
48 | compare(categoriesCountChangedSpy.count, 1, "onCountChanged"); | |
|
49 | compare(categoriesChangedSpy.count, 1, "onCategoriesChanged"); | |
|
50 | ||
|
51 | // Reset the original categories | |
|
52 | barSeries1.axisX.categories = cat; | |
|
53 | compare(barSeries1.axisX.count, 6, "AxisX count"); | |
|
54 | compare(categoriesCountChangedSpy.count, 2, "onCountChanged"); | |
|
55 | compare(categoriesChangedSpy.count, 2, "onCategoriesChanged"); | |
|
56 | } | |
|
57 | } | |
|
58 | ||
|
59 | ChartView { | |
|
60 | id: chartView | |
|
61 | anchors.fill: parent | |
|
62 | ||
|
63 | BarSeries { | |
|
64 | id: barSeries1 | |
|
65 | axisX: BarCategoryAxis { | |
|
66 | id: axisX | |
|
67 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
|
68 | } | |
|
69 | axisY: ValuesAxis { | |
|
70 | id: axisY | |
|
71 | min: 0 | |
|
72 | max: 10 | |
|
73 | } | |
|
74 | } | |
|
75 | ||
|
76 | SignalSpy { | |
|
77 | id: categoriesCountChangedSpy | |
|
78 | target: axisX | |
|
79 | signalName: "countChanged" | |
|
80 | } | |
|
81 | SignalSpy { | |
|
82 | id: categoriesChangedSpy | |
|
83 | target: axisX | |
|
84 | signalName: "categoriesChanged" | |
|
85 | } | |
|
86 | } | |
|
87 | } |
@@ -0,0 +1,87 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtQuickTest 1.0 | |
|
23 | import QtCommercial.Chart 1.1 | |
|
24 | ||
|
25 | Rectangle { | |
|
26 | width: 400 | |
|
27 | height: 300 | |
|
28 | ||
|
29 | TestCase { | |
|
30 | id: tc1 | |
|
31 | name: "tst_qml-qtquicktest BarCategoryAxis 1.1" | |
|
32 | when: windowShown | |
|
33 | ||
|
34 | function test_minMax() { | |
|
35 | compare(barSeries1.axisX.min, "Jan", "AxisX min"); | |
|
36 | compare(barSeries1.axisX.max, "Jun", "AxisX max"); | |
|
37 | compare(barSeries1.axisY.min, 0, "AxisY min"); | |
|
38 | compare(barSeries1.axisY.max, 10, "AxisY max"); | |
|
39 | } | |
|
40 | ||
|
41 | function test_categories() { | |
|
42 | compare(barSeries1.axisX.count, 6, "AxisX count"); | |
|
43 | ||
|
44 | // Replace categories | |
|
45 | var cat = barSeries1.axisX.categories; | |
|
46 | barSeries1.axisX.categories = ["Tam", "Hel", "Maa", "Huh"]; | |
|
47 | compare(barSeries1.axisX.count, 4, "AxisX count"); | |
|
48 | compare(categoriesCountChangedSpy.count, 1, "onCountChanged"); | |
|
49 | compare(categoriesChangedSpy.count, 1, "onCategoriesChanged"); | |
|
50 | ||
|
51 | // Reset the original categories | |
|
52 | barSeries1.axisX.categories = cat; | |
|
53 | compare(barSeries1.axisX.count, 6, "AxisX count"); | |
|
54 | compare(categoriesCountChangedSpy.count, 2, "onCountChanged"); | |
|
55 | compare(categoriesChangedSpy.count, 2, "onCategoriesChanged"); | |
|
56 | } | |
|
57 | } | |
|
58 | ||
|
59 | ChartView { | |
|
60 | id: chartView | |
|
61 | anchors.fill: parent | |
|
62 | ||
|
63 | BarSeries { | |
|
64 | id: barSeries1 | |
|
65 | axisX: BarCategoryAxis { | |
|
66 | id: axisX | |
|
67 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
|
68 | } | |
|
69 | axisY: ValuesAxis { | |
|
70 | id: axisY | |
|
71 | min: 0 | |
|
72 | max: 10 | |
|
73 | } | |
|
74 | } | |
|
75 | ||
|
76 | SignalSpy { | |
|
77 | id: categoriesCountChangedSpy | |
|
78 | target: axisX | |
|
79 | signalName: "countChanged" | |
|
80 | } | |
|
81 | SignalSpy { | |
|
82 | id: categoriesChangedSpy | |
|
83 | target: axisX | |
|
84 | signalName: "categoriesChanged" | |
|
85 | } | |
|
86 | } | |
|
87 | } |
@@ -0,0 +1,84 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtQuickTest 1.0 | |
|
23 | import QtCommercial.Chart 1.1 | |
|
24 | ||
|
25 | Rectangle { | |
|
26 | width: 400 | |
|
27 | height: 300 | |
|
28 | ||
|
29 | TestCase { | |
|
30 | id: tc1 | |
|
31 | name: "tst_qml-qtquicktest CategoryAxis 1.1" | |
|
32 | when: windowShown | |
|
33 | ||
|
34 | function test_minMax() { | |
|
35 | compare(lineSeries1.axisX.min, 0, "AxisX min"); | |
|
36 | compare(lineSeries1.axisX.max, 10, "AxisX max"); | |
|
37 | compare(lineSeries1.axisY.min, 0, "AxisY min"); | |
|
38 | compare(lineSeries1.axisY.max, 10, "AxisY max"); | |
|
39 | } | |
|
40 | ||
|
41 | function test_categories() { | |
|
42 | compare(lineSeries1.axisY.startValue, 0, "AxisY start value"); | |
|
43 | compare(lineSeries1.axisY.count, 3, "AxisY count"); | |
|
44 | compare(lineSeries1.axisY.categoriesLabels[0], "label0", "AxisY categories labels"); | |
|
45 | compare(lineSeries1.axisY.categoriesLabels[1], "label1", "AxisY categories labels"); | |
|
46 | compare(lineSeries1.axisY.categoriesLabels[2], "label2", "AxisY categories labels"); | |
|
47 | } | |
|
48 | } | |
|
49 | ||
|
50 | ChartView { | |
|
51 | id: chartView | |
|
52 | anchors.fill: parent | |
|
53 | ||
|
54 | LineSeries { | |
|
55 | id: lineSeries1 | |
|
56 | axisX: ValuesAxis { | |
|
57 | id: axisX | |
|
58 | min: 0 | |
|
59 | max: 10 | |
|
60 | } | |
|
61 | axisY: CategoryAxis { | |
|
62 | id: axisY | |
|
63 | min: 0 | |
|
64 | max: 10 | |
|
65 | startValue: 0 | |
|
66 | CategoryRange { | |
|
67 | label: "label0" | |
|
68 | endValue: 1 | |
|
69 | } | |
|
70 | CategoryRange { | |
|
71 | label: "label1" | |
|
72 | endValue: 3 | |
|
73 | } | |
|
74 | CategoryRange { | |
|
75 | label: "label2" | |
|
76 | endValue: 10 | |
|
77 | } | |
|
78 | } | |
|
79 | XYPoint { x: -1; y: -1 } | |
|
80 | XYPoint { x: 0; y: 0 } | |
|
81 | XYPoint { x: 5; y: 5 } | |
|
82 | } | |
|
83 | } | |
|
84 | } |
@@ -0,0 +1,102 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtQuickTest 1.0 | |
|
23 | import QtCommercial.Chart 1.2 | |
|
24 | ||
|
25 | Rectangle { | |
|
26 | width: 400 | |
|
27 | height: 300 | |
|
28 | ||
|
29 | TestCase { | |
|
30 | id: tc1 | |
|
31 | name: "tst_qml-qtquicktest ValueAxis" | |
|
32 | when: windowShown | |
|
33 | ||
|
34 | function test_defaultPropertyValues() { | |
|
35 | compare(lineSeries1.axisX.min, 0, "AxisX min"); | |
|
36 | compare(lineSeries1.axisX.max, 10, "AxisX max"); | |
|
37 | compare(lineSeries1.axisY.min, 0, "AxisY min"); | |
|
38 | compare(lineSeries1.axisY.max, 10, "AxisY max"); | |
|
39 | verify(axisX.tickCount > 0, "AxisX tick count"); | |
|
40 | verify(axisY.tickCount > 0, "AxisX tick count"); | |
|
41 | compare(axisX.niceNumbersEnabled, false, "nice numbers"); | |
|
42 | compare(axisX.labelFormat, "", "label format"); | |
|
43 | } | |
|
44 | ||
|
45 | function test_modifyProperties() { | |
|
46 | lineSeries1.axisX.tickCount = 3; | |
|
47 | compare(lineSeries1.axisX.tickCount, 3, "set tick count"); | |
|
48 | ||
|
49 | lineSeries1.axisX.niceNumbersEnabled = true; | |
|
50 | compare(axisX.niceNumbersEnabled, true, "nice numbers"); | |
|
51 | } | |
|
52 | ||
|
53 | function test_signals() { | |
|
54 | axisX.min = 2; | |
|
55 | compare(minChangedSpy.count, 1, "onMinChanged"); | |
|
56 | compare(maxChangedSpy.count, 0, "onMaxChanged"); | |
|
57 | ||
|
58 | axisX.max = 8; | |
|
59 | compare(minChangedSpy.count, 1, "onMinChanged"); | |
|
60 | compare(maxChangedSpy.count, 1, "onMaxChanged"); | |
|
61 | ||
|
62 | // restore original values | |
|
63 | axisX.min = 0; | |
|
64 | axisX.max = 10; | |
|
65 | compare(minChangedSpy.count, 2, "onMinChanged"); | |
|
66 | compare(maxChangedSpy.count, 2, "onMaxChanged"); | |
|
67 | } | |
|
68 | } | |
|
69 | ||
|
70 | ChartView { | |
|
71 | id: chartView | |
|
72 | anchors.fill: parent | |
|
73 | ||
|
74 | LineSeries { | |
|
75 | id: lineSeries1 | |
|
76 | axisX: ValueAxis { | |
|
77 | id: axisX | |
|
78 | min: 0 | |
|
79 | max: 10 | |
|
80 | } | |
|
81 | axisY: ValueAxis { | |
|
82 | id: axisY | |
|
83 | min: 0 | |
|
84 | max: 10 | |
|
85 | } | |
|
86 | XYPoint { x: -1; y: -1 } | |
|
87 | XYPoint { x: 0; y: 0 } | |
|
88 | XYPoint { x: 5; y: 5 } | |
|
89 | } | |
|
90 | ||
|
91 | SignalSpy { | |
|
92 | id: minChangedSpy | |
|
93 | target: axisX | |
|
94 | signalName: "minChanged" | |
|
95 | } | |
|
96 | SignalSpy { | |
|
97 | id: maxChangedSpy | |
|
98 | target: axisX | |
|
99 | signalName: "maxChanged" | |
|
100 | } | |
|
101 | } | |
|
102 | } |
@@ -1,151 +1,152 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "qabstractaxis.h" |
|
23 | 23 | #include "qvalueaxis.h" |
|
24 | 24 | #include "declarativecategoryaxis.h" |
|
25 | 25 | #include "qbarcategoryaxis.h" |
|
26 | 26 | #include "declarativechart.h" |
|
27 | 27 | #include "declarativexypoint.h" |
|
28 | 28 | #include "declarativelineseries.h" |
|
29 | 29 | #include "declarativesplineseries.h" |
|
30 | 30 | #include "declarativeareaseries.h" |
|
31 | 31 | #include "declarativescatterseries.h" |
|
32 | 32 | #include "declarativebarseries.h" |
|
33 | 33 | #include "declarativepieseries.h" |
|
34 | 34 | #include "qvxymodelmapper.h" |
|
35 | 35 | #include "qhxymodelmapper.h" |
|
36 | 36 | #include "qhpiemodelmapper.h" |
|
37 | 37 | #include "qvpiemodelmapper.h" |
|
38 | 38 | #include "qhbarmodelmapper.h" |
|
39 | 39 | #include "qvbarmodelmapper.h" |
|
40 | 40 | #include "declarativemargins.h" |
|
41 | 41 | #ifndef QT_ON_ARM |
|
42 | 42 | #include "qdatetimeaxis.h" |
|
43 | 43 | #endif |
|
44 | 44 | #include <QAbstractItemModel> |
|
45 | 45 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
46 | 46 | #include <QtDeclarative/qdeclarative.h> |
|
47 | 47 | |
|
48 | 48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
49 | 49 | |
|
50 | 50 | Q_DECLARE_METATYPE(QList<QPieSlice *>) |
|
51 | 51 | Q_DECLARE_METATYPE(QList<QBarSet *>) |
|
52 | 52 | |
|
53 | 53 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
54 | 54 | |
|
55 | 55 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
56 | 56 | { |
|
57 | 57 | Q_OBJECT |
|
58 | 58 | |
|
59 | 59 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
60 | 60 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface") |
|
61 | 61 | #endif |
|
62 | 62 | |
|
63 | 63 | public: |
|
64 | 64 | virtual void registerTypes(const char *uri) |
|
65 | 65 | { |
|
66 | 66 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
67 | 67 | |
|
68 | 68 | qRegisterMetaType<QList<QPieSlice *> >(); |
|
69 | 69 | qRegisterMetaType<QList<QBarSet *> >(); |
|
70 | 70 | |
|
71 | 71 | // QtCommercial.Chart 1.0 |
|
72 | 72 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
73 | 73 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
74 | 74 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
75 | 75 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
76 | 76 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
77 | 77 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
78 | 78 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
79 | 79 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
80 | 80 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
81 | 81 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
82 | 82 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
83 | 83 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
84 | 84 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
85 | 85 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
86 | 86 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
87 | 87 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
88 | 88 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
89 | 89 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
90 | 90 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); |
|
91 | 91 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis"); |
|
92 | 92 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
93 | 93 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
94 | 94 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
95 | 95 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
96 | 96 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
97 | 97 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
98 | 98 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
99 | 99 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
100 | 100 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
101 | 101 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
102 | 102 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
103 | 103 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
104 | 104 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
105 | 105 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
106 | 106 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", |
|
107 | 107 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); |
|
108 | 108 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
109 | 109 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); |
|
110 | 110 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase", |
|
111 | 111 | QLatin1String("Trying to create uncreatable: BarsetBase.")); |
|
112 | 112 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
113 | 113 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); |
|
114 | 114 | |
|
115 | 115 | // QtCommercial.Chart 1.1 |
|
116 | 116 | qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView"); |
|
117 | 117 | qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries"); |
|
118 | 118 | qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries"); |
|
119 | 119 | qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries"); |
|
120 | 120 | qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries"); |
|
121 | 121 | qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries"); |
|
122 | 122 | qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries"); |
|
123 | 123 | qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries"); |
|
124 | 124 | qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries"); |
|
125 | 125 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries"); |
|
126 | 126 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries"); |
|
127 | 127 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries"); |
|
128 | 128 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet"); |
|
129 | qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis"); | |
|
129 | 130 | #ifndef QT_ON_ARM |
|
130 | 131 | qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis"); |
|
131 | 132 | #endif |
|
132 | 133 | qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis"); |
|
133 | 134 | qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange"); |
|
134 | 135 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis"); |
|
135 | 136 | qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins", |
|
136 | 137 | QLatin1String("Trying to create uncreatable: Margins.")); |
|
137 | 138 | |
|
138 | 139 | // QtCommercial.Chart 1.2 |
|
139 | 140 | qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView"); |
|
140 | 141 | } |
|
141 | 142 | }; |
|
142 | 143 | |
|
143 | 144 | #include "plugin.moc" |
|
144 | 145 | |
|
145 | 146 | QTCOMMERCIALCHART_END_NAMESPACE |
|
146 | 147 | |
|
147 | 148 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
148 | 149 | |
|
149 | 150 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) |
|
150 | 151 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
151 | 152 | #endif |
@@ -1,553 +1,577 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarcategoryaxis.h" |
|
22 | 22 | #include "qbarcategoryaxis_p.h" |
|
23 | 23 | #include "chartbarcategoryaxisx_p.h" |
|
24 | 24 | #include "chartbarcategoryaxisy_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | /*! |
|
31 | 31 | \class QBarCategoryAxis |
|
32 | 32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | 36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
37 | 37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
38 | 38 | |
|
39 | 39 | Example code on how to use QBarCategoryAxis. |
|
40 | 40 | \code |
|
41 | 41 | QChartView *chartView = new QChartView; |
|
42 | 42 | QBarSeries *series = new QBarSeries; |
|
43 | 43 | // ... |
|
44 | 44 | chartView->chart()->addSeries(series); |
|
45 | 45 | chartView->chart()->createDefaultAxes(); |
|
46 | 46 | |
|
47 | 47 | QBarCategoryAxis *axisX = new QBarCategoryAxis; |
|
48 | 48 | QStringList categories; |
|
49 | 49 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
50 | 50 | axisX->append(categories); |
|
51 | 51 | axisX->setRange("Feb", "May"); |
|
52 | 52 | chartView->chart()->setAxisX(axisX, series); |
|
53 | 53 | \endcode |
|
54 | 54 | */ |
|
55 | 55 | |
|
56 | 56 | /*! |
|
57 | 57 | \qmlclass BarCategoryAxis QBarCategoryAxis |
|
58 | 58 | \inherits AbstractAxis |
|
59 | 59 | \brief The Axis element is used for manipulating chart's axes. |
|
60 | 60 | |
|
61 | 61 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
62 | 62 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
63 | 63 | |
|
64 | 64 | To access BarCategoryAxis you can use ChartView API. For example: |
|
65 | 65 | \code |
|
66 | 66 | ChartView { |
|
67 | 67 | BarCategoryAxis { |
|
68 | 68 | id: categoryAxis |
|
69 | 69 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
70 | 70 | } |
|
71 | 71 | // Add a few series... |
|
72 | 72 | } |
|
73 | 73 | \endcode |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QBarCategoryAxis::categories |
|
78 | 78 | Defines the categories of axis |
|
79 | 79 | */ |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty QStringList BarCategoryAxis::categories |
|
82 | 82 | Defines the categories of axis |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QBarCategoryAxis::min |
|
87 | 87 | Defines the minimum value on the axis. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty QString BarCategoryAxis::min |
|
91 | 91 | Defines the minimum value on the axis. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QBarCategoryAxis::max |
|
96 | 96 | Defines the maximum value on the axis. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty QString BarCategoryAxis::max |
|
100 | 100 | Defines the maximum value on the axis. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | /*! | |
|
104 | \property QBarCategoryAxis::count | |
|
105 | The count of categories. | |
|
106 | */ | |
|
107 | /*! | |
|
108 | \qmlproperty int BarCategoryAxis::count | |
|
109 | The count of categories. | |
|
110 | */ | |
|
103 | 111 | |
|
104 | 112 | /*! |
|
105 | 113 | \fn void QBarCategoryAxis::categoriesChanged() |
|
106 | 114 | Axis emits signal when the categories of the axis has changed. |
|
107 | 115 | */ |
|
116 | ||
|
108 | 117 | /*! |
|
109 | 118 | \fn void QBarCategoryAxis::minChanged(const QString &min) |
|
110 | 119 | Axis emits signal when \a min of axis has changed. |
|
111 | 120 | */ |
|
112 | 121 | /*! |
|
113 | 122 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) |
|
114 | 123 | Axis emits signal when \a min of axis has changed. |
|
115 | 124 | */ |
|
116 | 125 | |
|
117 | 126 | /*! |
|
118 | 127 | \fn void QBarCategoryAxis::maxChanged(const QString &max) |
|
119 | 128 | Axis emits signal when \a max of axis has changed. |
|
120 | 129 | */ |
|
121 | 130 | /*! |
|
122 | 131 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) |
|
123 | 132 | Axis emits signal when \a max of axis has changed. |
|
124 | 133 | */ |
|
125 | 134 | |
|
126 | 135 | /*! |
|
136 | \fn void QBarCategoryAxis::countChanged() | |
|
137 | Axis emits signal when the count of categories has changed. | |
|
138 | */ | |
|
139 | /*! | |
|
140 | \qmlsignal BarCategoryAxis::onCountChanged() | |
|
141 | Axis emits signal when the count of categories has changed. | |
|
142 | */ | |
|
143 | ||
|
144 | /*! | |
|
127 | 145 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) |
|
128 | 146 | Axis emits signal when \a min or \a max of axis has changed. |
|
129 | 147 | */ |
|
130 | 148 | |
|
131 | 149 | /*! |
|
132 | 150 | Constructs an axis object which is a child of \a parent. |
|
133 | 151 | */ |
|
134 | 152 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): |
|
135 | 153 | QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) |
|
136 | 154 | { |
|
137 | 155 | } |
|
138 | 156 | |
|
139 | 157 | /*! |
|
140 | 158 | Destroys the object |
|
141 | 159 | */ |
|
142 | 160 | QBarCategoryAxis::~QBarCategoryAxis() |
|
143 | 161 | { |
|
144 | 162 | Q_D(QBarCategoryAxis); |
|
145 | 163 | if (d->m_dataset) |
|
146 | 164 | d->m_dataset->removeAxis(this); |
|
147 | 165 | } |
|
148 | 166 | |
|
149 | 167 | /*! |
|
150 | 168 | \internal |
|
151 | 169 | */ |
|
152 | 170 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) |
|
153 | 171 | : QAbstractAxis(d, parent) |
|
154 | 172 | { |
|
155 | 173 | |
|
156 | 174 | } |
|
157 | 175 | |
|
158 | 176 | /*! |
|
159 | 177 | Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. |
|
160 | 178 | If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. |
|
161 | 179 | A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
162 | 180 | */ |
|
163 | 181 | void QBarCategoryAxis::append(const QStringList &categories) |
|
164 | 182 | { |
|
165 | 183 | if (categories.isEmpty()) |
|
166 | 184 | return; |
|
167 | 185 | |
|
168 | 186 | Q_D(QBarCategoryAxis); |
|
169 | 187 | |
|
170 | 188 | int count = d->m_categories.count(); |
|
171 | 189 | |
|
172 | 190 | foreach(QString category, categories) { |
|
173 | 191 | if (!d->m_categories.contains(category) && !category.isNull()) { |
|
174 | 192 | d->m_categories.append(category); |
|
175 | 193 | } |
|
176 | 194 | } |
|
177 | 195 | |
|
178 | 196 | if (d->m_categories.count() == count) |
|
179 | 197 | return; |
|
180 | 198 | |
|
181 | 199 | if (count == 0) |
|
182 | 200 | setRange(d->m_categories.first(), d->m_categories.last()); |
|
183 | 201 | else |
|
184 | 202 | setRange(d->m_minCategory, d->m_categories.last()); |
|
185 | 203 | |
|
186 | 204 | emit categoriesChanged(); |
|
205 | emit countChanged(); | |
|
187 | 206 | } |
|
188 | 207 | |
|
189 | 208 | /*! |
|
190 | 209 | Appends \a category to axis. A maximum of the axis will be changed to last \a category. |
|
191 | 210 | If there were no categories previously defined, minimum of axis will be also changed to \a category. |
|
192 | 211 | A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
193 | 212 | */ |
|
194 | 213 | void QBarCategoryAxis::append(const QString &category) |
|
195 | 214 | { |
|
196 | 215 | Q_D(QBarCategoryAxis); |
|
197 | 216 | |
|
198 | 217 | int count = d->m_categories.count(); |
|
199 | 218 | |
|
200 | 219 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
201 | 220 | d->m_categories.append(category); |
|
202 | 221 | |
|
203 | 222 | if (d->m_categories.count() == count) |
|
204 | 223 | return; |
|
205 | 224 | |
|
206 | 225 | if (count == 0) |
|
207 | 226 | setRange(d->m_categories.last(), d->m_categories.last()); |
|
208 | 227 | else |
|
209 | 228 | setRange(d->m_minCategory, d->m_categories.last()); |
|
210 | 229 | |
|
211 | 230 | emit categoriesChanged(); |
|
231 | emit countChanged(); | |
|
212 | 232 | } |
|
213 | 233 | |
|
214 | 234 | /*! |
|
215 | 235 | Removes \a category from axis. Removing category which is currently maximum or minimum |
|
216 | 236 | will affect the axis range. |
|
217 | 237 | */ |
|
218 | 238 | void QBarCategoryAxis::remove(const QString &category) |
|
219 | 239 | { |
|
220 | 240 | Q_D(QBarCategoryAxis); |
|
221 | 241 | |
|
222 | 242 | if (d->m_categories.contains(category)) { |
|
223 | 243 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
224 | 244 | if (!d->m_categories.isEmpty()) { |
|
225 | 245 | if (d->m_minCategory == category) { |
|
226 | 246 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
227 | 247 | } else if (d->m_maxCategory == category) { |
|
228 | 248 | setRange(d->m_minCategory, d->m_categories.last()); |
|
229 | 249 | } else { |
|
230 | 250 | d->updateCategoryDomain(); |
|
231 | 251 | d->emitUpdated(); |
|
232 | 252 | } |
|
233 | 253 | } else { |
|
234 | 254 | setRange(QString::null, QString::null); |
|
235 | 255 | } |
|
236 | 256 | emit categoriesChanged(); |
|
257 | emit countChanged(); | |
|
237 | 258 | } |
|
238 | 259 | } |
|
239 | 260 | |
|
240 | 261 | /*! |
|
241 | 262 | Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. |
|
242 | 263 | If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. |
|
243 | 264 | */ |
|
244 | 265 | void QBarCategoryAxis::insert(int index, const QString &category) |
|
245 | 266 | { |
|
246 | 267 | Q_D(QBarCategoryAxis); |
|
247 | 268 | |
|
248 | 269 | int count = d->m_categories.count(); |
|
249 | 270 | |
|
250 | 271 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
251 | 272 | d->m_categories.insert(index, category); |
|
252 | 273 | |
|
253 | 274 | if (d->m_categories.count() == count) |
|
254 | 275 | return; |
|
255 | 276 | |
|
256 | 277 | if (count == 0) { |
|
257 | 278 | setRange(d->m_categories.first(), d->m_categories.first()); |
|
258 | 279 | } else if (index == 0) { |
|
259 | 280 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
260 | 281 | } else if (index == count) { |
|
261 | 282 | setRange(d->m_minCategory, d->m_categories.last()); |
|
262 | 283 | } else { |
|
263 | 284 | d->updateCategoryDomain(); |
|
264 | 285 | d->emitUpdated(); |
|
265 | 286 | } |
|
266 | 287 | |
|
267 | 288 | emit categoriesChanged(); |
|
289 | emit countChanged(); | |
|
268 | 290 | } |
|
269 | 291 | |
|
270 | 292 | /*! |
|
271 | 293 | Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exits on the axis nothing is done. |
|
272 |
A \a new |
|
|
294 | A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, | |
|
273 | 295 | minimum and maximum of axis is updated accordingly. |
|
274 | 296 | */ |
|
275 | 297 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) |
|
276 | 298 | { |
|
277 | 299 | Q_D(QBarCategoryAxis); |
|
278 | 300 | |
|
279 | 301 | int pos = d->m_categories.indexOf(oldCategory); |
|
280 | 302 | |
|
281 | 303 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { |
|
282 | 304 | d->m_categories.replace(pos, newCategory); |
|
283 | 305 | if (d->m_minCategory == oldCategory) { |
|
284 | 306 | setRange(newCategory, d->m_maxCategory); |
|
285 | 307 | } else if (d->m_maxCategory == oldCategory) { |
|
286 | 308 | setRange(d->m_minCategory, newCategory); |
|
287 | 309 | } else { |
|
288 | 310 | d->emitUpdated(); |
|
289 | 311 | } |
|
290 | 312 | emit categoriesChanged(); |
|
313 | emit countChanged(); | |
|
291 | 314 | } |
|
292 | 315 | } |
|
293 | 316 | |
|
294 | 317 | /*! |
|
295 | 318 | Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. |
|
296 | 319 | */ |
|
297 | 320 | void QBarCategoryAxis::clear() |
|
298 | 321 | { |
|
299 | 322 | Q_D(QBarCategoryAxis); |
|
300 | 323 | d->m_categories.clear(); |
|
301 | 324 | setRange(QString::null, QString::null); |
|
302 | 325 | emit categoriesChanged(); |
|
326 | emit countChanged(); | |
|
303 | 327 | } |
|
304 | 328 | |
|
305 | 329 | /*! |
|
306 | 330 | Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. |
|
307 | 331 | A category has to be valid QStrings and can not be duplicated. |
|
308 | 332 | */ |
|
309 | 333 | void QBarCategoryAxis::setCategories(const QStringList &categories) |
|
310 | 334 | { |
|
311 | 335 | Q_D(QBarCategoryAxis); |
|
312 | 336 | d->m_categories.clear(); |
|
313 | 337 | d->m_minCategory = QString::null; |
|
314 | 338 | d->m_maxCategory = QString::null; |
|
315 | 339 | d->m_min = 0; |
|
316 | 340 | d->m_max = 0; |
|
317 | 341 | d->m_count = 0; |
|
318 | 342 | append(categories); |
|
319 | 343 | } |
|
320 | 344 | |
|
321 | 345 | /*! |
|
322 | 346 | Returns categories |
|
323 | 347 | */ |
|
324 | 348 | QStringList QBarCategoryAxis::categories() |
|
325 | 349 | { |
|
326 | 350 | Q_D(QBarCategoryAxis); |
|
327 | 351 | return d->m_categories; |
|
328 | 352 | } |
|
329 | 353 | |
|
330 | 354 | /*! |
|
331 | 355 | Returns number of categories. |
|
332 | 356 | */ |
|
333 | 357 | int QBarCategoryAxis::count() const |
|
334 | 358 | { |
|
335 | 359 | Q_D(const QBarCategoryAxis); |
|
336 | 360 | return d->m_categories.count(); |
|
337 | 361 | } |
|
338 | 362 | |
|
339 | 363 | /*! |
|
340 | 364 | Returns category at \a index. Index must be valid. |
|
341 | 365 | */ |
|
342 | 366 | QString QBarCategoryAxis::at(int index) const |
|
343 | 367 | { |
|
344 | 368 | Q_D(const QBarCategoryAxis); |
|
345 | 369 | return d->m_categories.at(index); |
|
346 | 370 | } |
|
347 | 371 | |
|
348 | 372 | /*! |
|
349 | 373 | Sets minimum category to \a min. |
|
350 | 374 | */ |
|
351 | 375 | void QBarCategoryAxis::setMin(const QString &min) |
|
352 | 376 | { |
|
353 | 377 | Q_D(QBarCategoryAxis); |
|
354 | 378 | setRange(min, d->m_maxCategory); |
|
355 | 379 | } |
|
356 | 380 | |
|
357 | 381 | /*! |
|
358 | 382 | Returns minimum category. |
|
359 | 383 | */ |
|
360 | 384 | QString QBarCategoryAxis::min() const |
|
361 | 385 | { |
|
362 | 386 | Q_D(const QBarCategoryAxis); |
|
363 | 387 | return d->m_minCategory; |
|
364 | 388 | } |
|
365 | 389 | |
|
366 | 390 | /*! |
|
367 | 391 | Sets maximum category to \a max. |
|
368 | 392 | */ |
|
369 | 393 | void QBarCategoryAxis::setMax(const QString &max) |
|
370 | 394 | { |
|
371 | 395 | Q_D(QBarCategoryAxis); |
|
372 | 396 | setRange(d->m_minCategory, max); |
|
373 | 397 | } |
|
374 | 398 | |
|
375 | 399 | /*! |
|
376 | 400 | Returns maximum category |
|
377 | 401 | */ |
|
378 | 402 | QString QBarCategoryAxis::max() const |
|
379 | 403 | { |
|
380 | 404 | Q_D(const QBarCategoryAxis); |
|
381 | 405 | return d->m_maxCategory; |
|
382 | 406 | } |
|
383 | 407 | |
|
384 | 408 | /*! |
|
385 | 409 | Sets range from \a minCategory to \a maxCategory |
|
386 | 410 | */ |
|
387 | 411 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) |
|
388 | 412 | { |
|
389 | 413 | Q_D(QBarCategoryAxis); |
|
390 | 414 | |
|
391 | 415 | bool changed = false; |
|
392 | 416 | |
|
393 | 417 | //special case in case or clearing all categories |
|
394 | 418 | if (minCategory.isNull() && maxCategory.isNull()) { |
|
395 | 419 | d->m_minCategory = minCategory; |
|
396 | 420 | d->m_maxCategory = maxCategory; |
|
397 | 421 | d->m_min = 0; |
|
398 | 422 | d->m_max = 0; |
|
399 | 423 | emit minChanged(minCategory); |
|
400 | 424 | emit maxChanged(maxCategory); |
|
401 | 425 | d->m_count = 0; |
|
402 | 426 | emit rangeChanged(d->m_minCategory, d->m_maxCategory); |
|
403 | 427 | d->emitUpdated(); |
|
404 | 428 | } |
|
405 | 429 | |
|
406 | 430 | if (d->m_categories.indexOf(maxCategory) < d->m_categories.indexOf(minCategory)) |
|
407 | 431 | return; |
|
408 | 432 | |
|
409 | 433 | if (!minCategory.isEmpty() && d->m_minCategory != minCategory && d->m_categories.contains(minCategory)) { |
|
410 | 434 | d->m_minCategory = minCategory; |
|
411 | 435 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
412 | 436 | changed = true; |
|
413 | 437 | emit minChanged(minCategory); |
|
414 | 438 | } |
|
415 | 439 | |
|
416 | 440 | if (!maxCategory.isEmpty() && d->m_maxCategory != maxCategory && d->m_categories.contains(maxCategory)) { |
|
417 | 441 | d->m_maxCategory = maxCategory; |
|
418 | 442 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
419 | 443 | changed = true; |
|
420 | 444 | emit maxChanged(maxCategory); |
|
421 | 445 | } |
|
422 | 446 | |
|
423 | 447 | if (changed) { |
|
424 | 448 | d->m_count = d->m_max - d->m_min; |
|
425 | 449 | emit rangeChanged(d->m_minCategory, d->m_maxCategory); |
|
426 | 450 | d->emitUpdated(); |
|
427 | 451 | } |
|
428 | 452 | } |
|
429 | 453 | |
|
430 | 454 | /*! |
|
431 | 455 | Returns the type of the axis |
|
432 | 456 | */ |
|
433 | 457 | QAbstractAxis::AxisType QBarCategoryAxis::type() const |
|
434 | 458 | { |
|
435 | 459 | return AxisTypeBarCategory; |
|
436 | 460 | } |
|
437 | 461 | |
|
438 | 462 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
439 | 463 | |
|
440 | 464 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) |
|
441 | 465 | : QAbstractAxisPrivate(q), |
|
442 | 466 | m_min(0.0), |
|
443 | 467 | m_max(0.0), |
|
444 | 468 | m_count(0) |
|
445 | 469 | { |
|
446 | 470 | |
|
447 | 471 | } |
|
448 | 472 | |
|
449 | 473 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() |
|
450 | 474 | { |
|
451 | 475 | |
|
452 | 476 | } |
|
453 | 477 | |
|
454 | 478 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) |
|
455 | 479 | { |
|
456 | 480 | setRange(min, m_maxCategory); |
|
457 | 481 | } |
|
458 | 482 | |
|
459 | 483 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) |
|
460 | 484 | { |
|
461 | 485 | setRange(m_minCategory, max); |
|
462 | 486 | } |
|
463 | 487 | |
|
464 | 488 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
465 | 489 | { |
|
466 | 490 | Q_Q(QBarCategoryAxis); |
|
467 | 491 | QString value1 = min.toString(); |
|
468 | 492 | QString value2 = max.toString(); |
|
469 | 493 | q->setRange(value1, value2); |
|
470 | 494 | } |
|
471 | 495 | |
|
472 | 496 | void QBarCategoryAxisPrivate::handleDomainUpdated() |
|
473 | 497 | { |
|
474 | 498 | Q_Q(QBarCategoryAxis); |
|
475 | 499 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
476 | 500 | |
|
477 | 501 | if (m_orientation == Qt::Horizontal) { |
|
478 | 502 | m_min = domain->minX(); |
|
479 | 503 | m_max = domain->maxX(); |
|
480 | 504 | } else if (m_orientation == Qt::Vertical) { |
|
481 | 505 | m_min = domain->minY(); |
|
482 | 506 | m_max = domain->maxY(); |
|
483 | 507 | } |
|
484 | 508 | |
|
485 | 509 | bool changed = false; |
|
486 | 510 | |
|
487 | 511 | int min = m_min + 0.5; |
|
488 | 512 | if (min >= 0 && min < m_categories.count()) { |
|
489 | 513 | QString minCategory = m_categories.at(min); |
|
490 | 514 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { |
|
491 | 515 | m_minCategory = minCategory; |
|
492 | 516 | changed = true; |
|
493 | 517 | emit q->minChanged(minCategory); |
|
494 | 518 | } |
|
495 | 519 | } |
|
496 | 520 | int max = m_max - 0.5; |
|
497 | 521 | if (max >= 0 && max < m_categories.count()) { |
|
498 | 522 | QString maxCategory = m_categories.at(max); |
|
499 | 523 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { |
|
500 | 524 | m_maxCategory = maxCategory; |
|
501 | 525 | emit q->maxChanged(maxCategory); |
|
502 | 526 | } |
|
503 | 527 | } |
|
504 | 528 | |
|
505 | 529 | if (changed) |
|
506 | 530 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
507 | 531 | } |
|
508 | 532 | |
|
509 | 533 | ChartAxis *QBarCategoryAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
510 | 534 | { |
|
511 | 535 | Q_Q(QBarCategoryAxis); |
|
512 | 536 | if (m_orientation == Qt::Vertical) |
|
513 | 537 | return new ChartBarCategoryAxisY(q, presenter); |
|
514 | 538 | return new ChartBarCategoryAxisX(q, presenter); |
|
515 | 539 | } |
|
516 | 540 | |
|
517 | 541 | void QBarCategoryAxisPrivate::updateCategoryDomain() |
|
518 | 542 | { |
|
519 | 543 | m_min = m_categories.indexOf(m_minCategory) - 0.5; |
|
520 | 544 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; |
|
521 | 545 | m_count = m_max - m_min; |
|
522 | 546 | } |
|
523 | 547 | |
|
524 | 548 | |
|
525 | 549 | void QBarCategoryAxisPrivate::intializeDomain(Domain *domain) |
|
526 | 550 | { |
|
527 | 551 | |
|
528 | 552 | Q_Q(QBarCategoryAxis); |
|
529 | 553 | if (m_max == m_min) { |
|
530 | 554 | int min; |
|
531 | 555 | int max; |
|
532 | 556 | if (m_orientation == Qt::Vertical) { |
|
533 | 557 | min = domain->minY() + 0.5; |
|
534 | 558 | max = domain->maxY() - 0.5; |
|
535 | 559 | } else { |
|
536 | 560 | min = domain->minX() + 0.5; |
|
537 | 561 | max = domain->maxX() - 0.5; |
|
538 | 562 | } |
|
539 | 563 | |
|
540 | 564 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) |
|
541 | 565 | q->setRange(m_categories.at(min), m_categories.at(max)); |
|
542 | 566 | } else { |
|
543 | 567 | if (m_orientation == Qt::Vertical) |
|
544 | 568 | domain->setRangeY(m_min, m_max); |
|
545 | 569 | else |
|
546 | 570 | domain->setRangeX(m_min, m_max); |
|
547 | 571 | } |
|
548 | 572 | } |
|
549 | 573 | |
|
550 | 574 | #include "moc_qbarcategoryaxis.cpp" |
|
551 | 575 | #include "moc_qbarcategoryaxis_p.cpp" |
|
552 | 576 | |
|
553 | 577 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,79 +1,81 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QBARCATEGORYAXIS_H |
|
22 | 22 | #define QBARCATEGORYAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | class QBarCategoryAxisPrivate; |
|
29 | 29 | |
|
30 | 30 | class QTCOMMERCIALCHART_EXPORT QBarCategoryAxis : public QAbstractAxis |
|
31 | 31 | { |
|
32 | 32 | Q_OBJECT |
|
33 | 33 | Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged) |
|
34 | 34 | Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged) |
|
35 | 35 | Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) |
|
36 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
|
36 | 37 | |
|
37 | 38 | public: |
|
38 | 39 | explicit QBarCategoryAxis(QObject *parent = 0); |
|
39 | 40 | ~QBarCategoryAxis(); |
|
40 | 41 | |
|
41 | 42 | protected: |
|
42 | 43 | QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent = 0); |
|
43 | 44 | |
|
44 | 45 | public: |
|
45 | 46 | AxisType type() const; |
|
46 | 47 | void append(const QStringList &categories); |
|
47 | 48 | void append(const QString &category); |
|
48 | 49 | void remove(const QString &category); |
|
49 | 50 | void insert(int index, const QString &category); |
|
50 | 51 | void replace(const QString &oldCategory, const QString &newCategory); |
|
51 | 52 | void clear(); |
|
52 | 53 | void setCategories(const QStringList &categories); |
|
53 | 54 | QStringList categories(); |
|
54 | 55 | int count() const; |
|
55 | 56 | QString at(int index) const; |
|
56 | 57 | |
|
57 | 58 | //range handling |
|
58 | 59 | void setMin(const QString &minCategory); |
|
59 | 60 | QString min() const; |
|
60 | 61 | void setMax(const QString &maxCategory); |
|
61 | 62 | QString max() const; |
|
62 | 63 | void setRange(const QString &minCategory, const QString &maxCategory); |
|
63 | 64 | |
|
64 | 65 | Q_SIGNALS: |
|
65 | 66 | void categoriesChanged(); |
|
66 | 67 | void minChanged(const QString &min); |
|
67 | 68 | void maxChanged(const QString &max); |
|
68 | 69 | void rangeChanged(const QString &min, const QString &max); |
|
70 | void countChanged(); | |
|
69 | 71 | |
|
70 | 72 | private: |
|
71 | 73 | Q_DECLARE_PRIVATE(QBarCategoryAxis) |
|
72 | 74 | Q_DISABLE_COPY(QBarCategoryAxis) |
|
73 | 75 | friend class ChartBarCategoryAxisX; |
|
74 | 76 | friend class ChartBarCategoryAxisY; |
|
75 | 77 | }; |
|
76 | 78 | |
|
77 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | 80 | |
|
79 | 81 | #endif // QBARCATEGORYAXIS_H |
@@ -1,299 +1,317 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qcategoryaxis.h" |
|
22 | 22 | #include "qcategoryaxis_p.h" |
|
23 | 23 | #include "chartcategoryaxisx_p.h" |
|
24 | 24 | #include "chartcategoryaxisy_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | /*! |
|
30 | 30 | \class QCategoryAxis |
|
31 | 31 | \brief The QCategoryAxis class allows putting a named ranges on the axis. |
|
32 | 32 | \mainclass |
|
33 | 33 | |
|
34 | 34 | This class can be used when the underlying data needs to be given extra meaning. |
|
35 | 35 | Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely. |
|
36 | 36 | |
|
37 | 37 | Example code on how to use QCategoryAxis: |
|
38 | 38 | \table |
|
39 | 39 | \row |
|
40 | 40 | \o \br |
|
41 | 41 | \br |
|
42 | 42 | \code |
|
43 | 43 | QChartView *chartView = new QChartView; |
|
44 | 44 | QLineSeries *series = new QLineSeries; |
|
45 | 45 | // ... |
|
46 | 46 | chartView->chart()->addSeries(series); |
|
47 | 47 | |
|
48 | 48 | QCategoryAxis *axisY = new QCategoryAxis; |
|
49 | 49 | axisY->setMin(0); |
|
50 | 50 | axisY->setMax(52); |
|
51 | 51 | axisY->setStartValue(15); |
|
52 | 52 | axisY->append("First", 20); |
|
53 | 53 | axisY->append("Second", 37); |
|
54 | 54 | axisY->append("Third", 52); |
|
55 | 55 | chartView->chart()->setAxisY(axisY, series); |
|
56 | 56 | \endcode |
|
57 | 57 | \o \br |
|
58 | 58 | \inlineimage api_category_axis.png |
|
59 | 59 | \endtable |
|
60 | 60 | */ |
|
61 | 61 | /*! |
|
62 | 62 | \qmlclass CategoryAxis QCategoryAxis |
|
63 | 63 | \inherits AbstractAxis |
|
64 | 64 | \brief CategoryAxis allows putting a named ranges on the axis. |
|
65 | 65 | |
|
66 | 66 | For example: |
|
67 | 67 | \table |
|
68 | 68 | \row |
|
69 | 69 | \o \br |
|
70 | 70 | \br |
|
71 | 71 | \br |
|
72 | 72 | \snippet ../demos/qmlaxes/qml/qmlaxes/View3.qml 1 |
|
73 | 73 | \o \inlineimage demos_qmlaxes3.png |
|
74 | 74 | \endtable |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QCategoryAxis::startValue |
|
79 | 79 | Defines the low end of the first category on the axis. |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty int CategoryAxis::startValue |
|
83 | 83 | Defines the low end of the first category on the axis. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | \property QCategoryAxis::count | |
|
88 | The count of categories. | |
|
89 | */ | |
|
90 | /*! | |
|
91 | \qmlproperty int CategoryAxis::count | |
|
92 | The count of categories. | |
|
93 | */ | |
|
94 | ||
|
95 | /*! | |
|
96 | \property QCategoryAxis::categoriesLabels | |
|
97 | The category labels as a string list. | |
|
98 | */ | |
|
99 | /*! | |
|
100 | \qmlproperty StringList CategoryAxis::categoriesLabels | |
|
101 | The category labels as a list of strings. | |
|
102 | */ | |
|
103 | ||
|
104 | /*! | |
|
87 | 105 | Constructs an axis object which is a child of \a parent. |
|
88 | 106 | */ |
|
89 | 107 | QCategoryAxis::QCategoryAxis(QObject *parent): |
|
90 | 108 | QValueAxis(*new QCategoryAxisPrivate(this), parent) |
|
91 | 109 | { |
|
92 | 110 | } |
|
93 | 111 | |
|
94 | 112 | /*! |
|
95 | 113 | Destroys the object |
|
96 | 114 | */ |
|
97 | 115 | QCategoryAxis::~QCategoryAxis() |
|
98 | 116 | { |
|
99 | 117 | } |
|
100 | 118 | |
|
101 | 119 | /*! |
|
102 | 120 | \internal |
|
103 | 121 | */ |
|
104 | 122 | QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d, QObject *parent): QValueAxis(d, parent) |
|
105 | 123 | { |
|
106 | 124 | |
|
107 | 125 | } |
|
108 | 126 | |
|
109 | 127 | /*! |
|
110 | 128 | \qmlmethod CategoryAxis::append(string label, real endValue) |
|
111 | 129 | Appends new category to the axis with an \a label. Category label has to be unique. |
|
112 | 130 | Parameter \a endValue specifies the high end limit of the category. |
|
113 | 131 | It has to be greater than the high end limit of the previous category. |
|
114 | 132 | Otherwise the method returns without adding a new category. |
|
115 | 133 | */ |
|
116 | 134 | /*! |
|
117 | 135 | Appends new category to the axis with an \a categoryLabel. |
|
118 | 136 | Category label has to be unique. |
|
119 | 137 | Parameter \a categoryEndValue specifies the high end limit of the category. |
|
120 | 138 | It has to be greater than the high end limit of the previous category. |
|
121 | 139 | Otherwise the method returns without adding a new category. |
|
122 | 140 | */ |
|
123 | 141 | void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue) |
|
124 | 142 | { |
|
125 | 143 | Q_D(QCategoryAxis); |
|
126 | 144 | |
|
127 | 145 | if (!d->m_categories.contains(categoryLabel)) { |
|
128 | 146 | if (d->m_categories.isEmpty()) { |
|
129 | 147 | Range range(d->m_categoryMinimum, categoryEndValue); |
|
130 | 148 | d->m_categoriesMap.insert(categoryLabel, range); |
|
131 | 149 | d->m_categories.append(categoryLabel); |
|
132 | 150 | } else if (categoryEndValue > endValue(d->m_categories.last())) { |
|
133 | 151 | Range previousRange = d->m_categoriesMap.value(d->m_categories.last()); |
|
134 | 152 | d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue)); |
|
135 | 153 | d->m_categories.append(categoryLabel); |
|
136 | 154 | } |
|
137 | 155 | } |
|
138 | 156 | } |
|
139 | 157 | |
|
140 | 158 | /*! |
|
141 | 159 | Sets \a min to be the low end limit of the first category on the axis. |
|
142 | 160 | If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range. |
|
143 | 161 | Otherwise nothing is done. |
|
144 | 162 | */ |
|
145 | 163 | void QCategoryAxis::setStartValue(qreal min) |
|
146 | 164 | { |
|
147 | 165 | Q_D(QCategoryAxis); |
|
148 | 166 | if (d->m_categories.isEmpty()) { |
|
149 | 167 | d->m_categoryMinimum = min; |
|
150 | 168 | } else { |
|
151 | 169 | Range range = d->m_categoriesMap.value(d->m_categories.first()); |
|
152 | 170 | if (min < range.second) |
|
153 | 171 | d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second)); |
|
154 | 172 | } |
|
155 | 173 | } |
|
156 | 174 | |
|
157 | 175 | /*! |
|
158 | 176 | Returns the low end limit of the category specified by an \a categoryLabel |
|
159 | 177 | */ |
|
160 | 178 | qreal QCategoryAxis::startValue(const QString &categoryLabel) const |
|
161 | 179 | { |
|
162 | 180 | Q_D(const QCategoryAxis); |
|
163 | 181 | if (categoryLabel.isEmpty()) |
|
164 | 182 | return d->m_categoryMinimum; |
|
165 | 183 | return d->m_categoriesMap.value(categoryLabel).first; |
|
166 | 184 | } |
|
167 | 185 | |
|
168 | 186 | /*! |
|
169 | 187 | Returns the high end limit of the interval specified by an \a categoryLabel |
|
170 | 188 | */ |
|
171 | 189 | qreal QCategoryAxis::endValue(const QString &categoryLabel) const |
|
172 | 190 | { |
|
173 | 191 | Q_D(const QCategoryAxis); |
|
174 | 192 | return d->m_categoriesMap.value(categoryLabel).second; |
|
175 | 193 | } |
|
176 | 194 | |
|
177 | 195 | /*! |
|
178 | 196 | \qmlmethod CategoryAxis::remove(string label) |
|
179 | 197 | Removes a category specified by the \a label from the axis |
|
180 | 198 | */ |
|
181 | 199 | /*! |
|
182 | 200 | Removes an interval specified by the \a categoryLabel from the axis |
|
183 | 201 | */ |
|
184 | 202 | void QCategoryAxis::remove(const QString &categoryLabel) |
|
185 | 203 | { |
|
186 | 204 | Q_D(QCategoryAxis); |
|
187 | 205 | int labelIndex = d->m_categories.indexOf(categoryLabel); |
|
188 | 206 | |
|
189 | 207 | // check if such label exists |
|
190 | 208 | if (labelIndex != -1) { |
|
191 | 209 | d->m_categories.removeAt(labelIndex); |
|
192 | 210 | d->m_categoriesMap.remove(categoryLabel); |
|
193 | 211 | |
|
194 | 212 | // the range of the interval that follows (if exists) needs to be updated |
|
195 | 213 | if (labelIndex < d->m_categories.count()) { |
|
196 | 214 | QString label = d->m_categories.at(labelIndex); |
|
197 | 215 | Range range = d->m_categoriesMap.value(label); |
|
198 | 216 | |
|
199 | 217 | // set the range |
|
200 | 218 | if (labelIndex == 0) { |
|
201 | 219 | range.first = d->m_categoryMinimum; |
|
202 | 220 | d->m_categoriesMap.insert(label, range); |
|
203 | 221 | } else { |
|
204 | 222 | range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second; |
|
205 | 223 | d->m_categoriesMap.insert(label, range); |
|
206 | 224 | } |
|
207 | 225 | } |
|
208 | 226 | d->emitUpdated(); |
|
209 | 227 | } |
|
210 | 228 | } |
|
211 | 229 | |
|
212 | 230 | /*! |
|
213 | 231 | \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel) |
|
214 | 232 | Replaces \a oldLabel of an existing category with a \a newLabel. |
|
215 | 233 | If the old label does not exist the method returns without making any changes. |
|
216 | 234 | */ |
|
217 | 235 | /*! |
|
218 | 236 | Replaces \a oldLabel of an existing category with a \a newLabel |
|
219 | 237 | If the old label does not exist the method returns without making any changes. |
|
220 | 238 | */ |
|
221 | 239 | void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabel) |
|
222 | 240 | { |
|
223 | 241 | Q_D(QCategoryAxis); |
|
224 | 242 | int labelIndex = d->m_categories.indexOf(oldLabel); |
|
225 | 243 | |
|
226 | 244 | // check if such label exists |
|
227 | 245 | if (labelIndex != -1) { |
|
228 | 246 | d->m_categories.replace(labelIndex, newLabel); |
|
229 | 247 | Range range = d->m_categoriesMap.value(oldLabel); |
|
230 | 248 | d->m_categoriesMap.remove(oldLabel); |
|
231 | 249 | d->m_categoriesMap.insert(newLabel, range); |
|
232 | 250 | d->emitUpdated(); |
|
233 | 251 | } |
|
234 | 252 | } |
|
235 | 253 | |
|
236 | 254 | /*! |
|
237 | 255 | Returns the list of the intervals labels |
|
238 | 256 | */ |
|
239 | 257 | QStringList QCategoryAxis::categoriesLabels() |
|
240 | 258 | { |
|
241 | 259 | Q_D(QCategoryAxis); |
|
242 | 260 | return d->m_categories; |
|
243 | 261 | } |
|
244 | 262 | |
|
245 | 263 | /*! |
|
246 | 264 | Returns number of intervals. |
|
247 | 265 | */ |
|
248 | 266 | int QCategoryAxis::count() const |
|
249 | 267 | { |
|
250 | 268 | Q_D(const QCategoryAxis); |
|
251 | 269 | return d->m_categories.count(); |
|
252 | 270 | } |
|
253 | 271 | |
|
254 | 272 | /*! |
|
255 | 273 | Returns the type of the axis |
|
256 | 274 | */ |
|
257 | 275 | QAbstractAxis::AxisType QCategoryAxis::type() const |
|
258 | 276 | { |
|
259 | 277 | return QAbstractAxis::AxisTypeCategory; |
|
260 | 278 | } |
|
261 | 279 | |
|
262 | 280 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
263 | 281 | |
|
264 | 282 | QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis *q) |
|
265 | 283 | : QValueAxisPrivate(q), |
|
266 | 284 | m_categoryMinimum(0) |
|
267 | 285 | { |
|
268 | 286 | |
|
269 | 287 | } |
|
270 | 288 | |
|
271 | 289 | QCategoryAxisPrivate::~QCategoryAxisPrivate() |
|
272 | 290 | { |
|
273 | 291 | |
|
274 | 292 | } |
|
275 | 293 | |
|
276 | 294 | int QCategoryAxisPrivate::ticksCount() const |
|
277 | 295 | { |
|
278 | 296 | return m_categories.count() + 1; |
|
279 | 297 | } |
|
280 | 298 | |
|
281 | 299 | void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max, int count) |
|
282 | 300 | { |
|
283 | 301 | Q_UNUSED(count); |
|
284 | 302 | Q_UNUSED(min); |
|
285 | 303 | Q_UNUSED(max); |
|
286 | 304 | } |
|
287 | 305 | |
|
288 | 306 | ChartAxis *QCategoryAxisPrivate::createGraphics(ChartPresenter *presenter) |
|
289 | 307 | { |
|
290 | 308 | Q_Q(QCategoryAxis); |
|
291 | 309 | if (m_orientation == Qt::Vertical) |
|
292 | 310 | return new ChartCategoryAxisY(q, presenter); |
|
293 | 311 | return new ChartCategoryAxisX(q, presenter); |
|
294 | 312 | } |
|
295 | 313 | |
|
296 | 314 | #include "moc_qcategoryaxis.cpp" |
|
297 | 315 | #include "moc_qcategoryaxis_p.cpp" |
|
298 | 316 | |
|
299 | 317 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,689 +1,709 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "../qabstractaxis/tst_qabstractaxis.h" |
|
22 | 22 | #include <qbarseries.h> |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | #include <qbarcategoryaxis.h> |
|
25 | 25 | |
|
26 | 26 | class tst_QBarCategoriesAxis: public tst_QAbstractAxis |
|
27 | 27 | { |
|
28 | 28 | Q_OBJECT |
|
29 | 29 | |
|
30 | 30 | public slots: |
|
31 | 31 | void initTestCase(); |
|
32 | 32 | void cleanupTestCase(); |
|
33 | 33 | void init(); |
|
34 | 34 | void cleanup(); |
|
35 | 35 | |
|
36 | 36 | private slots: |
|
37 | 37 | void qbarcategoryaxis_data(); |
|
38 | 38 | void qbarcategoryaxis(); |
|
39 | 39 | |
|
40 | 40 | void append2_data(); |
|
41 | 41 | void append2(); |
|
42 | 42 | void append_data(); |
|
43 | 43 | void append(); |
|
44 | 44 | void at_data(); |
|
45 | 45 | void at(); |
|
46 | 46 | void categories_data(); |
|
47 | 47 | void categories(); |
|
48 | 48 | void clear_data(); |
|
49 | 49 | void clear(); |
|
50 | 50 | void count_data(); |
|
51 | 51 | void count(); |
|
52 | 52 | void insert_data(); |
|
53 | 53 | void insert(); |
|
54 | 54 | void remove_data(); |
|
55 | 55 | void remove(); |
|
56 | 56 | void max_raw_data(); |
|
57 | 57 | void max_raw(); |
|
58 | 58 | void max_data(); |
|
59 | 59 | void max(); |
|
60 | 60 | void max_animation_data(); |
|
61 | 61 | void max_animation(); |
|
62 | 62 | void min_raw_data(); |
|
63 | 63 | void min_raw(); |
|
64 | 64 | void min_data(); |
|
65 | 65 | void min(); |
|
66 | 66 | void min_animation_data(); |
|
67 | 67 | void min_animation(); |
|
68 | 68 | void range_raw_data(); |
|
69 | 69 | void range_raw(); |
|
70 | 70 | void range_data(); |
|
71 | 71 | void range(); |
|
72 | 72 | void range_animation_data(); |
|
73 | 73 | void range_animation(); |
|
74 | 74 | void noautoscale_data(); |
|
75 | 75 | void noautoscale(); |
|
76 | 76 | void autoscale_data(); |
|
77 | 77 | void autoscale(); |
|
78 | 78 | |
|
79 | 79 | private: |
|
80 | 80 | QBarCategoryAxis* m_baraxis; |
|
81 | 81 | QBarSeries* m_series; |
|
82 | 82 | }; |
|
83 | 83 | |
|
84 | 84 | void tst_QBarCategoriesAxis::initTestCase() |
|
85 | 85 | { |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void tst_QBarCategoriesAxis::cleanupTestCase() |
|
89 | 89 | { |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | void tst_QBarCategoriesAxis::init() |
|
93 | 93 | { |
|
94 | 94 | m_baraxis = new QBarCategoryAxis(); |
|
95 | 95 | m_series = new QBarSeries(); |
|
96 | 96 | |
|
97 | 97 | QBarSet *set0 = new QBarSet("Jane"); |
|
98 | 98 | QBarSet *set1 = new QBarSet("John"); |
|
99 | 99 | QBarSet *set2 = new QBarSet("Axel"); |
|
100 | 100 | QBarSet *set3 = new QBarSet("Mary"); |
|
101 | 101 | QBarSet *set4 = new QBarSet("Samantha"); |
|
102 | 102 | |
|
103 | 103 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
104 | 104 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
105 | 105 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
106 | 106 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
107 | 107 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
108 | 108 | |
|
109 | 109 | m_series->append(set0); |
|
110 | 110 | m_series->append(set1); |
|
111 | 111 | m_series->append(set2); |
|
112 | 112 | m_series->append(set3); |
|
113 | 113 | m_series->append(set4); |
|
114 | 114 | |
|
115 | 115 | QStringList categories; |
|
116 | 116 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
117 | 117 | |
|
118 | 118 | foreach(QString category, categories) |
|
119 | 119 | m_baraxis->append(category); |
|
120 | 120 | |
|
121 | 121 | tst_QAbstractAxis::init(m_baraxis, m_series); |
|
122 | 122 | m_chart->addSeries(m_series); |
|
123 | 123 | m_chart->createDefaultAxes(); |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void tst_QBarCategoriesAxis::cleanup() |
|
127 | 127 | { |
|
128 | 128 | delete m_series; |
|
129 | 129 | delete m_baraxis; |
|
130 | 130 | m_series = 0; |
|
131 | 131 | m_baraxis = 0; |
|
132 | 132 | tst_QAbstractAxis::cleanup(); |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | void tst_QBarCategoriesAxis::qbarcategoryaxis_data() |
|
136 | 136 | { |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | void tst_QBarCategoriesAxis::qbarcategoryaxis() |
|
140 | 140 | { |
|
141 | 141 | qabstractaxis(); |
|
142 | 142 | QBarCategoryAxis axis; |
|
143 | 143 | axis.append(QStringList()); |
|
144 | 144 | axis.append(QString()); |
|
145 | 145 | QCOMPARE(axis.count(), 0); |
|
146 | 146 | QStringList test; |
|
147 | 147 | QCOMPARE(axis.categories(),test); |
|
148 | 148 | axis.clear(); |
|
149 | 149 | QCOMPARE(axis.count(), 0); |
|
150 | 150 | axis.insert(-1, QString()); |
|
151 | 151 | QCOMPARE(axis.max(), QString()); |
|
152 | 152 | QCOMPARE(axis.min(), QString()); |
|
153 | 153 | axis.remove(QString()); |
|
154 | 154 | axis.setCategories(QStringList()); |
|
155 | 155 | axis.setMax(QString()); |
|
156 | 156 | axis.setMin(QString()); |
|
157 | 157 | axis.setRange(QString(), QString()); |
|
158 | 158 | QCOMPARE(axis.type(), QAbstractAxis::AxisTypeBarCategory); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | void tst_QBarCategoriesAxis::append_data() |
|
162 | 162 | { |
|
163 | 163 | QTest::addColumn<QStringList>("categories"); |
|
164 | 164 | QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr"); |
|
165 | 165 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void tst_QBarCategoriesAxis::append() |
|
169 | 169 | { |
|
170 | 170 | QFETCH(QStringList, categories); |
|
171 | 171 | |
|
172 | 172 | QBarCategoryAxis axis; |
|
173 | 173 | |
|
174 | 174 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
175 | 175 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
176 | 176 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
177 | 177 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
178 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
178 | 179 | |
|
179 | 180 | axis.append(categories); |
|
180 | 181 | |
|
181 | 182 | QCOMPARE(spy0.count(), 1); |
|
182 | 183 | QCOMPARE(spy1.count(), 1); |
|
183 | 184 | QCOMPARE(spy2.count(), 1); |
|
184 | 185 | QCOMPARE(spy3.count(), 1); |
|
185 | 186 | |
|
186 | 187 | m_chart->setAxisX(&axis, m_series); |
|
187 | 188 | m_view->show(); |
|
188 | 189 | QTest::qWaitForWindowShown(m_view); |
|
189 | 190 | QCOMPARE(axis.categories(), categories); |
|
190 | 191 | |
|
191 | 192 | QCOMPARE(spy0.count(), 1); |
|
192 | 193 | QCOMPARE(spy1.count(), 1); |
|
193 | 194 | QCOMPARE(spy2.count(), 1); |
|
194 | 195 | QCOMPARE(spy3.count(), 1); |
|
196 | QCOMPARE(spy4.count(), 1); | |
|
195 | 197 | } |
|
196 | 198 | |
|
197 | 199 | void tst_QBarCategoriesAxis::append2_data() |
|
198 | 200 | { |
|
199 | 201 | QTest::addColumn<QStringList>("categories"); |
|
200 | 202 | QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr"); |
|
201 | 203 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
202 | 204 | } |
|
203 | 205 | |
|
204 | 206 | void tst_QBarCategoriesAxis::append2() |
|
205 | 207 | { |
|
206 | 208 | QFETCH(QStringList, categories); |
|
207 | 209 | |
|
208 | 210 | QBarCategoryAxis axis; |
|
209 | 211 | |
|
210 | 212 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
211 | 213 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
212 | 214 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
213 | 215 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
216 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
214 | 217 | |
|
215 | 218 | foreach(QString category, categories) |
|
216 | 219 | axis.append(category); |
|
217 | 220 | |
|
218 | 221 | QCOMPARE(spy0.count(), categories.count()); |
|
219 | 222 | QCOMPARE(spy1.count(), categories.count()); |
|
220 | 223 | QCOMPARE(spy2.count(), 1); |
|
221 | 224 | QCOMPARE(spy3.count(), categories.count()); |
|
222 | 225 | |
|
223 | 226 | m_chart->setAxisX(&axis, m_series); |
|
224 | 227 | m_view->show(); |
|
225 | 228 | QTest::qWaitForWindowShown(m_view); |
|
226 | 229 | QCOMPARE(axis.categories(), categories); |
|
227 | 230 | |
|
228 | 231 | QCOMPARE(spy0.count(), categories.count()); |
|
229 | 232 | QCOMPARE(spy1.count(), categories.count()); |
|
230 | 233 | QCOMPARE(spy2.count(), 1); |
|
231 | 234 | QCOMPARE(spy3.count(), categories.count()); |
|
235 | QCOMPARE(spy4.count(), categories.count()); | |
|
232 | 236 | } |
|
233 | 237 | |
|
234 | 238 | void tst_QBarCategoriesAxis::at_data() |
|
235 | 239 | { |
|
236 | 240 | QTest::addColumn<QStringList>("categories"); |
|
237 | 241 | QTest::addColumn<int>("index"); |
|
238 | 242 | QTest::addColumn<QString>("string"); |
|
239 | 243 | QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul"; |
|
240 | 244 | QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep"; |
|
241 | 245 | QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug"; |
|
242 | 246 | } |
|
243 | 247 | |
|
244 | 248 | void tst_QBarCategoriesAxis::at() |
|
245 | 249 | { |
|
246 | 250 | QFETCH(int, index); |
|
247 | 251 | QFETCH(QString, string); |
|
248 | 252 | QFETCH(QStringList, categories); |
|
249 | 253 | |
|
250 | 254 | QBarCategoryAxis axis; |
|
251 | 255 | axis.append(categories); |
|
252 | 256 | |
|
253 | 257 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
254 | 258 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
255 | 259 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
256 | 260 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
261 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
257 | 262 | |
|
258 | 263 | QCOMPARE(axis.at(index), string); |
|
259 | 264 | |
|
260 | 265 | QCOMPARE(spy0.count(), 0); |
|
261 | 266 | QCOMPARE(spy1.count(), 0); |
|
262 | 267 | QCOMPARE(spy2.count(), 0); |
|
263 | 268 | QCOMPARE(spy3.count(), 0); |
|
264 | 269 | |
|
265 | 270 | m_chart->setAxisX(&axis, m_series); |
|
266 | 271 | m_view->show(); |
|
267 | 272 | QTest::qWaitForWindowShown(m_view); |
|
268 | 273 | QCOMPARE(axis.at(index), string); |
|
269 | 274 | |
|
270 | 275 | QCOMPARE(spy0.count(), 0); |
|
271 | 276 | QCOMPARE(spy1.count(), 0); |
|
272 | 277 | QCOMPARE(spy2.count(), 0); |
|
273 | 278 | QCOMPARE(spy3.count(), 0); |
|
279 | QCOMPARE(spy4.count(), 0); | |
|
274 | 280 | } |
|
275 | 281 | |
|
276 | 282 | void tst_QBarCategoriesAxis::categories_data() |
|
277 | 283 | { |
|
278 | 284 | QTest::addColumn<QStringList>("categories"); |
|
279 | 285 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
280 | 286 | } |
|
281 | 287 | |
|
282 | 288 | void tst_QBarCategoriesAxis::categories() |
|
283 | 289 | { |
|
284 | 290 | QFETCH(QStringList, categories); |
|
285 | 291 | |
|
286 | 292 | QBarCategoryAxis axis; |
|
287 | 293 | |
|
288 | 294 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
289 | 295 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
290 | 296 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
291 | 297 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
298 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
292 | 299 | |
|
293 | 300 | axis.setCategories(categories); |
|
294 | 301 | QCOMPARE(axis.categories(), categories); |
|
295 | 302 | |
|
296 | 303 | QCOMPARE(spy0.count(), 1); |
|
297 | 304 | QCOMPARE(spy1.count(), 1); |
|
298 | 305 | QCOMPARE(spy2.count(), 1); |
|
299 | 306 | QCOMPARE(spy3.count(), 1); |
|
300 | 307 | |
|
301 | 308 | m_chart->setAxisX(&axis, m_series); |
|
302 | 309 | m_view->show(); |
|
303 | 310 | QTest::qWaitForWindowShown(m_view); |
|
304 | 311 | QCOMPARE(axis.categories(), categories); |
|
305 | 312 | |
|
306 | 313 | QCOMPARE(spy0.count(), 1); |
|
307 | 314 | QCOMPARE(spy1.count(), 1); |
|
308 | 315 | QCOMPARE(spy2.count(), 1); |
|
309 | 316 | QCOMPARE(spy3.count(), 1); |
|
310 | ||
|
317 | QCOMPARE(spy4.count(), 1); | |
|
311 | 318 | } |
|
312 | 319 | |
|
313 | 320 | void tst_QBarCategoriesAxis::clear_data() |
|
314 | 321 | { |
|
315 | 322 | QTest::addColumn<QStringList>("categories"); |
|
316 | 323 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
317 | 324 | } |
|
318 | 325 | |
|
319 | 326 | void tst_QBarCategoriesAxis::clear() |
|
320 | 327 | { |
|
321 | 328 | QFETCH(QStringList, categories); |
|
322 | 329 | |
|
323 | 330 | QBarCategoryAxis axis; |
|
324 | 331 | |
|
325 | 332 | axis.setCategories(categories); |
|
326 | 333 | QCOMPARE(axis.categories(), categories); |
|
327 | 334 | |
|
328 | 335 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
329 | 336 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
330 | 337 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
331 | 338 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
339 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
332 | 340 | |
|
333 | 341 | axis.clear(); |
|
334 | 342 | QCOMPARE(axis.categories(), QStringList()); |
|
335 | 343 | |
|
336 | 344 | QCOMPARE(spy0.count(), 1); |
|
337 | 345 | QCOMPARE(spy1.count(), 1); |
|
338 | 346 | QCOMPARE(spy2.count(), 1); |
|
339 | 347 | QCOMPARE(spy3.count(), 1); |
|
340 | 348 | |
|
341 | 349 | m_chart->setAxisX(&axis, m_series); |
|
342 | 350 | m_view->show(); |
|
343 | 351 | QTest::qWaitForWindowShown(m_view); |
|
344 | 352 | |
|
345 | 353 | QCOMPARE(spy0.count(), 2); |
|
346 | 354 | QCOMPARE(spy1.count(), 2); |
|
347 | 355 | QCOMPARE(spy2.count(), 2); |
|
348 | 356 | QCOMPARE(spy3.count(), 2); |
|
349 | 357 | |
|
350 | 358 | axis.clear(); |
|
351 | 359 | QCOMPARE(axis.categories().count(),0); |
|
352 | 360 | QCOMPARE(spy0.count(), 3); |
|
353 | 361 | QCOMPARE(spy1.count(), 3); |
|
354 | 362 | QCOMPARE(spy2.count(), 3); |
|
355 | 363 | QCOMPARE(spy3.count(), 3); |
|
364 | QCOMPARE(spy4.count(), 3); | |
|
356 | 365 | } |
|
357 | 366 | |
|
358 | 367 | void tst_QBarCategoriesAxis::count_data() |
|
359 | 368 | { |
|
360 | 369 | QTest::addColumn<QStringList>("categories"); |
|
361 | 370 | QTest::addColumn<int>("count"); |
|
362 | 371 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3; |
|
363 | 372 | QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2; |
|
364 | 373 | } |
|
365 | 374 | |
|
366 | 375 | void tst_QBarCategoriesAxis::count() |
|
367 | 376 | { |
|
368 | 377 | QFETCH(QStringList, categories); |
|
369 | 378 | QFETCH(int, count); |
|
370 | 379 | |
|
371 | 380 | QBarCategoryAxis axis; |
|
372 | 381 | axis.setCategories(categories); |
|
373 | 382 | |
|
374 | 383 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
375 | 384 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
376 | 385 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
377 | 386 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
387 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
378 | 388 | |
|
379 | 389 | QCOMPARE(axis.count(), count); |
|
380 | 390 | |
|
381 | 391 | QCOMPARE(spy0.count(), 0); |
|
382 | 392 | QCOMPARE(spy1.count(), 0); |
|
383 | 393 | QCOMPARE(spy2.count(), 0); |
|
384 | 394 | QCOMPARE(spy3.count(), 0); |
|
395 | QCOMPARE(spy4.count(), 0); | |
|
385 | 396 | |
|
386 | 397 | m_chart->setAxisX(&axis, m_series); |
|
387 | 398 | m_view->show(); |
|
388 | 399 | QTest::qWaitForWindowShown(m_view); |
|
389 | 400 | QCOMPARE(axis.count(), count); |
|
390 | 401 | } |
|
391 | 402 | |
|
392 | 403 | void tst_QBarCategoriesAxis::insert_data() |
|
393 | 404 | { |
|
394 | 405 | QTest::addColumn<QStringList>("categories"); |
|
395 | 406 | QTest::addColumn<int>("index"); |
|
396 | 407 | QTest::addColumn<QString>("category"); |
|
397 | 408 | QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Jun"; |
|
398 | 409 | QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer"; |
|
399 | 410 | } |
|
400 | 411 | |
|
401 | 412 | void tst_QBarCategoriesAxis::insert() |
|
402 | 413 | { |
|
403 | 414 | QFETCH(QStringList, categories); |
|
404 | 415 | QFETCH(int, index); |
|
405 | 416 | QFETCH(QString, category); |
|
406 | 417 | |
|
407 | 418 | QBarCategoryAxis axis; |
|
408 | 419 | axis.append(categories); |
|
409 | 420 | |
|
410 | 421 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
411 | 422 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
412 | 423 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
413 | 424 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
425 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
414 | 426 | |
|
415 | 427 | axis.insert(index, category); |
|
416 | 428 | QCOMPARE(axis.at(index),category); |
|
417 | 429 | |
|
418 | 430 | QCOMPARE(spy0.count(), 1); |
|
419 | 431 | QCOMPARE(spy1.count(), 0); |
|
420 | 432 | QCOMPARE(spy2.count(), 0); |
|
421 | 433 | QCOMPARE(spy3.count(), 0); |
|
434 | QCOMPARE(spy4.count(), 1); | |
|
422 | 435 | |
|
423 | 436 | m_chart->setAxisX(&axis, m_series); |
|
424 | 437 | m_view->show(); |
|
425 | 438 | QTest::qWaitForWindowShown(m_view); |
|
426 | 439 | } |
|
427 | 440 | |
|
428 | 441 | void tst_QBarCategoriesAxis::remove_data() |
|
429 | 442 | { |
|
430 | 443 | QTest::addColumn<QStringList>("categories"); |
|
431 | 444 | QTest::addColumn<QString>("category"); |
|
432 | 445 | QTest::addColumn<QStringList>("result"); |
|
433 | 446 | QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep"); |
|
434 | 447 | QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep"); |
|
435 | 448 | } |
|
436 | 449 | |
|
437 | 450 | void tst_QBarCategoriesAxis::remove() |
|
438 | 451 | { |
|
439 | 452 | QFETCH(QStringList, categories); |
|
440 | 453 | QFETCH(QString, category); |
|
441 | 454 | QFETCH(QStringList, result); |
|
442 | 455 | |
|
443 | 456 | QBarCategoryAxis axis; |
|
444 | 457 | axis.append(categories); |
|
445 | 458 | |
|
446 | 459 | int maxCount = axis.max() == category; |
|
447 | 460 | int minCount = axis.min() == category; |
|
448 | 461 | int rangeCount = maxCount + minCount; |
|
449 | 462 | |
|
450 | 463 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
451 | 464 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString))); |
|
452 | 465 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString))); |
|
453 | 466 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString,QString))); |
|
467 | QSignalSpy spy4(&axis, SIGNAL(countChanged())); | |
|
454 | 468 | |
|
455 | 469 | axis.remove(category); |
|
456 | 470 | QCOMPARE(axis.categories(),result); |
|
457 | 471 | |
|
458 | 472 | QCOMPARE(spy0.count(), 1); |
|
459 | 473 | QCOMPARE(spy1.count(), maxCount); |
|
460 | 474 | QCOMPARE(spy2.count(), minCount); |
|
461 | 475 | QCOMPARE(spy3.count(), rangeCount); |
|
476 | QCOMPARE(spy4.count(), 1); | |
|
462 | 477 | } |
|
463 | 478 | |
|
464 | 479 | void tst_QBarCategoriesAxis::max_raw_data() |
|
465 | 480 | { |
|
466 | 481 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
467 | 482 | QTest::addColumn<QString>("max"); |
|
468 | 483 | QTest::newRow("Feb") << "Feb"; |
|
469 | 484 | QTest::newRow("Apr") << "Apr"; |
|
470 | 485 | QTest::newRow("May") << "May"; |
|
471 | 486 | } |
|
472 | 487 | |
|
473 | 488 | void tst_QBarCategoriesAxis::max_raw() |
|
474 | 489 | { |
|
475 | 490 | QFETCH(QString, max); |
|
476 | 491 | |
|
477 | 492 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
478 | 493 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString))); |
|
479 | 494 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString))); |
|
480 | 495 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString))); |
|
496 | QSignalSpy spy4(m_baraxis, SIGNAL(countChanged())); | |
|
481 | 497 | |
|
482 | 498 | m_baraxis->setMax(max); |
|
483 | 499 | QCOMPARE(m_baraxis->max(), max); |
|
484 | 500 | |
|
485 | 501 | QCOMPARE(spy0.count(), 0); |
|
486 | 502 | QCOMPARE(spy1.count(), 1); |
|
487 | 503 | QCOMPARE(spy2.count(), 0); |
|
488 | 504 | QCOMPARE(spy3.count(), 1); |
|
505 | QCOMPARE(spy4.count(), 0); | |
|
489 | 506 | } |
|
490 | 507 | |
|
491 | 508 | void tst_QBarCategoriesAxis::max_data() |
|
492 | 509 | { |
|
493 | 510 | max_raw_data(); |
|
494 | 511 | } |
|
495 | 512 | |
|
496 | 513 | void tst_QBarCategoriesAxis::max() |
|
497 | 514 | { |
|
498 | 515 | m_chart->setAxisX(m_baraxis, m_series); |
|
499 | 516 | m_view->show(); |
|
500 | 517 | QTest::qWaitForWindowShown(m_view); |
|
501 | 518 | max_raw(); |
|
502 | 519 | } |
|
503 | 520 | |
|
504 | 521 | void tst_QBarCategoriesAxis::max_animation_data() |
|
505 | 522 | { |
|
506 | 523 | max_data(); |
|
507 | 524 | } |
|
508 | 525 | |
|
509 | 526 | void tst_QBarCategoriesAxis::max_animation() |
|
510 | 527 | { |
|
511 | 528 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
512 | 529 | max(); |
|
513 | 530 | } |
|
514 | 531 | |
|
515 | 532 | void tst_QBarCategoriesAxis::min_raw_data() |
|
516 | 533 | { |
|
517 | 534 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
518 | 535 | QTest::addColumn<QString>("min"); |
|
519 | 536 | QTest::newRow("Feb") << "Feb"; |
|
520 | 537 | QTest::newRow("Apr") << "Apr"; |
|
521 | 538 | QTest::newRow("May") << "May"; |
|
522 | 539 | } |
|
523 | 540 | |
|
524 | 541 | void tst_QBarCategoriesAxis::min_raw() |
|
525 | 542 | { |
|
526 | 543 | QFETCH(QString, min); |
|
527 | 544 | |
|
528 | 545 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
529 | 546 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString))); |
|
530 | 547 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString))); |
|
531 | 548 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString))); |
|
549 | QSignalSpy spy4(m_baraxis, SIGNAL(countChanged())); | |
|
532 | 550 | |
|
533 | 551 | m_baraxis->setMin(min); |
|
534 | 552 | QCOMPARE(m_baraxis->min(), min); |
|
535 | 553 | |
|
536 | 554 | QCOMPARE(spy0.count(), 0); |
|
537 | 555 | QCOMPARE(spy1.count(), 0); |
|
538 | 556 | QCOMPARE(spy2.count(), 1); |
|
539 | 557 | QCOMPARE(spy3.count(), 1); |
|
540 | ||
|
558 | QCOMPARE(spy4.count(), 0); | |
|
541 | 559 | } |
|
542 | 560 | |
|
543 | 561 | void tst_QBarCategoriesAxis::min_data() |
|
544 | 562 | { |
|
545 | 563 | min_raw_data(); |
|
546 | 564 | } |
|
547 | 565 | |
|
548 | 566 | void tst_QBarCategoriesAxis::min() |
|
549 | 567 | { |
|
550 | 568 | min_raw(); |
|
551 | 569 | m_chart->setAxisX(m_baraxis, m_series); |
|
552 | 570 | m_view->show(); |
|
553 | 571 | QTest::qWaitForWindowShown(m_view); |
|
554 | 572 | |
|
555 | 573 | } |
|
556 | 574 | |
|
557 | 575 | void tst_QBarCategoriesAxis::min_animation_data() |
|
558 | 576 | { |
|
559 | 577 | min_data(); |
|
560 | 578 | } |
|
561 | 579 | |
|
562 | 580 | void tst_QBarCategoriesAxis::min_animation() |
|
563 | 581 | { |
|
564 | 582 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
565 | 583 | min(); |
|
566 | 584 | } |
|
567 | 585 | |
|
568 | 586 | |
|
569 | 587 | void tst_QBarCategoriesAxis::range_raw_data() |
|
570 | 588 | { |
|
571 | 589 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
572 | 590 | QTest::addColumn<QString>("min"); |
|
573 | 591 | QTest::addColumn<QString>("max"); |
|
574 | 592 | QTest::newRow("Feb - Apr") << "Feb" << "Apr"; |
|
575 | 593 | QTest::newRow("Feb - May") << "Feb" << "May"; |
|
576 | 594 | QTest::newRow("Mar - Apr") << "Mar" << "Apr"; |
|
577 | 595 | } |
|
578 | 596 | |
|
579 | 597 | void tst_QBarCategoriesAxis::range_raw() |
|
580 | 598 | { |
|
581 | 599 | QFETCH(QString, min); |
|
582 | 600 | QFETCH(QString, max); |
|
583 | 601 | |
|
584 | 602 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
585 | 603 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString))); |
|
586 | 604 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString))); |
|
587 | 605 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString,QString))); |
|
606 | QSignalSpy spy4(m_baraxis, SIGNAL(countChanged())); | |
|
588 | 607 | |
|
589 | 608 | m_baraxis->setRange(min, max); |
|
590 | 609 | QCOMPARE(m_baraxis->min(), min); |
|
591 | 610 | QCOMPARE(m_baraxis->max(), max); |
|
592 | 611 | |
|
593 | 612 | QCOMPARE(spy0.count(), 0); |
|
594 | 613 | QCOMPARE(spy1.count(), 1); |
|
595 | 614 | QCOMPARE(spy2.count(), 1); |
|
596 | 615 | QCOMPARE(spy3.count(), 1); |
|
616 | QCOMPARE(spy4.count(), 0); | |
|
597 | 617 | } |
|
598 | 618 | |
|
599 | 619 | void tst_QBarCategoriesAxis::range_data() |
|
600 | 620 | { |
|
601 | 621 | range_raw_data(); |
|
602 | 622 | } |
|
603 | 623 | |
|
604 | 624 | void tst_QBarCategoriesAxis::range() |
|
605 | 625 | { |
|
606 | 626 | range_raw(); |
|
607 | 627 | m_chart->setAxisX(m_baraxis, m_series); |
|
608 | 628 | m_view->show(); |
|
609 | 629 | QTest::qWaitForWindowShown(m_view); |
|
610 | 630 | |
|
611 | 631 | } |
|
612 | 632 | |
|
613 | 633 | void tst_QBarCategoriesAxis::range_animation_data() |
|
614 | 634 | { |
|
615 | 635 | range_data(); |
|
616 | 636 | } |
|
617 | 637 | |
|
618 | 638 | void tst_QBarCategoriesAxis::range_animation() |
|
619 | 639 | { |
|
620 | 640 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
621 | 641 | range(); |
|
622 | 642 | } |
|
623 | 643 | |
|
624 | 644 | |
|
625 | 645 | void tst_QBarCategoriesAxis::noautoscale_data() |
|
626 | 646 | { |
|
627 | 647 | QTest::addColumn<QString>("min"); |
|
628 | 648 | QTest::addColumn<QString>("max"); |
|
629 | 649 | QTest::newRow("Feb - Mar") << "Feb" << "Mar"; |
|
630 | 650 | QTest::newRow("Feb - May") << "Feb" << "May"; |
|
631 | 651 | QTest::newRow("Apr - May") << "Apr" << "May"; |
|
632 | 652 | } |
|
633 | 653 | |
|
634 | 654 | void tst_QBarCategoriesAxis::noautoscale() |
|
635 | 655 | { |
|
636 | 656 | QFETCH(QString, min); |
|
637 | 657 | QFETCH(QString, max); |
|
638 | 658 | |
|
639 | 659 | QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); |
|
640 | 660 | QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); |
|
641 | 661 | QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString))); |
|
642 | 662 | |
|
643 | 663 | m_baraxis->setRange(min, max); |
|
644 | 664 | QCOMPARE(m_baraxis->min(),min); |
|
645 | 665 | QCOMPARE(m_baraxis->max(),max); |
|
646 | 666 | |
|
647 | 667 | QCOMPARE(spy0.count(), 1); |
|
648 | 668 | QCOMPARE(spy1.count(), 1); |
|
649 | 669 | QCOMPARE(spy2.count(), 1); |
|
650 | 670 | |
|
651 | 671 | m_chart->setAxisX(m_baraxis, m_series); |
|
652 | 672 | m_view->show(); |
|
653 | 673 | QTest::qWaitForWindowShown(m_view); |
|
654 | 674 | QCOMPARE(m_baraxis->min(),min); |
|
655 | 675 | QCOMPARE(m_baraxis->max(),max); |
|
656 | 676 | } |
|
657 | 677 | |
|
658 | 678 | void tst_QBarCategoriesAxis::autoscale_data() |
|
659 | 679 | { |
|
660 | 680 | |
|
661 | 681 | } |
|
662 | 682 | |
|
663 | 683 | void tst_QBarCategoriesAxis::autoscale() |
|
664 | 684 | { |
|
665 | 685 | delete m_baraxis; |
|
666 | 686 | m_baraxis = new QBarCategoryAxis(); |
|
667 | 687 | |
|
668 | 688 | QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); |
|
669 | 689 | QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); |
|
670 | 690 | QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString,QString))); |
|
671 | 691 | |
|
672 | 692 | QCOMPARE(m_baraxis->min(),QString()); |
|
673 | 693 | QCOMPARE(m_baraxis->max(),QString()); |
|
674 | 694 | m_chart->setAxisX(m_baraxis, m_series); |
|
675 | 695 | |
|
676 | 696 | QCOMPARE(spy0.count(), 1); |
|
677 | 697 | QCOMPARE(spy1.count(), 1); |
|
678 | 698 | QCOMPARE(spy2.count(), 1); |
|
679 | 699 | |
|
680 | 700 | m_view->show(); |
|
681 | 701 | QTest::qWaitForWindowShown(m_view); |
|
682 | 702 | QCOMPARE(m_baraxis->min(),QString("1")); |
|
683 | 703 | QCOMPARE(m_baraxis->max(),QString("6")); |
|
684 | 704 | } |
|
685 | 705 | |
|
686 | 706 | |
|
687 | 707 | QTEST_MAIN(tst_QBarCategoriesAxis) |
|
688 | 708 | #include "tst_qbarcategoryaxis.moc" |
|
689 | 709 |
|
1 | NO CONTENT: file renamed from tests/auto/qml-qtquicktest/tst_categoriesaxis.qml to tests/auto/qml-qtquicktest/tst_categoryaxis.qml |
@@ -1,63 +1,63 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtQuickTest 1.0 |
|
23 |
import QtCommercial.Chart 1. |
|
|
23 | import QtCommercial.Chart 1.1 | |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | width: 400 |
|
27 | 27 | height: 300 |
|
28 | 28 | |
|
29 | 29 | TestCase { |
|
30 | 30 | id: tc1 |
|
31 |
name: "tst_qml-qtquicktest Value |
|
|
31 | name: "tst_qml-qtquicktest ValueAxis 1.1" | |
|
32 | 32 | when: windowShown |
|
33 | 33 | |
|
34 | 34 | function test_minMax() { |
|
35 | 35 | compare(lineSeries1.axisX.min, 0, "AxisX min"); |
|
36 | 36 | compare(lineSeries1.axisX.max, 10, "AxisX max"); |
|
37 | 37 | compare(lineSeries1.axisY.min, 0, "AxisY min"); |
|
38 | 38 | compare(lineSeries1.axisY.max, 10, "AxisY max"); |
|
39 | 39 | } |
|
40 | 40 | } |
|
41 | 41 | |
|
42 | 42 | ChartView { |
|
43 | 43 | id: chartView |
|
44 | 44 | anchors.fill: parent |
|
45 | 45 | |
|
46 | 46 | LineSeries { |
|
47 | 47 | id: lineSeries1 |
|
48 |
axisX: Value |
|
|
48 | axisX: ValueAxis { | |
|
49 | 49 | id: axisX |
|
50 | 50 | min: 0 |
|
51 | 51 | max: 10 |
|
52 | 52 | } |
|
53 |
axisY: Value |
|
|
53 | axisY: ValueAxis { | |
|
54 | 54 | id: axisY |
|
55 | 55 | min: 0 |
|
56 | 56 | max: 10 |
|
57 | 57 | } |
|
58 | 58 | XYPoint { x: -1; y: -1 } |
|
59 | 59 | XYPoint { x: 0; y: 0 } |
|
60 | 60 | XYPoint { x: 5; y: 5 } |
|
61 | 61 | } |
|
62 | 62 | } |
|
63 | 63 | } |
General Comments 0
You need to be logged in to leave comments.
Login now