##// END OF EJS Templates
QML Plugins and sample for that...
Mika Salmela -
r2481:20a93e498d73
parent child
Show More
@@ -0,0 +1,36
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 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 #include <QApplication>
22 #include <QtDeclarative/QDeclarativeEngine>
23 #include "qmlapplicationviewer.h"
24
25 Q_DECL_EXPORT int main(int argc, char *argv[])
26 {
27 QScopedPointer<QApplication> app(createApplication(argc, argv));
28 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
29
30 // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
31 viewer->setSource(QUrl("qrc:/qml/qmlboxplot/main.qml"));
32 viewer->setRenderHint(QPainter::Antialiasing, true);
33 viewer->showExpanded();
34
35 return app->exec();
36 }
@@ -0,0 +1,49
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 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 //![1]
22 import QtQuick 1.0
23 import QtCommercial.Chart 1.1
24
25 ChartView {
26 title: "Box Plot series"
27 width: 400
28 height: 300
29 theme: ChartView.ChartThemeBrownSand
30 legend.alignment: Qt.AlignBottom
31
32 //![1]
33 //![2]
34 BoxPlotSeries {
35 id: plotSeries
36 name: "Income"
37 axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] }
38 BarSet { label: "Jan"; values: [3, 4, 4.4, 6, 7] }
39 BarSet { label: "Feb"; values: [5, 6, 7.5, 8, 12] }
40 BarSet { label: "Mar"; values: [2, 5, 5.7, 8, 9] }
41 BarSet { label: "Apr"; values: [5, 6, 6.8, 7, 8] }
42 BarSet { label: "May"; values: [4, 5, 5.2, 6, 7] }
43 }
44 //![2]
45
46
47 //![3]
48 }
49 //![3]
@@ -0,0 +1,177
1 // checksum 0xbd34 version 0x80016
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #include "qmlapplicationviewer.h"
12
13 #include <QDir>
14 #include <QFileInfo>
15 #include <QApplication>
16 #include <QDeclarativeComponent>
17 #include <QDeclarativeEngine>
18 #include <QDeclarativeContext>
19
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
24 #endif
25
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27
28 #include <qt_private/qdeclarativedebughelper_p.h>
29
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
32 #endif
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
35 #endif
36
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
39 {
40 QmlJsDebuggingEnabler()
41 {
42 QDeclarativeDebugHelper::enableDebugging();
43 }
44 };
45
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
48
49 #endif // QMLJSDEBUGGER
50
51 class QmlApplicationViewerPrivate
52 {
53 QString mainQmlFile;
54 friend class QmlApplicationViewer;
55 static QString adjustPath(const QString &path);
56 };
57
58 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
59 {
60 #ifdef Q_OS_MAC
61 if (!QDir::isAbsolutePath(path))
62 return QString::fromLatin1("%1/../Resources/%2")
63 .arg(QCoreApplication::applicationDirPath(), path);
64 #elif defined(Q_OS_QNX)
65 if (!QDir::isAbsolutePath(path))
66 return QString::fromLatin1("app/native/%1").arg(path);
67 #elif !defined(Q_OS_ANDROID)
68 QString pathInInstallDir =
69 QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
70 if (QFileInfo(pathInInstallDir).exists())
71 return pathInInstallDir;
72 pathInInstallDir =
73 QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path);
74 if (QFileInfo(pathInInstallDir).exists())
75 return pathInInstallDir;
76 #endif
77 return path;
78 }
79
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 : QDeclarativeView(parent)
82 , d(new QmlApplicationViewerPrivate())
83 {
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86
87 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
88 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
89 #if !defined(NO_JSDEBUGGER)
90 new QmlJSDebugger::JSDebuggerAgent(engine());
91 #endif
92 #if !defined(NO_QMLOBSERVER)
93 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
94 #endif
95 #endif
96 }
97
98 QmlApplicationViewer::~QmlApplicationViewer()
99 {
100 delete d;
101 }
102
103 QmlApplicationViewer *QmlApplicationViewer::create()
104 {
105 return new QmlApplicationViewer();
106 }
107
108 void QmlApplicationViewer::setMainQmlFile(const QString &file)
109 {
110 d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
111 #ifdef Q_OS_ANDROID
112 setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile));
113 #else
114 setSource(QUrl::fromLocalFile(d->mainQmlFile));
115 #endif
116 }
117
118 void QmlApplicationViewer::addImportPath(const QString &path)
119 {
120 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
121 }
122
123 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
124 {
125 #if QT_VERSION < 0x050000
126 Qt::WidgetAttribute attribute;
127 switch (orientation) {
128 #if QT_VERSION < 0x040702
129 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
130 case ScreenOrientationLockPortrait:
131 attribute = static_cast<Qt::WidgetAttribute>(128);
132 break;
133 case ScreenOrientationLockLandscape:
134 attribute = static_cast<Qt::WidgetAttribute>(129);
135 break;
136 default:
137 case ScreenOrientationAuto:
138 attribute = static_cast<Qt::WidgetAttribute>(130);
139 break;
140 #else // QT_VERSION < 0x040702
141 case ScreenOrientationLockPortrait:
142 attribute = Qt::WA_LockPortraitOrientation;
143 break;
144 case ScreenOrientationLockLandscape:
145 attribute = Qt::WA_LockLandscapeOrientation;
146 break;
147 default:
148 case ScreenOrientationAuto:
149 attribute = Qt::WA_AutoOrientation;
150 break;
151 #endif // QT_VERSION < 0x040702
152 };
153 setAttribute(attribute, true);
154 #else // QT_VERSION < 0x050000
155 Q_UNUSED(orientation)
156 #endif // QT_VERSION < 0x050000
157 }
158
159 void QmlApplicationViewer::showExpanded()
160 {
161 #if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
162 showFullScreen();
163 #elif defined(Q_WS_MAEMO_5) || defined(Q_OS_QNX)
164 showMaximized();
165 #else
166 show();
167 #endif
168 }
169
170 QApplication *createApplication(int &argc, char **argv)
171 {
172 #ifdef HARMATTAN_BOOSTER
173 return MDeclarativeCache::qApplication(argc, argv);
174 #else
175 return new QApplication(argc, argv);
176 #endif
177 }
@@ -0,0 +1,46
1 // checksum 0xc67a version 0x80016
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #ifndef QMLAPPLICATIONVIEWER_H
12 #define QMLAPPLICATIONVIEWER_H
13
14 #include <QDeclarativeView>
15
16 class QmlApplicationViewer : public QDeclarativeView
17 {
18 Q_OBJECT
19
20 public:
21 enum ScreenOrientation {
22 ScreenOrientationLockPortrait,
23 ScreenOrientationLockLandscape,
24 ScreenOrientationAuto
25 };
26
27 explicit QmlApplicationViewer(QWidget *parent = 0);
28 virtual ~QmlApplicationViewer();
29
30 static QmlApplicationViewer *create();
31
32 void setMainQmlFile(const QString &file);
33 void addImportPath(const QString &path);
34
35 // Note that this will only have an effect on Fremantle.
36 void setOrientation(ScreenOrientation orientation);
37
38 void showExpanded();
39
40 private:
41 class QmlApplicationViewerPrivate *d;
42 };
43
44 QApplication *createApplication(int &argc, char **argv);
45
46 #endif // QMLAPPLICATIONVIEWER_H
@@ -0,0 +1,13
1 QT += declarative
2
3 SOURCES += $$PWD/qmlapplicationviewer.cpp
4 HEADERS += $$PWD/qmlapplicationviewer.h
5 INCLUDEPATH += $$PWD
6
7 # Include JS debugger library if QMLJSDEBUGGER_PATH is set
8 !isEmpty(QMLJSDEBUGGER_PATH) {
9 include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
10 } else {
11 DEFINES -= QMLJSDEBUGGER
12 }
13
@@ -0,0 +1,11
1 !include( ../examples.pri ) {
2 error( "Couldn't find the examples.pri file!" )
3 }
4
5 RESOURCES += resources.qrc
6 SOURCES += main.cpp
7
8 include(qmlapplicationviewer/qmlapplicationviewer.pri)
9
10 OTHER_FILES += \
11 qml/qmlboxplot/main.qml
@@ -0,0 +1,93
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <svg
3 xmlns:dc="http://purl.org/dc/elements/1.1/"
4 xmlns:cc="http://creativecommons.org/ns#"
5 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6 xmlns:svg="http://www.w3.org/2000/svg"
7 xmlns="http://www.w3.org/2000/svg"
8 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
9 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
10 height="44px"
11 version="1.1"
12 viewBox="0 0 44 44"
13 width="44px"
14 x="0px"
15 y="0px"
16 id="svg2"
17 inkscape:version="0.47 r22583"
18 sodipodi:docname="qt.svg">
19 <metadata
20 id="metadata18">
21 <rdf:RDF>
22 <cc:Work
23 rdf:about="">
24 <dc:format>image/svg+xml</dc:format>
25 <dc:type
26 rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
27 </cc:Work>
28 </rdf:RDF>
29 </metadata>
30 <defs
31 id="defs16">
32 <inkscape:perspective
33 sodipodi:type="inkscape:persp3d"
34 inkscape:vp_x="0 : 22 : 1"
35 inkscape:vp_y="0 : 1000 : 0"
36 inkscape:vp_z="44 : 22 : 1"
37 inkscape:persp3d-origin="22 : 14.666667 : 1"
38 id="perspective2836" />
39 </defs>
40 <sodipodi:namedview
41 pagecolor="#ffffff"
42 bordercolor="#666666"
43 borderopacity="1"
44 objecttolerance="10"
45 gridtolerance="10"
46 guidetolerance="10"
47 inkscape:pageopacity="0"
48 inkscape:pageshadow="2"
49 inkscape:window-width="1920"
50 inkscape:window-height="1020"
51 id="namedview14"
52 showgrid="false"
53 inkscape:zoom="21.454545"
54 inkscape:cx="49.412871"
55 inkscape:cy="21.894358"
56 inkscape:window-x="-4"
57 inkscape:window-y="-4"
58 inkscape:window-maximized="1"
59 inkscape:current-layer="g3" />
60 <g
61 transform="matrix(0.18308778,0,0,0.18308778,6.6100946,3.2385199)"
62 id="g3">
63 <path
64 d="M 43.09,0.3586 C 40.94,0.0036 38.84,-0.0824 36.81,0.0776 31.968136,0.39505671 27.122677,0.73638425 22.28,1.0696 9.62,2.0816 0,12.4996 0,26.8896 l 0,169.7 14.19,13.2 28.87,-209.42 0.03,-0.011 z"
65 style="fill:#006225"
66 id="path5"
67 sodipodi:nodetypes="cccccccc" />
68 <path
69 d="m 174.4,160 c 0,12.5 -7.75,24.07 -17.57,25.77 L 14.23,209.73 V 25.93 C 14.23,9.21 27.57,-2.27 43.12,0.3 l 131.3,21.52 v 138.2 z"
70 style="fill:#80c342"
71 id="path7" />
72 <path
73 d="m 154.9,80.96 -12.96,-0.598 0,0.278 6.945,0.32 6.016,0 z"
74 style="fill:#006225"
75 id="path11" />
76 <path
77 d="m 144.6,135.6 c 0.66,0.328 1.43,0.476 2.351,0.476 0.161,0 0.329,-0.004 0.497,-0.016 2.55,-0.148 5.32,-0.933 8.343,-2.308 h -6.015 c -1.821,0.832 -3.532,1.457 -5.176,1.848 z"
78 style="fill:#006225"
79 id="path13" />
80 <path
81 id="path17"
82 style="fill:#ffffff"
83 d="m 91.15,132.4 c 2.351,-6.051 3.511,-17.91 3.511,-35.62 0,-15.89 -1.148,-26.82 -3.484,-32.81 -2.336,-6.027 -5.832,-9.281 -10.52,-9.691 -0.359,-0.031 -0.714,-0.051 -1.058,-0.051 -4.34,0 -7.68,2.535 -10.01,7.625 -2.52,5.543 -3.793,17.04 -3.793,34.44 0,16.82 1.238,28.75 3.734,35.75 2.356,6.672 5.879,9.976 10.5,9.976 0.207,0 0.41,-0.008 0.621,-0.019 4.633,-0.293 8.121,-3.496 10.49,-9.602 m 17.98,3.75 c -4.117,9.707 -10.39,16.06 -18.99,19 0.867,4.449 2.176,7.441 3.922,9.019 1.351,1.211 3.433,1.821 6.222,1.821 0.805,0 1.668,-0.055 2.59,-0.157 v 13.12 l -5.961,0.782 c -1.758,0.23 -3.426,0.343 -5.004,0.343 -5.218,0 -9.445,-1.265 -12.62,-3.824 -4.207,-3.379 -7.308,-9.894 -9.297,-19.54 -9.136,-1.945 -16.26,-7.754 -21.19,-17.5 -5.004,-9.902 -7.551,-24.39 -7.551,-43.34 0,-20.43 3.484,-35.51 10.34,-45.07 5.789,-8.07 13.86,-12.04 24.02,-12.04 1.629,0 3.309,0.102 5.043,0.305 11.95,1.375 20.62,7.016 26.26,16.79 5.535,9.562 8.254,23.27 8.254,41.26 0,16.48 -2,29.45 -6.043,39.02 z M 130.4,45.91 l 11.52,1.238 0,20.21 12.96,0.914 0,12.68 -12.96,-0.598 0,46.33 c 0,4.032 0.445,6.625 1.34,7.789 0.8,1.067 2.046,1.594 3.71,1.594 0.161,0 0.329,-0.004 0.497,-0.016 2.55,-0.148 5.32,-0.933 8.343,-2.308 v 11.65 c -5.136,2.258 -10.18,3.598 -15.12,4.02 -0.718,0.055 -1.41,0.086 -2.078,0.086 -4.48,0 -7.906,-1.301 -10.25,-3.934 -2.73,-3.051 -4.09,-7.949 -4.09,-14.67 V 79.535 L 118.046,79.25 V 65.66 l 7.586,0.547 4.773,-20.3 z" />
84 <path
85 d="m 100.3,166 c 0.809,0 1.672,-0.055 2.59,-0.157 H 98.054 C 98.73,165.949 99.507,166 100.3,166 z"
86 style="fill:#006225"
87 id="path19" />
88 <path
89 id="path21"
90 style="fill:#006225"
91 d="m 84.85,63.98 c 2.336,5.997 3.484,16.92 3.484,32.81 0,17.7 -1.16,29.57 -3.512,35.62 -1.894,4.879 -4.527,7.902 -7.863,9.07 0.965,0.368 1.992,0.551 3.078,0.551 0.207,0 0.41,-0.008 0.621,-0.019 4.633,-0.293 8.121,-3.496 10.49,-9.602 2.351,-6.051 3.511,-17.91 3.511,-35.62 0,-15.89 -1.148,-26.82 -3.484,-32.81 -2.336,-6.027 -5.832,-9.281 -10.52,-9.691 -0.359,-0.031 -0.714,-0.051 -1.058,-0.051 -1.09,0 -2.117,0.16 -3.082,0.481 h -0.004 c 3.601,1.121 6.379,4.215 8.336,9.261 z m -2.344,114.3 c -0.113,-0.05 -0.227,-0.105 -0.336,-0.16 -0.012,-0.004 -0.023,-0.012 -0.035,-0.015 -0.102,-0.051 -0.207,-0.106 -0.309,-0.157 -0.019,-0.011 -0.039,-0.019 -0.058,-0.031 -0.09,-0.051 -0.184,-0.098 -0.278,-0.148 -0.027,-0.016 -0.054,-0.036 -0.086,-0.051 -0.082,-0.043 -0.164,-0.09 -0.242,-0.137 -0.039,-0.023 -0.078,-0.047 -0.113,-0.07 -0.07,-0.039 -0.145,-0.082 -0.215,-0.125 -0.047,-0.031 -0.094,-0.059 -0.14,-0.09 -0.059,-0.039 -0.118,-0.074 -0.176,-0.113 -0.059,-0.039 -0.114,-0.075 -0.168,-0.114 -0.051,-0.031 -0.102,-0.066 -0.149,-0.097 -0.066,-0.047 -0.132,-0.094 -0.195,-0.137 -0.039,-0.027 -0.078,-0.055 -0.113,-0.082 -0.078,-0.055 -0.153,-0.113 -0.231,-0.172 -0.023,-0.016 -0.05,-0.035 -0.078,-0.055 -0.098,-0.078 -0.199,-0.156 -0.297,-0.234 -4.207,-3.379 -7.308,-9.894 -9.297,-19.54 -9.136,-1.945 -16.26,-7.754 -21.19,-17.5 -5.004,-9.902 -7.551,-24.39 -7.551,-43.34 0,-20.43 3.484,-35.51 10.34,-45.07 5.789,-8.07 13.86,-12.04 24.02,-12.04 h -6.351 c -10.15,0.008 -18.22,3.977 -24,12.04 -6.855,9.563 -10.34,24.64 -10.34,45.07 0,18.95 2.547,33.44 7.551,43.34 4.934,9.75 12.05,15.56 21.19,17.5 1.989,9.641 5.09,16.16 9.297,19.54 3.176,2.559 7.403,3.824 12.62,3.824 0.098,0 0.199,0 0.297,-0.004 h 5.539 c -3.406,-0.05 -6.383,-0.66 -8.906,-1.828 L 82.498,178.28 z M 128.4,145.6 c -2.73,-3.051 -4.09,-7.949 -4.09,-14.67 V 79.57 l -6.226,-0.285 v -13.59 h -6.016 v 3.035 c 0.871,3.273 1.555,6.82 2.063,10.64 l 4.164,0.192 v 51.36 c 0,6.723 1.367,11.62 4.09,14.67 2.343,2.633 5.765,3.934 10.25,3.934 h 6.015 c -4.48,0 -7.906,-1.301 -10.25,-3.934 z m 2.043,-99.66 -6.016,0 -4.668,19.88 5.911,0.422 4.773,-20.3 z" />
92 </g>
93 </svg>
@@ -0,0 +1,5
1 <RCC>
2 <qresource prefix="/">
3 <file>qml/qmlboxplot/main.qml</file>
4 </qresource>
5 </RCC>
@@ -0,0 +1,93
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 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 #include "declarativebarseries.h"
22 #include "declarativeboxplotseries.h"
23 #include "qbarset.h"
24 #include "qvbarmodelmapper.h"
25 #include "qhbarmodelmapper.h"
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDeclarativeItem *parent) :
30 QBoxPlotSeries(parent),
31 m_axes(new DeclarativeAxes(this))
32 {
33 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisXChanged(QAbstractAxis*)));
34 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
35 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
36 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
37 }
38
39 void DeclarativeBoxPlotSeries::classBegin()
40 {
41 }
42
43 void DeclarativeBoxPlotSeries::componentComplete()
44 {
45 foreach (QObject *child, children()) {
46 if (qobject_cast<DeclarativeBarSet *>(child)) {
47 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
48 } else if (qobject_cast<QVBarModelMapper *>(child)) {
49 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
50 mapper->setSeries(this);
51 } else if (qobject_cast<QHBarModelMapper *>(child)) {
52 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
53 mapper->setSeries(this);
54 }
55 }
56 }
57
58 QDeclarativeListProperty<QObject> DeclarativeBoxPlotSeries::seriesChildren()
59 {
60 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBoxPlotSeries::appendSeriesChildren);
61 }
62
63 void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
64 {
65 // Empty implementation; the children are parsed in componentComplete instead
66 Q_UNUSED(list);
67 Q_UNUSED(element);
68 }
69
70 DeclarativeBarSet *DeclarativeBoxPlotSeries::at(int index)
71 {
72 QList<QBarSet *> setList = barSets();
73 if (index >= 0 && index < setList.count())
74 return qobject_cast<DeclarativeBarSet *>(setList[index]);
75
76 return 0;
77 }
78
79 DeclarativeBarSet *DeclarativeBoxPlotSeries::insert(int index, QString label, QVariantList values)
80 {
81 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
82 barset->setLabel(label);
83 barset->setValues(values);
84 if (QBoxPlotSeries::insert(index, barset))
85 return barset;
86 delete barset;
87 return 0;
88 }
89
90
91 #include "moc_declarativeboxplotseries.cpp"
92
93 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,81
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 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 #ifndef DECLARATIVEBOXPLOT_H
22 #define DECLARATIVEBOXPLOT_H
23
24 #include "qbarset.h"
25 #include "declarativeaxes.h"
26 #include "qboxplotseries.h"
27 #include <QtDeclarative/QDeclarativeItem>
28 #include <QtDeclarative/QDeclarativeParserStatus>
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
32 class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDeclarativeParserStatus
33 {
34 Q_OBJECT
35 Q_INTERFACES(QDeclarativeParserStatus)
36 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged REVISION 1)
37 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
38 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
39 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
40 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
41 Q_CLASSINFO("DefaultProperty", "seriesChildren")
42
43 public:
44 explicit DeclarativeBoxPlotSeries(QDeclarativeItem *parent = 0);
45 QAbstractAxis *axisX() { return m_axes->axisX(); }
46 void setAxisX(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
47 QAbstractAxis *axisY() { return m_axes->axisY(); }
48 void setAxisY(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
49 Q_REVISION(2) QAbstractAxis *axisXTop() { return m_axes->axisXTop(); }
50 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
51 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
52 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
53 QDeclarativeListProperty<QObject> seriesChildren();
54
55 public:
56 Q_INVOKABLE DeclarativeBarSet *at(int index);
57 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
58 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
59 Q_INVOKABLE bool remove(QBarSet *barset) { return QBoxPlotSeries::remove(barset); }
60 Q_INVOKABLE void clear() { return QBoxPlotSeries::clear(); }
61
62 public: // from QDeclarativeParserStatus
63 void classBegin();
64 void componentComplete();
65
66 Q_SIGNALS:
67 Q_REVISION(1) void axisXChanged(QAbstractAxis *axis);
68 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
69 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
70 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
71
72 public Q_SLOTS:
73 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
74
75 public:
76 DeclarativeAxes *m_axes;
77 };
78
79 QTCOMMERCIALCHART_END_NAMESPACE
80
81 #endif // DECLARATIVEBOXPLOT_H
@@ -1,40 +1,41
1 CURRENTLY_BUILDING_COMPONENTS = "examples"
1 CURRENTLY_BUILDING_COMPONENTS = "examples"
2 !include( ../config.pri ) {
2 !include( ../config.pri ) {
3 error( "Couldn't find the config.pri file!" )
3 error( "Couldn't find the config.pri file!" )
4 }
4 }
5
5
6 TEMPLATE = subdirs
6 TEMPLATE = subdirs
7 SUBDIRS += \
7 SUBDIRS += \
8 areachart \
8 areachart \
9 customchart \
9 customchart \
10 linechart \
10 linechart \
11 percentbarchart \
11 percentbarchart \
12 piechart \
12 piechart \
13 piechartdrilldown \
13 piechartdrilldown \
14 scatterchart \
14 scatterchart \
15 scatterinteractions \
15 scatterinteractions \
16 splinechart \
16 splinechart \
17 stackedbarchart \
17 stackedbarchart \
18 stackedbarchartdrilldown \
18 stackedbarchartdrilldown \
19 zoomlinechart \
19 zoomlinechart \
20 modeldata \
20 modeldata \
21 barchart \
21 barchart \
22 boxplotchart \
22 boxplotchart \
23 legend \
23 legend \
24 barmodelmapper \
24 barmodelmapper \
25 qmlboxplot \
25 qmlpiechart \
26 qmlpiechart \
26 lineandbar \
27 lineandbar \
27 horizontalbarchart \
28 horizontalbarchart \
28 horizontalstackedbarchart \
29 horizontalstackedbarchart \
29 horizontalpercentbarchart \
30 horizontalpercentbarchart \
30 donutbreakdown \
31 donutbreakdown \
31 temperaturerecords \
32 temperaturerecords \
32 donutchart \
33 donutchart \
33 multiaxis \
34 multiaxis \
34 legendmarkers \
35 legendmarkers \
35 logvalueaxis
36 logvalueaxis
36
37
37 !linux-arm*: {
38 !linux-arm*: {
38 SUBDIRS += \
39 SUBDIRS += \
39 datetimeaxis
40 datetimeaxis
40 }
41 }
@@ -1,52 +1,54
1 !include( ../plugins.pri ) {
1 !include( ../plugins.pri ) {
2 error( "Couldn't find the plugins.pri file!" )
2 error( "Couldn't find the plugins.pri file!" )
3 }
3 }
4
4
5 TARGET = qtcommercialchartqml
5 TARGET = qtcommercialchartqml
6 QT += declarative
6 QT += declarative
7 DESTDIR = $$CHART_BUILD_QML_PLUGIN_DIR
7 DESTDIR = $$CHART_BUILD_QML_PLUGIN_DIR
8 INCLUDEPATH += $$CHART_BUILD_PRIVATE_HEADER_DIR
8 INCLUDEPATH += $$CHART_BUILD_PRIVATE_HEADER_DIR
9
9
10 CONFIG(debug, debug|release) {
10 CONFIG(debug, debug|release) {
11 mac: TARGET = $$join(TARGET,,,_debug)
11 mac: TARGET = $$join(TARGET,,,_debug)
12 win32: TARGET = $$join(TARGET,,,d)
12 win32: TARGET = $$join(TARGET,,,d)
13 }
13 }
14
14
15 SOURCES += \
15 SOURCES += \
16 plugin.cpp \
16 plugin.cpp \
17 declarativechart.cpp \
17 declarativechart.cpp \
18 declarativexypoint.cpp \
18 declarativexypoint.cpp \
19 declarativexyseries.cpp \
19 declarativexyseries.cpp \
20 declarativelineseries.cpp \
20 declarativelineseries.cpp \
21 declarativesplineseries.cpp \
21 declarativesplineseries.cpp \
22 declarativeareaseries.cpp \
22 declarativeareaseries.cpp \
23 declarativescatterseries.cpp \
23 declarativescatterseries.cpp \
24 declarativepieseries.cpp \
24 declarativepieseries.cpp \
25 declarativebarseries.cpp \
25 declarativebarseries.cpp \
26 declarativecategoryaxis.cpp \
26 declarativecategoryaxis.cpp \
27 declarativemargins.cpp \
27 declarativemargins.cpp \
28 declarativeaxes.cpp
28 declarativeaxes.cpp \
29 declarativeboxplotseries.cpp
29
30
30 HEADERS += \
31 HEADERS += \
31 declarativechart.h \
32 declarativechart.h \
32 declarativexypoint.h \
33 declarativexypoint.h \
33 declarativexyseries.h \
34 declarativexyseries.h \
34 declarativelineseries.h \
35 declarativelineseries.h \
35 declarativesplineseries.h \
36 declarativesplineseries.h \
36 declarativeareaseries.h \
37 declarativeareaseries.h \
37 declarativescatterseries.h \
38 declarativescatterseries.h \
38 declarativepieseries.h \
39 declarativepieseries.h \
39 declarativebarseries.h \
40 declarativebarseries.h \
40 declarativecategoryaxis.h \
41 declarativecategoryaxis.h \
41 declarativemargins.h \
42 declarativemargins.h \
42 declarativeaxes.h
43 declarativeaxes.h \
44 declarativeboxplotseries.h
43
45
44 TARGETPATH = QtCommercial/Chart
46 TARGETPATH = QtCommercial/Chart
45 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
47 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
46 qmldir.files += $$PWD/qmldir
48 qmldir.files += $$PWD/qmldir
47 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
49 qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
48 INSTALLS += target qmldir
50 INSTALLS += target qmldir
49
51
50 FILE = $$PWD/qmldir
52 FILE = $$PWD/qmldir
51 win32:{FILE = $$replace(FILE, "/","\\")}
53 win32:{FILE = $$replace(FILE, "/","\\")}
52 QMAKE_POST_LINK += $$QMAKE_COPY $$FILE $$CHART_BUILD_QML_PLUGIN_DIR
54 QMAKE_POST_LINK += $$QMAKE_COPY $$FILE $$CHART_BUILD_QML_PLUGIN_DIR
@@ -1,762 +1,768
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QDeclarativeEngine>
23 #include <QDeclarativeEngine>
24 #include "declarativelineseries.h"
24 #include "declarativelineseries.h"
25 #include "declarativeareaseries.h"
25 #include "declarativeareaseries.h"
26 #include "declarativebarseries.h"
26 #include "declarativebarseries.h"
27 #include "declarativepieseries.h"
27 #include "declarativepieseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.h"
29 #include "declarativeboxplotseries.h"
29 #include "declarativescatterseries.h"
30 #include "declarativescatterseries.h"
30 #include "qbarcategoryaxis.h"
31 #include "qbarcategoryaxis.h"
31 #include "qvalueaxis.h"
32 #include "qvalueaxis.h"
32 #include "qcategoryaxis.h"
33 #include "qcategoryaxis.h"
33 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
34 #include "declarativemargins.h"
35 #include "declarativemargins.h"
35 #include "chartdataset_p.h"
36 #include "chartdataset_p.h"
36 #include "declarativeaxes.h"
37 #include "declarativeaxes.h"
37 #include "qchart_p.h"
38 #include "qchart_p.h"
38
39
39 #ifndef QT_ON_ARM
40 #ifndef QT_ON_ARM
40 #include "qdatetimeaxis.h"
41 #include "qdatetimeaxis.h"
41 #endif
42 #endif
42
43
43 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44
45
45 /*!
46 /*!
46 \qmlclass ChartView DeclarativeChart
47 \qmlclass ChartView DeclarativeChart
47
48
48 ChartView element is the parent that is responsible for showing different chart series types.
49 ChartView element is the parent that is responsible for showing different chart series types.
49
50
50 The following QML shows how to create a simple chart with one pie series:
51 The following QML shows how to create a simple chart with one pie series:
51 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
52 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
52 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
54 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
54
55
55 \beginfloatleft
56 \beginfloatleft
56 \image examples_qmlpiechart.png
57 \image examples_qmlpiechart.png
57 \endfloat
58 \endfloat
58 \clearfloat
59 \clearfloat
59 */
60 */
60
61
61 /*!
62 /*!
62 \qmlproperty Theme ChartView::theme
63 \qmlproperty Theme ChartView::theme
63 Theme defines the visual appearance of the chart, including for example colors, fonts, line
64 Theme defines the visual appearance of the chart, including for example colors, fonts, line
64 widths and chart background.
65 widths and chart background.
65 */
66 */
66
67
67 /*!
68 /*!
68 \qmlproperty Animation ChartView::animationOptions
69 \qmlproperty Animation ChartView::animationOptions
69 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
70 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
70 ChartView.SeriesAnimations or ChartView.AllAnimations.
71 ChartView.SeriesAnimations or ChartView.AllAnimations.
71 */
72 */
72
73
73 /*!
74 /*!
74 \qmlproperty Font ChartView::titleFont
75 \qmlproperty Font ChartView::titleFont
75 The title font of the chart
76 The title font of the chart
76
77
77 See the \l {Font} {QML Font Element} for detailed documentation.
78 See the \l {Font} {QML Font Element} for detailed documentation.
78 */
79 */
79
80
80 /*!
81 /*!
81 \qmlproperty string ChartView::title
82 \qmlproperty string ChartView::title
82 The title of the chart, shown on top of the chart.
83 The title of the chart, shown on top of the chart.
83 \sa ChartView::titleColor
84 \sa ChartView::titleColor
84 */
85 */
85
86
86 /*!
87 /*!
87 \qmlproperty color ChartView::titleColor
88 \qmlproperty color ChartView::titleColor
88 The color of the title text.
89 The color of the title text.
89 */
90 */
90
91
91 /*!
92 /*!
92 \qmlproperty Legend ChartView::legend
93 \qmlproperty Legend ChartView::legend
93 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
94 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
94 */
95 */
95
96
96 /*!
97 /*!
97 \qmlproperty int ChartView::count
98 \qmlproperty int ChartView::count
98 The count of series added to the chart.
99 The count of series added to the chart.
99 */
100 */
100
101
101 /*!
102 /*!
102 \qmlproperty color ChartView::backgroundColor
103 \qmlproperty color ChartView::backgroundColor
103 The color of the chart's background. By default background color is defined by chart theme.
104 The color of the chart's background. By default background color is defined by chart theme.
104 \sa ChartView::theme
105 \sa ChartView::theme
105 */
106 */
106
107
107 /*!
108 /*!
108 \qmlproperty bool ChartView::dropShadowEnabled
109 \qmlproperty bool ChartView::dropShadowEnabled
109 The chart's border drop shadow. Set to true to enable drop shadow.
110 The chart's border drop shadow. Set to true to enable drop shadow.
110 */
111 */
111
112
112 /*!
113 /*!
113 \qmlproperty real ChartView::topMargin
114 \qmlproperty real ChartView::topMargin
114 */
115 */
115
116
116 /*!
117 /*!
117 \qmlproperty real ChartView::bottomMargin
118 \qmlproperty real ChartView::bottomMargin
118 */
119 */
119
120
120 /*!
121 /*!
121 \qmlproperty real ChartView::leftMargin
122 \qmlproperty real ChartView::leftMargin
122 */
123 */
123
124
124 /*!
125 /*!
125 \qmlproperty real ChartView::rightMargin
126 \qmlproperty real ChartView::rightMargin
126 */
127 */
127
128
128 /*!
129 /*!
129 \qmlproperty Margins ChartView::minimumMargins
130 \qmlproperty Margins ChartView::minimumMargins
130 Deprecated; use margins instead.
131 Deprecated; use margins instead.
131 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
132 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
132 area of ChartView is used for drawing title, axes and legend. Please note that setting the
133 area of ChartView is used for drawing title, axes and legend. Please note that setting the
133 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
134 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
134 properties that affect it's layout. If you need to know the actual plotting area used at any
135 properties that affect it's layout. If you need to know the actual plotting area used at any
135 given time, you can check ChartView::plotArea instead.
136 given time, you can check ChartView::plotArea instead.
136 */
137 */
137
138
138 /*!
139 /*!
139 \qmlproperty rect ChartView::plotArea
140 \qmlproperty rect ChartView::plotArea
140 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
141 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
141 margins.
142 margins.
142 \sa ChartView::minimumMargins
143 \sa ChartView::minimumMargins
143 */
144 */
144
145
145 /*!
146 /*!
146 \qmlproperty Margins ChartView::margins
147 \qmlproperty Margins ChartView::margins
147 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
148 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
148 area of ChartView is used for drawing title, axes and legend.
149 area of ChartView is used for drawing title, axes and legend.
149 */
150 */
150
151
151 /*!
152 /*!
152 \qmlmethod AbstractSeries ChartView::series(int index)
153 \qmlmethod AbstractSeries ChartView::series(int index)
153 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
154 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
154 the count property of the chart.
155 the count property of the chart.
155 */
156 */
156
157
157 /*!
158 /*!
158 \qmlmethod AbstractSeries ChartView::series(string name)
159 \qmlmethod AbstractSeries ChartView::series(string name)
159 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
160 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
160 */
161 */
161
162
162 /*!
163 /*!
163 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
164 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
164 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
165 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
165 optional axis \a axisY. For example:
166 optional axis \a axisY. For example:
166 \code
167 \code
167 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
168 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
168 var myAxisX = chartView.axisX(lineSeries);
169 var myAxisX = chartView.axisX(lineSeries);
169 var myAxisY = chartView.axisY(lineSeries);
170 var myAxisY = chartView.axisY(lineSeries);
170 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
171 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
171 \endcode
172 \endcode
172 */
173 */
173
174
174 /*!
175 /*!
175 \qmlmethod ChartView::removeSeries(AbstractSeries series)
176 \qmlmethod ChartView::removeSeries(AbstractSeries series)
176 Removes the \a series from the chart. The series object is also destroyed.
177 Removes the \a series from the chart. The series object is also destroyed.
177 */
178 */
178
179
179 /*!
180 /*!
180 \qmlmethod ChartView::removeAllSeries()
181 \qmlmethod ChartView::removeAllSeries()
181 Removes all series from the chart. All the series objects are also destroyed.
182 Removes all series from the chart. All the series objects are also destroyed.
182 */
183 */
183
184
184 /*!
185 /*!
185 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
186 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
186 The x-axis of the series.
187 The x-axis of the series.
187 */
188 */
188
189
189 /*!
190 /*!
190 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
191 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
191 The y-axis of the series.
192 The y-axis of the series.
192 */
193 */
193
194
194 /*!
195 /*!
195 \qmlmethod ChartView::zoomY(real factor)
196 \qmlmethod ChartView::zoomY(real factor)
196 Zooms in by \a factor on the center of the chart.
197 Zooms in by \a factor on the center of the chart.
197 */
198 */
198
199
199 /*!
200 /*!
200 \qmlmethod ChartView::scrollLeft(real pixels)
201 \qmlmethod ChartView::scrollLeft(real pixels)
201 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
202 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
202 */
203 */
203
204
204 /*!
205 /*!
205 \qmlmethod ChartView::scrollRight(real pixels)
206 \qmlmethod ChartView::scrollRight(real pixels)
206 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
207 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
207 */
208 */
208
209
209 /*!
210 /*!
210 \qmlmethod ChartView::scrollUp(real pixels)
211 \qmlmethod ChartView::scrollUp(real pixels)
211 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
212 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
212 */
213 */
213
214
214 /*!
215 /*!
215 \qmlmethod ChartView::scrollDown(real pixels)
216 \qmlmethod ChartView::scrollDown(real pixels)
216 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
217 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
217 */
218 */
218
219
219 /*!
220 /*!
220 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
221 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
221 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
222 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
222 or if you resize the chart, or if you modify font size related properties of the legend or chart
223 or if you resize the chart, or if you modify font size related properties of the legend or chart
223 title.
224 title.
224 */
225 */
225
226
226 /*!
227 /*!
227 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
228 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
228 The \a series has been added to the chart.
229 The \a series has been added to the chart.
229 */
230 */
230
231
231 /*!
232 /*!
232 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
233 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
233 The \a series has been removed from the chart. Please note that \a series is no longer a valid
234 The \a series has been removed from the chart. Please note that \a series is no longer a valid
234 object after the signal handler has completed.
235 object after the signal handler has completed.
235 */
236 */
236
237
237 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
238 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
238 : QDeclarativeItem(parent),
239 : QDeclarativeItem(parent),
239 m_chart(new QChart(this))
240 m_chart(new QChart(this))
240 {
241 {
241 setFlag(QGraphicsItem::ItemHasNoContents, false);
242 setFlag(QGraphicsItem::ItemHasNoContents, false);
242 m_margins = new DeclarativeMargins(this);
243 m_margins = new DeclarativeMargins(this);
243 m_margins->setTop(m_chart->margins().top());
244 m_margins->setTop(m_chart->margins().top());
244 m_margins->setLeft(m_chart->margins().left());
245 m_margins->setLeft(m_chart->margins().left());
245 m_margins->setRight(m_chart->margins().right());
246 m_margins->setRight(m_chart->margins().right());
246 m_margins->setBottom(m_chart->margins().bottom());
247 m_margins->setBottom(m_chart->margins().bottom());
247 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
248 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
248 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
249 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
249 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
250 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
250 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
251 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
251 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
252 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
252 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
253 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
253 }
254 }
254
255
255 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
256 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
256 {
257 {
257 emit seriesAdded(series);
258 emit seriesAdded(series);
258 }
259 }
259
260
260 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
261 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
261 {
262 {
262 m_chart->setMargins(QMargins(left, top, right, bottom));
263 m_chart->setMargins(QMargins(left, top, right, bottom));
263 emit minimumMarginsChanged();
264 emit minimumMarginsChanged();
264 emit plotAreaChanged(m_chart->plotArea());
265 emit plotAreaChanged(m_chart->plotArea());
265 }
266 }
266
267
267 DeclarativeChart::~DeclarativeChart()
268 DeclarativeChart::~DeclarativeChart()
268 {
269 {
269 delete m_chart;
270 delete m_chart;
270 }
271 }
271
272
272 void DeclarativeChart::childEvent(QChildEvent *event)
273 void DeclarativeChart::childEvent(QChildEvent *event)
273 {
274 {
274 if (event->type() == QEvent::ChildAdded) {
275 if (event->type() == QEvent::ChildAdded) {
275 if (qobject_cast<QAbstractSeries *>(event->child())) {
276 if (qobject_cast<QAbstractSeries *>(event->child())) {
276 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
277 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
277 }
278 }
278 }
279 }
279 }
280 }
280
281
281 void DeclarativeChart::componentComplete()
282 void DeclarativeChart::componentComplete()
282 {
283 {
283 foreach (QObject *child, children()) {
284 foreach (QObject *child, children()) {
284 if (qobject_cast<QAbstractSeries *>(child)) {
285 if (qobject_cast<QAbstractSeries *>(child)) {
285 // Add series to the chart
286 // Add series to the chart
286 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
287 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
287 m_chart->addSeries(series);
288 m_chart->addSeries(series);
288
289
289 // Connect to axis changed signals (unless this is a pie series)
290 // Connect to axis changed signals (unless this is a pie series)
290 if (!qobject_cast<DeclarativePieSeries *>(series)) {
291 if (!qobject_cast<DeclarativePieSeries *>(series)) {
291 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
292 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
292 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
293 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
293 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
294 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
294 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
295 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
295 }
296 }
296
297
297 initializeAxes(series);
298 initializeAxes(series);
298 }
299 }
299 }
300 }
300
301
301 QDeclarativeItem::componentComplete();
302 QDeclarativeItem::componentComplete();
302 }
303 }
303
304
304 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
305 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
305 {
306 {
306 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
307 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
307 if (axis && s) {
308 if (axis && s) {
308 if (!m_chart->axes(Qt::Horizontal).contains(axis))
309 if (!m_chart->axes(Qt::Horizontal).contains(axis))
309 m_chart->addAxis(axis, Qt::AlignBottom);
310 m_chart->addAxis(axis, Qt::AlignBottom);
310 if (!s->attachedAxes().contains(axis))
311 if (!s->attachedAxes().contains(axis))
311 s->attachAxis(axis);
312 s->attachAxis(axis);
312 } else {
313 } else {
313 qWarning() << "Trying to set axisX to null.";
314 qWarning() << "Trying to set axisX to null.";
314 }
315 }
315 }
316 }
316
317
317 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
318 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
318 {
319 {
319 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
320 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
320 if (axis && s) {
321 if (axis && s) {
321 if (!m_chart->axes(Qt::Horizontal).contains(axis))
322 if (!m_chart->axes(Qt::Horizontal).contains(axis))
322 m_chart->addAxis(axis, Qt::AlignTop);
323 m_chart->addAxis(axis, Qt::AlignTop);
323 if (!s->attachedAxes().contains(axis))
324 if (!s->attachedAxes().contains(axis))
324 s->attachAxis(axis);
325 s->attachAxis(axis);
325 } else {
326 } else {
326 qWarning() << "Trying to set axisXTop to null.";
327 qWarning() << "Trying to set axisXTop to null.";
327 }
328 }
328 }
329 }
329
330
330 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
331 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
331 {
332 {
332 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
333 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
333 if (axis && s) {
334 if (axis && s) {
334 if (!m_chart->axes(Qt::Vertical).contains(axis))
335 if (!m_chart->axes(Qt::Vertical).contains(axis))
335 m_chart->addAxis(axis, Qt::AlignLeft);
336 m_chart->addAxis(axis, Qt::AlignLeft);
336 if (!s->attachedAxes().contains(axis))
337 if (!s->attachedAxes().contains(axis))
337 s->attachAxis(axis);
338 s->attachAxis(axis);
338 } else {
339 } else {
339 qWarning() << "Trying to set axisY to null.";
340 qWarning() << "Trying to set axisY to null.";
340 }
341 }
341 }
342 }
342
343
343 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
344 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
344 {
345 {
345 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
346 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
346 if (axis && s) {
347 if (axis && s) {
347 if (!m_chart->axes(Qt::Vertical).contains(axis))
348 if (!m_chart->axes(Qt::Vertical).contains(axis))
348 m_chart->addAxis(axis, Qt::AlignRight);
349 m_chart->addAxis(axis, Qt::AlignRight);
349 if (!s->attachedAxes().contains(axis))
350 if (!s->attachedAxes().contains(axis))
350 s->attachAxis(axis);
351 s->attachAxis(axis);
351 } else {
352 } else {
352 qWarning() << "Trying to set axisYRight to null.";
353 qWarning() << "Trying to set axisYRight to null.";
353 }
354 }
354 }
355 }
355
356
356 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
357 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
357 {
358 {
358 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
359 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
359 if (newGeometry.isValid()) {
360 if (newGeometry.isValid()) {
360 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
361 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
361 m_chart->resize(newGeometry.width(), newGeometry.height());
362 m_chart->resize(newGeometry.width(), newGeometry.height());
362 }
363 }
363 }
364 }
364 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
365 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
365
366
366 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
367 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
367 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
368 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
368 // to implement it here for the QML API purposes.
369 // to implement it here for the QML API purposes.
369 emit plotAreaChanged(m_chart->plotArea());
370 emit plotAreaChanged(m_chart->plotArea());
370 }
371 }
371
372
372 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
373 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
373 {
374 {
374 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
375 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
375 if (chartTheme != m_chart->theme())
376 if (chartTheme != m_chart->theme())
376 m_chart->setTheme(chartTheme);
377 m_chart->setTheme(chartTheme);
377 }
378 }
378
379
379 DeclarativeChart::Theme DeclarativeChart::theme()
380 DeclarativeChart::Theme DeclarativeChart::theme()
380 {
381 {
381 return (DeclarativeChart::Theme) m_chart->theme();
382 return (DeclarativeChart::Theme) m_chart->theme();
382 }
383 }
383
384
384 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
385 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
385 {
386 {
386 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
387 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
387 if (animationOptions != m_chart->animationOptions())
388 if (animationOptions != m_chart->animationOptions())
388 m_chart->setAnimationOptions(animationOptions);
389 m_chart->setAnimationOptions(animationOptions);
389 }
390 }
390
391
391 DeclarativeChart::Animation DeclarativeChart::animationOptions()
392 DeclarativeChart::Animation DeclarativeChart::animationOptions()
392 {
393 {
393 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
394 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
394 return DeclarativeChart::AllAnimations;
395 return DeclarativeChart::AllAnimations;
395 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
396 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
396 return DeclarativeChart::GridAxisAnimations;
397 return DeclarativeChart::GridAxisAnimations;
397 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
398 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
398 return DeclarativeChart::SeriesAnimations;
399 return DeclarativeChart::SeriesAnimations;
399 else
400 else
400 return DeclarativeChart::NoAnimation;
401 return DeclarativeChart::NoAnimation;
401 }
402 }
402
403
403 void DeclarativeChart::setTitle(QString title)
404 void DeclarativeChart::setTitle(QString title)
404 {
405 {
405 if (title != m_chart->title())
406 if (title != m_chart->title())
406 m_chart->setTitle(title);
407 m_chart->setTitle(title);
407 }
408 }
408 QString DeclarativeChart::title()
409 QString DeclarativeChart::title()
409 {
410 {
410 return m_chart->title();
411 return m_chart->title();
411 }
412 }
412
413
413 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
414 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
414 {
415 {
415 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
416 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
416 if (axes.count())
417 if (axes.count())
417 return axes[0];
418 return axes[0];
418 return 0;
419 return 0;
419 }
420 }
420
421
421 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
422 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
422 {
423 {
423 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
424 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
424 if (axes.count())
425 if (axes.count())
425 return axes[0];
426 return axes[0];
426 return 0;
427 return 0;
427 }
428 }
428
429
429 QLegend *DeclarativeChart::legend()
430 QLegend *DeclarativeChart::legend()
430 {
431 {
431 return m_chart->legend();
432 return m_chart->legend();
432 }
433 }
433
434
434 void DeclarativeChart::setTitleColor(QColor color)
435 void DeclarativeChart::setTitleColor(QColor color)
435 {
436 {
436 QBrush b = m_chart->titleBrush();
437 QBrush b = m_chart->titleBrush();
437 if (color != b.color()) {
438 if (color != b.color()) {
438 b.setColor(color);
439 b.setColor(color);
439 m_chart->setTitleBrush(b);
440 m_chart->setTitleBrush(b);
440 emit titleColorChanged(color);
441 emit titleColorChanged(color);
441 }
442 }
442 }
443 }
443
444
444 QFont DeclarativeChart::titleFont() const
445 QFont DeclarativeChart::titleFont() const
445 {
446 {
446 return m_chart->titleFont();
447 return m_chart->titleFont();
447 }
448 }
448
449
449 void DeclarativeChart::setTitleFont(const QFont &font)
450 void DeclarativeChart::setTitleFont(const QFont &font)
450 {
451 {
451 m_chart->setTitleFont(font);
452 m_chart->setTitleFont(font);
452 }
453 }
453
454
454 QColor DeclarativeChart::titleColor()
455 QColor DeclarativeChart::titleColor()
455 {
456 {
456 return m_chart->titleBrush().color();
457 return m_chart->titleBrush().color();
457 }
458 }
458
459
459 void DeclarativeChart::setBackgroundColor(QColor color)
460 void DeclarativeChart::setBackgroundColor(QColor color)
460 {
461 {
461 QBrush b = m_chart->backgroundBrush();
462 QBrush b = m_chart->backgroundBrush();
462 if (b.style() != Qt::SolidPattern || color != b.color()) {
463 if (b.style() != Qt::SolidPattern || color != b.color()) {
463 b.setStyle(Qt::SolidPattern);
464 b.setStyle(Qt::SolidPattern);
464 b.setColor(color);
465 b.setColor(color);
465 m_chart->setBackgroundBrush(b);
466 m_chart->setBackgroundBrush(b);
466 emit backgroundColorChanged();
467 emit backgroundColorChanged();
467 }
468 }
468 }
469 }
469
470
470 QColor DeclarativeChart::backgroundColor()
471 QColor DeclarativeChart::backgroundColor()
471 {
472 {
472 return m_chart->backgroundBrush().color();
473 return m_chart->backgroundBrush().color();
473 }
474 }
474
475
475 int DeclarativeChart::count()
476 int DeclarativeChart::count()
476 {
477 {
477 return m_chart->series().count();
478 return m_chart->series().count();
478 }
479 }
479
480
480 void DeclarativeChart::setDropShadowEnabled(bool enabled)
481 void DeclarativeChart::setDropShadowEnabled(bool enabled)
481 {
482 {
482 if (enabled != m_chart->isDropShadowEnabled()) {
483 if (enabled != m_chart->isDropShadowEnabled()) {
483 m_chart->setDropShadowEnabled(enabled);
484 m_chart->setDropShadowEnabled(enabled);
484 dropShadowEnabledChanged(enabled);
485 dropShadowEnabledChanged(enabled);
485 }
486 }
486 }
487 }
487
488
488 bool DeclarativeChart::dropShadowEnabled()
489 bool DeclarativeChart::dropShadowEnabled()
489 {
490 {
490 return m_chart->isDropShadowEnabled();
491 return m_chart->isDropShadowEnabled();
491 }
492 }
492
493
493 qreal DeclarativeChart::topMargin()
494 qreal DeclarativeChart::topMargin()
494 {
495 {
495 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
496 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
496 return m_chart->margins().top();
497 return m_chart->margins().top();
497 }
498 }
498
499
499 qreal DeclarativeChart::bottomMargin()
500 qreal DeclarativeChart::bottomMargin()
500 {
501 {
501 qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead.";
502 qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead.";
502 return m_chart->margins().bottom();
503 return m_chart->margins().bottom();
503 }
504 }
504
505
505 qreal DeclarativeChart::leftMargin()
506 qreal DeclarativeChart::leftMargin()
506 {
507 {
507 qWarning() << "ChartView.leftMargin is deprecated. Use margins instead.";
508 qWarning() << "ChartView.leftMargin is deprecated. Use margins instead.";
508 return m_chart->margins().left();
509 return m_chart->margins().left();
509 }
510 }
510
511
511 qreal DeclarativeChart::rightMargin()
512 qreal DeclarativeChart::rightMargin()
512 {
513 {
513 qWarning() << "ChartView.rightMargin is deprecated. Use margins instead.";
514 qWarning() << "ChartView.rightMargin is deprecated. Use margins instead.";
514 return m_chart->margins().right();
515 return m_chart->margins().right();
515 }
516 }
516
517
517 void DeclarativeChart::zoom(qreal factor)
518 void DeclarativeChart::zoom(qreal factor)
518 {
519 {
519 m_chart->zoom(factor);
520 m_chart->zoom(factor);
520 }
521 }
521
522
522 void DeclarativeChart::scrollLeft(qreal pixels)
523 void DeclarativeChart::scrollLeft(qreal pixels)
523 {
524 {
524 m_chart->scroll(-pixels, 0);
525 m_chart->scroll(-pixels, 0);
525 }
526 }
526
527
527 void DeclarativeChart::scrollRight(qreal pixels)
528 void DeclarativeChart::scrollRight(qreal pixels)
528 {
529 {
529 m_chart->scroll(pixels, 0);
530 m_chart->scroll(pixels, 0);
530 }
531 }
531
532
532 void DeclarativeChart::scrollUp(qreal pixels)
533 void DeclarativeChart::scrollUp(qreal pixels)
533 {
534 {
534 m_chart->scroll(0, pixels);
535 m_chart->scroll(0, pixels);
535 }
536 }
536
537
537 void DeclarativeChart::scrollDown(qreal pixels)
538 void DeclarativeChart::scrollDown(qreal pixels)
538 {
539 {
539 m_chart->scroll(0, -pixels);
540 m_chart->scroll(0, -pixels);
540 }
541 }
541
542
542 QDeclarativeListProperty<QAbstractAxis> DeclarativeChart::axes()
543 QDeclarativeListProperty<QAbstractAxis> DeclarativeChart::axes()
543 {
544 {
544 return QDeclarativeListProperty<QAbstractAxis>(this, 0,
545 return QDeclarativeListProperty<QAbstractAxis>(this, 0,
545 &DeclarativeChart::axesAppendFunc,
546 &DeclarativeChart::axesAppendFunc,
546 &DeclarativeChart::axesCountFunc,
547 &DeclarativeChart::axesCountFunc,
547 &DeclarativeChart::axesAtFunc);
548 &DeclarativeChart::axesAtFunc);
548 }
549 }
549
550
550 void DeclarativeChart::axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element)
551 void DeclarativeChart::axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element)
551 {
552 {
552 // Empty implementation
553 // Empty implementation
553 Q_UNUSED(list);
554 Q_UNUSED(list);
554 Q_UNUSED(element);
555 Q_UNUSED(element);
555 }
556 }
556
557
557 int DeclarativeChart::axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list)
558 int DeclarativeChart::axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list)
558 {
559 {
559 if (qobject_cast<DeclarativeChart *>(list->object)) {
560 if (qobject_cast<DeclarativeChart *>(list->object)) {
560 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
561 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
561 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
562 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
562 }
563 }
563 return 0;
564 return 0;
564 }
565 }
565
566
566 QAbstractAxis *DeclarativeChart::axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index)
567 QAbstractAxis *DeclarativeChart::axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index)
567 {
568 {
568 if (qobject_cast<DeclarativeChart *>(list->object)) {
569 if (qobject_cast<DeclarativeChart *>(list->object)) {
569 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
570 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
570 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
571 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
571 return axes.at(index);
572 return axes.at(index);
572 }
573 }
573 return 0;
574 return 0;
574 }
575 }
575
576
576 QAbstractSeries *DeclarativeChart::series(int index)
577 QAbstractSeries *DeclarativeChart::series(int index)
577 {
578 {
578 if (index < m_chart->series().count()) {
579 if (index < m_chart->series().count()) {
579 return m_chart->series().at(index);
580 return m_chart->series().at(index);
580 }
581 }
581 return 0;
582 return 0;
582 }
583 }
583
584
584 QAbstractSeries *DeclarativeChart::series(QString seriesName)
585 QAbstractSeries *DeclarativeChart::series(QString seriesName)
585 {
586 {
586 foreach (QAbstractSeries *series, m_chart->series()) {
587 foreach (QAbstractSeries *series, m_chart->series()) {
587 if (series->name() == seriesName)
588 if (series->name() == seriesName)
588 return series;
589 return series;
589 }
590 }
590 return 0;
591 return 0;
591 }
592 }
592
593
593 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
594 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
594 {
595 {
595 QAbstractSeries *series = 0;
596 QAbstractSeries *series = 0;
596
597
597 switch (type) {
598 switch (type) {
598 case DeclarativeChart::SeriesTypeLine:
599 case DeclarativeChart::SeriesTypeLine:
599 series = new DeclarativeLineSeries();
600 series = new DeclarativeLineSeries();
600 break;
601 break;
601 case DeclarativeChart::SeriesTypeArea: {
602 case DeclarativeChart::SeriesTypeArea: {
602 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
603 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
603 area->setUpperSeries(new DeclarativeLineSeries());
604 area->setUpperSeries(new DeclarativeLineSeries());
604 series = area;
605 series = area;
605 break;
606 break;
606 }
607 }
607 case DeclarativeChart::SeriesTypeStackedBar:
608 case DeclarativeChart::SeriesTypeStackedBar:
608 series = new DeclarativeStackedBarSeries();
609 series = new DeclarativeStackedBarSeries();
609 break;
610 break;
610 case DeclarativeChart::SeriesTypePercentBar:
611 case DeclarativeChart::SeriesTypePercentBar:
611 series = new DeclarativePercentBarSeries();
612 series = new DeclarativePercentBarSeries();
612 break;
613 break;
613 case DeclarativeChart::SeriesTypeBar:
614 case DeclarativeChart::SeriesTypeBar:
614 series = new DeclarativeBarSeries();
615 series = new DeclarativeBarSeries();
615 break;
616 break;
616 case DeclarativeChart::SeriesTypeHorizontalBar:
617 case DeclarativeChart::SeriesTypeHorizontalBar:
617 series = new DeclarativeHorizontalBarSeries();
618 series = new DeclarativeHorizontalBarSeries();
618 break;
619 break;
619 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
620 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
620 series = new DeclarativeHorizontalPercentBarSeries();
621 series = new DeclarativeHorizontalPercentBarSeries();
621 break;
622 break;
622 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
623 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
623 series = new DeclarativeHorizontalStackedBarSeries();
624 series = new DeclarativeHorizontalStackedBarSeries();
624 break;
625 break;
626 case DeclarativeChart::SeriesTypeBoxPlot:
627 series = new DeclarativeBoxPlotSeries();
628 break;
625 case DeclarativeChart::SeriesTypePie:
629 case DeclarativeChart::SeriesTypePie:
626 series = new DeclarativePieSeries();
630 series = new DeclarativePieSeries();
627 break;
631 break;
628 case DeclarativeChart::SeriesTypeScatter:
632 case DeclarativeChart::SeriesTypeScatter:
629 series = new DeclarativeScatterSeries();
633 series = new DeclarativeScatterSeries();
630 break;
634 break;
631 case DeclarativeChart::SeriesTypeSpline:
635 case DeclarativeChart::SeriesTypeSpline:
632 series = new DeclarativeSplineSeries();
636 series = new DeclarativeSplineSeries();
633 break;
637 break;
634 default:
638 default:
635 qWarning() << "Illegal series type";
639 qWarning() << "Illegal series type";
636 }
640 }
637
641
638 if (series) {
642 if (series) {
639 // Connect to axis changed signals (unless this is a pie series)
643 // Connect to axis changed signals (unless this is a pie series)
640 if (!qobject_cast<DeclarativePieSeries *>(series)) {
644 if (!qobject_cast<DeclarativePieSeries *>(series)) {
641 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
645 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
642 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
646 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
643 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
647 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
644 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
648 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
645 }
649 }
646
650
647 series->setName(name);
651 series->setName(name);
648 m_chart->addSeries(series);
652 m_chart->addSeries(series);
649
653
650 if (axisX)
654 if (axisX)
651 setAxisX(axisX, series);
655 setAxisX(axisX, series);
652 if (axisY)
656 if (axisY)
653 setAxisY(axisY, series);
657 setAxisY(axisY, series);
654
658
655 if (series->attachedAxes().count() < 2)
659 if (series->attachedAxes().count() < 2)
656 initializeAxes(series);
660 initializeAxes(series);
657 }
661 }
658
662
659 return series;
663 return series;
660 }
664 }
661
665
662 void DeclarativeChart::removeSeries(QAbstractSeries *series)
666 void DeclarativeChart::removeSeries(QAbstractSeries *series)
663 {
667 {
664 if (series)
668 if (series)
665 m_chart->removeSeries(series);
669 m_chart->removeSeries(series);
666 else
670 else
667 qWarning("removeSeries: cannot remove null");
671 qWarning("removeSeries: cannot remove null");
668 }
672 }
669
673
670 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
674 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
671 {
675 {
672 if (axis)
676 if (axis)
673 m_chart->setAxisX(axis, series);
677 m_chart->setAxisX(axis, series);
674 }
678 }
675
679
676 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
680 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
677 {
681 {
678 if (axis)
682 if (axis)
679 m_chart->setAxisY(axis, series);
683 m_chart->setAxisY(axis, series);
680 }
684 }
681
685
682 void DeclarativeChart::createDefaultAxes()
686 void DeclarativeChart::createDefaultAxes()
683 {
687 {
684 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
688 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
685 }
689 }
686
690
687 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
691 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
688 {
692 {
689 if (!series) {
693 if (!series) {
690 qWarning() << "No axis type defined for null series";
694 qWarning() << "No axis type defined for null series";
691 return 0;
695 return 0;
692 }
696 }
693
697
694 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
698 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
695 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
699 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
696 return existingAxis;
700 return existingAxis;
697 }
701 }
698
702
699 switch (series->d_ptr->defaultAxisType(orientation)) {
703 switch (series->d_ptr->defaultAxisType(orientation)) {
700 case QAbstractAxis::AxisTypeValue:
704 case QAbstractAxis::AxisTypeValue:
701 return new QValueAxis(this);
705 return new QValueAxis(this);
702 case QAbstractAxis::AxisTypeBarCategory:
706 case QAbstractAxis::AxisTypeBarCategory:
703 return new QBarCategoryAxis(this);
707 return new QBarCategoryAxis(this);
704 case QAbstractAxis::AxisTypeCategory:
708 case QAbstractAxis::AxisTypeCategory:
705 return new QCategoryAxis(this);
709 return new QCategoryAxis(this);
706 #ifndef QT_ON_ARM
710 #ifndef QT_ON_ARM
707 case QAbstractAxis::AxisTypeDateTime:
711 case QAbstractAxis::AxisTypeDateTime:
708 return new QDateTimeAxis(this);
712 return new QDateTimeAxis(this);
709 #endif
713 #endif
710 default:
714 default:
711 // assume AxisTypeNoAxis
715 // assume AxisTypeNoAxis
712 return 0;
716 return 0;
713 }
717 }
714 }
718 }
715
719
716 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
720 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
717 {
721 {
718 if (qobject_cast<DeclarativeLineSeries *>(series))
722 if (qobject_cast<DeclarativeLineSeries *>(series))
719 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
723 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
720 else if (qobject_cast<DeclarativeScatterSeries *>(series))
724 else if (qobject_cast<DeclarativeScatterSeries *>(series))
721 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
725 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
722 else if (qobject_cast<DeclarativeSplineSeries *>(series))
726 else if (qobject_cast<DeclarativeSplineSeries *>(series))
723 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
727 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
724 else if (qobject_cast<DeclarativeAreaSeries *>(series))
728 else if (qobject_cast<DeclarativeAreaSeries *>(series))
725 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
729 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
726 else if (qobject_cast<DeclarativeBarSeries *>(series))
730 else if (qobject_cast<DeclarativeBarSeries *>(series))
727 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
731 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
728 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
732 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
729 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
733 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
730 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
734 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
731 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
735 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
732 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
736 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
733 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
737 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
734 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
738 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
735 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
739 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
736 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
740 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
737 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
741 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
742 else if (qobject_cast<DeclarativeBoxPlotSeries *>(series))
743 doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes);
738 // else: do nothing
744 // else: do nothing
739 }
745 }
740
746
741 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
747 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
742 {
748 {
743 // Initialize axis X
749 // Initialize axis X
744 if (axes->axisX())
750 if (axes->axisX())
745 axes->emitAxisXChanged();
751 axes->emitAxisXChanged();
746 else if (axes->axisXTop())
752 else if (axes->axisXTop())
747 axes->emitAxisXTopChanged();
753 axes->emitAxisXTopChanged();
748 else
754 else
749 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
755 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
750
756
751 // Initialize axis Y
757 // Initialize axis Y
752 if (axes->axisY())
758 if (axes->axisY())
753 axes->emitAxisYChanged();
759 axes->emitAxisYChanged();
754 else if (axes->axisYRight())
760 else if (axes->axisYRight())
755 axes->emitAxisYRightChanged();
761 axes->emitAxisYRightChanged();
756 else
762 else
757 axes->setAxisY(defaultAxis(Qt::Vertical, series));
763 axes->setAxisY(defaultAxis(Qt::Vertical, series));
758 }
764 }
759
765
760 #include "moc_declarativechart.cpp"
766 #include "moc_declarativechart.cpp"
761
767
762 QTCOMMERCIALCHART_END_NAMESPACE
768 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,183 +1,184
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
23
23
24 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
25 #include <QtDeclarative/QDeclarativeItem>
25 #include <QtDeclarative/QDeclarativeItem>
26
26
27 #include "qchart.h"
27 #include "qchart.h"
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeMargins;
31 class DeclarativeMargins;
32 class Domain;
32 class Domain;
33 class DeclarativeAxes;
33 class DeclarativeAxes;
34
34
35 class DeclarativeChart : public QDeclarativeItem
35 class DeclarativeChart : public QDeclarativeItem
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
38 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
39 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
39 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
40 Q_PROPERTY(QString title READ title WRITE setTitle)
40 Q_PROPERTY(QString title READ title WRITE setTitle)
41 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
41 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
42 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
42 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
43 Q_PROPERTY(QLegend *legend READ legend)
43 Q_PROPERTY(QLegend *legend READ legend)
44 Q_PROPERTY(int count READ count)
44 Q_PROPERTY(int count READ count)
45 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
45 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
46 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
46 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
47 Q_PROPERTY(qreal topMargin READ topMargin)
47 Q_PROPERTY(qreal topMargin READ topMargin)
48 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
48 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
49 Q_PROPERTY(qreal leftMargin READ leftMargin)
49 Q_PROPERTY(qreal leftMargin READ leftMargin)
50 Q_PROPERTY(qreal rightMargin READ rightMargin)
50 Q_PROPERTY(qreal rightMargin READ rightMargin)
51 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
51 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
52 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
52 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
53 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
53 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
54 Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2)
54 Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2)
55 Q_ENUMS(Animation)
55 Q_ENUMS(Animation)
56 Q_ENUMS(Theme)
56 Q_ENUMS(Theme)
57 Q_ENUMS(SeriesType)
57 Q_ENUMS(SeriesType)
58
58
59 public:
59 public:
60 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
60 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
61 enum Theme {
61 enum Theme {
62 ChartThemeLight = 0,
62 ChartThemeLight = 0,
63 ChartThemeBlueCerulean,
63 ChartThemeBlueCerulean,
64 ChartThemeDark,
64 ChartThemeDark,
65 ChartThemeBrownSand,
65 ChartThemeBrownSand,
66 ChartThemeBlueNcs,
66 ChartThemeBlueNcs,
67 ChartThemeHighContrast,
67 ChartThemeHighContrast,
68 ChartThemeBlueIcy
68 ChartThemeBlueIcy
69 };
69 };
70
70
71 enum Animation {
71 enum Animation {
72 NoAnimation = 0x0,
72 NoAnimation = 0x0,
73 GridAxisAnimations = 0x1,
73 GridAxisAnimations = 0x1,
74 SeriesAnimations = 0x2,
74 SeriesAnimations = 0x2,
75 AllAnimations = 0x3
75 AllAnimations = 0x3
76 };
76 };
77
77
78 enum SeriesType {
78 enum SeriesType {
79 SeriesTypeLine,
79 SeriesTypeLine,
80 SeriesTypeArea,
80 SeriesTypeArea,
81 SeriesTypeBar,
81 SeriesTypeBar,
82 SeriesTypeStackedBar,
82 SeriesTypeStackedBar,
83 SeriesTypePercentBar,
83 SeriesTypePercentBar,
84 SeriesTypeBoxPlot,
84 SeriesTypePie,
85 SeriesTypePie,
85 SeriesTypeScatter,
86 SeriesTypeScatter,
86 SeriesTypeSpline,
87 SeriesTypeSpline,
87 SeriesTypeHorizontalBar,
88 SeriesTypeHorizontalBar,
88 SeriesTypeHorizontalStackedBar,
89 SeriesTypeHorizontalStackedBar,
89 SeriesTypeHorizontalPercentBar
90 SeriesTypeHorizontalPercentBar
90 };
91 };
91
92
92 public:
93 public:
93 DeclarativeChart(QDeclarativeItem *parent = 0);
94 DeclarativeChart(QDeclarativeItem *parent = 0);
94 ~DeclarativeChart();
95 ~DeclarativeChart();
95
96
96 public: // From QDeclarativeItem/QGraphicsItem
97 public: // From QDeclarativeItem/QGraphicsItem
97 void childEvent(QChildEvent *event);
98 void childEvent(QChildEvent *event);
98 void componentComplete();
99 void componentComplete();
99 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
100 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
100
101
101 public:
102 public:
102 void setTheme(DeclarativeChart::Theme theme);
103 void setTheme(DeclarativeChart::Theme theme);
103 DeclarativeChart::Theme theme();
104 DeclarativeChart::Theme theme();
104 void setAnimationOptions(DeclarativeChart::Animation animations);
105 void setAnimationOptions(DeclarativeChart::Animation animations);
105 DeclarativeChart::Animation animationOptions();
106 DeclarativeChart::Animation animationOptions();
106 void setTitle(QString title);
107 void setTitle(QString title);
107 QString title();
108 QString title();
108 QLegend *legend();
109 QLegend *legend();
109 QFont titleFont() const;
110 QFont titleFont() const;
110 void setTitleFont(const QFont &font);
111 void setTitleFont(const QFont &font);
111 void setTitleColor(QColor color);
112 void setTitleColor(QColor color);
112 QColor titleColor();
113 QColor titleColor();
113 void setBackgroundColor(QColor color);
114 void setBackgroundColor(QColor color);
114 QColor backgroundColor();
115 QColor backgroundColor();
115 int count();
116 int count();
116 void setDropShadowEnabled(bool enabled);
117 void setDropShadowEnabled(bool enabled);
117 bool dropShadowEnabled();
118 bool dropShadowEnabled();
118
119
119 // Margins & plotArea
120 // Margins & plotArea
120 qreal topMargin();
121 qreal topMargin();
121 qreal bottomMargin();
122 qreal bottomMargin();
122 qreal leftMargin();
123 qreal leftMargin();
123 qreal rightMargin();
124 qreal rightMargin();
124 DeclarativeMargins *minimumMargins() { return m_margins; }
125 DeclarativeMargins *minimumMargins() { return m_margins; }
125 Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; }
126 Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; }
126 QRectF plotArea() { return m_chart->plotArea(); }
127 QRectF plotArea() { return m_chart->plotArea(); }
127
128
128 // Axis handling
129 // Axis handling
129 QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series);
130 QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series);
130 void initializeAxes(QAbstractSeries *series);
131 void initializeAxes(QAbstractSeries *series);
131 void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes);
132 void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes);
132 QDeclarativeListProperty<QAbstractAxis> axes();
133 QDeclarativeListProperty<QAbstractAxis> axes();
133 static void axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element);
134 static void axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element);
134 static int axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list);
135 static int axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list);
135 static QAbstractAxis *axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index);
136 static QAbstractAxis *axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index);
136
137
137 public:
138 public:
138 Q_INVOKABLE QAbstractSeries *series(int index);
139 Q_INVOKABLE QAbstractSeries *series(int index);
139 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
140 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
140 Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0);
141 Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0);
141 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
142 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
142 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
143 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
143 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
144 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
144 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
145 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
145 Q_INVOKABLE void createDefaultAxes();
146 Q_INVOKABLE void createDefaultAxes();
146 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
147 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
147 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
148 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
148 Q_INVOKABLE void zoom(qreal factor);
149 Q_INVOKABLE void zoom(qreal factor);
149 Q_INVOKABLE void scrollLeft(qreal pixels);
150 Q_INVOKABLE void scrollLeft(qreal pixels);
150 Q_INVOKABLE void scrollRight(qreal pixels);
151 Q_INVOKABLE void scrollRight(qreal pixels);
151 Q_INVOKABLE void scrollUp(qreal pixels);
152 Q_INVOKABLE void scrollUp(qreal pixels);
152 Q_INVOKABLE void scrollDown(qreal pixels);
153 Q_INVOKABLE void scrollDown(qreal pixels);
153
154
154 Q_SIGNALS:
155 Q_SIGNALS:
155 void axisLabelsChanged();
156 void axisLabelsChanged();
156 void titleColorChanged(QColor color);
157 void titleColorChanged(QColor color);
157 void backgroundColorChanged();
158 void backgroundColorChanged();
158 void dropShadowEnabledChanged(bool enabled);
159 void dropShadowEnabledChanged(bool enabled);
159 void minimumMarginsChanged();
160 void minimumMarginsChanged();
160 Q_REVISION(2) void marginsChanged();
161 Q_REVISION(2) void marginsChanged();
161 void plotAreaChanged(QRectF plotArea);
162 void plotAreaChanged(QRectF plotArea);
162 void seriesAdded(QAbstractSeries *series);
163 void seriesAdded(QAbstractSeries *series);
163 void seriesRemoved(QAbstractSeries *series);
164 void seriesRemoved(QAbstractSeries *series);
164
165
165 private Q_SLOTS:
166 private Q_SLOTS:
166 void changeMinimumMargins(int top, int bottom, int left, int right);
167 void changeMinimumMargins(int top, int bottom, int left, int right);
167 void handleAxisXSet(QAbstractAxis *axis);
168 void handleAxisXSet(QAbstractAxis *axis);
168 void handleAxisYSet(QAbstractAxis *axis);
169 void handleAxisYSet(QAbstractAxis *axis);
169 void handleAxisXTopSet(QAbstractAxis *axis);
170 void handleAxisXTopSet(QAbstractAxis *axis);
170 void handleAxisYRightSet(QAbstractAxis *axis);
171 void handleAxisYRightSet(QAbstractAxis *axis);
171 void handleSeriesAdded(QAbstractSeries *series);
172 void handleSeriesAdded(QAbstractSeries *series);
172
173
173 private:
174 private:
174 // Extending QChart with DeclarativeChart is not possible because QObject does not support
175 // Extending QChart with DeclarativeChart is not possible because QObject does not support
175 // multi inheritance, so we now have a QChart as a member instead
176 // multi inheritance, so we now have a QChart as a member instead
176 QChart *m_chart;
177 QChart *m_chart;
177 //QMargins m_chartMargins;
178 //QMargins m_chartMargins;
178 DeclarativeMargins *m_margins;
179 DeclarativeMargins *m_margins;
179 };
180 };
180
181
181 QTCOMMERCIALCHART_END_NAMESPACE
182 QTCOMMERCIALCHART_END_NAMESPACE
182
183
183 #endif // DECLARATIVECHART_H
184 #endif // DECLARATIVECHART_H
@@ -1,227 +1,232
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 "declarativeboxplotseries.h"
33 #include "declarativepieseries.h"
34 #include "declarativepieseries.h"
34 #include "declarativeaxes.h"
35 #include "declarativeaxes.h"
35 #include "qvxymodelmapper.h"
36 #include "qvxymodelmapper.h"
36 #include "qhxymodelmapper.h"
37 #include "qhxymodelmapper.h"
37 #include "qhpiemodelmapper.h"
38 #include "qhpiemodelmapper.h"
38 #include "qvpiemodelmapper.h"
39 #include "qvpiemodelmapper.h"
39 #include "qhbarmodelmapper.h"
40 #include "qhbarmodelmapper.h"
40 #include "qvbarmodelmapper.h"
41 #include "qvbarmodelmapper.h"
41 #include "declarativemargins.h"
42 #include "declarativemargins.h"
42 #include "qarealegendmarker.h"
43 #include "qarealegendmarker.h"
43 #include "qbarlegendmarker.h"
44 #include "qbarlegendmarker.h"
44 #include "qpielegendmarker.h"
45 #include "qpielegendmarker.h"
45 #include "qxylegendmarker.h"
46 #include "qxylegendmarker.h"
46 #ifndef QT_ON_ARM
47 #ifndef QT_ON_ARM
47 #include "qdatetimeaxis.h"
48 #include "qdatetimeaxis.h"
48 #endif
49 #endif
49 #include <QAbstractItemModel>
50 #include <QAbstractItemModel>
50 #include <QtDeclarative/qdeclarativeextensionplugin.h>
51 #include <QtDeclarative/qdeclarativeextensionplugin.h>
51 #include <QtDeclarative/qdeclarative.h>
52 #include <QtDeclarative/qdeclarative.h>
52
53
53 QTCOMMERCIALCHART_USE_NAMESPACE
54 QTCOMMERCIALCHART_USE_NAMESPACE
54
55
55 Q_DECLARE_METATYPE(QList<QPieSlice *>)
56 Q_DECLARE_METATYPE(QList<QPieSlice *>)
56 Q_DECLARE_METATYPE(QList<QBarSet *>)
57 Q_DECLARE_METATYPE(QList<QBarSet *>)
57 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
58 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
58
59
59 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
60 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
60
61
61 // NOTE: Hackish fixes for Qt5 (beta2).
62 // NOTE: Hackish fixes for Qt5 (beta2).
62 // These should not be needed or at least they are not needed in Qt4.
63 // These should not be needed or at least they are not needed in Qt4.
63
64
64 Q_DECLARE_METATYPE(DeclarativeChart *)
65 Q_DECLARE_METATYPE(DeclarativeChart *)
65 Q_DECLARE_METATYPE(DeclarativeMargins *)
66 Q_DECLARE_METATYPE(DeclarativeMargins *)
66 Q_DECLARE_METATYPE(DeclarativeAreaSeries *)
67 Q_DECLARE_METATYPE(DeclarativeAreaSeries *)
67 Q_DECLARE_METATYPE(DeclarativeBarSeries *)
68 Q_DECLARE_METATYPE(DeclarativeBarSeries *)
69 Q_DECLARE_METATYPE(DeclarativeBoxPlotSeries *)
68 Q_DECLARE_METATYPE(DeclarativeLineSeries *)
70 Q_DECLARE_METATYPE(DeclarativeLineSeries *)
69 Q_DECLARE_METATYPE(DeclarativePieSeries *)
71 Q_DECLARE_METATYPE(DeclarativePieSeries *)
70 Q_DECLARE_METATYPE(DeclarativeScatterSeries *)
72 Q_DECLARE_METATYPE(DeclarativeScatterSeries *)
71 Q_DECLARE_METATYPE(DeclarativeSplineSeries *)
73 Q_DECLARE_METATYPE(DeclarativeSplineSeries *)
72
74
73 Q_DECLARE_METATYPE(QAbstractAxis *)
75 Q_DECLARE_METATYPE(QAbstractAxis *)
74 Q_DECLARE_METATYPE(QValueAxis *)
76 Q_DECLARE_METATYPE(QValueAxis *)
75 Q_DECLARE_METATYPE(QBarCategoryAxis *)
77 Q_DECLARE_METATYPE(QBarCategoryAxis *)
76 Q_DECLARE_METATYPE(QCategoryAxis *)
78 Q_DECLARE_METATYPE(QCategoryAxis *)
77 Q_DECLARE_METATYPE(QDateTimeAxis *)
79 Q_DECLARE_METATYPE(QDateTimeAxis *)
78
80
79 Q_DECLARE_METATYPE(QLegend *)
81 Q_DECLARE_METATYPE(QLegend *)
80 Q_DECLARE_METATYPE(QLegendMarker *)
82 Q_DECLARE_METATYPE(QLegendMarker *)
81 Q_DECLARE_METATYPE(QAreaLegendMarker *)
83 Q_DECLARE_METATYPE(QAreaLegendMarker *)
82 Q_DECLARE_METATYPE(QBarLegendMarker *)
84 Q_DECLARE_METATYPE(QBarLegendMarker *)
83 Q_DECLARE_METATYPE(QPieLegendMarker *)
85 Q_DECLARE_METATYPE(QPieLegendMarker *)
84
86
85 Q_DECLARE_METATYPE(QHPieModelMapper *)
87 Q_DECLARE_METATYPE(QHPieModelMapper *)
86 Q_DECLARE_METATYPE(QHXYModelMapper *)
88 Q_DECLARE_METATYPE(QHXYModelMapper *)
87 Q_DECLARE_METATYPE(QPieModelMapper *)
89 Q_DECLARE_METATYPE(QPieModelMapper *)
88 Q_DECLARE_METATYPE(QHBarModelMapper *)
90 Q_DECLARE_METATYPE(QHBarModelMapper *)
89 Q_DECLARE_METATYPE(QBarModelMapper *)
91 Q_DECLARE_METATYPE(QBarModelMapper *)
90 Q_DECLARE_METATYPE(QVBarModelMapper *)
92 Q_DECLARE_METATYPE(QVBarModelMapper *)
91 Q_DECLARE_METATYPE(QVPieModelMapper *)
93 Q_DECLARE_METATYPE(QVPieModelMapper *)
92 Q_DECLARE_METATYPE(QVXYModelMapper *)
94 Q_DECLARE_METATYPE(QVXYModelMapper *)
93 Q_DECLARE_METATYPE(QXYLegendMarker *)
95 Q_DECLARE_METATYPE(QXYLegendMarker *)
94 Q_DECLARE_METATYPE(QXYModelMapper *)
96 Q_DECLARE_METATYPE(QXYModelMapper *)
95
97
96 Q_DECLARE_METATYPE(QAbstractSeries *)
98 Q_DECLARE_METATYPE(QAbstractSeries *)
97 Q_DECLARE_METATYPE(QXYSeries *)
99 Q_DECLARE_METATYPE(QXYSeries *)
98 Q_DECLARE_METATYPE(QAbstractBarSeries *)
100 Q_DECLARE_METATYPE(QAbstractBarSeries *)
99 Q_DECLARE_METATYPE(QBarSeries *)
101 Q_DECLARE_METATYPE(QBarSeries *)
100 Q_DECLARE_METATYPE(QBarSet *)
102 Q_DECLARE_METATYPE(QBarSet *)
101 Q_DECLARE_METATYPE(QAreaSeries *)
103 Q_DECLARE_METATYPE(QAreaSeries *)
102 Q_DECLARE_METATYPE(QHorizontalBarSeries *)
104 Q_DECLARE_METATYPE(QHorizontalBarSeries *)
103 Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *)
105 Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *)
104 Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *)
106 Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *)
105 Q_DECLARE_METATYPE(QLineSeries *)
107 Q_DECLARE_METATYPE(QLineSeries *)
106 Q_DECLARE_METATYPE(QPercentBarSeries *)
108 Q_DECLARE_METATYPE(QPercentBarSeries *)
107 Q_DECLARE_METATYPE(QPieSeries *)
109 Q_DECLARE_METATYPE(QPieSeries *)
108 Q_DECLARE_METATYPE(QPieSlice *)
110 Q_DECLARE_METATYPE(QPieSlice *)
109 Q_DECLARE_METATYPE(QScatterSeries *)
111 Q_DECLARE_METATYPE(QScatterSeries *)
110 Q_DECLARE_METATYPE(QSplineSeries *)
112 Q_DECLARE_METATYPE(QSplineSeries *)
111 Q_DECLARE_METATYPE(QStackedBarSeries *)
113 Q_DECLARE_METATYPE(QStackedBarSeries *)
112
114
113 #endif
115 #endif
114
116
115 QTCOMMERCIALCHART_BEGIN_NAMESPACE
117 QTCOMMERCIALCHART_BEGIN_NAMESPACE
116
118
117 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
119 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
118 {
120 {
119 Q_OBJECT
121 Q_OBJECT
120
122
121 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
123 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
122 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface")
124 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface")
123 #endif
125 #endif
124
126
125 public:
127 public:
126 virtual void registerTypes(const char *uri)
128 virtual void registerTypes(const char *uri)
127 {
129 {
128 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
130 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
129
131
130 qRegisterMetaType<QList<QPieSlice *> >();
132 qRegisterMetaType<QList<QPieSlice *> >();
131 qRegisterMetaType<QList<QBarSet *> >();
133 qRegisterMetaType<QList<QBarSet *> >();
132 qRegisterMetaType<QList<QAbstractAxis *> >();
134 qRegisterMetaType<QList<QAbstractAxis *> >();
133
135
134 // QtCommercial.Chart 1.0
136 // QtCommercial.Chart 1.0
135 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
137 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
136 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
138 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
137 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
139 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
138 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
140 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
139 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
141 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
140 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
142 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
141 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
143 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
142 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
144 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
143 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
145 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
146 qmlRegisterType<DeclarativeBoxPlotSeries>(uri, 1, 0, "BoxPlotSeries");
144 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
147 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
145 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
148 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
146 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
149 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
147 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
150 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
148 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
151 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
149 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
152 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
150 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
153 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
151 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
154 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
152 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
155 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
153 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
156 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
154 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
157 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
155 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
158 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
156 QLatin1String("Trying to create uncreatable: Legend."));
159 QLatin1String("Trying to create uncreatable: Legend."));
157 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
160 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
158 QLatin1String("Trying to create uncreatable: XYSeries."));
161 QLatin1String("Trying to create uncreatable: XYSeries."));
159 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
162 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
160 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
163 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
161 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
164 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
162 QLatin1String("Trying to create uncreatable: XYModelMapper."));
165 QLatin1String("Trying to create uncreatable: XYModelMapper."));
163 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
166 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
164 QLatin1String("Trying to create uncreatable: PieModelMapper."));
167 QLatin1String("Trying to create uncreatable: PieModelMapper."));
165 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
168 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
166 QLatin1String("Trying to create uncreatable: BarModelMapper."));
169 QLatin1String("Trying to create uncreatable: BarModelMapper."));
167 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
170 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
168 QLatin1String("Trying to create uncreatable: AbstractSeries."));
171 QLatin1String("Trying to create uncreatable: AbstractSeries."));
169 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
172 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
170 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
173 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
171 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
174 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
172 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
175 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
173 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase",
176 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase",
174 QLatin1String("Trying to create uncreatable: BarsetBase."));
177 QLatin1String("Trying to create uncreatable: BarsetBase."));
175 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
178 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
176 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
179 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
177 qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes",
180 qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes",
178 QLatin1String("Trying to create uncreatable: DeclarativeAxes."));
181 QLatin1String("Trying to create uncreatable: DeclarativeAxes."));
179
182
180 // QtCommercial.Chart 1.1
183 // QtCommercial.Chart 1.1
181 qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView");
184 qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView");
182 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
185 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
183 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
186 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
184 qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries");
187 qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries");
185 qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries");
188 qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries");
186 qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries");
189 qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries");
187 qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries");
190 qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries");
188 qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries");
191 qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries");
192 qmlRegisterType<DeclarativeBoxPlotSeries, 1>(uri, 1, 1, "BoxPlotSeries");
189 qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries");
193 qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries");
190 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries");
194 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries");
191 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries");
195 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries");
192 qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries");
196 qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries");
193 qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet");
197 qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet");
194 qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis");
198 qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis");
195 #ifndef QT_ON_ARM
199 #ifndef QT_ON_ARM
196 qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis");
200 qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis");
197 #endif
201 #endif
198 qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis");
202 qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis");
199 qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange");
203 qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange");
200 qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis");
204 qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis");
201 qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins",
205 qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins",
202 QLatin1String("Trying to create uncreatable: Margins."));
206 QLatin1String("Trying to create uncreatable: Margins."));
203
207
204 // QtCommercial.Chart 1.2
208 // QtCommercial.Chart 1.2
205 qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView");
209 qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView");
206 qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries");
210 qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries");
207 qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries");
211 qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries");
208 qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries");
212 qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries");
209 qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries");
213 qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries");
210 qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries");
214 qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries");
211 qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries");
215 qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries");
212 qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries");
216 qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries");
217 qmlRegisterType<DeclarativeBoxPlotSeries, 2>(uri, 1, 2, "BoxPlotSeries");
213 qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries");
218 qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries");
214 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries");
219 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries");
215 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
220 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
216 }
221 }
217 };
222 };
218
223
219 #include "plugin.moc"
224 #include "plugin.moc"
220
225
221 QTCOMMERCIALCHART_END_NAMESPACE
226 QTCOMMERCIALCHART_END_NAMESPACE
222
227
223 QTCOMMERCIALCHART_USE_NAMESPACE
228 QTCOMMERCIALCHART_USE_NAMESPACE
224
229
225 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
230 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
226 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
231 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
227 #endif
232 #endif
General Comments 0
You need to be logged in to leave comments. Login now