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