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