##// END OF EJS Templates
Added CategoryAxis and CategoryRange to QML API
Tero Ahola -
r1870:102af68fd8c5
parent child
Show More
@@ -1,101 +1,112
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.0
22 22 import QtCommercial.Chart 1.1
23 23
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 //![1]
28 28 ChartView {
29 29 title: "NHL All-Star Team Players"
30 30 anchors.fill: parent
31 31
32 BarCategoriesAxis {
33 id: catergoriesAxis
34 categories: ["2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008",
35 "2009", "2010", "2011" ]
32 CategoryAxis {
33 id: categoriesAxis
34 startValue: -0.5
35 CategoryRange { endValue: 0.5; label: "2000" }
36 CategoryRange { endValue: 1.5; label: "2001" }
37 CategoryRange { endValue: 2.5; label: "2002" }
38 CategoryRange { endValue: 3.5; label: "2003" }
39 CategoryRange { endValue: 4.5; label: "2004" }
40 CategoryRange { endValue: 5.5; label: "2005" }
41 CategoryRange { endValue: 6.5; label: "2006" }
42 CategoryRange { endValue: 7.5; label: "2007" }
43 CategoryRange { endValue: 8.5; label: "2008" }
44 CategoryRange { endValue: 9.5; label: "2009" }
45 CategoryRange { endValue: 10.5; label: "2010" }
46 CategoryRange { endValue: 11.5; label: "2011" }
36 47 }
37 48
38 49 AreaSeries {
39 50 name: "Russian"
40 axisX: catergoriesAxis
51 axisX: categoriesAxis
41 52 upperSeries: LineSeries {
42 53 XYPoint { x: 0; y: 1 }
43 54 XYPoint { x: 1; y: 1 }
44 55 XYPoint { x: 2; y: 1 }
45 56 XYPoint { x: 3; y: 1 }
46 57 XYPoint { x: 4; y: 1 }
47 58 XYPoint { x: 5; y: 0 }
48 59 XYPoint { x: 6; y: 1 }
49 60 XYPoint { x: 7; y: 1 }
50 61 XYPoint { x: 8; y: 4 }
51 62 XYPoint { x: 9; y: 3 }
52 63 XYPoint { x: 10; y: 2 }
53 64 XYPoint { x: 11; y: 1 }
54 65 }
55 66 }
56 67 // ...
57 68 //![1]
58 69
59 70 AreaSeries {
60 71 name: "Swedish"
61 axisX: catergoriesAxis
72 axisX: categoriesAxis
62 73 upperSeries: LineSeries {
63 74 XYPoint { x: 0; y: 1 }
64 75 XYPoint { x: 1; y: 1 }
65 76 XYPoint { x: 2; y: 3 }
66 77 XYPoint { x: 3; y: 3 }
67 78 XYPoint { x: 4; y: 2 }
68 79 XYPoint { x: 5; y: 0 }
69 80 XYPoint { x: 6; y: 2 }
70 81 XYPoint { x: 7; y: 1 }
71 82 XYPoint { x: 8; y: 2 }
72 83 XYPoint { x: 9; y: 1 }
73 84 XYPoint { x: 10; y: 3 }
74 85 XYPoint { x: 11; y: 3 }
75 86 }
76 87 }
77 88
78 89 AreaSeries {
79 90 name: "Finnish"
80 axisX: catergoriesAxis
91 axisX: categoriesAxis
81 92 upperSeries: LineSeries {
82 93 XYPoint { x: 0; y: 0 }
83 94 XYPoint { x: 1; y: 0 }
84 95 XYPoint { x: 2; y: 0 }
85 96 XYPoint { x: 3; y: 0 }
86 97 XYPoint { x: 4; y: 0 }
87 98 XYPoint { x: 5; y: 0 }
88 99 XYPoint { x: 6; y: 1 }
89 100 XYPoint { x: 7; y: 0 }
90 101 XYPoint { x: 8; y: 0 }
91 102 XYPoint { x: 9; y: 0 }
92 103 XYPoint { x: 10; y: 0 }
93 104 XYPoint { x: 11; y: 1 }
94 105 }
95 106 onClicked: {
96 107 color = "white";
97 108 borderColor = "blue";
98 109 }
99 110 }
100 111 }
101 112 }
@@ -1,80 +1,82
1 1 /*!
2 2 \page qml.html
3 3 \title QtCommercial Charts QML API
4 4 \keyword Charts QML API
5 5
6 6 QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML
7 7 applications. The following QML shows you to create a simple pie chart:
8 8 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
9 9 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
10 10 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
11 11
12 12 \raw HTML
13 13 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
14 14 <tr>
15 15 <th class="titleheader" width="25%"> ChartView and it's properties </th>
16 16 </tr>
17 17 <tr>
18 18 <td valign="top">
19 19 <ul>
20 20 <li><a href="qml-chartview.html">ChartView</a></li>
21 21 <li><a href="qml-abstractaxis.html">AbstractAxis</a></li>
22 22 <li><a href="qml-valueaxis.html">ValueAxis</a></li>
23 <li><a href="qml-categoryaxis.html">CategoryAxis</a></li>
24 <li><a href="qml-categoryrange.html">CategoryRange</a></li>
23 25 <li><a href="qml-barcategoryaxis.html">BarCategoryAxis</a></li>
24 26 <li><a href="qml-legend.html">Legend</a></li>
25 27 <li><a href="qml-abstractseries.html">AbstractSeries</a></li>
26 28 </ul>
27 29 </td>
28 30 </tr>
29 31 </table>
30 32 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
31 33 <tr>
32 34 <th class="titleheader" width="25%"> XY chart </th>
33 35 </tr>
34 36 <tr>
35 37 <td valign="top">
36 38 <ul>
37 39 <li><a href="qml-xyseries.html">XYSeries</a></li>
38 40 <li><a href="qml-lineseries.html">LineSeries</a></li>
39 41 <li><a href="qml-areaseries.html">AreaSeries</a></li>
40 42 <li><a href="qml-scatterseries.html">ScatterSeries</a></li>
41 43 <li><a href="qml-splineseries.html">SplineSeries</a></li>
42 44 <li><a href="qml-xypoint.html">XYPoint</a></li>
43 45 <li><a href="qml-hxymodelmapper.html">HXYModelMapper</a></li>
44 46 <li><a href="qml-vxymodelmapper.html">VXYModelMapper</a></li>
45 47 </ul>
46 48 </td>
47 49 </tr>
48 50 </table>
49 51 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
50 52 <tr>
51 53 <th class="titleheader" width="25%"> Pie chart </th>
52 54 <tr>
53 55 <td valign="top">
54 56 <ul>
55 57 <li><a href="qml-pieseries.html">PieSeries</a></li>
56 58 <li><a href="qml-pieslice.html">PieSlice</a></li>
57 59 <li><a href="qml-hpiemodelmapper.html">HPieModelMapper</a></li>
58 60 <li><a href="qml-vpiemodelmapper.html">VPieModelMapper</a></li>
59 61 </ul>
60 62 </td>
61 63 </tr>
62 64 </table>
63 65 <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable">
64 66 <tr>
65 67 <th class="titleheader" width="25%"> Bar chart </th>
66 68 <tr>
67 69 <td valign="top">
68 70 <ul>
69 71 <li><a href="qml-barseries.html">BarSeries</a></li>
70 72 <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li>
71 73 <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li>
72 74 <li><a href="qml-barset.html">BarSet</a></li>
73 75 <li><a href="qml-hbarmodelmapper.html">HBarModelMapper</a></li>
74 76 <li><a href="qml-vbarmodelmapper.html">VBarModelMapper</a></li>
75 77 </ul>
76 78 </td>
77 79 </tr>
78 80 </table>
79 81 \endraw
80 82 */
@@ -1,50 +1,52
1 1 TARGET = qtcommercialchartqml
2 2 QT += declarative
3 3
4 4 !include( ../plugins.pri ) {
5 5 error( "Couldn't find the plugins.pri file!" )
6 6 }
7 7 INCLUDEPATH += $$CHART_BUILD_PRIVATE_HEADER_DIR
8 8
9 9 contains(QT_MAJOR_VERSION, 5) {
10 10 # TODO: QtQuick2 not supported by the implementation currently
11 11 DEFINES += QTQUICK2
12 12 }
13 13
14 14 CONFIG(debug, debug|release) {
15 15 mac: TARGET = $$join(TARGET,,,_debug)
16 16 win32: TARGET = $$join(TARGET,,,d)
17 17 }
18 18
19 19 SOURCES += \
20 20 plugin.cpp \
21 21 declarativechart.cpp \
22 22 declarativexypoint.cpp \
23 23 declarativexyseries.cpp \
24 24 declarativelineseries.cpp \
25 25 declarativesplineseries.cpp \
26 26 declarativeareaseries.cpp \
27 27 declarativescatterseries.cpp \
28 28 declarativepieseries.cpp \
29 declarativebarseries.cpp
30
29 declarativebarseries.cpp \
30 declarativecategoryaxis.cpp
31
31 32 HEADERS += \
32 33 declarativechart.h \
33 34 declarativexypoint.h \
34 35 declarativexyseries.h \
35 36 declarativelineseries.h \
36 37 declarativesplineseries.h \
37 38 declarativeareaseries.h \
38 39 declarativescatterseries.h \
39 40 declarativepieseries.h \
40 declarativebarseries.h
41 declarativebarseries.h \
42 declarativecategoryaxis.h
41 43
42 44 TARGETPATH = QtCommercial/Chart
43 45 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
44 46 qmldir.files += $$PWD/qmldir
45 47 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
46 48 INSTALLS += target qmldir
47 49
48 50 FILE = $$PWD/qmldir
49 51 win32:{FILE = $$replace(FILE, "/","\\")}
50 52 QMAKE_POST_LINK += $$QMAKE_COPY $$FILE $$CHART_BUILD_PLUGIN_DIR
@@ -1,144 +1,149
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qabstractaxis.h"
25 25 #include "qvalueaxis.h"
26 #include "qdatetimeaxis.h"
27 #include "declarativecategoryaxis.h"
26 28 #include "qbarcategoryaxis.h"
27 29 #include "declarativechart.h"
28 30 #include "declarativexypoint.h"
29 31 #include "declarativelineseries.h"
30 32 #include "declarativesplineseries.h"
31 33 #include "declarativeareaseries.h"
32 34 #include "declarativescatterseries.h"
33 35 #include "declarativebarseries.h"
34 36 #include "declarativepieseries.h"
35 37 #include "qvxymodelmapper.h"
36 38 #include "qhxymodelmapper.h"
37 39 #include "qhpiemodelmapper.h"
38 40 #include "qvpiemodelmapper.h"
39 41 #include "qhbarmodelmapper.h"
40 42 #include "qvbarmodelmapper.h"
41 43 #include <QAbstractItemModel>
42 44
43 45 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44 46
45 47 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
46 48 {
47 49 Q_OBJECT
48 50 public:
49 51 virtual void registerTypes(const char *uri)
50 52 {
51 53 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
52 54
53 55 // QtCommercial.Chart 1.0
54 56 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
55 57 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
56 58 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
57 59 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
58 60 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
59 61 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
60 62 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
61 63 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
62 64 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
63 65 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
64 66 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
65 67 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
66 68 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
67 69 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
68 70 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
69 71 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
70 72 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
71 73 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
72 74 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
73 75 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
74 76 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
75 77 QLatin1String("Trying to create uncreatable: Legend."));
76 78 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
77 79 QLatin1String("Trying to create uncreatable: XYSeries."));
78 80 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
79 81 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
80 82 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
81 83 QLatin1String("Trying to create uncreatable: XYModelMapper."));
82 84 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
83 85 QLatin1String("Trying to create uncreatable: PieModelMapper."));
84 86 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
85 87 QLatin1String("Trying to create uncreatable: BarModelMapper."));
86 88 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
87 89 QLatin1String("Trying to create uncreatable: AbstractSeries."));
88 90 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
89 91 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
90 92 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
91 93 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
92 94
93 95 // QtCommercial.Chart 1.1
94 96 qmlRegisterType<DeclarativeChart>(uri, 1, 1, "ChartView");
95 97 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 1, "XYPoint");
96 98 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
97 99 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
98 100 qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries");
99 101 qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries");
100 102 qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries");
101 103 qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries");
102 104 qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries");
103 105 qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries");
104 106 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries");
105 107 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries");
106 108 qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries");
107 109 qmlRegisterType<QPieSlice>(uri, 1, 1, "PieSlice");
108 110 qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet");
109 111 qmlRegisterType<QHXYModelMapper>(uri, 1, 1, "HXYModelMapper");
110 112 qmlRegisterType<QVXYModelMapper>(uri, 1, 1, "VXYModelMapper");
111 113 qmlRegisterType<QHPieModelMapper>(uri, 1, 1, "HPieModelMapper");
112 114 qmlRegisterType<QVPieModelMapper>(uri, 1, 1, "VPieModelMapper");
113 115 qmlRegisterType<QHBarModelMapper>(uri, 1, 1, "HBarModelMapper");
114 116 qmlRegisterType<QVBarModelMapper>(uri, 1, 1, "VBarModelMapper");
115 117 qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis");
118 qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis");
119 qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis");
120 qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange");
116 121 qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis");
117 122 qmlRegisterUncreatableType<QLegend>(uri, 1, 1, "Legend",
118 123 QLatin1String("Trying to create uncreatable: Legend."));
119 124 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 1, "XYSeries",
120 125 QLatin1String("Trying to create uncreatable: XYSeries."));
121 126 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 1, "AbstractItemModel",
122 127 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
123 128 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 1, "XYModelMapper",
124 129 QLatin1String("Trying to create uncreatable: XYModelMapper."));
125 130 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 1, "PieModelMapper",
126 131 QLatin1String("Trying to create uncreatable: PieModelMapper."));
127 132 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 1, "BarModelMapper",
128 133 QLatin1String("Trying to create uncreatable: BarModelMapper."));
129 134 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 1, "AbstractSeries",
130 135 QLatin1String("Trying to create uncreatable: AbstractSeries."));
131 136 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 1, "AbstractBarSeries",
132 137 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
133 138 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 1, "AbstractAxis",
134 139 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
135 140 }
136 141 };
137 142
138 143 #include "plugin.moc"
139 144
140 145 QTCOMMERCIALCHART_END_NAMESPACE
141 146
142 147 QTCOMMERCIALCHART_USE_NAMESPACE
143 148
144 149 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,262 +1,286
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qcategoryaxis.h"
22 22 #include "qcategoryaxis_p.h"
23 23 #include "chartcategoryaxisx_p.h"
24 24 #include "chartcategoryaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \class QCategoryAxis
31 31 \brief The QCategoryAxis class allows putting a named ranges on the axis.
32 32 \mainclass
33 33
34 34 This class can be used when the underlying data needs to be given extra meaning.
35 35 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
36 36 */
37
38 37 /*!
39 38 \qmlclass CategoryAxis QCategoryAxis
40 39 \inherits AbstractAxis
41 \brief The QCategoryAxis class allows putting a named ranges on the axis.
40 \brief CategoryAxis allows putting a named ranges on the axis.
41
42 For example:
43 \code
44 CategoryAxis {
45 startValue: 0.0
46 CategoryRange { endValue: 1.0; label: "min (0-1)" }
47 CategoryRange { endValue: 3.0; label: "standard (1-3)" }
48 CategoryRange { endValue: 4.0; label: "high (3-4)" }
49 }
50 \endcode
42 51 */
43 52
44 53 /*!
45 54 \property QCategoryAxis::startValue
46 55 Defines the low end of the first category on the axis.
47 56 */
48
49 57 /*!
50 58 \qmlproperty int CategoryAxis::startValue
51 59 Defines the low end of the first category on the axis.
52 60 */
53 61
54 62 /*!
55 63 Constructs an axis object which is a child of \a parent.
56 64 */
57 65 QCategoryAxis::QCategoryAxis(QObject *parent):
58 66 QValueAxis(*new QCategoryAxisPrivate(this),parent)
59 67 {
60 68 }
61 69
62 70 /*!
63 71 Destroys the object
64 72 */
65 73 QCategoryAxis::~QCategoryAxis()
66 74 {
67 75 // Q_D(QValueAxis);
68 76 // if(d->m_dataset) {
69 77 // d->m_dataset->removeAxis(this);
70 78 // }
71 79 }
72 80
73 81 /*!
74 82 \internal
75 83 */
76 84 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
77 85 {
78 86
79 87 }
80 88
81 89 /*!
90 \qmlmethod CategoryAxis::append(string label, real endValue)
91 Appends new category to the axis with an \a label. Category label has to be unique.
92 Parameter \a endValue specifies the high end limit of the category.
93 It has to be greater than the high end limit of the previous category.
94 Otherwise the method returns without adding a new category.
95 */
96 /*!
82 97 Appends new category to the axis with an \a categoryLabel.
83 98 Category label has to be unique.
84 99 Parameter \a categoryEndValue specifies the high end limit of the category.
85 100 It has to be greater than the high end limit of the previous category.
86 101 Otherwise the method returns without adding a new category.
87 102 */
88 103 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue)
89 104 {
90 105 Q_D(QCategoryAxis);
91 106
92 107 if (!d->m_categories.contains(categoryLabel))
93 108 {
94 109 if(d->m_categories.isEmpty()){
95 110 Range range(d->m_categoryMinimum, categoryEndValue);
96 111 d->m_categoriesMap.insert(categoryLabel, range);
97 112 d->m_categories.append(categoryLabel);
98 113 }else if (categoryEndValue > endValue(d->m_categories.last())){
99 114 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
100 115 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
101 116 d->m_categories.append(categoryLabel);
102 117 }
103 118 }
104 119 }
105 120
106 121 /*!
107 122 Sets \a min to be the low end limit of the first category on the axis.
108 123 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.
109 124 Otherwise nothing is done.
110 125 */
111 126 void QCategoryAxis::setStartValue(qreal min)
112 127 {
113 128 Q_D(QCategoryAxis);
114 129 if(d->m_categories.isEmpty()){
115 130 d->m_categoryMinimum = min;
116 131 }else{
117 132 Range range = d->m_categoriesMap.value(d->m_categories.first());
118 133 if (min < range.second)
119 134 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
120 135 }
121 136 }
122 137
123 138 /*!
124 139 Returns the low end limit of the category specified by an \a categoryLabel
125 140 */
126 141 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
127 142 {
128 143 Q_D(const QCategoryAxis);
129 144 if (categoryLabel == QString())
130 145 return d->m_categoryMinimum;
131 146 else
132 147 return d->m_categoriesMap.value(categoryLabel).first;
133 148 }
134 149
135 150 /*!
136 151 Returns the high end limit of the interval specified by an \a categoryLabel
137 152 */
138 153 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
139 154 {
140 155 Q_D(const QCategoryAxis);
141 156 return d->m_categoriesMap.value(categoryLabel).second;
142 157 }
143 158
144 159 /*!
160 \qmlmethod CategoryAxis::remove(string label)
161 Removes a category specified by the \a label from the axis
162 */
163 /*!
145 164 Removes an interval specified by the \a categoryLabel from the axis
146 165 */
147 166 void QCategoryAxis::remove(const QString &categoryLabel)
148 167 {
149 168 Q_D(QCategoryAxis);
150 169 int labelIndex = d->m_categories.indexOf(categoryLabel);
151 170
152 171 // check if such label exists
153 172 if (labelIndex != -1) {
154 173 d->m_categories.removeAt(labelIndex);
155 174 d->m_categoriesMap.remove(categoryLabel);
156 175
157 176 // the range of the interval that follows (if exists) needs to be updated
158 177 if (labelIndex < d->m_categories.count()) {
159 178 QString label = d->m_categories.at(labelIndex);
160 179 Range range = d->m_categoriesMap.value(label);
161 180
162 181 // set the range
163 182 if (labelIndex == 0) {
164 183 range.first = d->m_categoryMinimum;
165 184 d->m_categoriesMap.insert(label, range);
166 185 } else {
167 186 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
168 187 d->m_categoriesMap.insert(label, range);
169 188 }
170 189 }
171 190 d->emitUpdated();
172 191 }
173 192 }
174 193
175 194 /*!
195 \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel)
196 Replaces \a oldLabel of an existing category with a \a newLabel.
197 If the old label does not exist the method returns without making any changes.
198 */
199 /*!
176 200 Replaces \a oldLabel of an existing category with a \a newLabel
177 201 If the old label does not exist the method returns without making any changes.
178 202 */
179 203 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
180 204 {
181 205 Q_D(QCategoryAxis);
182 206 int labelIndex = d->m_categories.indexOf(oldLabel);
183 207
184 208 // check if such label exists
185 209 if (labelIndex != -1) {
186 210 d->m_categories.replace(labelIndex, newLabel);
187 211 Range range = d->m_categoriesMap.value(oldLabel);
188 212 d->m_categoriesMap.remove(oldLabel);
189 213 d->m_categoriesMap.insert(newLabel, range);
190 214 d->emitUpdated();
191 215 }
192 216
193 217 }
194 218
195 219 /*!
196 220 Returns the list of the intervals labels
197 221 */
198 222 QStringList QCategoryAxis::categoriesLabels()
199 223 {
200 224 Q_D(QCategoryAxis);
201 225 return d->m_categories;
202 226 }
203 227
204 228 /*!
205 229 Returns number of intervals.
206 230 */
207 231 int QCategoryAxis::count() const
208 232 {
209 233 Q_D(const QCategoryAxis);
210 234 return d->m_categories.count();
211 235 }
212 236
213 237 /*!
214 238 Returns the type of the axis
215 239 */
216 240 QAbstractAxis::AxisType QCategoryAxis::type() const
217 241 {
218 242 return QAbstractAxis::AxisTypeCategory;
219 243 }
220 244
221 245 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
222 246
223 247 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
224 248 QValueAxisPrivate(q),
225 249 m_categoryMinimum(0)
226 250 {
227 251
228 252 }
229 253
230 254 QCategoryAxisPrivate::~QCategoryAxisPrivate()
231 255 {
232 256
233 257 }
234 258
235 259 int QCategoryAxisPrivate::ticksCount() const
236 260 {
237 261 return m_categories.count() + 1;
238 262 }
239 263
240 264 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
241 265 {
242 266 Q_UNUSED(count);
243 267 Q_UNUSED(min);
244 268 Q_UNUSED(max);
245 269 //m_min = min;
246 270 //m_max = max;
247 271 }
248 272
249 273 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
250 274 {
251 275 Q_Q(QCategoryAxis);
252 276 if(m_orientation == Qt::Vertical){
253 277 return new ChartCategoryAxisY(q,presenter);
254 278 }else{
255 279 return new ChartCategoryAxisX(q,presenter);
256 280 }
257 281 }
258 282
259 283 #include "moc_qcategoryaxis.cpp"
260 284 #include "moc_qcategoryaxis_p.cpp"
261 285
262 286 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now